Skip to content

Commit 9c811a2

Browse files
Rel1cxCopilot
andauthored
Improve location reporting for jsx-dollar rule (#1303)
Signed-off-by: REL1CX <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 39e1084 commit 9c811a2

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-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.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ruleTester.run(RULE_NAME, rule, {
1212
errors: [
1313
{
1414
messageId: "jsxDollar",
15+
column: 35,
16+
endColumn: 36,
17+
endLine: 1,
18+
line: 1,
1519
suggestions: [
1620
{
1721
messageId: "removeDollarSign",
@@ -32,6 +36,10 @@ ruleTester.run(RULE_NAME, rule, {
3236
errors: [
3337
{
3438
messageId: "jsxDollar",
39+
column: 23,
40+
endColumn: 24,
41+
endLine: 2,
42+
line: 2,
3543
suggestions: [
3644
{
3745
messageId: "removeDollarSign",
@@ -54,6 +62,10 @@ ruleTester.run(RULE_NAME, rule, {
5462
errors: [
5563
{
5664
messageId: "jsxDollar",
65+
column: 17,
66+
endColumn: 18,
67+
endLine: 2,
68+
line: 2,
5769
suggestions: [
5870
{
5971
messageId: "removeDollarSign",
@@ -76,6 +88,10 @@ ruleTester.run(RULE_NAME, rule, {
7688
errors: [
7789
{
7890
messageId: "jsxDollar",
91+
column: 23,
92+
endColumn: 24,
93+
endLine: 2,
94+
line: 2,
7995
suggestions: [
8096
{
8197
messageId: "removeDollarSign",

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)