Skip to content

Exclude composite literals from goconst instead of raising its threshold - #124

Merged
jugonzalez12 merged 1 commit into
mainfrom
jugonzalez/goconst-exclude-types
Sep 22, 2026
Merged

jugonzalez12 merged 1 commit into
mainfrom
jugonzalez/goconst-exclude-types

Conversation

@jugonzalez12

Copy link
Copy Markdown
Contributor

The goconst block shipped with the v2.13.2 pin held the linter's prior signal with ignore-map-keys and min-occurrences: 6. Measured against the fleet after deployment, that covers map keys only. goconst v1.9.0 reports every element of a composite literal, and two more shapes survive:

  • slice elements and map values: baton-1password's permission lists (view_items x10, view_and_copy_passwords x8) and baton-axiomatic's "Error" as a map value and struct field (x6)
  • struct field values in test helpers: Method: "GET" in the go-github mock tables of baton-github and baton-github-test

exclude-types: [CompositeLit] names that shape directly. Call stays in the list because golangci-lint's goconst default is exclude-types: [Call] (pkg/config/linters_settings.go:74) and any value replaces the default rather than extending it; measured without Call, string arguments to functions are reported everywhere and baton-github-test goes from 1 finding to 19, baton-github from 1 to 22, baton-demo from 0 to 6.

min-occurrences: 6 is dropped. It only ever compensated for the composite-literal reports, and it loosened goconst on assignments, comparisons, case labels and returns from the default 3 to 6, which the v2.11.4 pin never did. With composite literals excluded, the default threshold is the pre-bump behavior.

The goconst block shipped with the v2.13.2 pin held the linter's prior
signal with ignore-map-keys and min-occurrences: 6. Measured against the
fleet after deployment, that covers map keys only. goconst v1.9.0 reports
every element of a composite literal, and two more shapes survive:

  - slice elements and map values: baton-1password's permission lists
    (`view_items` x10, `view_and_copy_passwords` x8) and baton-axiomatic's
    `"Error"` as a map value and struct field (x6)
  - struct field values in test helpers: `Method: "GET"` in the go-github
    mock tables of baton-github and baton-github-test

exclude-types: [CompositeLit] names that shape directly. Call stays in
the list because golangci-lint's goconst default is exclude-types: [Call]
(pkg/config/linters_settings.go:74) and any value replaces the default
rather than extending it; measured without Call, string arguments to
functions are reported everywhere and baton-github-test goes from 1
finding to 19, baton-github from 1 to 22, baton-demo from 0 to 6.

min-occurrences: 6 is dropped. It only ever compensated for the
composite-literal reports, and it loosened goconst on assignments,
comparisons, case labels and returns from the default 3 to 6, which the
v2.11.4 pin never did. With composite literals excluded, the default
threshold is the pre-bump behavior.

Validated with golangci-lint v2.13.2 on baton-1password, baton-github-test,
baton-github, baton-demo and baton-snyk: 0 goconst findings on all five,
the same result as keeping both prior settings alongside this one. The
deployed config leaves 3, 1, 1, 0 and 0 respectively.

baton-admin syncs this file into pkg/files/.golangci.yml daily and pushes
it to every managed connector; the fleet is already on v2.13.2, which
accepts exclude-types.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@jugonzalez12
jugonzalez12 merged commit e5bd795 into main Sep 22, 2026
2 checks passed
@jugonzalez12
jugonzalez12 deleted the jugonzalez/goconst-exclude-types branch September 22, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants