Skip to content

Commit 6043ccf

Browse files
committed
fix to draw a line under the prop name when the prop name is wrong
1 parent e7758c4 commit 6043ccf

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,11 @@ impl Rule for JsxHandlerNames {
286286
return;
287287
}
288288

289-
let prop_key = match &jsx_attribute.name {
290-
JSXAttributeName::Identifier(ident) => ident.name.as_str(),
291-
JSXAttributeName::NamespacedName(namespaced_name) => namespaced_name.name.name.as_str(),
289+
let (prop_key, prop_span) = match &jsx_attribute.name {
290+
JSXAttributeName::Identifier(ident) => (ident.name.as_str(), ident.span),
291+
JSXAttributeName::NamespacedName(namespaced_name) => {
292+
(namespaced_name.name.name.as_str(), namespaced_name.span)
293+
}
292294
};
293295

294296
let prop_value = if self.check_inline_functions && is_inline_handler {
@@ -324,7 +326,7 @@ impl Rule for JsxHandlerNames {
324326
}
325327
(Some(value), Some(false), Some(true)) => {
326328
ctx.diagnostic(bad_handler_prop_name_diagnostic(
327-
expression_container.span,
329+
prop_span,
328330
prop_key,
329331
&value,
330332
&self.event_handler_prop_prefixes,

crates/oxc_linter/src/snapshots/react_jsx_handler_names.snap

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,51 +58,51 @@ source: crates/oxc_linter/src/tester.rs
5858
help: Handler function for onChange prop key must be a camelCase name beginning with 'handle' only
5959

6060
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: only
61-
╭─[jsx_handler_names.tsx:1:21]
61+
╭─[jsx_handler_names.tsx:1:16]
6262
1 │ <TestComponent only={this.handleChange} />
63-
· ───────────────────
63+
· ────
6464
╰────
6565
help: Prop key for handleChange must begin with 'on'
6666

6767
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: only
68-
╭─[jsx_handler_names.tsx:1:22]
68+
╭─[jsx_handler_names.tsx:1:17]
6969
1 │ <TestComponent2 only={this.handleChange} />
70-
· ───────────────────
70+
· ────
7171
╰────
7272
help: Prop key for handleChange must begin with 'on'
7373

7474
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: handleChange
75-
╭─[jsx_handler_names.tsx:1:29]
75+
╭─[jsx_handler_names.tsx:1:16]
7676
1 │ <TestComponent handleChange={this.handleChange} />
77-
· ───────────────────
77+
· ────────────
7878
╰────
7979
help: Prop key for handleChange must begin with 'on'
8080

8181
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: whenChange
82-
╭─[jsx_handler_names.tsx:1:27]
82+
╭─[jsx_handler_names.tsx:1:16]
8383
1 │ <TestComponent whenChange={handleChange} />
84-
· ──────────────
84+
· ──────────
8585
╰────
8686
help: Prop key for handleChange must begin with 'on'
8787

8888
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: whenChange
89-
╭─[jsx_handler_names.tsx:1:27]
89+
╭─[jsx_handler_names.tsx:1:16]
9090
1 │ <TestComponent whenChange={() => handleChange()} />
91-
· ──────────────────────
91+
· ──────────
9292
╰────
9393
help: Prop key for handleChange must begin with 'on'
9494

9595
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: onChange
96-
╭─[jsx_handler_names.tsx:1:25]
96+
╭─[jsx_handler_names.tsx:1:16]
9797
1 │ <TestComponent onChange={handleChange} />
98-
· ──────────────
98+
· ────────
9999
╰────
100100
help: Prop key for handleChange must begin with 'when'
101101

102102
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: onChange
103-
╭─[jsx_handler_names.tsx:1:25]
103+
╭─[jsx_handler_names.tsx:1:16]
104104
1 │ <TestComponent onChange={() => handleChange()} />
105-
· ──────────────────────
105+
· ────────
106106
╰────
107107
help: Prop key for handleChange must begin with 'when'
108108

@@ -114,9 +114,9 @@ source: crates/oxc_linter/src/tester.rs
114114
help: Handler function for onChange prop key must be a camelCase name beginning with 'when|on' only
115115

116116
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: somePrefixChange
117-
╭─[jsx_handler_names.tsx:1:33]
117+
╭─[jsx_handler_names.tsx:1:16]
118118
1 │ <TestComponent somePrefixChange={handleChange} />
119-
· ──────────────
119+
· ────────────────
120120
╰────
121121
help: Prop key for handleChange must begin with 'when|on'
122122

@@ -142,28 +142,28 @@ source: crates/oxc_linter/src/tester.rs
142142
╰────
143143
144144
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: customPropNameBar
145-
╭─[jsx_handler_names.tsx:5:49]
145+
╭─[jsx_handler_names.tsx:5:31]
146146
4 │ <div>
147147
5 │ <MyLibInput customPropNameBar={handleInput} />;
148-
· ─────────────
148+
· ─────────────────
149149
6 │ <MyLibCheckbox customPropNameBar={handleCheckbox} />;
150150
╰────
151151
help: Prop key for handleInput must begin with 'on'
152152
153153
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: customPropNameBar
154-
╭─[jsx_handler_names.tsx:6:52]
154+
╭─[jsx_handler_names.tsx:6:34]
155155
5 │ <MyLibInput customPropNameBar={handleInput} />;
156156
6 │ <MyLibCheckbox customPropNameBar={handleCheckbox} />;
157-
· ────────────────
157+
· ────────────────
158158
7 │ <MyLibButton customPropNameBar={handleButton} />;
159159
╰────
160160
help: Prop key for handleCheckbox must begin with 'on'
161161
162162
⚠ eslint-plugin-react(jsx-handler-names): Invalid handler prop name: customPropNameBar
163-
╭─[jsx_handler_names.tsx:7:50]
163+
╭─[jsx_handler_names.tsx:7:32]
164164
6 │ <MyLibCheckbox customPropNameBar={handleCheckbox} />;
165165
7 │ <MyLibButton customPropNameBar={handleButton} />;
166-
· ──────────────
166+
· ─────────────────
167167
8 │ </div>
168168
╰────
169169
help: Prop key for handleButton must begin with 'on'

0 commit comments

Comments
 (0)