diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index c7efb8f420ba..c4376c516399 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -62,7 +62,6 @@ linters: - gomodguard - goprintffuncname - gosec - - gosimple - gosmopolitan - govet - grouper @@ -105,7 +104,6 @@ linters: - spancheck - sqlclosecheck - staticcheck - - stylecheck - tagalign - tagliatelle - testableexamples @@ -175,7 +173,6 @@ linters: - gomodguard - goprintffuncname - gosec - - gosimple - gosmopolitan - govet - grouper @@ -218,7 +215,6 @@ linters: - spancheck - sqlclosecheck - staticcheck - - stylecheck - tagalign - tagliatelle - testableexamples @@ -1334,116 +1330,6 @@ linters: # Default: false local-replace-directives: false - gosimple: - # Sxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks - # Default: ["*"] - checks: - # Use plain channel send or receive instead of single-case select. - # https://staticcheck.dev/docs/checks/#S1000 - - S1000 - # Replace for loop with call to copy. - # https://staticcheck.dev/docs/checks/#S1001 - - S1001 - # Omit comparison with boolean constant. - # https://staticcheck.dev/docs/checks/#S1002 - - S1002 - # Replace call to 'strings.Index' with 'strings.Contains'. - # https://staticcheck.dev/docs/checks/#S1003 - - S1003 - # Replace call to 'bytes.Compare' with 'bytes.Equal'. - # https://staticcheck.dev/docs/checks/#S1004 - - S1004 - # Drop unnecessary use of the blank identifier. - # https://staticcheck.dev/docs/checks/#S1005 - - S1005 - # Use "for { ... }" for infinite loops. - # https://staticcheck.dev/docs/checks/#S1006 - - S1006 - # Simplify regular expression by using raw string literal. - # https://staticcheck.dev/docs/checks/#S1007 - - S1007 - # Simplify returning boolean expression. - # https://staticcheck.dev/docs/checks/#S1008 - - S1008 - # Omit redundant nil check on slices, maps, and channels. - # https://staticcheck.dev/docs/checks/#S1009 - - S1009 - # Omit default slice index. - # https://staticcheck.dev/docs/checks/#S1010 - - S1010 - # Use a single 'append' to concatenate two slices. - # https://staticcheck.dev/docs/checks/#S1011 - - S1011 - # Replace 'time.Now().Sub(x)' with 'time.Since(x)'. - # https://staticcheck.dev/docs/checks/#S1012 - - S1012 - # Use a type conversion instead of manually copying struct fields. - # https://staticcheck.dev/docs/checks/#S1016 - - S1016 - # Replace manual trimming with 'strings.TrimPrefix'. - # https://staticcheck.dev/docs/checks/#S1017 - - S1017 - # Use "copy" for sliding elements. - # https://staticcheck.dev/docs/checks/#S1018 - - S1018 - # Simplify "make" call by omitting redundant arguments. - # https://staticcheck.dev/docs/checks/#S1019 - - S1019 - # Omit redundant nil check in type assertion. - # https://staticcheck.dev/docs/checks/#S1020 - - S1020 - # Merge variable declaration and assignment. - # https://staticcheck.dev/docs/checks/#S1021 - - S1021 - # Omit redundant control flow. - # https://staticcheck.dev/docs/checks/#S1023 - - S1023 - # Replace 'x.Sub(time.Now())' with 'time.Until(x)'. - # https://staticcheck.dev/docs/checks/#S1024 - - S1024 - # Don't use 'fmt.Sprintf("%s", x)' unnecessarily. - # https://staticcheck.dev/docs/checks/#S1025 - - S1025 - # Simplify error construction with 'fmt.Errorf'. - # https://staticcheck.dev/docs/checks/#S1028 - - S1028 - # Range over the string directly. - # https://staticcheck.dev/docs/checks/#S1029 - - S1029 - # Use 'bytes.Buffer.String' or 'bytes.Buffer.Bytes'. - # https://staticcheck.dev/docs/checks/#S1030 - - S1030 - # Omit redundant nil check around loop. - # https://staticcheck.dev/docs/checks/#S1031 - - S1031 - # Use 'sort.Ints(x)', 'sort.Float64s(x)', and 'sort.Strings(x)'. - # https://staticcheck.dev/docs/checks/#S1032 - - S1032 - # Unnecessary guard around call to "delete". - # https://staticcheck.dev/docs/checks/#S1033 - - S1033 - # Use result of type assertion to simplify cases. - # https://staticcheck.dev/docs/checks/#S1034 - - S1034 - # Redundant call to 'net/http.CanonicalHeaderKey' in method call on 'net/http.Header'. - # https://staticcheck.dev/docs/checks/#S1035 - - S1035 - # Unnecessary guard around map access. - # https://staticcheck.dev/docs/checks/#S1036 - - S1036 - # Elaborate way of sleeping. - # https://staticcheck.dev/docs/checks/#S1037 - - S1037 - # Unnecessarily complex way of printing formatted string. - # https://staticcheck.dev/docs/checks/#S1038 - - S1038 - # Unnecessary use of 'fmt.Sprint'. - # https://staticcheck.dev/docs/checks/#S1039 - - S1039 - # Type assertion to current type. - # https://staticcheck.dev/docs/checks/#S1040 - - S1040 - gosec: # To select a subset of rules to run. # Available rules: https://github.com/securego/gosec#available-rules @@ -2859,9 +2745,19 @@ linters: - "github.com/user/repo/telemetry/trace.Start:opentelemetry" staticcheck: + # https://staticcheck.dev/docs/configuration/options/#dot_import_whitelist + # Default: ["github.com/mmcloughlin/avo/build", "github.com/mmcloughlin/avo/operand", "github.com/mmcloughlin/avo/reg"] + dot-import-whitelist: + - fmt + # https://staticcheck.dev/docs/configuration/options/#initialisms + # Default: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"] + initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS" ] + # https://staticcheck.dev/docs/configuration/options/#http_status_code_whitelist + # Default: ["200", "400", "404", "500"] + http-status-code-whitelist: [ "200", "400", "404", "500" ] # SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks # Example (to disable some checks): [ "all", "-SA1000", "-SA1001"] - # Default: ["*"] + # Default: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"] checks: # Invalid regular expression. # https://staticcheck.dev/docs/checks/#SA1000 @@ -3148,22 +3044,6 @@ linters: # Ineffectual Go compiler directive. # https://staticcheck.dev/docs/checks/#SA9009 - SA9009 - - stylecheck: - # https://staticcheck.dev/docs/configuration/options/#dot_import_whitelist - # Default: ["github.com/mmcloughlin/avo/build", "github.com/mmcloughlin/avo/operand", "github.com/mmcloughlin/avo/reg"] - dot-import-whitelist: - - fmt - # https://staticcheck.dev/docs/configuration/options/#initialisms - # Default: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"] - initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS" ] - # https://staticcheck.dev/docs/configuration/options/#http_status_code_whitelist - # Default: ["200", "400", "404", "500"] - http-status-code-whitelist: [ "200", "400", "404", "500" ] - # STxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks - # Example (to disable some checks): [ "all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022" ] - # Default: ["*"] - checks: # Incorrect or missing package comment. # https://staticcheck.dev/docs/checks/#ST1000 - ST1000 @@ -3218,6 +3098,147 @@ linters: # Redundant type in variable declaration. # https://staticcheck.dev/docs/checks/#ST1023 - ST1023 + # Use plain channel send or receive instead of single-case select. + # https://staticcheck.dev/docs/checks/#S1000 + - S1000 + # Replace for loop with call to copy. + # https://staticcheck.dev/docs/checks/#S1001 + - S1001 + # Omit comparison with boolean constant. + # https://staticcheck.dev/docs/checks/#S1002 + - S1002 + # Replace call to 'strings.Index' with 'strings.Contains'. + # https://staticcheck.dev/docs/checks/#S1003 + - S1003 + # Replace call to 'bytes.Compare' with 'bytes.Equal'. + # https://staticcheck.dev/docs/checks/#S1004 + - S1004 + # Drop unnecessary use of the blank identifier. + # https://staticcheck.dev/docs/checks/#S1005 + - S1005 + # Use "for { ... }" for infinite loops. + # https://staticcheck.dev/docs/checks/#S1006 + - S1006 + # Simplify regular expression by using raw string literal. + # https://staticcheck.dev/docs/checks/#S1007 + - S1007 + # Simplify returning boolean expression. + # https://staticcheck.dev/docs/checks/#S1008 + - S1008 + # Omit redundant nil check on slices, maps, and channels. + # https://staticcheck.dev/docs/checks/#S1009 + - S1009 + # Omit default slice index. + # https://staticcheck.dev/docs/checks/#S1010 + - S1010 + # Use a single 'append' to concatenate two slices. + # https://staticcheck.dev/docs/checks/#S1011 + - S1011 + # Replace 'time.Now().Sub(x)' with 'time.Since(x)'. + # https://staticcheck.dev/docs/checks/#S1012 + - S1012 + # Use a type conversion instead of manually copying struct fields. + # https://staticcheck.dev/docs/checks/#S1016 + - S1016 + # Replace manual trimming with 'strings.TrimPrefix'. + # https://staticcheck.dev/docs/checks/#S1017 + - S1017 + # Use "copy" for sliding elements. + # https://staticcheck.dev/docs/checks/#S1018 + - S1018 + # Simplify "make" call by omitting redundant arguments. + # https://staticcheck.dev/docs/checks/#S1019 + - S1019 + # Omit redundant nil check in type assertion. + # https://staticcheck.dev/docs/checks/#S1020 + - S1020 + # Merge variable declaration and assignment. + # https://staticcheck.dev/docs/checks/#S1021 + - S1021 + # Omit redundant control flow. + # https://staticcheck.dev/docs/checks/#S1023 + - S1023 + # Replace 'x.Sub(time.Now())' with 'time.Until(x)'. + # https://staticcheck.dev/docs/checks/#S1024 + - S1024 + # Don't use 'fmt.Sprintf("%s", x)' unnecessarily. + # https://staticcheck.dev/docs/checks/#S1025 + - S1025 + # Simplify error construction with 'fmt.Errorf'. + # https://staticcheck.dev/docs/checks/#S1028 + - S1028 + # Range over the string directly. + # https://staticcheck.dev/docs/checks/#S1029 + - S1029 + # Use 'bytes.Buffer.String' or 'bytes.Buffer.Bytes'. + # https://staticcheck.dev/docs/checks/#S1030 + - S1030 + # Omit redundant nil check around loop. + # https://staticcheck.dev/docs/checks/#S1031 + - S1031 + # Use 'sort.Ints(x)', 'sort.Float64s(x)', and 'sort.Strings(x)'. + # https://staticcheck.dev/docs/checks/#S1032 + - S1032 + # Unnecessary guard around call to "delete". + # https://staticcheck.dev/docs/checks/#S1033 + - S1033 + # Use result of type assertion to simplify cases. + # https://staticcheck.dev/docs/checks/#S1034 + - S1034 + # Redundant call to 'net/http.CanonicalHeaderKey' in method call on 'net/http.Header'. + # https://staticcheck.dev/docs/checks/#S1035 + - S1035 + # Unnecessary guard around map access. + # https://staticcheck.dev/docs/checks/#S1036 + - S1036 + # Elaborate way of sleeping. + # https://staticcheck.dev/docs/checks/#S1037 + - S1037 + # Unnecessarily complex way of printing formatted string. + # https://staticcheck.dev/docs/checks/#S1038 + - S1038 + # Unnecessary use of 'fmt.Sprint'. + # https://staticcheck.dev/docs/checks/#S1039 + - S1039 + # Type assertion to current type. + # https://staticcheck.dev/docs/checks/#S1040 + - S1040 + # Apply De Morgan's law. + # https://staticcheck.dev/docs/checks/#QF1001 + - QF1001 + # Convert untagged switch to tagged switch. + # https://staticcheck.dev/docs/checks/#QF1002 + - QF1002 + # Convert if/else-if chain to tagged switch. + # https://staticcheck.dev/docs/checks/#QF1003 + - QF1003 + # Use 'strings.ReplaceAll' instead of 'strings.Replace' with 'n == -1'. + # https://staticcheck.dev/docs/checks/#QF1004 + - QF1004 + # Expand call to 'math.Pow'. + # https://staticcheck.dev/docs/checks/#QF1005 + - QF1005 + # Lift 'if'+'break' into loop condition. + # https://staticcheck.dev/docs/checks/#QF1006 + - QF1006 + # Merge conditional assignment into variable declaration. + # https://staticcheck.dev/docs/checks/#QF1007 + - QF1007 + # Omit embedded fields from selector expression. + # https://staticcheck.dev/docs/checks/#QF1008 + - QF1008 + # Use 'time.Time.Equal' instead of '==' operator. + # https://staticcheck.dev/docs/checks/#QF1009 + - QF1009 + # Convert slice of bytes to string when printing it. + # https://staticcheck.dev/docs/checks/#QF1010 + - QF1010 + # Omit redundant type from variable declaration. + # https://staticcheck.dev/docs/checks/#QF1011 + - QF1011 + # Use 'fmt.Fprintf(x, ...)' instead of 'x.Write(fmt.Sprintf(...))'. + # https://staticcheck.dev/docs/checks/#QF1012 + - QF1012 tagalign: # Align and sort can be used together or separately. diff --git a/.golangci.yml b/.golangci.yml index a90002a784e4..eaba71e80319 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,7 +36,6 @@ linters: - mnd - goprintffuncname - gosec - - gosimple - govet - intrange - ineffassign @@ -47,7 +46,6 @@ linters: - nolintlint - revive - staticcheck - - stylecheck - testifylint - unconvert - unparam diff --git a/assets/github-action-config-v1.json b/assets/github-action-config-v1.json index 573bbe4cd84f..3b6bf9821567 100644 --- a/assets/github-action-config-v1.json +++ b/assets/github-action-config-v1.json @@ -1,7 +1,7 @@ { "MinorVersionToConfig": { "latest": { - "TargetVersion": "v1.64.5" + "TargetVersion": "v1.64.6" }, "v1.10": { "Error": "golangci-lint version 'v1.10' isn't supported: we support only v1.28.3 and later versions" @@ -178,7 +178,7 @@ "TargetVersion": "v1.63.4" }, "v1.64": { - "TargetVersion": "v1.64.5" + "TargetVersion": "v1.64.6" }, "v1.7": { "Error": "golangci-lint version 'v1.7' isn't supported: we support only v1.28.3 and later versions" diff --git a/assets/github-action-config.json b/assets/github-action-config.json index 573bbe4cd84f..3b6bf9821567 100644 --- a/assets/github-action-config.json +++ b/assets/github-action-config.json @@ -1,7 +1,7 @@ { "MinorVersionToConfig": { "latest": { - "TargetVersion": "v1.64.5" + "TargetVersion": "v1.64.6" }, "v1.10": { "Error": "golangci-lint version 'v1.10' isn't supported: we support only v1.28.3 and later versions" @@ -178,7 +178,7 @@ "TargetVersion": "v1.63.4" }, "v1.64": { - "TargetVersion": "v1.64.5" + "TargetVersion": "v1.64.6" }, "v1.7": { "Error": "golangci-lint version 'v1.7' isn't supported: we support only v1.28.3 and later versions" diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 6ded83e2f751..f1293f3d3481 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -123,6 +123,360 @@ "security" ] }, + "staticcheck-checks": { + "enum": [ + "*", + "all", + "SA*", + "-SA*", + "SA1*", + "-SA1*", + "SA1000", + "-SA1000", + "SA1001", + "-SA1001", + "SA1002", + "-SA1002", + "SA1003", + "-SA1003", + "SA1004", + "-SA1004", + "SA1005", + "-SA1005", + "SA1006", + "-SA1006", + "SA1007", + "-SA1007", + "SA1008", + "-SA1008", + "SA1010", + "-SA1010", + "SA1011", + "-SA1011", + "SA1012", + "-SA1012", + "SA1013", + "-SA1013", + "SA1014", + "-SA1014", + "SA1015", + "-SA1015", + "SA1016", + "-SA1016", + "SA1017", + "-SA1017", + "SA1018", + "-SA1018", + "SA1019", + "-SA1019", + "SA1020", + "-SA1020", + "SA1021", + "-SA1021", + "SA1023", + "-SA1023", + "SA1024", + "-SA1024", + "SA1025", + "-SA1025", + "SA1026", + "-SA1026", + "SA1027", + "-SA1027", + "SA1028", + "-SA1028", + "SA1029", + "-SA1029", + "SA1030", + "-SA1030", + "SA1031", + "-SA1031", + "SA1032", + "-SA1032", + "SA2*", + "-SA2*", + "SA2000", + "-SA2000", + "SA2001", + "-SA2001", + "SA2002", + "-SA2002", + "SA2003", + "-SA2003", + "SA3*", + "-SA3*", + "SA3000", + "-SA3000", + "SA3001", + "-SA3001", + "SA4*", + "-SA4*", + "SA4000", + "-SA4000", + "SA4001", + "-SA4001", + "SA4003", + "-SA4003", + "SA4004", + "-SA4004", + "SA4005", + "-SA4005", + "SA4006", + "-SA4006", + "SA4008", + "-SA4008", + "SA4009", + "-SA4009", + "SA4010", + "-SA4010", + "SA4011", + "-SA4011", + "SA4012", + "-SA4012", + "SA4013", + "-SA4013", + "SA4014", + "-SA4014", + "SA4015", + "-SA4015", + "SA4016", + "-SA4016", + "SA4017", + "-SA4017", + "SA4018", + "-SA4018", + "SA4019", + "-SA4019", + "SA4020", + "-SA4020", + "SA4021", + "-SA4021", + "SA4022", + "-SA4022", + "SA4023", + "-SA4023", + "SA4024", + "-SA4024", + "SA4025", + "-SA4025", + "SA4026", + "-SA4026", + "SA4027", + "-SA4027", + "SA4028", + "-SA4028", + "SA4029", + "-SA4029", + "SA4030", + "-SA4030", + "SA4031", + "-SA4031", + "SA4032", + "-SA4032", + "SA5*", + "-SA5*", + "SA5000", + "-SA5000", + "SA5001", + "-SA5001", + "SA5002", + "-SA5002", + "SA5003", + "-SA5003", + "SA5004", + "-SA5004", + "SA5005", + "-SA5005", + "SA5007", + "-SA5007", + "SA5008", + "-SA5008", + "SA5009", + "-SA5009", + "SA5010", + "-SA5010", + "SA5011", + "-SA5011", + "SA5012", + "-SA5012", + "SA6*", + "-SA6*", + "SA6000", + "-SA6000", + "SA6001", + "-SA6001", + "SA6002", + "-SA6002", + "SA6003", + "-SA6003", + "SA6005", + "-SA6005", + "SA6006", + "-SA6006", + "SA9*", + "-SA9*", + "SA9001", + "-SA9001", + "SA9002", + "-SA9002", + "SA9003", + "-SA9003", + "SA9004", + "-SA9004", + "SA9005", + "-SA9005", + "SA9006", + "-SA9006", + "SA9007", + "-SA9007", + "SA9008", + "-SA9008", + "SA9009", + "-SA9009", + "ST*", + "-ST*", + "ST1*", + "-ST1*", + "ST1000", + "-ST1000", + "ST1001", + "-ST1001", + "ST1003", + "-ST1003", + "ST1005", + "-ST1005", + "ST1006", + "-ST1006", + "ST1008", + "-ST1008", + "ST1011", + "-ST1011", + "ST1012", + "-ST1012", + "ST1013", + "-ST1013", + "ST1015", + "-ST1015", + "ST1016", + "-ST1016", + "ST1017", + "-ST1017", + "ST1018", + "-ST1018", + "ST1019", + "-ST1019", + "ST1020", + "-ST1020", + "ST1021", + "-ST1021", + "ST1022", + "-ST1022", + "ST1023", + "-ST1023", + "S*", + "-S*", + "S1*", + "-S1*", + "S1000", + "-S1000", + "S1001", + "-S1001", + "S1002", + "-S1002", + "S1003", + "-S1003", + "S1004", + "-S1004", + "S1005", + "-S1005", + "S1006", + "-S1006", + "S1007", + "-S1007", + "S1008", + "-S1008", + "S1009", + "-S1009", + "S1010", + "-S1010", + "S1011", + "-S1011", + "S1012", + "-S1012", + "S1016", + "-S1016", + "S1017", + "-S1017", + "S1018", + "-S1018", + "S1019", + "-S1019", + "S1020", + "-S1020", + "S1021", + "-S1021", + "S1023", + "-S1023", + "S1024", + "-S1024", + "S1025", + "-S1025", + "S1028", + "-S1028", + "S1029", + "-S1029", + "S1030", + "-S1030", + "S1031", + "-S1031", + "S1032", + "-S1032", + "S1033", + "-S1033", + "S1034", + "-S1034", + "S1035", + "-S1035", + "S1036", + "-S1036", + "S1037", + "-S1037", + "S1038", + "-S1038", + "S1039", + "-S1039", + "S1040", + "-S1040", + "QF*", + "-QF*", + "QF1*", + "-QF1*", + "QF1001", + "-QF1001", + "QF1002", + "-QF1002", + "QF1003", + "-QF1003", + "QF1004", + "-QF1004", + "QF1005", + "-QF1005", + "QF1006", + "-QF1006", + "QF1007", + "-QF1007", + "QF1008", + "-QF1008", + "QF1009", + "-QF1009", + "QF1010", + "-QF1010", + "QF1011", + "-QF1011", + "QF1012", + "-QF1012" + ] + }, "gosec-rules": { "enum": [ "G101", @@ -1705,25 +2059,6 @@ } } }, - "gosimpleSettings": { - "type": "object", - "additionalProperties": false, - "properties": { - "checks": { - "type": "array", - "items": { - "anyOf": [ - { - "enum": ["all"] - }, - { - "type": "string" - } - ] - } - } - } - }, "gosecSettings": { "type": "object", "additionalProperties": false, @@ -2661,41 +2996,13 @@ "items": { "anyOf": [ { - "enum": ["all"] + "$ref": "#/definitions/staticcheck-checks" }, { "type": "string" } ] } - } - } - }, - "stylecheckSettings": { - "type": "object", - "additionalProperties": false, - "properties": { - "checks": { - "type": "array", - "items": { - "anyOf": [ - { - "enum": ["all"] - }, - { - "type": "string" - } - ] - }, - "default": [ - "all", - "-ST1000", - "-ST1003", - "-ST1016", - "-ST1020", - "-ST1021", - "-ST1022" - ] }, "dot-import-whitelist": { "description": "By default, ST1001 forbids all uses of dot imports in non-test packages. This setting allows setting a whitelist of import paths that can be dot-imported anywhere.", @@ -4013,9 +4320,6 @@ "gomodguard": { "$ref": "#/definitions/settings/definitions/gomodguardSettings" }, - "gosimple": { - "$ref": "#/definitions/settings/definitions/gosimpleSettings" - }, "gosec": { "$ref": "#/definitions/settings/definitions/gosecSettings" }, @@ -4118,9 +4422,6 @@ "staticcheck":{ "$ref": "#/definitions/settings/definitions/staticcheckSettings" }, - "stylecheck": { - "$ref": "#/definitions/settings/definitions/stylecheckSettings" - }, "tagalign": { "$ref": "#/definitions/settings/definitions/tagalignSettings" }, diff --git a/pkg/commands/internal/builder.go b/pkg/commands/internal/builder.go index f0e259fb0265..e95c0d2477e1 100644 --- a/pkg/commands/internal/builder.go +++ b/pkg/commands/internal/builder.go @@ -243,7 +243,7 @@ func (b Builder) getBinaryName() string { func sanitizeVersion(v string) string { fn := func(c rune) bool { - return !(unicode.IsLetter(c) || unicode.IsNumber(c) || c == '.' || c == '/') + return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '.' && c != '/' } return strings.Join(strings.FieldsFunc(v, fn), "") diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index b151f8f407b1..7391e4a25dbd 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -226,7 +226,6 @@ type LintersSettings struct { GoModDirectives GoModDirectivesSettings `mapstructure:"gomoddirectives"` Gomodguard GoModGuardSettings `mapstructure:"gomodguard"` Gosec GoSecSettings `mapstructure:"gosec"` - Gosimple StaticCheckSettings `mapstructure:"gosimple"` Gosmopolitan GosmopolitanSettings `mapstructure:"gosmopolitan"` Govet GovetSettings `mapstructure:"govet"` Grouper GrouperSettings `mapstructure:"grouper"` @@ -261,7 +260,6 @@ type LintersSettings struct { SlogLint SlogLintSettings `mapstructure:"sloglint"` Spancheck SpancheckSettings `mapstructure:"spancheck"` Staticcheck StaticCheckSettings `mapstructure:"staticcheck"` - Stylecheck StaticCheckSettings `mapstructure:"stylecheck"` TagAlign TagAlignSettings `mapstructure:"tagalign"` Tagliatelle TagliatelleSettings `mapstructure:"tagliatelle"` Tenv TenvSettings `mapstructure:"tenv"` diff --git a/pkg/golinters/gosimple/gosimple.go b/pkg/golinters/gosimple/gosimple.go deleted file mode 100644 index c03871adf9b5..000000000000 --- a/pkg/golinters/gosimple/gosimple.go +++ /dev/null @@ -1,22 +0,0 @@ -package gosimple - -import ( - "honnef.co/go/tools/simple" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/goanalysis" - "github.com/golangci/golangci-lint/pkg/golinters/internal" -) - -func New(settings *config.StaticCheckSettings) *goanalysis.Linter { - cfg := internal.StaticCheckConfig(settings) - - analyzers := internal.SetupStaticCheckAnalyzers(simple.Analyzers, cfg.Checks) - - return goanalysis.NewLinter( - "gosimple", - "Linter for Go source code that specializes in simplifying code", - analyzers, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) -} diff --git a/pkg/golinters/gosimple/gosimple_integration_test.go b/pkg/golinters/gosimple/gosimple_integration_test.go deleted file mode 100644 index 9f8f583f032c..000000000000 --- a/pkg/golinters/gosimple/gosimple_integration_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package gosimple - -import ( - "testing" - - "github.com/golangci/golangci-lint/test/testshared/integration" -) - -func TestFromTestdata(t *testing.T) { - integration.RunTestdata(t) -} - -func TestFix(t *testing.T) { - integration.RunFix(t) -} - -func TestFixPathPrefix(t *testing.T) { - integration.RunFixPathPrefix(t) -} diff --git a/pkg/golinters/internal/staticcheck_common.go b/pkg/golinters/internal/staticcheck_common.go deleted file mode 100644 index e5a0e33b7d8b..000000000000 --- a/pkg/golinters/internal/staticcheck_common.go +++ /dev/null @@ -1,143 +0,0 @@ -package internal - -import ( - "strings" - "unicode" - - "golang.org/x/tools/go/analysis" - "honnef.co/go/tools/analysis/lint" - scconfig "honnef.co/go/tools/config" - - "github.com/golangci/golangci-lint/pkg/config" -) - -func SetupStaticCheckAnalyzers(src []*lint.Analyzer, checks []string) []*analysis.Analyzer { - var names []string - for _, a := range src { - names = append(names, a.Analyzer.Name) - } - - filter := filterAnalyzerNames(names, checks) - - var ret []*analysis.Analyzer - for _, a := range src { - if filter[a.Analyzer.Name] { - ret = append(ret, a.Analyzer) - } - } - - return ret -} - -func StaticCheckConfig(settings *config.StaticCheckSettings) *scconfig.Config { - var cfg *scconfig.Config - - if settings == nil || !settings.HasConfiguration() { - return &scconfig.Config{ - Checks: []string{"*"}, // override for compatibility reason. Must drop in the next major version. - Initialisms: scconfig.DefaultConfig.Initialisms, - DotImportWhitelist: scconfig.DefaultConfig.DotImportWhitelist, - HTTPStatusCodeWhitelist: scconfig.DefaultConfig.HTTPStatusCodeWhitelist, - } - } - - cfg = &scconfig.Config{ - Checks: settings.Checks, - Initialisms: settings.Initialisms, - DotImportWhitelist: settings.DotImportWhitelist, - HTTPStatusCodeWhitelist: settings.HTTPStatusCodeWhitelist, - } - - if len(cfg.Checks) == 0 { - cfg.Checks = append(cfg.Checks, "*") // override for compatibility reason. Must drop in the next major version. - } - - if len(cfg.Initialisms) == 0 { - cfg.Initialisms = append(cfg.Initialisms, scconfig.DefaultConfig.Initialisms...) - } - - if len(cfg.DotImportWhitelist) == 0 { - cfg.DotImportWhitelist = append(cfg.DotImportWhitelist, scconfig.DefaultConfig.DotImportWhitelist...) - } - - if len(cfg.HTTPStatusCodeWhitelist) == 0 { - cfg.HTTPStatusCodeWhitelist = append(cfg.HTTPStatusCodeWhitelist, scconfig.DefaultConfig.HTTPStatusCodeWhitelist...) - } - - cfg.Checks = normalizeList(cfg.Checks) - cfg.Initialisms = normalizeList(cfg.Initialisms) - cfg.DotImportWhitelist = normalizeList(cfg.DotImportWhitelist) - cfg.HTTPStatusCodeWhitelist = normalizeList(cfg.HTTPStatusCodeWhitelist) - - return cfg -} - -// https://github.com/dominikh/go-tools/blob/9bf17c0388a65710524ba04c2d821469e639fdc2/lintcmd/lint.go#L437-L477 -// -//nolint:gocritic // Keep the original source code. -func filterAnalyzerNames(analyzers []string, checks []string) map[string]bool { - allowedChecks := map[string]bool{} - - for _, check := range checks { - b := true - if len(check) > 1 && check[0] == '-' { - b = false - check = check[1:] - } - - if check == "*" || check == "all" { - // Match all - for _, c := range analyzers { - allowedChecks[c] = b - } - } else if strings.HasSuffix(check, "*") { - // Glob - prefix := check[:len(check)-1] - isCat := strings.IndexFunc(prefix, func(r rune) bool { return unicode.IsNumber(r) }) == -1 - - for _, a := range analyzers { - idx := strings.IndexFunc(a, func(r rune) bool { return unicode.IsNumber(r) }) - if isCat { - // Glob is S*, which should match S1000 but not SA1000 - cat := a[:idx] - if prefix == cat { - allowedChecks[a] = b - } - } else { - // Glob is S1* - if strings.HasPrefix(a, prefix) { - allowedChecks[a] = b - } - } - } - } else { - // Literal check name - allowedChecks[check] = b - } - } - return allowedChecks -} - -// https://github.com/dominikh/go-tools/blob/9bf17c0388a65710524ba04c2d821469e639fdc2/config/config.go#L95-L116 -func normalizeList(list []string) []string { - if len(list) > 1 { - nlist := make([]string, 0, len(list)) - nlist = append(nlist, list[0]) - for i, el := range list[1:] { - if el != list[i] { - nlist = append(nlist, el) - } - } - list = nlist - } - - for _, el := range list { - if el == "inherit" { - // This should never happen, because the default config - // should not use "inherit" - panic(`unresolved "inherit"`) - } - } - - return list -} diff --git a/pkg/golinters/staticcheck/staticcheck.go b/pkg/golinters/staticcheck/staticcheck.go index 79394bdb7f8a..f66d2c84fe2b 100644 --- a/pkg/golinters/staticcheck/staticcheck.go +++ b/pkg/golinters/staticcheck/staticcheck.go @@ -1,22 +1,172 @@ package staticcheck import ( + "slices" + "strings" + "unicode" + + "golang.org/x/tools/go/analysis" + "honnef.co/go/tools/analysis/lint" + scconfig "honnef.co/go/tools/config" + "honnef.co/go/tools/quickfix" + "honnef.co/go/tools/simple" "honnef.co/go/tools/staticcheck" + "honnef.co/go/tools/stylecheck" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/goanalysis" - "github.com/golangci/golangci-lint/pkg/golinters/internal" ) func New(settings *config.StaticCheckSettings) *goanalysis.Linter { - cfg := internal.StaticCheckConfig(settings) - analyzers := internal.SetupStaticCheckAnalyzers(staticcheck.Analyzers, cfg.Checks) + cfg := createConfig(settings) + + // `scconfig.Analyzer` is a singleton. + scconfig.Analyzer.Run = func(_ *analysis.Pass) (any, error) { + return cfg, nil + } + + allAnalyzers := slices.Concat(staticcheck.Analyzers, stylecheck.Analyzers, simple.Analyzers, quickfix.Analyzers) + + analyzers := setupAnalyzers(allAnalyzers, cfg.Checks) return goanalysis.NewLinter( "staticcheck", - "It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary."+ + "It's the set of rules from staticcheck. It's not the same thing as the staticcheck binary."+ " The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint.", analyzers, nil, ).WithLoadMode(goanalysis.LoadModeTypesInfo) } + +func createConfig(settings *config.StaticCheckSettings) *scconfig.Config { + defaultChecks := []string{"all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"} + + var cfg *scconfig.Config + + if settings == nil || !settings.HasConfiguration() { + return &scconfig.Config{ + Checks: defaultChecks, + Initialisms: scconfig.DefaultConfig.Initialisms, + DotImportWhitelist: scconfig.DefaultConfig.DotImportWhitelist, + HTTPStatusCodeWhitelist: scconfig.DefaultConfig.HTTPStatusCodeWhitelist, + } + } + + cfg = &scconfig.Config{ + Checks: settings.Checks, + Initialisms: settings.Initialisms, + DotImportWhitelist: settings.DotImportWhitelist, + HTTPStatusCodeWhitelist: settings.HTTPStatusCodeWhitelist, + } + + if len(cfg.Checks) == 0 { + cfg.Checks = defaultChecks + } + + if len(cfg.Initialisms) == 0 { + cfg.Initialisms = append(cfg.Initialisms, scconfig.DefaultConfig.Initialisms...) + } + + if len(cfg.DotImportWhitelist) == 0 { + cfg.DotImportWhitelist = append(cfg.DotImportWhitelist, scconfig.DefaultConfig.DotImportWhitelist...) + } + + if len(cfg.HTTPStatusCodeWhitelist) == 0 { + cfg.HTTPStatusCodeWhitelist = append(cfg.HTTPStatusCodeWhitelist, scconfig.DefaultConfig.HTTPStatusCodeWhitelist...) + } + + cfg.Checks = normalizeList(cfg.Checks) + cfg.Initialisms = normalizeList(cfg.Initialisms) + cfg.DotImportWhitelist = normalizeList(cfg.DotImportWhitelist) + cfg.HTTPStatusCodeWhitelist = normalizeList(cfg.HTTPStatusCodeWhitelist) + + return cfg +} + +// https://github.com/dominikh/go-tools/blob/9bf17c0388a65710524ba04c2d821469e639fdc2/config/config.go#L95-L116 +func normalizeList(list []string) []string { + if len(list) > 1 { + nlist := make([]string, 0, len(list)) + nlist = append(nlist, list[0]) + for i, el := range list[1:] { + if el != list[i] { + nlist = append(nlist, el) + } + } + list = nlist + } + + for _, el := range list { + if el == "inherit" { + // This should never happen, because the default config + // should not use "inherit" + panic(`unresolved "inherit"`) + } + } + + return list +} + +func setupAnalyzers(src []*lint.Analyzer, checks []string) []*analysis.Analyzer { + var names []string + for _, a := range src { + names = append(names, a.Analyzer.Name) + } + + filter := filterAnalyzerNames(names, checks) + + var ret []*analysis.Analyzer + for _, a := range src { + if filter[a.Analyzer.Name] { + ret = append(ret, a.Analyzer) + } + } + + return ret +} + +// https://github.com/dominikh/go-tools/blob/9bf17c0388a65710524ba04c2d821469e639fdc2/lintcmd/lint.go#L437-L477 +// +//nolint:gocritic // Keep the original source code. +func filterAnalyzerNames(analyzers []string, checks []string) map[string]bool { + allowedChecks := map[string]bool{} + + for _, check := range checks { + b := true + if len(check) > 1 && check[0] == '-' { + b = false + check = check[1:] + } + + if check == "*" || check == "all" { + // Match all + for _, c := range analyzers { + allowedChecks[c] = b + } + } else if strings.HasSuffix(check, "*") { + // Glob + prefix := check[:len(check)-1] + isCat := strings.IndexFunc(prefix, func(r rune) bool { return unicode.IsNumber(r) }) == -1 + + for _, a := range analyzers { + idx := strings.IndexFunc(a, func(r rune) bool { return unicode.IsNumber(r) }) + if isCat { + // Glob is S*, which should match S1000 but not SA1000 + cat := a[:idx] + if prefix == cat { + allowedChecks[a] = b + } + } else { + // Glob is S1* + if strings.HasPrefix(a, prefix) { + allowedChecks[a] = b + } + } + } + } else { + // Literal check name + allowedChecks[check] = b + } + } + return allowedChecks +} diff --git a/pkg/golinters/gosimple/testdata/fix/in/gosimple.go b/pkg/golinters/staticcheck/testdata/fix/in/gosimple.go similarity index 62% rename from pkg/golinters/gosimple/testdata/fix/in/gosimple.go rename to pkg/golinters/staticcheck/testdata/fix/in/gosimple.go index 8dca57b42cee..ef812eb4f269 100644 --- a/pkg/golinters/gosimple/testdata/fix/in/gosimple.go +++ b/pkg/golinters/staticcheck/testdata/fix/in/gosimple.go @@ -1,4 +1,5 @@ -//golangcitest:args -Egosimple +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/gosimple.yml //golangcitest:expected_exitcode 0 package testdata diff --git a/pkg/golinters/staticcheck/testdata/fix/in/staticcheck.go b/pkg/golinters/staticcheck/testdata/fix/in/staticcheck.go index 68c84c6c7ca5..cad41910d7cc 100644 --- a/pkg/golinters/staticcheck/testdata/fix/in/staticcheck.go +++ b/pkg/golinters/staticcheck/testdata/fix/in/staticcheck.go @@ -1,4 +1,5 @@ //golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/staticcheck.yml //golangcitest:expected_exitcode 0 package testdata diff --git a/pkg/golinters/stylecheck/testdata/fix/in/stylecheck.go b/pkg/golinters/staticcheck/testdata/fix/in/stylecheck.go similarity index 57% rename from pkg/golinters/stylecheck/testdata/fix/in/stylecheck.go rename to pkg/golinters/staticcheck/testdata/fix/in/stylecheck.go index 2469f148320d..7d6ca2f61f27 100644 --- a/pkg/golinters/stylecheck/testdata/fix/in/stylecheck.go +++ b/pkg/golinters/staticcheck/testdata/fix/in/stylecheck.go @@ -1,6 +1,7 @@ // Package testdata ... // -//golangcitest:args -Estylecheck +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/stylecheck.yml //golangcitest:expected_exitcode 0 package testdata diff --git a/pkg/golinters/gosimple/testdata/fix/out/gosimple.go b/pkg/golinters/staticcheck/testdata/fix/out/gosimple.go similarity index 57% rename from pkg/golinters/gosimple/testdata/fix/out/gosimple.go rename to pkg/golinters/staticcheck/testdata/fix/out/gosimple.go index b03a15c5f992..ad5cbd6d41bc 100644 --- a/pkg/golinters/gosimple/testdata/fix/out/gosimple.go +++ b/pkg/golinters/staticcheck/testdata/fix/out/gosimple.go @@ -1,4 +1,5 @@ -//golangcitest:args -Egosimple +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/gosimple.yml //golangcitest:expected_exitcode 0 package testdata diff --git a/pkg/golinters/staticcheck/testdata/fix/out/staticcheck.go b/pkg/golinters/staticcheck/testdata/fix/out/staticcheck.go index 37f1cb4d772e..67bf3ca21a51 100644 --- a/pkg/golinters/staticcheck/testdata/fix/out/staticcheck.go +++ b/pkg/golinters/staticcheck/testdata/fix/out/staticcheck.go @@ -1,4 +1,5 @@ //golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/staticcheck.yml //golangcitest:expected_exitcode 0 package testdata diff --git a/pkg/golinters/stylecheck/testdata/fix/out/stylecheck.go b/pkg/golinters/staticcheck/testdata/fix/out/stylecheck.go similarity index 57% rename from pkg/golinters/stylecheck/testdata/fix/out/stylecheck.go rename to pkg/golinters/staticcheck/testdata/fix/out/stylecheck.go index 2450d9309b18..1a0bd4372bd2 100644 --- a/pkg/golinters/stylecheck/testdata/fix/out/stylecheck.go +++ b/pkg/golinters/staticcheck/testdata/fix/out/stylecheck.go @@ -1,6 +1,7 @@ // Package testdata ... // -//golangcitest:args -Estylecheck +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/stylecheck.yml //golangcitest:expected_exitcode 0 package testdata diff --git a/pkg/golinters/gosimple/testdata/gosimple.go b/pkg/golinters/staticcheck/testdata/gosimple.go similarity index 70% rename from pkg/golinters/gosimple/testdata/gosimple.go rename to pkg/golinters/staticcheck/testdata/gosimple.go index d8d90315ca46..9215aab8149a 100644 --- a/pkg/golinters/gosimple/testdata/gosimple.go +++ b/pkg/golinters/staticcheck/testdata/gosimple.go @@ -1,4 +1,5 @@ -//golangcitest:args -Egosimple +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/gosimple.yml package testdata import ( @@ -14,7 +15,7 @@ func Gosimple(ss []string) { } func GosimpleNolintGosimple(ss []string) { - if ss != nil { //nolint:gosimple + if ss != nil { //nolint:staticcheck for _, s := range ss { log.Printf(s) } diff --git a/pkg/golinters/staticcheck/testdata/gosimple.yml b/pkg/golinters/staticcheck/testdata/gosimple.yml new file mode 100644 index 000000000000..5851e3f82364 --- /dev/null +++ b/pkg/golinters/staticcheck/testdata/gosimple.yml @@ -0,0 +1,11 @@ +version: "2" + +linters: + settings: + staticcheck: + checks: + - all + - '-SA*' + - '-ST*' + - '-QF*' + diff --git a/pkg/golinters/gosimple/testdata/gosimple_cgo.go b/pkg/golinters/staticcheck/testdata/gosimple_cgo.go similarity index 82% rename from pkg/golinters/gosimple/testdata/gosimple_cgo.go rename to pkg/golinters/staticcheck/testdata/gosimple_cgo.go index 99f1cebf30b1..9a8f45ba8220 100644 --- a/pkg/golinters/gosimple/testdata/gosimple_cgo.go +++ b/pkg/golinters/staticcheck/testdata/gosimple_cgo.go @@ -1,4 +1,5 @@ -//golangcitest:args -Egosimple +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/gosimple.yml package testdata /* diff --git a/pkg/golinters/staticcheck/testdata/staticcheck.go b/pkg/golinters/staticcheck/testdata/staticcheck.go index f8080f37bc56..f8512bbff715 100644 --- a/pkg/golinters/staticcheck/testdata/staticcheck.go +++ b/pkg/golinters/staticcheck/testdata/staticcheck.go @@ -1,4 +1,5 @@ //golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/staticcheck.yml package testdata import ( diff --git a/pkg/golinters/staticcheck/testdata/staticcheck.yml b/pkg/golinters/staticcheck/testdata/staticcheck.yml new file mode 100644 index 000000000000..e1111d14e94e --- /dev/null +++ b/pkg/golinters/staticcheck/testdata/staticcheck.yml @@ -0,0 +1,10 @@ +version: "2" + +linters: + settings: + staticcheck: + checks: + - all + - '-ST*' + - '-S*' + - '-QF*' diff --git a/pkg/golinters/staticcheck/testdata/staticcheck_cgo.go b/pkg/golinters/staticcheck/testdata/staticcheck_cgo.go index 71370eb9dc1a..363f7e823910 100644 --- a/pkg/golinters/staticcheck/testdata/staticcheck_cgo.go +++ b/pkg/golinters/staticcheck/testdata/staticcheck_cgo.go @@ -1,4 +1,5 @@ //golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/staticcheck.yml package testdata /* diff --git a/pkg/golinters/stylecheck/testdata/stylecheck.go b/pkg/golinters/staticcheck/testdata/stylecheck.go similarity index 73% rename from pkg/golinters/stylecheck/testdata/stylecheck.go rename to pkg/golinters/staticcheck/testdata/stylecheck.go index 6258dc81ab60..8391cd43587b 100644 --- a/pkg/golinters/stylecheck/testdata/stylecheck.go +++ b/pkg/golinters/staticcheck/testdata/stylecheck.go @@ -1,4 +1,5 @@ -//golangcitest:args -Estylecheck +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/stylecheck.yml // Package testdata ... package testdata @@ -17,7 +18,7 @@ func StylecheckNolintStylecheck(x int) { switch x { case 1: return - default: //nolint:stylecheck + default: //nolint:staticcheck return case 2: return diff --git a/pkg/golinters/staticcheck/testdata/stylecheck.yml b/pkg/golinters/staticcheck/testdata/stylecheck.yml new file mode 100644 index 000000000000..e53a744868b9 --- /dev/null +++ b/pkg/golinters/staticcheck/testdata/stylecheck.yml @@ -0,0 +1,11 @@ +version: "2" + +linters: + settings: + staticcheck: + checks: + - all + - '-SA*' + - '-S*' + - '-QF*' + diff --git a/pkg/golinters/stylecheck/testdata/stylecheck_cgo.go b/pkg/golinters/staticcheck/testdata/stylecheck_cgo.go similarity index 83% rename from pkg/golinters/stylecheck/testdata/stylecheck_cgo.go rename to pkg/golinters/staticcheck/testdata/stylecheck_cgo.go index e2747585bba4..fa2a0ed17435 100644 --- a/pkg/golinters/stylecheck/testdata/stylecheck_cgo.go +++ b/pkg/golinters/staticcheck/testdata/stylecheck_cgo.go @@ -1,4 +1,5 @@ -//golangcitest:args -Estylecheck +//golangcitest:args -Estaticcheck +//golangcitest:config_path testdata/stylecheck.yml // Package testdata ... package testdata diff --git a/pkg/golinters/stylecheck/stylecheck.go b/pkg/golinters/stylecheck/stylecheck.go deleted file mode 100644 index 60859f28afc3..000000000000 --- a/pkg/golinters/stylecheck/stylecheck.go +++ /dev/null @@ -1,31 +0,0 @@ -package stylecheck - -import ( - "golang.org/x/tools/go/analysis" - scconfig "honnef.co/go/tools/config" - "honnef.co/go/tools/stylecheck" - - "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/goanalysis" - "github.com/golangci/golangci-lint/pkg/golinters/internal" -) - -func New(settings *config.StaticCheckSettings) *goanalysis.Linter { - cfg := internal.StaticCheckConfig(settings) - - // `scconfig.Analyzer` is a singleton, then it's not possible to have more than one instance for all staticcheck "sub-linters". - // When we will merge the 4 "sub-linters", the problem will disappear: https://github.com/golangci/golangci-lint/issues/357 - // Currently only stylecheck analyzer has a configuration in staticcheck. - scconfig.Analyzer.Run = func(_ *analysis.Pass) (any, error) { - return cfg, nil - } - - analyzers := internal.SetupStaticCheckAnalyzers(stylecheck.Analyzers, cfg.Checks) - - return goanalysis.NewLinter( - "stylecheck", - "Stylecheck is a replacement for golint", - analyzers, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) -} diff --git a/pkg/golinters/stylecheck/stylecheck_integration_test.go b/pkg/golinters/stylecheck/stylecheck_integration_test.go deleted file mode 100644 index 2ee404e24b4b..000000000000 --- a/pkg/golinters/stylecheck/stylecheck_integration_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package stylecheck - -import ( - "testing" - - "github.com/golangci/golangci-lint/test/testshared/integration" -) - -func TestFromTestdata(t *testing.T) { - integration.RunTestdata(t) -} - -func TestFix(t *testing.T) { - integration.RunFix(t) -} - -func TestFixPathPrefix(t *testing.T) { - integration.RunFixPathPrefix(t) -} diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index e5b79d5007f3..b0a8c456e08f 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -51,7 +51,6 @@ import ( "github.com/golangci/golangci-lint/pkg/golinters/gomodguard" "github.com/golangci/golangci-lint/pkg/golinters/goprintffuncname" "github.com/golangci/golangci-lint/pkg/golinters/gosec" - "github.com/golangci/golangci-lint/pkg/golinters/gosimple" "github.com/golangci/golangci-lint/pkg/golinters/gosmopolitan" "github.com/golangci/golangci-lint/pkg/golinters/govet" "github.com/golangci/golangci-lint/pkg/golinters/grouper" @@ -94,7 +93,6 @@ import ( "github.com/golangci/golangci-lint/pkg/golinters/spancheck" "github.com/golangci/golangci-lint/pkg/golinters/sqlclosecheck" "github.com/golangci/golangci-lint/pkg/golinters/staticcheck" - "github.com/golangci/golangci-lint/pkg/golinters/stylecheck" "github.com/golangci/golangci-lint/pkg/golinters/tagalign" "github.com/golangci/golangci-lint/pkg/golinters/tagliatelle" "github.com/golangci/golangci-lint/pkg/golinters/testableexamples" @@ -373,13 +371,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithURL("https://github.com/securego/gosec"), - linter.NewConfig(gosimple.New(&cfg.Linters.Settings.Gosimple)). - WithGroups(config.GroupStandard). - WithSince("v1.20.0"). - WithLoadForGoAnalysis(). - WithAutoFix(). - WithURL("https://github.com/dominikh/go-tools/tree/HEAD/simple"), - linter.NewConfig(gosmopolitan.New(&cfg.Linters.Settings.Gosmopolitan)). WithSince("v1.53.0"). WithLoadForGoAnalysis(). @@ -581,12 +572,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithAutoFix(). WithURL("https://staticcheck.dev/"), - linter.NewConfig(stylecheck.New(&cfg.Linters.Settings.Stylecheck)). - WithSince("v1.20.0"). - WithLoadForGoAnalysis(). - WithAutoFix(). - WithURL("https://github.com/dominikh/go-tools/tree/HEAD/stylecheck"), - linter.NewConfig(tagalign.New(&cfg.Linters.Settings.TagAlign)). WithSince("v1.53.0"). WithAutoFix(). diff --git a/pkg/printers/printer.go b/pkg/printers/printer.go index 314ffb361e0d..b43a19de29e1 100644 --- a/pkg/printers/printer.go +++ b/pkg/printers/printer.go @@ -65,7 +65,7 @@ func NewPrinter(log logutils.Log, cfg *config.Formats, reportData *report.Data, //nolint:gocyclo,funlen // the complexity is related to the number of formats. func (c *Printer) Print(issues []result.Issue) error { if c.cfg.IsEmpty() { - c.cfg.Text.SimpleFormat.Path = outputStdOut + c.cfg.Text.Path = outputStdOut } var printers []issuePrinter diff --git a/pkg/result/processors/exclusion_presets.go b/pkg/result/processors/exclusion_presets.go index fb2f9cf3c154..4ab6c0e54d64 100644 --- a/pkg/result/processors/exclusion_presets.go +++ b/pkg/result/processors/exclusion_presets.go @@ -9,7 +9,7 @@ var LinterExclusionPresets = map[string][]config.ExcludeRule{ // CheckPackageComment, CheckExportedFunctionDocs, CheckExportedTypeDocs, CheckExportedVarDocs BaseRule: config.BaseRule{ Text: "(ST1000|ST1020|ST1021|ST1022)", - Linters: []string{"stylecheck"}, + Linters: []string{"staticcheck"}, InternalReference: "EXC0011", }, }, diff --git a/test/testdata/configs/default_exclude.yml b/test/testdata/configs/default_exclude.yml index eb719139cfd1..486d201e6e58 100644 --- a/test/testdata/configs/default_exclude.yml +++ b/test/testdata/configs/default_exclude.yml @@ -1,6 +1,11 @@ version: "2" linters: + settings: + staticcheck: + checks: + - all + exclusions: presets: - std-error-handling diff --git a/test/testdata/default_exclude.go b/test/testdata/default_exclude.go index dd78e76b84a2..9e69ab0023ac 100644 --- a/test/testdata/default_exclude.go +++ b/test/testdata/default_exclude.go @@ -1,12 +1,12 @@ -//golangcitest:args -Estylecheck,revive --internal-cmd-test +//golangcitest:args -Estaticcheck,revive --internal-cmd-test //golangcitest:config_path testdata/configs/default_exclude.yml /*Package testdata ...*/ package testdata -// InvalidFuncComment, both revive and stylecheck will complain about this, // want `exported: comment on exported function ExportedFunc1 should be of the form "ExportedFunc1 ..."` +// InvalidFuncComment, both revive and staticcheck (stylecheck) will complain about this, // want `exported: comment on exported function ExportedFunc1 should be of the form "ExportedFunc1 ..."` // if include EXC0011, only the warning from revive will be ignored. -// And only the warning from stylecheck will start with "ST1020". +// And only the warning from staticcheck (stylecheck) will start with "ST1020". func ExportedFunc1() { } @@ -16,6 +16,6 @@ func ExportedFunc1() { func ExportedFunc2() { } -//nolint:stylecheck +//nolint:staticcheck func IgnoreAll() { // want "exported: exported function IgnoreAll should have comment or be unexported" }