Skip to content

Commit 5f8ecbd

Browse files
committed
Improve location reporting for jsx-dollar rule
Set the diagnostic loc to the dollar sign position for clarity.
1 parent 39e1084 commit 5f8ecbd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/jsx-dollar.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ import React from "react";
5353

5454
function MyComponent({ user }) {
5555
return <div>Hello ${user.name}</div>;
56-
// ^^^^^^^
57-
// - Possible unnecessary '$' character before expression.
56+
// ^
57+
// - Possible unnecessary '$' character before expression.
5858
}
5959
```
6060

packages/plugins/eslint-plugin-react-x/src/rules/jsx-dollar.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,20 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
4646
if (node.children[index + 1]?.type !== T.JSXExpressionContainer) continue;
4747
// Skip if there are only two children (the dollar sign and the expression) it doesn't seem to be split from a template literal
4848
if (child.value === "$" && node.children.length === 2) continue;
49+
const pos = child.loc.end;
4950
context.report({
5051
messageId: "jsxDollar",
5152
node: child,
53+
loc: {
54+
end: {
55+
column: pos.column,
56+
line: pos.line,
57+
},
58+
start: {
59+
column: pos.column - 1,
60+
line: pos.line,
61+
},
62+
},
5263
suggest: [
5364
{
5465
messageId: "removeDollarSign",

0 commit comments

Comments
 (0)