diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 848a7b567d98..3a2833fc099b 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -122,6 +122,10 @@ var defaultLintersSettings = LintersSettings{ Unparam: UnparamSettings{ Algo: "cha", }, + UseStdlibVars: UseStdlibVarsSettings{ + HTTPMethod: true, + HTTPStatusCode: true, + }, Varnamelen: VarnamelenSettings{ MaxDistance: 5, MinNameLength: 3, diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 89ad5b606442..ffe10721cf43 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -252,6 +252,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { thelperCfg = &m.cfg.LintersSettings.Thelper unparamCfg = &m.cfg.LintersSettings.Unparam unusedCfg = new(config.StaticCheckSettings) + usestdlibvars = &m.cfg.LintersSettings.UseStdlibVars varcheckCfg = &m.cfg.LintersSettings.Varcheck varnamelenCfg = &m.cfg.LintersSettings.Varnamelen whitespaceCfg = &m.cfg.LintersSettings.Whitespace diff --git a/test/testdata/configs/usestdlibvars_non_default.yml b/test/testdata/configs/usestdlibvars_non_default.yml new file mode 100644 index 000000000000..f50ce6fc341e --- /dev/null +++ b/test/testdata/configs/usestdlibvars_non_default.yml @@ -0,0 +1,12 @@ +linters-settings: + usestdlibvars: + http-method: false + http-status-code: false + time-weekday: true + time-month: true + time-layout: true + crypto-hash: true + default-rpc-path: true + sql-isolation-level: true + tls-signature-scheme: true + constant-kind: true diff --git a/test/testdata/usestdlibvars_non_default.go b/test/testdata/usestdlibvars_non_default.go new file mode 100644 index 000000000000..c9915fad7a01 --- /dev/null +++ b/test/testdata/usestdlibvars_non_default.go @@ -0,0 +1,54 @@ +//golangcitest:args -Eusestdlibvars +//golangcitest:config_path testdata/configs/usestdlibvars_non_default.yml +package testdata + +import "net/http" + +func _200() { + _ = 200 +} + +func _200_1() { + var w http.ResponseWriter + w.WriteHeader(200) +} + +const ( + _ = "Bool" // want `"Bool" can be replaced by constant\.Bool\.String\(\)` + _ = "Complex" // want `"Complex" can be replaced by constant\.Complex\.String\(\)` +) + +const ( + _ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)` + _ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)` +) + +const ( + _ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath` + _ = "/debug/rpc" // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath` +) + +const ( + _ = "Read Committed" // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)` + _ = "Read Uncommitted" // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)` +) + +const ( + _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout` + _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z` +) + +const ( + _ = "April" // want `"April" can be replaced by time\.April\.String\(\)` + _ = "August" // want `"August" can be replaced by time\.August\.String\(\)` +) + +const ( + _ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)` +) + +const ( + _ = "ECDSAWithP256AndSHA256" // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)` + _ = "ECDSAWithP384AndSHA384" // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)` +)