Skip to content

Add unchecked os cleanup analyzer - #75765

Merged
pelikhan merged 4 commits into
mainfrom
copilot/linter-mineros-remove-unchecked-cleanup-analyzer
Nov 8, 2026
Merged

pelikhan merged 4 commits into
mainfrom
copilot/linter-mineros-remove-unchecked-cleanup-analyzer

Conversation

Copilot AI commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Bare os.Remove and os.RemoveAll calls can silently discard cleanup errors. This adds a type-aware analyzer that reports those calls while allowing handled or returned errors, deferred calls, and matching nolint directives.

  • Rule: Match standard-library functions by resolved package, including aliased imports; ignore same-named methods from other packages.
  • Scope: Cover bare calls and _ = assignments. Register and document the analyzer without enabling CI enforcement.
  • Example:
os.Remove(path) // reported

if err := os.Remove(path); err != nil {
    return err
}
defer os.Remove(path) // not reported

Copilot AI changed the title [WIP] Add os-remove-unchecked-cleanup analyzer Add unchecked os cleanup analyzer Nov 7, 2026
Copilot AI requested a review from gh-aw-bot November 7, 2026 23:50
@pelikhan
pelikhan marked this pull request as ready for review November 7, 2026 23:52
Copilot AI adaptive review requested due to automatic review settings November 7, 2026 23:52
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #75765

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 7, 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: gpt56 max · ~1 AIC · ⌖ ~2 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

🔎 PR Code Quality Reviewer is reviewing code quality for this pull request...

@github-actions

github-actions Bot commented Nov 7, 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 · ~1 AIC · ⌖ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #75765

@github-actions

github-actions Bot commented Nov 7, 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 a type-aware analyzer for discarded errors from os.Remove and os.RemoveAll. It registers and documents the analyzer and adds analysis fixtures for handled calls, aliases, deferred calls, and suppressions.

Should fix:

  1. One-element slices are traversed with loops (pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go:45-59)

    • What this is: The length checks guarantee exactly one left- and right-hand expression.
    • Problem: The two loops, temporary expressions, and break statements add control flow that cannot do more than one iteration.
    • Fix: Index stmt.Lhs[0] and stmt.Rhs[0] directly, using the existing (nolint/redacted):uncheckedsliceindex convention for checked indexes.
    • If we skip it: This matcher is harder to read and maintain than the equivalent direct extraction.
  2. A known package name is normalized through path.Base (pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go:80)

    • What this is: The preceding condition has already narrowed pkgPath to the literal os.
    • Problem: Calling path.Base and importing path add machinery without changing the result.
    • Fix: Report os.%s directly and remove the import.
    • If we skip it: A fixed string continues to take an indirect path through a general-purpose helper.

Not checked: Correctness, security, performance, and generated or lock-file changes were outside this complexity-only review.

Verdict: fix 1 and 2 first.
Lean: -9 lines possible.

Generated by ✂️ Ponytail Reviewer for #75765 · codex · routed: gpt56 max · ~4 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again

return
}
var lhs ast.Expr
for _, expr := range stmt.Lhs {

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.

Ponytail: stmt.Lhs and stmt.Rhs are proven to have one element at lines 42-43, so these one-iteration loops and temporary variables add needless control flow; use [0] with the repository standard (nolint/redacted):uncheckedsliceindex guard to remove it.

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.

Replaced the single-element loops with bounds-guarded direct indexing in 517ef28.

return
}

pass.ReportRangef(call, "error return from %s.%s is discarded; cleanup failures may be silently ignored", path.Base(pkgPath), funcName)

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.

Ponytail: pkgPath was just narrowed to the literal "os" on line 68, so path.Base(pkgPath) and the path import add no behavior; report "os.%s" directly and delete the import.

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.

Removed the redundant path import and report os.%s directly in 517ef28.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Warning

The push_to_pull_request_branch operation failed: Cannot verify branch protection rules for "copilot/linter-mineros-remove-unchecked-cleanup-analyzer": Resource not accessible by integration - https://docs.github.com/rest/branches/branch-protection\#get-branch-protection. Reading classic branch protection requires a GitHub App installation token or fine-grained PAT with Administration: read repository permission; GITHUB_TOKEN cannot provide this permission. Push blocked to prevent accidental writes to protected branches.. The code changes were not applied.

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR).

Evidence: the gate summary records 163 new lines in default business directories, and the diff adds the pkg/linters/osremoveuncheckedcleanup analyzer plus registry and documentation changes. No ADR is linked in the PR body, and linked issue #73905 does not contain the four required ADR sections.

📄 Draft ADR committed: docs/adr/75765-add-os-remove-unchecked-cleanup-analyzer.md (link unavailable: invalid HTTPS URL) — 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-75765: Add an Unchecked os Cleanup Analyzer (link unavailable: invalid HTTPS URL)

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

❓ Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. They make significant design trade-offs reviewable for future contributors.

📋 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/ as Markdown files numbered by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: gpt56 max · ~3 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷
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 linter misses discarded cleanup errors in multi-value assignments and assignments to parenthesized blank targets.

2 open issues
What changed in this PR

Adds a type-aware cleanup-error analyzer to gh-aw’s custom Go linters, while leaving CI enforcement disabled pending remediation of existing findings.

Changes:

  • Detects bare and blank-assigned os.Remove and os.RemoveAll calls using resolved package information.
  • Adds fixtures for discarded, handled, returned, deferred, and suppressed errors, plus unrelated same-named methods.
  • Registers the analyzer and updates documentation and consistency tests.
File Description
pkg/​linters/​spec_test.go Adds the analyzer to documentation specification checks.
pkg/​linters/​registry.go Registers the analyzer.
pkg/​linters/​README.md Documents the rule and package.
pkg/​linters/​osremoveuncheckedcleanup/​testdata/​src/​osremoveuncheckedcleanup/​other/​cleanup.go Supplies unrelated methods for false-positive checks.
pkg/​linters/​osremoveuncheckedcleanup/​testdata/​src/​osremoveuncheckedcleanup/​osremoveuncheckedcleanup.go Adds diagnostic and exemption fixtures.
pkg/​linters/​osremoveuncheckedcleanup/​osremoveuncheckedcleanup.go Implements cleanup-error detection and suppression handling.
pkg/​linters/​osremoveuncheckedcleanup/​osremoveuncheckedcleanup_test.go Runs the analyzer’s fixture tests.
pkg/​linters/​doc.go Updates the analyzer catalog and count.
pkg/​linters/​doc_sync_test.go Records the deferred CI enforcement status.

Review effort: Balanced (auto)

Comment on lines +42 to +43
if len(stmt.Lhs) != 1 || len(stmt.Rhs) != 1 {
return
lhs = expr
break
}
blank, ok := lhs.(*ast.Ident)

@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 /tdd, /grill-with-docs, and /codebase-design. No blocking issues. Two small follow-ups are left as inline comments.

📋 Verification and key themes

Verification

  • go test ./pkg/linters/osremoveuncheckedcleanup/ passes.
  • go test ./pkg/linters/ passes, including the doc-sync and spec tests.
  • go vet is clean.
  • Running the new analyzer over ./pkg/... and ./cmd/... reports 24 real findings. This supports the notYetEnforced rationale in doc_sync_test.go, which says remediation is needed before CI enforcement.
  • cgo.yml passes explicit LINTER_FLAGS lists that exclude the new analyzer, so it is not enforced in CI, as intended.

Key themes

  • Documentation count drift: the spec_test.go prose comment still says 88. The table and documentedAnalyzers() list 89. The sync test passes because it compares lists, not prose.
  • Readability: the single-element for ... break loops in analyzeDiscardedCleanup can be stmt.Lhs[0] and stmt.Rhs[0].

Positive highlights

  • ✅ Test data covers aliased imports, parenthesised calls, _ =, handled, returned, deferred, same-named methods on other types, and nolint suppression.
  • ✅ Method-name collisions are correctly rejected through *types.Func package matching.
  • ✅ Registration in registry.go, doc.go, and the README is consistent with the sibling osexitinlibrary pattern.

Not covered

  • go os.Remove(path) (a GoStmt) has no testdata case. The current ExprStmt filter ignores it, which matches the defer exemption, so a case would document the intent.

@copilot please address the review comments above.

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

return
}
var lhs ast.Expr
for _, expr := range stmt.Lhs {

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] The for _, expr := range stmt.Lhs { lhs = expr; break } loop is an indirect way to take the only element of a slice. The len(...) != 1 guard above already ensures there is exactly one element, so stmt.Lhs[0] says the same thing more directly. The same applies to the stmt.Rhs loop at lines 55–58.

@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.

Replaced the single-element loops with bounds-guarded direct indexing in 517ef28.

Comment thread pkg/linters/spec_test.go Outdated

// documentedAnalyzers returns the analyzer subpackages documented in the README
// "Public API > Subpackages" table. The README documents 87 analyzer
// "Public API > Subpackages" table. The README documents 88 analyzer

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] Stale count: this comment says the README documents 88 analyzer subpackages, but the README Subpackages table and documentedAnalyzers() both list 89 analyzers (the internal helper row is the only exclusion). This PR moves the figure from 87 to 88 while the list grows to 89, so update it to 89 to match what the sync test enforces.

@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.

Updated the documented analyzer count to 89 in 517ef28.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

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/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go:46): Ponytail: stmt.Lhs and stmt.Rhs are proven to have one element at lines 42-43, so these one-iteration loops and temporary variables add needless control flow; use [0] with the repository standard (nolint/redacted):uncheckedsliceindex guard to remove it. - Add unchecked os cleanup analyzer #75765 (comment)
  3. Review (pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go:80): Ponytail: pkgPath was just narrowed to the literal "os" on line 68, so path.Base(pkgPath) and the path import add no behavior; report "os.%s" directly and delete the import. - Add unchecked os cleanup analyzer #75765 (comment)
  4. Review (pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go:46): [/codebase-design] The for _, expr := range stmt.Lhs { lhs = expr; break } loop is an indirect way to take the only element of a slice. The len(...) != 1 guard above already ensures there is exactly one element, so stmt.Lhs[0] says the same thing more directly. The same applies to the stmt.Rhs loop at lines 55–58. - Add unchecked os cleanup analyzer #75765 (comment)
  5. Review (pkg/linters/spec_test.go:118): [/grill-with-docs] Stale count: this comment says the README documents 88 analyzer subpackages, but the README Subpackages table and documentedAnalyzers() both list 89 analyzers (the internal helper row is the only exclusion). This PR moves the figure from 87 to 88 while the list grows to 89, so update it to 89 to match what the sync test enforces. - Add unchecked os cleanup analyzer #75765 (comment)
  6. Fix failing check conclusion (FAILURE): https://github.com/github/gh-aw/actions/runs/42427197436/job/128569415898.
  7. Fix failing check safe_outputs (FAILURE): https://github.com/github/gh-aw/actions/runs/42427197477/job/128569253749.

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: 0a7f491
Sous-chef requested-work: 10c12c7188c890e79bfff8fa2b38b8702379a0a12f3c70d736d0361ea18afa44 21780173ed562161ad68d4dc3fee27ffe4f03428ea548bc250e99d50d1e6d983 51e2287c3d1ee41b7e13769862add61dcd292a623cf943abc5968c984e246bcf 9fc6edbe97ad26cf0f08f967fedcdea809a079bb2c10543a2da676c878eef330 a50f8500311e5955a120d185d17a51422c92d4784fcd5c197dbec0a337dd9b30 c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: d79cfed2fde9d38810e5f8ee8b314c8c5493495d66193f2e912be83f220bd45f

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~13 AIC · ⌖ ~19 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot assignment requested for the following outstanding work:...

Sous-chef requested-head: 0a7f491
Sous-chef requested-work: 10c12c7188c890e79bfff8fa2b38b8702379a0a12f3c70d736d0361ea18afa44 21780173ed562161ad68d4dc3fee27ffe4f03428ea548bc250e99d50d1e6d983 51e2287c3d1ee41b7e13769862add61dcd292a623cf943abc5968c984e246bcf a50f8500311e5955a120d185d17a51422c92d4784fcd5c197dbec0a337dd9b30 c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: d79cfed2fde9d38810e5f8ee8b314c8c5493495d66193f2e912be83f220bd45f

Copilot AI and others added 2 commits November 8, 2026 00:55
@pelikhan
pelikhan merged commit 1a8585c into main Nov 8, 2026
46 checks passed
@pelikhan
pelikhan deleted the copilot/linter-mineros-remove-unchecked-cleanup-analyzer branch November 8, 2026 01:32
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

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.

[linter-miner] Add os-remove-unchecked-cleanup analyzer

4 participants