Skip to content

Commit cec16b6

Browse files
authored
usestdlibvars: fix configuration (#3797)
1 parent f648894 commit cec16b6

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

pkg/config/linters_settings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ var defaultLintersSettings = LintersSettings{
122122
Unparam: UnparamSettings{
123123
Algo: "cha",
124124
},
125+
UseStdlibVars: UseStdlibVarsSettings{
126+
HTTPMethod: true,
127+
HTTPStatusCode: true,
128+
},
125129
Varnamelen: VarnamelenSettings{
126130
MaxDistance: 5,
127131
MinNameLength: 3,

pkg/lint/lintersdb/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
252252
thelperCfg = &m.cfg.LintersSettings.Thelper
253253
unparamCfg = &m.cfg.LintersSettings.Unparam
254254
unusedCfg = new(config.StaticCheckSettings)
255+
usestdlibvars = &m.cfg.LintersSettings.UseStdlibVars
255256
varcheckCfg = &m.cfg.LintersSettings.Varcheck
256257
varnamelenCfg = &m.cfg.LintersSettings.Varnamelen
257258
whitespaceCfg = &m.cfg.LintersSettings.Whitespace
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
linters-settings:
2+
usestdlibvars:
3+
http-method: false
4+
http-status-code: false
5+
time-weekday: true
6+
time-month: true
7+
time-layout: true
8+
crypto-hash: true
9+
default-rpc-path: true
10+
sql-isolation-level: true
11+
tls-signature-scheme: true
12+
constant-kind: true
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//golangcitest:args -Eusestdlibvars
2+
//golangcitest:config_path testdata/configs/usestdlibvars_non_default.yml
3+
package testdata
4+
5+
import "net/http"
6+
7+
func _200() {
8+
_ = 200
9+
}
10+
11+
func _200_1() {
12+
var w http.ResponseWriter
13+
w.WriteHeader(200)
14+
}
15+
16+
const (
17+
_ = "Bool" // want `"Bool" can be replaced by constant\.Bool\.String\(\)`
18+
_ = "Complex" // want `"Complex" can be replaced by constant\.Complex\.String\(\)`
19+
)
20+
21+
const (
22+
_ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)`
23+
_ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)`
24+
)
25+
26+
const (
27+
_ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath`
28+
_ = "/debug/rpc" // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath`
29+
)
30+
31+
const (
32+
_ = "Read Committed" // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)`
33+
_ = "Read Uncommitted" // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)`
34+
)
35+
36+
const (
37+
_ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout`
38+
_ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z`
39+
)
40+
41+
const (
42+
_ = "April" // want `"April" can be replaced by time\.April\.String\(\)`
43+
_ = "August" // want `"August" can be replaced by time\.August\.String\(\)`
44+
)
45+
46+
const (
47+
_ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)`
48+
_ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)`
49+
)
50+
51+
const (
52+
_ = "ECDSAWithP256AndSHA256" // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)`
53+
_ = "ECDSAWithP384AndSHA384" // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)`
54+
)

0 commit comments

Comments
 (0)