Skip to content

Commit 68b8e8e

Browse files
committed
staticcheck: allow empty options
1 parent fe730db commit 68b8e8e

File tree

6 files changed

+48
-5
lines changed

6 files changed

+48
-5
lines changed

pkg/config/linters_settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ type StaticCheckSettings struct {
838838
}
839839

840840
func (s *StaticCheckSettings) HasConfiguration() bool {
841-
return len(s.Initialisms) > 0 || len(s.HTTPStatusCodeWhitelist) > 0 || len(s.DotImportWhitelist) > 0 || len(s.Checks) > 0
841+
return s.Initialisms == nil || s.HTTPStatusCodeWhitelist == nil || s.DotImportWhitelist == nil || s.Checks == nil
842842
}
843843

844844
type TagAlignSettings struct {

pkg/golinters/staticcheck/staticcheck.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ func createConfig(settings *config.StaticCheckSettings) *scconfig.Config {
7979
HTTPStatusCodeWhitelist: settings.HTTPStatusCodeWhitelist,
8080
}
8181

82-
if len(cfg.Checks) == 0 {
82+
if cfg.Checks == nil {
8383
cfg.Checks = defaultChecks
8484
}
8585

86-
if len(cfg.Initialisms) == 0 {
86+
if cfg.Initialisms == nil {
8787
cfg.Initialisms = append(cfg.Initialisms, scconfig.DefaultConfig.Initialisms...)
8888
}
8989

90-
if len(cfg.DotImportWhitelist) == 0 {
90+
if cfg.DotImportWhitelist == nil {
9191
cfg.DotImportWhitelist = append(cfg.DotImportWhitelist, scconfig.DefaultConfig.DotImportWhitelist...)
9292
}
9393

94-
if len(cfg.HTTPStatusCodeWhitelist) == 0 {
94+
if cfg.HTTPStatusCodeWhitelist == nil {
9595
cfg.HTTPStatusCodeWhitelist = append(cfg.HTTPStatusCodeWhitelist, scconfig.DefaultConfig.HTTPStatusCodeWhitelist...)
9696
}
9797

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//golangcitest:args -Estaticcheck
2+
//golangcitest:config_path testdata/stylecheck_empty.yml
3+
package testdata
4+
5+
import "net/http"
6+
7+
func _() {
8+
http.StatusText(200) // want "ST1013: should use constant http.StatusOK instead of numeric literal 200"
9+
http.StatusText(400) // want "ST1013: should use constant http.StatusBadRequest instead of numeric literal 400"
10+
http.StatusText(404) // want "ST1013: should use constant http.StatusNotFound instead of numeric literal 404"
11+
http.StatusText(418) // want "ST1013: should use constant http.StatusTeapot instead of numeric literal 418"
12+
http.StatusText(500) // want "ST1013: should use constant http.StatusInternalServerError instead of numeric literal 500"
13+
http.StatusText(503) // want "ST1013: should use constant http.StatusServiceUnavailable instead of numeric literal 503"
14+
http.StatusText(600)
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: "2"
2+
3+
linters:
4+
settings:
5+
staticcheck:
6+
checks: ["ST1013"]
7+
http-status-code-whitelist: [ ]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//golangcitest:args -Estaticcheck
2+
//golangcitest:config_path testdata/stylecheck_nil.yml
3+
package testdata
4+
5+
import "net/http"
6+
7+
func _() {
8+
http.StatusText(200)
9+
http.StatusText(400)
10+
http.StatusText(404)
11+
http.StatusText(418) // want "ST1013: should use constant http.StatusTeapot instead of numeric literal 418"
12+
http.StatusText(500)
13+
http.StatusText(503) // want "ST1013: should use constant http.StatusServiceUnavailable instead of numeric literal 503"
14+
http.StatusText(600)
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "2"
2+
3+
linters:
4+
settings:
5+
staticcheck:
6+
checks: ["ST1013"]

0 commit comments

Comments
 (0)