Skip to content
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
2 changes: 1 addition & 1 deletion pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ type StaticCheckSettings struct {
}

func (s *StaticCheckSettings) HasConfiguration() bool {
return len(s.Initialisms) > 0 || len(s.HTTPStatusCodeWhitelist) > 0 || len(s.DotImportWhitelist) > 0 || len(s.Checks) > 0
return s.Initialisms == nil || s.HTTPStatusCodeWhitelist == nil || s.DotImportWhitelist == nil || s.Checks == nil
}

type TagAlignSettings struct {
Expand Down
8 changes: 4 additions & 4 deletions pkg/golinters/staticcheck/staticcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ func createConfig(settings *config.StaticCheckSettings) *scconfig.Config {
HTTPStatusCodeWhitelist: settings.HTTPStatusCodeWhitelist,
}

if len(cfg.Checks) == 0 {
if cfg.Checks == nil {
cfg.Checks = defaultChecks
}

if len(cfg.Initialisms) == 0 {
if cfg.Initialisms == nil {
cfg.Initialisms = append(cfg.Initialisms, scconfig.DefaultConfig.Initialisms...)
}

if len(cfg.DotImportWhitelist) == 0 {
if cfg.DotImportWhitelist == nil {
cfg.DotImportWhitelist = append(cfg.DotImportWhitelist, scconfig.DefaultConfig.DotImportWhitelist...)
}

if len(cfg.HTTPStatusCodeWhitelist) == 0 {
if cfg.HTTPStatusCodeWhitelist == nil {
cfg.HTTPStatusCodeWhitelist = append(cfg.HTTPStatusCodeWhitelist, scconfig.DefaultConfig.HTTPStatusCodeWhitelist...)
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/golinters/staticcheck/testdata/stylecheck_empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//golangcitest:args -Estaticcheck
//golangcitest:config_path testdata/stylecheck_empty.yml
package testdata

import "net/http"

func _() {
http.StatusText(200) // want "ST1013: should use constant http.StatusOK instead of numeric literal 200"
http.StatusText(400) // want "ST1013: should use constant http.StatusBadRequest instead of numeric literal 400"
http.StatusText(404) // want "ST1013: should use constant http.StatusNotFound instead of numeric literal 404"
http.StatusText(418) // want "ST1013: should use constant http.StatusTeapot instead of numeric literal 418"
http.StatusText(500) // want "ST1013: should use constant http.StatusInternalServerError instead of numeric literal 500"
http.StatusText(503) // want "ST1013: should use constant http.StatusServiceUnavailable instead of numeric literal 503"
http.StatusText(600)
}
7 changes: 7 additions & 0 deletions pkg/golinters/staticcheck/testdata/stylecheck_empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "2"

linters:
settings:
staticcheck:
checks: ["ST1013"]
http-status-code-whitelist: [ ]
15 changes: 15 additions & 0 deletions pkg/golinters/staticcheck/testdata/stylecheck_nil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//golangcitest:args -Estaticcheck
//golangcitest:config_path testdata/stylecheck_nil.yml
package testdata

import "net/http"

func _() {
http.StatusText(200)
http.StatusText(400)
http.StatusText(404)
http.StatusText(418) // want "ST1013: should use constant http.StatusTeapot instead of numeric literal 418"
http.StatusText(500)
http.StatusText(503) // want "ST1013: should use constant http.StatusServiceUnavailable instead of numeric literal 503"
http.StatusText(600)
}
6 changes: 6 additions & 0 deletions pkg/golinters/staticcheck/testdata/stylecheck_nil.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "2"

linters:
settings:
staticcheck:
checks: ["ST1013"]
Loading