Skip to content

tools: add lint rule for aborted AbortController#63541

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:eslint-abort-signal-abort
Open

tools: add lint rule for aborted AbortController#63541
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:eslint-abort-signal-abort

Conversation

@trivikr
Copy link
Copy Markdown
Member

@trivikr trivikr commented May 24, 2026

This adds an ESLint rule to prefer AbortSignal.abort() when a test creates an
AbortController, immediately aborts it, and only uses the resulting
controller.signal.

The rule is intentionally conservative and only fixes the simple already-aborted
signal pattern from #63489.


The rule uses ESLint scope analysis rather than text matching. After finding a
candidate declaration, it gets the declared variable with
sourceCode.scopeManager.getDeclaredVariables() and checks all references to
that variable.

It only reports when the variable has exactly two non-declaration references:

  1. the immediate controller.abort() call
  2. one controller.signal read

If the controller is logged, passed somewhere else, aborted later, read more than
once, or otherwise referenced, the rule does not report or autofix it.


Assisted-by: openai:gpt-5.5

@trivikr trivikr requested a review from aduh95 May 24, 2026 16:14
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/quic

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. tools Issues and PRs related to the tools directory. labels May 24, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.33%. Comparing base (c55b126) to head (2cd59c6).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63541      +/-   ##
==========================================
+ Coverage   90.26%   90.33%   +0.06%     
==========================================
  Files         730      730              
  Lines      234004   234161     +157     
  Branches    43829    43909      +80     
==========================================
+ Hits       211223   211519     +296     
+ Misses      14502    14385     -117     
+ Partials     8279     8257      -22     

see 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label May 24, 2026
Refs: nodejs#63489

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
@trivikr trivikr force-pushed the eslint-abort-signal-abort branch from 55470dd to 2cd59c6 Compare May 25, 2026 01:44
Comment on lines +164 to +165
const signal = AbortSignal.abort('reason');
assert.strictEqual(signal.reason, 'reason');
Copy link
Copy Markdown
Contributor

@aduh95 aduh95 May 25, 2026

Choose a reason for hiding this comment

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

This is testing AbortController (see the file name), not AbortSignal; it should be reverted and excluded via a // eslint-disable-next-line comment

Comment on lines +18 to +23
`
const controller = new AbortController();
controller.abort();
controller.abort();
fn(controller.signal);
`,
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.

For readability sake, let's indent

Suggested change
`
const controller = new AbortController();
controller.abort();
controller.abort();
fn(controller.signal);
`,
`
const controller = new AbortController();
controller.abort();
controller.abort();
fn(controller.signal);
`,

Comment on lines +25 to +27
const controller = new AbortController();
controller.abort();
fn(controller.signal, controller.signal);
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.

ditto, and why is this a valid case?

Comment on lines +121 to +122
if (references.length !== 2 ||
signalReferences.length !== 1 ||
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.

Suggested change
if (references.length !== 2 ||
signalReferences.length !== 1 ||
if (references.length !== (1 + signalReferences.length) ||

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

Labels

needs-ci PRs that need a full CI run. request-ci Add this label to start a Jenkins CI on a PR. tools Issues and PRs related to the tools directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants