Skip to content

Align threshold linters with sibling analyzer behavior#40740

Merged
pelikhan merged 2 commits into
mainfrom
copilot/fix-excessivefuncparams-linter
Jun 22, 2026
Merged

Align threshold linters with sibling analyzer behavior#40740
pelikhan merged 2 commits into
mainfrom
copilot/fix-excessivefuncparams-linter

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

excessivefuncparams was the only FuncDecl-based linter still analyzing _test.go, and neither excessivefuncparams nor largefunc supported per-site //nolint suppression. That made both threshold linters noisy in tests and hard to enforce without weakening global limits.

  • Analyzer behavior

    • excessivefuncparams now skips _test.go, matching the existing behavior of sibling FuncDecl linters.
    • excessivefuncparams now honors //nolint:excessivefuncparams.
    • largefunc now honors //nolint:largefunc.
  • Implementation shape

    • Wired both analyzers to the shared internal/nolint helpers (BuildLineIndex / HasDirective) used elsewhere in pkg/linters.
    • Gated reports on the resolved source position so threshold violations can be suppressed at the declaration site without changing analyzer-wide thresholds.
  • Analysistest coverage

    • Added a _test.go fixture for excessivefuncparams to assert test helpers are ignored.
    • Added suppression fixtures for both analyzers to assert //nolint prevents diagnostics while unsuppressed cases still report.
//nolint:excessivefuncparams
func suppressedTooManyParams(a, b, c, d, e, f, g, h, i int) {}

//nolint:largefunc
func suppressedLargeFunc() {
	// body intentionally over threshold
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix excessivefuncparams linter to skip test files and honor nolint directives Align threshold linters with sibling analyzer behavior Jun 22, 2026
Copilot AI requested a review from pelikhan June 22, 2026 06:43
@github-actions github-actions Bot mentioned this pull request Jun 22, 2026
@pelikhan pelikhan marked this pull request as ready for review June 22, 2026 14:15
Copilot AI review requested due to automatic review settings June 22, 2026 14:15
@pelikhan pelikhan merged commit 2fd1791 into main Jun 22, 2026
@pelikhan pelikhan deleted the copilot/fix-excessivefuncparams-linter branch June 22, 2026 14:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Aligns the excessivefuncparams and largefunc threshold linters with other FuncDecl-based analyzers by reducing noise in _test.go and enabling per-declaration //nolint suppression.

Changes:

  • Skip _test.go files in excessivefuncparams to match sibling analyzers’ behavior.
  • Add //nolint:<linter> directive support for both excessivefuncparams and largefunc via shared internal/nolint helpers.
  • Extend analysistest fixtures to cover _test.go skipping and suppression behavior.
Show a summary per file
File Description
pkg/linters/largefunc/largefunc.go Adds nolint directive handling and uses source positions for suppression and test-file skipping.
pkg/linters/largefunc/testdata/src/a/a.go Adds a suppressed large function fixture to validate //nolint:largefunc.
pkg/linters/excessivefuncparams/excessivefuncparams.go Skips _test.go and adds nolint suppression for excessive parameter diagnostics.
pkg/linters/excessivefuncparams/testdata/src/a/a.go Adds a suppressed excessive-params fixture to validate //nolint:excessivefuncparams.
pkg/linters/excessivefuncparams/testdata/src/a/a_test.go Adds a _test.go fixture to ensure the analyzer ignores test helpers.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 2

Comment on lines +68 to 71
position := pass.Fset.PositionFor(reportNode.Pos(), false)
if filecheck.IsTestFile(position.Filename) {
return
}
Comment on lines +55 to +58
position := pass.Fset.PositionFor(fn.Name.Pos(), false)
if filecheck.IsTestFile(position.Filename) {
return
}
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.

3 participants