Skip to content

Commit 05c49d4

Browse files
pfhayesljharb
authored andcommitted
[Fix] jsx-child-element-spacing: fix error location
1 parent d818f2b commit 05c49d4

File tree

2 files changed

+64
-36
lines changed

2 files changed

+64
-36
lines changed

lib/rules/jsx-child-element-spacing.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ module.exports = {
8585
) {
8686
if (lastChild && child.value.match(TEXT_FOLLOWING_ELEMENT_PATTERN)) {
8787
context.report({
88-
node: child,
89-
loc: child.loc,
88+
node: lastChild,
89+
loc: lastChild.loc.end,
9090
message: `Ambiguous spacing after previous element ${elementName(lastChild)}`
9191
});
9292
} else if (nextChild && child.value.match(TEXT_PRECEDING_ELEMENT_PATTERN)) {
9393
context.report({
94-
node: child,
95-
loc: child.loc,
94+
node: nextChild,
95+
loc: nextChild.loc.start,
9696
message: `Ambiguous spacing before next element ${elementName(nextChild)}`
9797
});
9898
}

tests/lib/rules/jsx-child-element-spacing.js

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -132,65 +132,93 @@ ruleTester.run('jsx-child-element-spacing', rule, {
132132

133133
invalid: [{
134134
code: `
135-
<App>
136-
foo
137-
<a>bar</a>
138-
</App>
135+
<App>
136+
foo
137+
<a>bar</a>
138+
</App>
139139
`,
140140
errors: [
141-
{message: 'Ambiguous spacing before next element a'}
141+
{
142+
message: 'Ambiguous spacing before next element a',
143+
line: 4,
144+
column: 3
145+
}
142146
]
143147
}, {
144148
code: `
145-
<App>
146-
<a>bar</a>
147-
baz
148-
</App>
149+
<App>
150+
<a>bar</a>
151+
baz
152+
</App>
149153
`,
150154
errors: [
151-
{message: 'Ambiguous spacing after previous element a'}
155+
{
156+
message: 'Ambiguous spacing after previous element a',
157+
line: 3,
158+
column: 13
159+
}
152160
]
153161
}, {
154162
code: `
155-
<App>
156-
{' '}<a>bar</a>
157-
baz
158-
</App>
163+
<App>
164+
{' '}<a>bar</a>
165+
baz
166+
</App>
159167
`,
160168
errors: [
161-
{message: 'Ambiguous spacing after previous element a'}
169+
{
170+
message: 'Ambiguous spacing after previous element a',
171+
line: 3,
172+
column: 18
173+
}
162174
]
163175
}, {
164176
code: `
165-
<App>
166-
Please take a look at
167-
<a href="https://js.org">this link</a>.
168-
</App>
177+
<App>
178+
Please take a look at
179+
<a href="https://js.org">this link</a>.
180+
</App>
169181
`,
170182
errors: [
171-
{message: 'Ambiguous spacing before next element a'}
183+
{
184+
message: 'Ambiguous spacing before next element a',
185+
line: 4,
186+
column: 3
187+
}
172188
]
173189
}, {
174190
code: `
175-
<App>
176-
Some <code>loops</code> and some
177-
<code>if</code> statements.
178-
</App>
191+
<App>
192+
Some <code>loops</code> and some
193+
<code>if</code> statements.
194+
</App>
179195
`,
180196
errors: [
181-
{message: 'Ambiguous spacing before next element code'}
197+
{
198+
message: 'Ambiguous spacing before next element code',
199+
line: 4,
200+
column: 3
201+
}
182202
]
183203
}, {
184204
code: `
185-
<App>
186-
Here is
187-
<a href="https://js.org">a link</a> and here is
188-
<a href="https://js.org">another</a>
189-
</App>
205+
<App>
206+
Here is
207+
<a href="https://js.org">a link</a> and here is
208+
<a href="https://js.org">another</a>
209+
</App>
190210
`,
191211
errors: [
192-
{message: 'Ambiguous spacing before next element a'},
193-
{message: 'Ambiguous spacing before next element a'}
212+
{
213+
message: 'Ambiguous spacing before next element a',
214+
line: 4,
215+
column: 3
216+
},
217+
{
218+
message: 'Ambiguous spacing before next element a',
219+
line: 5,
220+
column: 3
221+
}
194222
]
195223
}]
196224
});

0 commit comments

Comments
 (0)