Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usestdlibvars: fix configuration #3797

Merged
merged 3 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ var defaultLintersSettings = LintersSettings{
Unparam: UnparamSettings{
Algo: "cha",
},
UseStdlibVars: UseStdlibVarsSettings{
HTTPMethod: true,
HTTPStatusCode: true,
},
Varnamelen: VarnamelenSettings{
MaxDistance: 5,
MinNameLength: 3,
Expand Down
1 change: 1 addition & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/testdata/configs/usestdlibvars_non_default.yml
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions test/testdata/usestdlibvars_non_default.go
Original file line number Diff line number Diff line change
@@ -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\(\)`
)
Loading