diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index d372c128b82d..36af28206aa1 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -3616,6 +3616,9 @@ linters: # Suggest the use of http.StatusXX. # Default: true http-status-code: false + # Suggest the use of time.Month in time.Date. + # Default: false + time-date-month: true # Suggest the use of time.Weekday.String(). # Default: true time-weekday: true diff --git a/go.mod b/go.mod index b6c4dcfee25d..ba56a47d0d6e 100644 --- a/go.mod +++ b/go.mod @@ -97,7 +97,7 @@ require ( github.com/sanposhiho/wastedassign/v2 v2.1.0 github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 github.com/sashamelentyev/interfacebloat v1.1.0 - github.com/sashamelentyev/usestdlibvars v1.28.0 + github.com/sashamelentyev/usestdlibvars v1.29.0 github.com/securego/gosec/v2 v2.22.4 github.com/shirou/gopsutil/v4 v4.25.4 github.com/sirupsen/logrus v1.9.3 diff --git a/go.sum b/go.sum index 6e693c71c7a1..68835b872663 100644 --- a/go.sum +++ b/go.sum @@ -517,8 +517,8 @@ github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+x github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/sashamelentyev/interfacebloat v1.1.0 h1:xdRdJp0irL086OyW1H/RTZTr1h/tMEOsumirXcOJqAw= github.com/sashamelentyev/interfacebloat v1.1.0/go.mod h1:+Y9yU5YdTkrNvoX0xHc84dxiN1iBi9+G8zZIhPVoNjQ= -github.com/sashamelentyev/usestdlibvars v1.28.0 h1:jZnudE2zKCtYlGzLVreNp5pmCdOxXUzwsMDBkR21cyQ= -github.com/sashamelentyev/usestdlibvars v1.28.0/go.mod h1:9nl0jgOfHKWNFS43Ojw0i7aRoS4j6EBye3YBhmAIRF8= +github.com/sashamelentyev/usestdlibvars v1.29.0 h1:8J0MoRrw4/NAXtjQqTHrbW9NN+3iMf7Knkq057v4XOQ= +github.com/sashamelentyev/usestdlibvars v1.29.0/go.mod h1:8PpnjHMk5VdeWlVb4wCdrB8PNbLqZ3wBZTZWkrpZZL8= github.com/securego/gosec/v2 v2.22.4 h1:21VdNGcKicFSv6rUDBc0cEtEl7lWyCKZxKIm0iwvrIM= github.com/securego/gosec/v2 v2.22.4/go.mod h1:ww5Yie7KJ3AH8XZQTletkW5zOmIse6FACs/Ys8VR3qE= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 1bd33923a5de..a84a30121f38 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -3728,6 +3728,11 @@ "type": "boolean", "default": false }, + "time-date-month": { + "description": "Suggest the use of time.Month in time.Date.", + "type": "boolean", + "default": false + }, "crypto-hash": { "description": "Suggest the use of crypto.Hash.String().", "type": "boolean", diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 2398186d3812..e2838d808acb 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -934,6 +934,7 @@ type UseStdlibVarsSettings struct { SQLIsolationLevel bool `mapstructure:"sql-isolation-level"` TLSSignatureScheme bool `mapstructure:"tls-signature-scheme"` ConstantKind bool `mapstructure:"constant-kind"` + TimeDateMonth bool `mapstructure:"time-date-month"` } type UseTestingSettings struct { diff --git a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go index 14f4a93a6b3c..9eee473f0d6d 100644 --- a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go +++ b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go @@ -2,7 +2,10 @@ //golangcitest:config_path testdata/usestdlibvars_non_default.yml package testdata -import "net/http" +import ( + "net/http" + "time" +) func _200() { _ = 200 @@ -52,3 +55,8 @@ const ( _ = "ECDSAWithP256AndSHA256" // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)` _ = "ECDSAWithP384AndSHA384" // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)` ) + +func _() { + var _ = time.Date(2023, 1, 2, 3, 4, 5, 0, time.UTC) // want `"1" can be replaced by time\.January` + var _ = time.Date(2023, 10, 2, 3, 4, 5, 0, time.UTC) // want `"10" can be replaced by time\.October` +} diff --git a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml index 8100af59cdb1..d2942621daee 100644 --- a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml +++ b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml @@ -13,3 +13,4 @@ linters: sql-isolation-level: true tls-signature-scheme: true constant-kind: true + time-date-month: true diff --git a/pkg/golinters/usestdlibvars/usestdlibvars.go b/pkg/golinters/usestdlibvars/usestdlibvars.go index 9342c4ccd7a3..e4a900ff6465 100644 --- a/pkg/golinters/usestdlibvars/usestdlibvars.go +++ b/pkg/golinters/usestdlibvars/usestdlibvars.go @@ -24,6 +24,7 @@ func New(settings *config.UseStdlibVarsSettings) *goanalysis.Linter { analyzer.TimeMonthFlag: settings.TimeMonth, analyzer.TimeWeekdayFlag: settings.TimeWeekday, analyzer.TLSSignatureSchemeFlag: settings.TLSSignatureScheme, + analyzer.TimeDateMonthFlag: settings.TimeDateMonth, } }