Skip to content

Commit

Permalink
[Fix] jsx-child-element-spacing: fix error location
Browse files Browse the repository at this point in the history
  • Loading branch information
pfhayes authored and ljharb committed Jan 30, 2018
1 parent d818f2b commit 05c49d4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 36 deletions.
8 changes: 4 additions & 4 deletions lib/rules/jsx-child-element-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ module.exports = {
) {
if (lastChild && child.value.match(TEXT_FOLLOWING_ELEMENT_PATTERN)) {
context.report({
node: child,
loc: child.loc,
node: lastChild,
loc: lastChild.loc.end,
message: `Ambiguous spacing after previous element ${elementName(lastChild)}`
});
} else if (nextChild && child.value.match(TEXT_PRECEDING_ELEMENT_PATTERN)) {
context.report({
node: child,
loc: child.loc,
node: nextChild,
loc: nextChild.loc.start,
message: `Ambiguous spacing before next element ${elementName(nextChild)}`
});
}
Expand Down
92 changes: 60 additions & 32 deletions tests/lib/rules/jsx-child-element-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,65 +132,93 @@ ruleTester.run('jsx-child-element-spacing', rule, {

invalid: [{
code: `
<App>
foo
<a>bar</a>
</App>
<App>
foo
<a>bar</a>
</App>
`,
errors: [
{message: 'Ambiguous spacing before next element a'}
{
message: 'Ambiguous spacing before next element a',
line: 4,
column: 3
}
]
}, {
code: `
<App>
<a>bar</a>
baz
</App>
<App>
<a>bar</a>
baz
</App>
`,
errors: [
{message: 'Ambiguous spacing after previous element a'}
{
message: 'Ambiguous spacing after previous element a',
line: 3,
column: 13
}
]
}, {
code: `
<App>
{' '}<a>bar</a>
baz
</App>
<App>
{' '}<a>bar</a>
baz
</App>
`,
errors: [
{message: 'Ambiguous spacing after previous element a'}
{
message: 'Ambiguous spacing after previous element a',
line: 3,
column: 18
}
]
}, {
code: `
<App>
Please take a look at
<a href="https://js.org">this link</a>.
</App>
<App>
Please take a look at
<a href="https://js.org">this link</a>.
</App>
`,
errors: [
{message: 'Ambiguous spacing before next element a'}
{
message: 'Ambiguous spacing before next element a',
line: 4,
column: 3
}
]
}, {
code: `
<App>
Some <code>loops</code> and some
<code>if</code> statements.
</App>
<App>
Some <code>loops</code> and some
<code>if</code> statements.
</App>
`,
errors: [
{message: 'Ambiguous spacing before next element code'}
{
message: 'Ambiguous spacing before next element code',
line: 4,
column: 3
}
]
}, {
code: `
<App>
Here is
<a href="https://js.org">a link</a> and here is
<a href="https://js.org">another</a>
</App>
<App>
Here is
<a href="https://js.org">a link</a> and here is
<a href="https://js.org">another</a>
</App>
`,
errors: [
{message: 'Ambiguous spacing before next element a'},
{message: 'Ambiguous spacing before next element a'}
{
message: 'Ambiguous spacing before next element a',
line: 4,
column: 3
},
{
message: 'Ambiguous spacing before next element a',
line: 5,
column: 3
}
]
}]
});

0 comments on commit 05c49d4

Please sign in to comment.