From 213e413dc0fbac4fef4e66270ccaac21ebe0a5e8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Jun 2026 06:32:40 +0000 Subject: [PATCH 1/2] Initial plan From b0451e94d5cfcca6571e4144bdea997d315bc01d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Jun 2026 06:41:58 +0000 Subject: [PATCH 2/2] fix threshold linter skips and nolint handling Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .../excessivefuncparams.go | 10 +++ .../excessivefuncparams/testdata/src/a/a.go | 3 + .../testdata/src/a/a_test.go | 10 +++ pkg/linters/largefunc/largefunc.go | 8 ++- pkg/linters/largefunc/testdata/src/a/a.go | 65 +++++++++++++++++++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 pkg/linters/excessivefuncparams/testdata/src/a/a_test.go diff --git a/pkg/linters/excessivefuncparams/excessivefuncparams.go b/pkg/linters/excessivefuncparams/excessivefuncparams.go index d805ccdcf6f..a058fd98f7a 100644 --- a/pkg/linters/excessivefuncparams/excessivefuncparams.go +++ b/pkg/linters/excessivefuncparams/excessivefuncparams.go @@ -9,6 +9,8 @@ import ( "golang.org/x/tools/go/analysis/passes/inspect" "github.com/github/gh-aw/pkg/linters/internal/astutil" + "github.com/github/gh-aw/pkg/linters/internal/filecheck" + "github.com/github/gh-aw/pkg/linters/internal/nolint" ) // DefaultMaxParams is the default maximum number of parameters allowed in a function declaration. @@ -36,6 +38,7 @@ func run(pass *analysis.Pass) (any, error) { if err != nil { return nil, err } + noLintLinesByFile := nolint.BuildLineIndex(pass, "excessivefuncparams") nodeFilter := []ast.Node{ (*ast.FuncDecl)(nil), @@ -49,6 +52,10 @@ func run(pass *analysis.Pass) (any, error) { if fn.Type == nil || fn.Type.Params == nil { return } + position := pass.Fset.PositionFor(fn.Name.Pos(), false) + if filecheck.IsTestFile(position.Filename) { + return + } params := 0 for _, field := range fn.Type.Params.List { @@ -60,6 +67,9 @@ func run(pass *analysis.Pass) (any, error) { } if params > maxParams { + if nolint.HasDirective(position, noLintLinesByFile) { + return + } pass.ReportRangef( fn.Name, "%s has %d parameters (limit: %d); consider using an options struct", diff --git a/pkg/linters/excessivefuncparams/testdata/src/a/a.go b/pkg/linters/excessivefuncparams/testdata/src/a/a.go index 768d6c070f9..cc55cb0e183 100644 --- a/pkg/linters/excessivefuncparams/testdata/src/a/a.go +++ b/pkg/linters/excessivefuncparams/testdata/src/a/a.go @@ -7,3 +7,6 @@ func fewParams(a, b, c int) {} // tooManyParams has more than 8 parameters and should be flagged. func tooManyParams(a, b, c, d, e, f, g, h, i int) { // want `tooManyParams has 9 parameters \(limit: 8\); consider using an options struct` } + +//nolint:excessivefuncparams +func suppressedTooManyParams(a, b, c, d, e, f, g, h, i int) {} diff --git a/pkg/linters/excessivefuncparams/testdata/src/a/a_test.go b/pkg/linters/excessivefuncparams/testdata/src/a/a_test.go new file mode 100644 index 00000000000..21a16623b71 --- /dev/null +++ b/pkg/linters/excessivefuncparams/testdata/src/a/a_test.go @@ -0,0 +1,10 @@ +package a + +import "testing" + +func tooManyParamsTestHelper( + t *testing.T, + a, b, c, d, e, f, g, h int, +) { + _ = t +} diff --git a/pkg/linters/largefunc/largefunc.go b/pkg/linters/largefunc/largefunc.go index 4d4deac5f40..59bd184d551 100644 --- a/pkg/linters/largefunc/largefunc.go +++ b/pkg/linters/largefunc/largefunc.go @@ -10,6 +10,7 @@ import ( "github.com/github/gh-aw/pkg/linters/internal/astutil" "github.com/github/gh-aw/pkg/linters/internal/filecheck" + "github.com/github/gh-aw/pkg/linters/internal/nolint" ) // DefaultMaxLines is the default maximum number of lines allowed in a function body. @@ -37,6 +38,7 @@ func run(pass *analysis.Pass) (any, error) { if err != nil { return nil, err } + noLintLinesByFile := nolint.BuildLineIndex(pass, "largefunc") nodeFilter := []ast.Node{ (*ast.FuncDecl)(nil), @@ -63,7 +65,8 @@ func run(pass *analysis.Pass) (any, error) { return } - if filecheck.IsTestFile(pass.Fset.Position(body.Pos()).Filename) { + position := pass.Fset.PositionFor(reportNode.Pos(), false) + if filecheck.IsTestFile(position.Filename) { return } @@ -73,6 +76,9 @@ func run(pass *analysis.Pass) (any, error) { lines := end.Line - start.Line - 1 if lines > maxLines { + if nolint.HasDirective(position, noLintLinesByFile) { + return + } pass.ReportRangef( reportNode, "%s is %d lines long (limit: %d); consider breaking it up", diff --git a/pkg/linters/largefunc/testdata/src/a/a.go b/pkg/linters/largefunc/testdata/src/a/a.go index 64e47b810c1..2ff3ae49959 100644 --- a/pkg/linters/largefunc/testdata/src/a/a.go +++ b/pkg/linters/largefunc/testdata/src/a/a.go @@ -71,3 +71,68 @@ func largeFunc() { // want `largeFunc is 61 lines long \(limit: 60\); consider b _ = 60 _ = 61 } + +//nolint:largefunc +func suppressedLargeFunc() { + _ = 1 + _ = 2 + _ = 3 + _ = 4 + _ = 5 + _ = 6 + _ = 7 + _ = 8 + _ = 9 + _ = 10 + _ = 11 + _ = 12 + _ = 13 + _ = 14 + _ = 15 + _ = 16 + _ = 17 + _ = 18 + _ = 19 + _ = 20 + _ = 21 + _ = 22 + _ = 23 + _ = 24 + _ = 25 + _ = 26 + _ = 27 + _ = 28 + _ = 29 + _ = 30 + _ = 31 + _ = 32 + _ = 33 + _ = 34 + _ = 35 + _ = 36 + _ = 37 + _ = 38 + _ = 39 + _ = 40 + _ = 41 + _ = 42 + _ = 43 + _ = 44 + _ = 45 + _ = 46 + _ = 47 + _ = 48 + _ = 49 + _ = 50 + _ = 51 + _ = 52 + _ = 53 + _ = 54 + _ = 55 + _ = 56 + _ = 57 + _ = 58 + _ = 59 + _ = 60 + _ = 61 +}