Skip to content

goconst: surface ExcludeTypes[CompositeLit] toggle in linter settings #6571

@mikkeldamsgaard

Description

@mikkeldamsgaard

Welcome

  • Yes, I've searched similar issues on GitHub and didn't find any.
  • I agree to follow this project's Code of Conduct.

How did you install golangci-lint?

Official binary

Your feature request related to a problem? Please describe

goconst's Config.ExcludeTypes map can suppress findings by AST context (Assignment, Binary, Case, Return, Call, CompositeLit). golangci-lint only surfaces the Call entry, via ignore-calls.

There is no way to opt out of CompositeLit from config. Since v2.12 bundled goconst v1.9.0+, which added composite-literal element walking, every string used as a map key, struct field value, or slice element is now reported:

metav1.TypeMeta{APIVersion: "v1", Kind: "ConfigMap"}
map[string]any{"phase": "Pending", "message": "..."}

In a repo with Pulumi stacks and Kubernetes controllers, the v2.11 → v2.12 bump took us from ~5 to 383 findings, ~95% of them inside composite literals.

Describe the solution you'd like

Surface ExcludeTypes[CompositeLit] (and ideally the other Type values) in the goconst linter settings, the same way ExcludeTypes[Call] is surfaced today via ignore-calls.

Describe alternatives you've considered

  • linters.exclusions.rules with path: — drops goconst wholesale on the affected directories.
  • goconst.ignore-string-values listing every repeated Helm key / Kubernetes Kind / apiVersion — needs ~70 lines of yaml that grows with every new chart.
  • source:-regex exclusion matching ^\s*"[^"]+":\s* — covers map-key lines but not struct-field-value lines.

All three are workarounds for a knob that already exists in the underlying linter.

Additional context

Supporter

  • I am a sponsor/backer of this project.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions