Skip to content

feat(linter): implement n/handle-callback-err rule#19616

Merged
camc314 merged 9 commits intooxc-project:mainfrom
baevm:n/handle_callback_error
Mar 12, 2026
Merged

feat(linter): implement n/handle-callback-err rule#19616
camc314 merged 9 commits intooxc-project:mainfrom
baevm:n/handle_callback_error

Conversation

@baevm
Copy link
Contributor

@baevm baevm commented Feb 22, 2026

this PR implements n/handle-callback-err rule, passes all tests from original rule

issue #493

@baevm baevm requested a review from camc314 as a code owner February 22, 2026 09:50
Copilot AI review requested due to automatic review settings February 22, 2026 09:50
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Feb 22, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the n/handle-callback-err rule from eslint-plugin-n, which enforces proper error handling in Node.js callback functions. The rule checks whether the first parameter of a function (typically named "err" or "error") is referenced within the function body, helping developers avoid forgetting to handle errors in callback patterns.

Changes:

  • Implements the HandleCallbackErr rule with configurable pattern matching (plain string or regex) for identifying error parameters
  • Adds comprehensive test coverage covering various scenarios including nested callbacks, arrow functions, and custom error parameter names
  • Integrates the rule into the linter infrastructure through generated enum and runner files

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/oxc_linter/src/rules/node/handle_callback_err.rs New rule implementation with pattern matching, configuration parsing, and logic to detect unhandled error parameters
crates/oxc_linter/src/snapshots/node_handle_callback_err.snap Snapshot tests showing expected diagnostic output for failing test cases
crates/oxc_linter/src/rules.rs Adds the new rule module to the node rules collection
crates/oxc_linter/src/generated/rules_enum.rs Generated code integrating the rule into the RuleEnum system
crates/oxc_linter/src/generated/rule_runner_impls.rs Generated code specifying which AST node types the rule should run on

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 22, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 52 skipped benchmarks1


Comparing baevm:n/handle_callback_error (9a30a7e) with main (1c07b3b)2

Open in CodSpeed

Footnotes

  1. 52 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (910c941) during the generation of this report, so 1c07b3b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@baevm
Copy link
Contributor Author

baevm commented Feb 22, 2026

CI spell check is failing for test case with regex option, not sure how to fix/ignore it

image

@camc314
Copy link
Contributor

camc314 commented Feb 22, 2026

@baevm you should be able to do // spellchecker:disable-line ?

@baevm
Copy link
Contributor Author

baevm commented Feb 22, 2026

@baevm you should be able to do // spellchecker:disable-line ?

ty! fixed it

@baevm baevm force-pushed the n/handle_callback_error branch 3 times, most recently from d716c47 to 3eae25e Compare February 25, 2026 08:52
graphite-app bot pushed a commit that referenced this pull request Feb 26, 2026
#19731)

Previously, we did not correctly handle config docs for rules that only take one primitive argument. As a result, some docs were missing the config section entirely.

This fixes the problem by handling that case when generating docs. It fixes the docs for `typescript/class-literal-property-style`, `node/handle-callback-err` (not merged yet), and `react/no-will-update-set-state`.

I have checked this change against the existing docs site, and no changes to the docs seem to be problematic here, only a small handful of rules were impacted.

We discovered this problem in #19616

The change to the docs generation itself was generated by Claude Code, I tested the change manually and verified it worked, and also added the two extra rules to the docs snapshot.
graphite-app bot pushed a commit that referenced this pull request Feb 26, 2026
#19731)

Previously, we did not correctly handle config docs for rules that only take one primitive argument. As a result, some docs were missing the config section entirely.

This fixes the problem by handling that case when generating docs. It fixes the docs for `typescript/class-literal-property-style`, `node/handle-callback-err` (not merged yet), and `react/no-will-update-set-state`.

I have checked this change against the existing docs site, and no changes to the docs seem to be problematic here, only a small handful of rules were impacted.

We discovered this problem in #19616

The change to the docs generation itself was generated by Claude Code, I tested the change manually and verified it worked, and also added the two extra rules to the docs snapshot.
@baevm baevm force-pushed the n/handle_callback_error branch from 3eae25e to eb9e8db Compare February 26, 2026 13:13
@baevm baevm requested a review from connorshea February 27, 2026 14:42
@camc314 camc314 self-assigned this Feb 27, 2026
Copy link
Member

@connorshea connorshea left a comment

Choose a reason for hiding this comment

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

From a docs/config perspective this looks fine to me now.

@camc314 camc314 force-pushed the n/handle_callback_error branch from 9ed0f41 to 9a30a7e Compare March 12, 2026 16:43
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

thank you!

@camc314 camc314 merged commit 7a2a7d0 into oxc-project:main Mar 12, 2026
20 checks passed
camc314 pushed a commit that referenced this pull request Mar 16, 2026
# Oxlint
### 🚀 Features

- c95951f linter/plugins: Implement `sourceCode.markVariableAsUsed` (#20357) (overlookmotel)
- 7a2a7d0 linter: Implement `n/handle-callback-err` rule (#19616) (Mikhail Baev)

### 🐛 Bug Fixes

- f8fbd6e linter/plugins: Remove `hashbang` property from AST (#20365) (overlookmotel)
- 6eb5b01 linter/prefer-await-to-then: Ignore Promise static methods (#20347) (camc314)
- a4b61f7 linter: Remove `defineConfig` check (#20308) (camc314)
- 3ad7f53 linter/explicit-module-boundary-types: False positive with satisfies expr (#20309) (camc314)
- f547401 linter/no-unused-private-class-members: Treat switch discriminants as read (#20307) (camc314)
- 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen)

### ⚡ Performance

- e4f7248 linter: Remove unnecessary clone of owned String in drain loop (#20388) (Boshen)
- 4a67f1d linter: Eliminate Vec allocation in disable directive matching (#20387) (Boshen)
- 618a598 linter/plugins: Add fast path for files with no comments (#20366) (overlookmotel)
- b0125c5 linter/plugins: Deserialize comments without AST (#20364) (overlookmotel)
- 9cd612f linter/plugins: Recycle comment objects (#20362) (overlookmotel)
- bf442f8 linter/plugins: Cheaper `Token` creation (#20360) (overlookmotel)
- 5474d0a semantic: V8-style walk-up reference resolution (#20292) (Boshen)
- 7946eba linter/plugins: Avoid arguments spread and temp array when merging (#20318) (overlookmotel)
- fc7cf8a linter/plugins: Pre-define less CFG merger functions (#20317) (overlookmotel)
- 3b9eb28 linter/plugins: Streamline getting/creating visit fn mergers (#20319) (overlookmotel)
- f04e850 linter/plugins: Inline binary search functions into call sites (#20312) (overlookmotel)
- fe24afe linter/plugins: Apply replace globals TSDown plugin to JS files (#20305) (overlookmotel)
- 77cdacc linter/plugins: Use array buffer views for tokens (#20301) (overlookmotel)
- 910c941 linter/plugins: Reorder branches in `getTokenByRangeStart` (#20296) (overlookmotel)
- af7674c linter/tokens: Avoid extra token value allocation (#20013) (camc314)

### 📚 Documentation

- 24490b5 linter: Improve formatting for 80ish rules' docs. (#20411) (connorshea)
- 3383523 linter: Improve `--tsconfig` flag docs (#20342) (camc314)
# Oxfmt
### 🚀 Features

- d22c443 oxfmt: Export `OxfmtConfig` type (#20275) (leaysgur)
- a11ecff oxfmt/lsp: Respect `angular` language id as `.component.html` file (#20242) (Sysix)

### 🐛 Bug Fixes

- ce65099 formatter: Preserve parentheses around as expression before private field access (#20419) (bab)
- f908742 oxfmt: Revert #20326 partially (#20413) (leaysgur)
- 4ef93ea formatter: Honor trailing ignore comments after list separators (#19925) (Andreas Lubbe)
- 68fb0d0 oxfmt: Skip vite.config.ts which fails to import (#20326) (leaysgur)
- 88ee826 oxfmt: Handle literalline for script-in-vue (#20130) (leaysgur)
- 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants