feat(linter): implement n/handle-callback-err rule#19616
feat(linter): implement n/handle-callback-err rule#19616baevm wants to merge 7 commits intooxc-project:mainfrom
n/handle-callback-err rule#19616Conversation
There was a problem hiding this comment.
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
HandleCallbackErrrule 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 |
Merging this PR will not alter performance
Comparing Footnotes
|
|
@baevm you should be able to do |
ty! fixed it |
d716c47 to
3eae25e
Compare
#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.
#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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mikhail Baev <baev2m@gmail.com>
3eae25e to
eb9e8db
Compare
|
|
||
| #[derive(Debug, Default, Clone, JsonSchema, Deserialize)] | ||
| pub struct HandleCallbackErr( | ||
| #[serde(deserialize_with = "deserialize_error_pattern")] Box<ErrorPattern>, |
There was a problem hiding this comment.
Is there a reason not to format this as:
| #[serde(deserialize_with = "deserialize_error_pattern")] Box<ErrorPattern>, | |
| #[serde(deserialize_with = "deserialize_error_pattern")] | |
| Box<ErrorPattern>, |
connorshea
left a comment
There was a problem hiding this comment.
From a docs/config perspective this looks fine to me now.

this PR implements
n/handle-callback-errrule, passes all tests from original ruleissue #493