Skip to content

Commit 11f2e81

Browse files
committed
allow the props name pattern for the event handler name only when the direct parent's name is "props"
1 parent b707b0a commit 11f2e81

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

crates/oxc_linter/src/rules/react/jsx_handler_names.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,8 @@ fn get_event_handler_name_from_static_member_expression(
388388
(name.into(), span, obj_name == "props")
389389
}
390390
Expression::StaticMemberExpression(expr) => {
391-
let (obj_name, _obj_span, is_props) =
392-
get_event_handler_name_from_static_member_expression(expr, ctx);
393-
(name.into(), span, !is_props && obj_name == "props")
391+
let (obj_name, _, _) = get_event_handler_name_from_static_member_expression(expr, ctx);
392+
(name.into(), span, obj_name == "props")
394393
}
395394
_ => (ctx.source_range(member_expr.span).into(), member_expr.span, false),
396395
}
@@ -622,6 +621,8 @@ fn test() {
622621
("<TestComponent onChange={this.handl3Change} />", None),
623622
("<TestComponent onChange={this.handle4change} />", None),
624623
("<TestComponent onChange={this.props.doSomethingOnChange} />", None),
624+
("<TestComponent onChange={this.props.obj.onChange} />", None),
625+
("<TestComponent onChange={props.obj.onChange} />", None),
625626
(
626627
"<TestComponent onChange={takeCareOfChange} />",
627628
Some(serde_json::json!([{ "checkLocalVariables": true }])),

crates/oxc_linter/src/snapshots/react_jsx_handler_names.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ source: crates/oxc_linter/src/tester.rs
5050
╰────
5151
help: Handler function for onChange prop key must be a camelCase name beginning with 'handle' only
5252

53+
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler name: onChange
54+
╭─[jsx_handler_names.tsx:1:41]
55+
1 │ <TestComponent onChange={this.props.obj.onChange} />
56+
· ────────
57+
╰────
58+
help: Handler function for onChange prop key must be a camelCase name beginning with 'handle' only
59+
60+
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler name: onChange
61+
╭─[jsx_handler_names.tsx:1:36]
62+
1 │ <TestComponent onChange={props.obj.onChange} />
63+
· ────────
64+
╰────
65+
help: Handler function for onChange prop key must be a camelCase name beginning with 'handle' only
66+
5367
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler name: takeCareOfChange
5468
╭─[jsx_handler_names.tsx:1:26]
5569
1 │ <TestComponent onChange={takeCareOfChange} />

0 commit comments

Comments
 (0)