From e254e224fa017cdf75537e8aa3dbf51243142084 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Jul 2026 04:33:23 +0000 Subject: [PATCH] Add debug logging to custom Go analysis linters --- pkg/linters/errormessage/errormessage.go | 7 +++++++ pkg/linters/hardcodedfilepath/hardcodedfilepath.go | 6 ++++++ pkg/linters/internal/filecheck/filecheck.go | 6 ++++++ pkg/linters/internal/nolint/nolint.go | 6 ++++++ .../jsonmarshalignoredeerror/jsonmarshalignoredeerror.go | 5 +++++ 5 files changed, 30 insertions(+) diff --git a/pkg/linters/errormessage/errormessage.go b/pkg/linters/errormessage/errormessage.go index 48e31e6cb1e..2557a55979f 100644 --- a/pkg/linters/errormessage/errormessage.go +++ b/pkg/linters/errormessage/errormessage.go @@ -15,8 +15,11 @@ 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" + "github.com/github/gh-aw/pkg/logger" ) +var pkgLog = logger.New("linters:errormessage") + var ( // changedFilesCSV allows CI to scope linting to changed files only, // preventing legacy violations from blocking incremental adoption. @@ -39,8 +42,10 @@ func init() { func run(pass *analysis.Pass) (any, error) { changed := parseChangedFiles(changedFilesCSV) if len(changed) == 0 { + pkgLog.Printf("no changed files provided for %s, skipping", pass.Pkg.Path()) return nil, nil } + pkgLog.Printf("analyzing package %s (%d changed files)", pass.Pkg.Path(), len(changed)) insp, err := astutil.Inspector(pass) if err != nil { @@ -150,11 +155,13 @@ func checkNegativeLanguage(pass *analysis.Pass, call *ast.CallExpr, msg string) if containsAnyWholeWord(lower, "expected", "requires", "should", "example", "valid") { return } + pkgLog.Printf("flagging negative-language error message: %q", msg) pass.ReportRangef(call, "error message uses negative language without constructive guidance; include expected/requires/should/example details") } func checkNewValidationSuggestion(pass *analysis.Pass, call *ast.CallExpr) { if len(call.Args) < 4 { + pkgLog.Printf("flagging NewValidationError call with %d args, missing suggestion", len(call.Args)) pass.ReportRangef(call, "NewValidationError(...) should include a non-empty suggestion with an example") return } diff --git a/pkg/linters/hardcodedfilepath/hardcodedfilepath.go b/pkg/linters/hardcodedfilepath/hardcodedfilepath.go index 1d2db6b395e..4e5a17eff4e 100644 --- a/pkg/linters/hardcodedfilepath/hardcodedfilepath.go +++ b/pkg/linters/hardcodedfilepath/hardcodedfilepath.go @@ -26,8 +26,11 @@ 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" + "github.com/github/gh-aw/pkg/logger" ) +var pkgLog = logger.New("linters:hardcodedfilepath") + // Analyzer is the hardcoded-file-path analysis pass. var Analyzer = &analysis.Analyzer{ Name: "hardcodedfilepath", @@ -210,6 +213,7 @@ func collectKnownPathConsts(pass *analysis.Pass) map[string]constRef { } } + pkgLog.Printf("collected %d known path constants", len(out)) return out } @@ -246,6 +250,7 @@ func run(pass *analysis.Pass) (any, error) { return nil, err } knownConsts := collectKnownPathConsts(pass) + pkgLog.Printf("analyzing package %s (%d known path constants)", pass.Pkg.Path(), len(knownConsts)) for cur := range insp.Root().Preorder((*ast.BasicLit)(nil)) { checkHardcodedFilePath(pass, cur, generatedFiles, noLintIndex, knownConsts) @@ -278,6 +283,7 @@ func checkHardcodedFilePath(pass *analysis.Pass, cur inspector.Cursor, generated return } inLog := enclosingCallIsLogPrint(pass, cur) + pkgLog.Printf("flagging hardcoded path %q (in log/print call=%v)", raw, inLog) if ref, found := knownConsts[raw]; found { msg := fmt.Sprintf( "hard-coded file path %q: use constant %s instead of inline string literal", diff --git a/pkg/linters/internal/filecheck/filecheck.go b/pkg/linters/internal/filecheck/filecheck.go index df99c76ece9..297bafbcd19 100644 --- a/pkg/linters/internal/filecheck/filecheck.go +++ b/pkg/linters/internal/filecheck/filecheck.go @@ -8,8 +8,12 @@ import ( "strings" "golang.org/x/tools/go/analysis" + + "github.com/github/gh-aw/pkg/logger" ) +var pkgLog = logger.New("linters:filecheck") + // GeneratedIndex records generated Go source files by filename. type GeneratedIndex map[string]struct{} @@ -36,6 +40,7 @@ func Index(pass *analysis.Pass) (GeneratedIndex, error) { // BuildGeneratedIndex returns the set of generated Go source files in pass. func BuildGeneratedIndex(pass *analysis.Pass) GeneratedIndex { + pkgLog.Printf("building generated-file index for %s (%d files)", pass.Pkg.Path(), len(pass.Files)) generated := make(GeneratedIndex) for _, file := range pass.Files { if !ast.IsGenerated(file) { @@ -55,6 +60,7 @@ func BuildGeneratedIndex(pass *analysis.Pass) GeneratedIndex { generated[adjustedFilename] = struct{}{} } } + pkgLog.Printf("indexed %d generated files", len(generated)) return generated } diff --git a/pkg/linters/internal/nolint/nolint.go b/pkg/linters/internal/nolint/nolint.go index 18b18445bce..2b42588a0bd 100644 --- a/pkg/linters/internal/nolint/nolint.go +++ b/pkg/linters/internal/nolint/nolint.go @@ -10,8 +10,12 @@ import ( "strings" "golang.org/x/tools/go/analysis" + + "github.com/github/gh-aw/pkg/logger" ) +var pkgLog = logger.New("linters:nolint") + // DirectiveIndex records nolint directives by filename, line, and linter name. type DirectiveIndex map[string]map[int]map[string]struct{} @@ -39,6 +43,7 @@ func Index(pass *analysis.Pass) (DirectiveIndex, error) { // BuildDirectiveIndex scans all comments in the analysis pass and returns a map // from filename → line → set of linter names that carry a nolint directive. func BuildDirectiveIndex(pass *analysis.Pass) DirectiveIndex { + pkgLog.Printf("building nolint directive index for %s (%d files)", pass.Pkg.Path(), len(pass.Files)) noLintLinesByFile := make(DirectiveIndex, len(pass.Files)) for _, file := range pass.Files { filename := pass.Fset.PositionFor(file.Pos(), false).Filename @@ -75,6 +80,7 @@ func BuildDirectiveIndex(pass *analysis.Pass) DirectiveIndex { } } } + pkgLog.Printf("indexed nolint directives in %d files", len(noLintLinesByFile)) return noLintLinesByFile } diff --git a/pkg/linters/jsonmarshalignoredeerror/jsonmarshalignoredeerror.go b/pkg/linters/jsonmarshalignoredeerror/jsonmarshalignoredeerror.go index 9935ae603e0..a3e1b8d0288 100644 --- a/pkg/linters/jsonmarshalignoredeerror/jsonmarshalignoredeerror.go +++ b/pkg/linters/jsonmarshalignoredeerror/jsonmarshalignoredeerror.go @@ -11,8 +11,11 @@ import ( "github.com/github/gh-aw/pkg/linters/internal/astutil" "github.com/github/gh-aw/pkg/linters/internal/nolint" + "github.com/github/gh-aw/pkg/logger" ) +var pkgLog = logger.New("linters:jsonmarshalignoredeerror") + // Analyzer is the json-marshal-ignored-error analysis pass. var Analyzer = &analysis.Analyzer{ Name: "jsonmarshalignoredeerror", @@ -23,6 +26,7 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (any, error) { + pkgLog.Printf("analyzing package %s", pass.Pkg.Path()) insp, err := astutil.Inspector(pass) if err != nil { return nil, err @@ -86,6 +90,7 @@ func reportDiscardedJSONCall(pass *analysis.Pass, call *ast.CallExpr, noLintInde if nolint.HasDirectiveForLinter(position, noLintIndex, "jsonmarshalignoredeerror") { return } + pkgLog.Printf("flagging discarded json error at %s:%d", position.Filename, position.Line) pass.ReportRangef(call, "%s", message) }