Skip to content

chore(lint): hold Promise.reject to the never-throw rule and narrow the inputs exemption - #547

Merged
Vivswan merged 1 commit into
mainfrom
refactor/never-throw-rejections
Oct 11, 2026
Merged

Vivswan merged 1 commit into
mainfrom
refactor/never-throw-rejections

Conversation

@Vivswan

@Vivswan Vivswan commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

What this changes

before: lint/never-throw.grit matches `throw $arg`                      biome.json exempts all of src/cli/inputs.ts
        registry.ts: Promise.reject(error) with no BUG: prefix           (two sites the rule never saw)
after:  the rule matches throw and Promise.reject (untyped, typed, bare)   src/** under the rule; one biome-ignore on
        registry.ts: Promise.reject(new Error(`BUG: ...`)) at each site   commander's InvalidArgumentError throw
$ bun test test/lint/never-throw.test.ts test/sections/registry.test.ts
 39 pass
 0 fail

How

  • A rejection is a throw by another spelling. The GritQL or binds either form to one site and applies the same BUG-literal-or-catch-binding rule.
  • The Error is built where it is rejected, so the rule sees the BUG: prefix in source text; the foreign-context helper now returns the message.
  • The exemption shrinks to one line. biome check . is clean on the whole tree with inputs.ts under the rule.
  • The plugin test proves both halves: six rejection spellings outside the rule are flagged, two inside are not, and the real inputs.ts lints clean until its one suppression line is removed.

Proof

  • Tests: plugin and registry suites pass at 39; before the registry edit the extended rule flagged both rejection sites.
  • Gate: biome check ., typecheck, and knip green.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 08:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The rule misses zero-argument rejections and incorrectly exempts detached catch-binding rejections.

2 open findings
What changed in this PR

Extends the never-throw lint rule to cover Promise.reject and narrows the CLI exemption to one justified throw.

Changes:

  • Adds rejection matching and test fixtures.
  • Marks registry invariant rejections with BUG:.
  • Replaces the file-wide CLI exemption with an inline suppression.
File Description
lint/​never-throw.grit Extends linting to rejected promises.
test/​lint/​never-throw.test.ts Tests rule behavior and suppression scope.
src/​sections/​registry.ts Marks foreign-context rejections as invariants.
src/​cli/​inputs.ts Suppresses the required Commander throw.
biome.json Applies the plugin across all src/**.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lint/never-throw.grit Resolved
Comment thread lint/never-throw.grit Resolved
Copilot AI balanced review requested due to automatic review settings October 11, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Generic Promise.reject<T> calls currently bypass the expanded lint rule.

0 open findings

2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Handle typed Promise.reject calls in the rule

lint/​never-throw.grit:24

Generic Promise.reject calls bypass the rule.

For example, return Promise.reject<void>(new Error("x")); and return Promise.reject<void>(); produce no diagnostic because the typed call has a TsInstantiationExpression; this repository's lint/rule-gate.grit:8-11 already needs separate typed and untyped call patterns for the same reason. Add typed one-argument and zero-argument alternatives, and cover both in the fixture.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 11, 2026 08:51
@Vivswan Vivswan changed the title lint: hold Promise.reject to the never-throw rule and narrow the inputs exemption chore(lint): hold Promise.reject to the never-throw rule and narrow the inputs exemption Oct 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation is consistent with repository policy and covers the new lint behavior with targeted tests.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 11, 2026 08:54
@Vivswan
Vivswan force-pushed the refactor/never-throw-rejections branch from b1ef2e4 to 4c38393 Compare October 11, 2026 08:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The release-pipeline command and managed-label removal are operational changes absent from the stated lint-only scope.

2 open findings

🧠 Review effort: Balanced

Comment thread .github/settings.yml Resolved
Comment thread .github/scripts/release-pipeline.ts Resolved
…he inputs exemption

The plugin matched throw statements alone, so a rejection built without the BUG: prefix passed. The rule now reads Promise.reject beside throw, in the untyped, typed, and zero-argument forms, and the registry's two foreign-context rejections build their Error at the site with the prefix. The whole-file exemption for src/cli/inputs.ts shrinks to one suppression on commander's InvalidArgumentError throw, and the plugin test proves the suppression is live and flags every new rejection form.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 08:58
@Vivswan
Vivswan force-pushed the refactor/never-throw-rejections branch from 4c38393 to e81113c Compare October 11, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The lint expansion, source updates, and focused regression coverage are consistent and complete.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@Vivswan
Vivswan marked this pull request as ready for review October 11, 2026 09:03
@Vivswan
Vivswan merged commit 260d393 into main Oct 11, 2026
31 checks passed
@Vivswan
Vivswan deleted the refactor/never-throw-rejections branch October 11, 2026 21:49
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.

2 participants