Skip to content

[linter-miner] Add ignored local error linter - #76620

Merged
pelikhan merged 6 commits into
mainfrom
copilot/linter-minerignored-local-error
Nov 11, 2026
Merged

pelikhan merged 6 commits into
mainfrom
copilot/linter-minerignored-local-error

Conversation

Copilot AI commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Discarded errors from github.com/github/gh-aw functions can go unnoticed, especially with errcheck disabled. Add a custom analyzer to flag these cases.

  • Detection: Covers bare calls and blank-assigned error results from local and imported module functions; skips generated files and supports //nolint:ignoredlocalerror.
  • Registration and docs: Registers and documents the analyzer; records it as not yet enforced in CI.

For example, both calls are reported when the functions return an error:

ghaw.DoThing()
_, _ = ghaw.Load()

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ignored local error linter [linter-miner] Add ignored local error linter Nov 10, 2026
Copilot AI requested a review from gh-aw-bot November 10, 2026 22:18
@pelikhan
pelikhan marked this pull request as ready for review November 10, 2026 23:21
Copilot AI dynamic review requested due to automatic review settings November 10, 2026 23:21
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

Generated by PR Specification Reviewer for #76620

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Code Quality Reviewer · gpt56 · ~3 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #76620

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions github-actions Bot 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.

What this change does: Adds an analyzer for discarded errors from functions in the gh-aw module and registers it with the linter suite.

One signature lookup can be simplified as noted inline.

Verdict: Ship.
Lean: -8 lines possible.

Generated by ✂️ Ponytail Reviewer for #76620 · codex · routed: gpt61 medium · ~5 AIC · ⌖ ~1 AIC · ⊞ 181
Comment /ponytail to run again

}

var callType types.Type
if selector, isSelector := astutil.UnwrapParenExpr(call.Fun).(*ast.SelectorExpr); isSelector {

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.

Should fix: For calls such as testsupport.Error() and receiver{}.methodError(), TypesInfo.TypeOf(call.Fun) already gives the call signature. Use that lookup for selectors too and remove this branch; it avoids maintaining two paths for the same result and saves 8 lines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified signature lookup to use TypesInfo.TypeOf for all callees while preserving package resolution. Addressed in 6943f8f.

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-10T23:25:01Z
review_event: REQUEST_CHANGES
top_themes: [incomplete AST coverage for discarded calls, concrete error types not recognized]
files_reviewed: [pkg/linters/ignoredlocalerror/ignoredlocalerror.go, pkg/linters/ignoredlocalerror/ignoredlocalerror_test.go]
comment_count: 2

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot 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.

Found two correctness gaps in the new analyzer: several AST forms that discard call results are not traversed, and concrete error implementations are not recognized as error results. These can produce silent false negatives in the linter. Inline comments provide repro patterns and suggested fixes. Review was static; tests were not run per review instructions.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

return signature, ok
}

func isErrorType(t types.Type) bool {

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.

types.Identical only recognizes the builtin error interface. A module function returning a concrete type that implements error (for example *MyError) is still an error result that can be discarded, but _ = f() will be silently missed. Consider checking assignability/implementation against the error interface and add a test case, or document this intentional restriction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched to the shared nolint.ImplementsError helper and added concrete and extended error-type fixtures. Addressed in 6943f8f.

return nil, err
}

nodeFilter := []ast.Node{(*ast.AssignStmt)(nil), (*ast.ExprStmt)(nil)}

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.

This traversal only considers AssignStmt and ExprStmt, so discarded errors in defer ghaw.DoThing(), go ghaw.DoThing(), and blank assignments in declarations such as var _ = ghaw.DoThing() are missed. Those are valid discard forms and can hide exactly the failures this analyzer is intended to catch. Please handle the corresponding AST nodes (or explicitly narrow and document the scope), with regression tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added handling for ValueSpec, defer, and go statements, with regression fixtures for the discarded results. Addressed in 6943f8f.

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (231 new lines in pkg/, above the 100-line threshold) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/76620-add-ignored-local-error-linter.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff

  2. Complete the missing sections — add context the AI could not infer, refine the decision rationale, and list real alternatives you considered

  3. Commit the finalized ADR to docs/adr/ on your branch

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-76620: Flag Discarded Errors from Module-Local Functions (link unavailable: invalid HTTPS URL)

Checked for an existing ADR in the PR body, on the PR branch (docs/adr/), and in linked issue #76567. None was found.

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

🧾 Open items in the draft
  • Verify the current golangci-lint v2 status of the errcheck exclude-functions problem (Alternative 1).
  • Measure how many existing call sites the analyzer would flag (Consequences: Negative).
  • Confirm the deciders and whether the analyzer should be enforced in CI.
❓ Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide? Why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/, numbered by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 8.5K · ◷
Comment /review to run again

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.

🟡 Changes recommended

The analyzer misses discarded errors in explicitly instantiated generic calls, blank-assigned declarations, and results whose declared types implement error but are not the built-in error interface.

3 open issues
1 file not reviewed
  • pkg/linters/ignoredlocalerror/testdata/src/github.com/github/gh-aw/pkg/linters/ignoredlocalerror/generated.go: Generated file
What changed in this PR

Adds ignoredlocalerror to gh-aw’s custom Go analyzers to detect discarded errors from functions within the module.

Changes:

  • Detects bare calls and blank-assigned error results, with generated-file exclusions and nolint support.
  • Adds analyzer tests and fixtures for local functions, methods, and imported functions.
  • Registers and documents the analyzer while deferring CI enforcement.
File Description
pkg/​linters/​spec_test.go Includes the analyzer in documentation checks.
pkg/​linters/​registry.go Registers the analyzer.
pkg/​linters/​README.md Documents the analyzer and its package.
pkg/​linters/​ignoredlocalerror/​testdata/​src/​github.com/​github/​gh-aw/​pkg/​testsupport/​errors.go Provides imported error-returning test functions.
pkg/​linters/​ignoredlocalerror/​testdata/​src/​github.com/​github/​gh-aw/​pkg/​linters/​ignoredlocalerror/​ignoredlocalerror.go Covers detection and suppression cases.
pkg/​linters/​ignoredlocalerror/​testdata/​src/​github.com/​github/​gh-aw/​pkg/​linters/​ignoredlocalerror/​generated.go Verifies generated-file exclusion.
pkg/​linters/​ignoredlocalerror/​ignoredlocalerror.go Implements discarded-error detection.
pkg/​linters/​ignoredlocalerror/​ignoredlocalerror_test.go Runs the analyzer against fixtures.
pkg/​linters/​doc.go Updates the analyzer catalog and count.
pkg/​linters/​doc_sync_test.go Records deferred CI enforcement.

Review effort: Balanced (auto)

Comment on lines +29 to +32
nodeFilter := []ast.Node{(*ast.AssignStmt)(nil), (*ast.ExprStmt)(nil)}
return analyzerutil.Preorder(pass, nodeFilter, func(n ast.Node) {
analyzeStmt(pass, n, generatedFiles, nolintIndex)
})
}

func callSignature(pass *analysis.Pass, call *ast.CallExpr) (*types.Signature, bool) {
pkgPath, _, ok := astutil.PackageCall(pass, call)
}

func isErrorType(t types.Type) bool {
return types.Identical(t, types.Universe.Lookup("error").Type())

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs, /tdd, /codebase-design and /grill-with-docs. Requesting changes on one correctness gap (generic calls) and missing test coverage.

📋 Key Themes & Highlights

Key Themes

  • Correctness: generic calls such as pkg.F[int]() that return error are silently missed (false negative), because callSignature does not unwrap IndexExpr/IndexListExpr.
  • Test coverage: the multi-value blank assign, parenthesised calls and generic calls have no // want cases.
  • Reuse: isErrorType duplicates nolint.ImplementsError / astutil.UniverseErrorInterface().
  • Docs: ignoredlocalerror is in notYetEnforced but missing from the README "excluded from CI enforcement" notes.

Positive Highlights

  • ✅ Clean, self-contained analyzer with nolint and generated-file skip support.
  • ✅ Registry, doc.go count (94 to 95) and README analyzer entries are consistent for ignoredlocalerror.
  • ✅ TestAnalyzer passes, and gofmt is clean.

Notes on Scope

  • pr-triage was unavailable, so skill selection used the fallback heuristic on pr-meta.json and the diff.
  • TestDocGo_AnalyzersMatchREADME and TestDocSurfacesMatchRegistryAndSpecList fail on five analyzers this PR does not touch (deferrerrorunchecked, reflectdeepequalusage, unchecked_deferredclose, uncheckedsliceindex, walkdirignoredeerror). ignoredlocalerror itself matches all surfaces. This looks like pre-existing drift, but I did not confirm it against the base commit.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~8 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again

func callSignature(pass *analysis.Pass, call *ast.CallExpr) (*types.Signature, bool) {
pkgPath, _, ok := astutil.PackageCall(pass, call)
if !ok {
if selector, isSelector := astutil.UnwrapParenExpr(call.Fun).(*ast.SelectorExpr); isSelector {

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.

[/diagnosing-bugs] Generic calls are not flagged. A probe with testsupport.Generic[int]() (an ExprStmt that returns only error) produced no diagnostic, so this is a false negative. For an instantiated call, call.Fun is an *ast.IndexExpr, not an *ast.SelectorExpr, so the selector lookup at lines 101-107 never resolves the package path.

💡 Suggested fix

Unwrap instantiation before the selector check, then add a // want case for Generic[int]() to the testdata:

func unwrapInstantiation(expr ast.Expr) ast.Expr {
	switch e := astutil.UnwrapParenExpr(expr).(type) {
	case *ast.IndexExpr:
		return e.X
	case *ast.IndexListExpr:
		return e.X
	}
	return expr
}

Apply it wherever astutil.UnwrapParenExpr(call.Fun) feeds the selector lookup in callSignature.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Package lookup now unwraps IndexExpr and IndexListExpr, while signature lookup uses the instantiated callee. Regression fixtures cover both forms. Addressed in 6943f8f.

}

func isErrorType(t types.Type) bool {
return types.Identical(t, types.Universe.Lookup("error").Type())

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.

[/codebase-design] isErrorType re-implements error detection that already exists in nolint.ImplementsError (pkg/linters/internal/nolint/nolint.go) and astutil.UniverseErrorInterface(). Sharing one helper keeps error-type semantics consistent across analyzers. Check semantics before swapping: types.Identical here is stricter than an Implements check and may treat named error types differently.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Error result checks now use the shared nolint.ImplementsError helper. Added concrete and extended error-type coverage. Addressed in 6943f8f.


func badCalls() {
localError() // want `error return from a github.com/github/gh-aw function is discarded`
_, _ = localResult() // want `error return from a github.com/github/gh-aw function is discarded`

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.

[/tdd] Several discard shapes are flagged but not pinned by any test: the multi-value blank assign a, _ = 1, testsupport.Error(), the parenthesised (testsupport.Error()) statement, and the generic call covered above. Add each as a // want case. The first two should pass on the current code. The generic case will fail until the false negative is fixed. Without these cases, a refactor of the len(rhs) branch or of callSignature could change behaviour unnoticed.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added regression cases for the multi-value blank assignment and parenthesized call, alongside the generic-call cases. Addressed in 6943f8f.

"fprintferrorunchecked": "existing production violations need remediation before enforcement; nolint suppression already works",
"goroutineresourceleak": "requires an enforcement-readiness audit before native and WebAssembly CI enable it",
"hardcodedfilepath": "requires an enforcement audit after the same-package constant fix (#52428)",
"ignoredlocalerror": "existing ignored local errors need review before CI enforcement",

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.

[/grill-with-docs] ignoredlocalerror is parked in notYetEnforced with the reason: existing ignored local errors need review before CI enforcement. The "excluded from CI enforcement" notes in pkg/linters/README.md (around lines 459-461) do not mention it, while the peer entries typeassertionnil, unchecked_deferredclose and walkdirignoredeerror each have a bullet there. Add one for consistency, naming the same blocker.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the excluded-from-CI note for ignoredlocalerror with the existing-error review blocker. Addressed in 6943f8f.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/linters/ignoredlocalerror/ignoredlocalerror.go:113): address unresolved feedback - Review comment
  3. Review (pkg/linters/ignoredlocalerror/ignoredlocalerror.go:125): address unresolved feedback - Review comment
  4. Review (pkg/linters/ignoredlocalerror/ignoredlocalerror.go:29): address unresolved feedback - Review comment
  5. Review (pkg/linters/ignoredlocalerror/ignoredlocalerror.go:101): address unresolved feedback - Review comment
  6. Review (pkg/linters/ignoredlocalerror/ignoredlocalerror.go:126): address unresolved feedback - Review comment
  7. Review (pkg/linters/ignoredlocalerror/testdata/src/github.com/github/gh-aw/pkg/linters/ignoredlocalerror/ignoredlocalerror.go:26): address unresolved feedback - Review comment
  8. Review (pkg/linters/doc_sync_test.go:41): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "8daa5233fa11f028a7513ca2c7ad6a187a36a515",
  "kind": "requested",
  "schema_version": "1",
  "state": "03020d3e0f59b52d424bf1cd46f7164bdee7eb68d53cb7a8774af0ee056910f2",
  "work": [
    "0fb829fcc365175db5780590ce32fd2f22b484bb05518ab5d1960672fb09d852",
    "31d9aeffd180a945244cd1e032eb73358bef3b5909ede172e70195df823075e0",
    "43b3dc21dbb0041c93400316c8bd040441d4296fa5974f2d6e620d42e507463e",
    "5619f039459fec101ee27c968fe851323467193e53c741bbe8990d76bae32cf4",
    "739532412c31b38a15aa0587973fea60d2003310979e39bde6559f0275c2f8e8",
    "d73a27c32bc30166fcb2403098ceac525b82a736606d5f422c1bb24b041885fa",
    "dbb513dce94086a1d4f70f5270a6871134826a2c3d342cda07205b85052fdb60"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 6.9K · ◷
Comment /souschef to run again

@github-actions

Copy link
Copy Markdown
Contributor

Category: feature | Risk: medium | Score: 58 (impact 31 + urgency 15 + quality 12) | Action: batch_review | Batch: pr-batch:eligible-copilot

Generated by 🔧 PR Triage Agent · copilot · mai11 · ~5 AIC · ⌖ ~1 AIC · ⊞ 14.9K · ◷

Copilot AI and others added 3 commits November 11, 2026 00:46
…gnored-local-error

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Merged main with make merge-main and addressed the linked feedback in 6943f8f; d97d9a3 resolves the final custom-linter bounds-check finding. The final repository gate passed. CodeQL timed out and was not retried.

@pelikhan
pelikhan merged commit 56e6bb1 into main Nov 11, 2026
109 checks passed
@pelikhan
pelikhan deleted the copilot/linter-minerignored-local-error branch November 11, 2026 02:46
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[linter-miner] Add ignored local error linter

4 participants