Skip to content

Fix error location #1666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
]
}]
});