diff --git a/lib/rules/jsx-child-element-spacing.js b/lib/rules/jsx-child-element-spacing.js
index 73ea2dc2a7..838d9de091 100644
--- a/lib/rules/jsx-child-element-spacing.js
+++ b/lib/rules/jsx-child-element-spacing.js
@@ -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)}`
});
}
diff --git a/tests/lib/rules/jsx-child-element-spacing.js b/tests/lib/rules/jsx-child-element-spacing.js
index 51ebfcd671..fdd19149fb 100644
--- a/tests/lib/rules/jsx-child-element-spacing.js
+++ b/tests/lib/rules/jsx-child-element-spacing.js
@@ -132,65 +132,93 @@ ruleTester.run('jsx-child-element-spacing', rule, {
invalid: [{
code: `
-
- foo
- bar
-
+
+ foo
+ bar
+
`,
errors: [
- {message: 'Ambiguous spacing before next element a'}
+ {
+ message: 'Ambiguous spacing before next element a',
+ line: 4,
+ column: 3
+ }
]
}, {
code: `
-
- bar
- baz
-
+
+ bar
+ baz
+
`,
errors: [
- {message: 'Ambiguous spacing after previous element a'}
+ {
+ message: 'Ambiguous spacing after previous element a',
+ line: 3,
+ column: 13
+ }
]
}, {
code: `
-
- {' '}bar
- baz
-
+
+ {' '}bar
+ baz
+
`,
errors: [
- {message: 'Ambiguous spacing after previous element a'}
+ {
+ message: 'Ambiguous spacing after previous element a',
+ line: 3,
+ column: 18
+ }
]
}, {
code: `
-
- Please take a look at
- this link.
-
+
+ Please take a look at
+ this link.
+
`,
errors: [
- {message: 'Ambiguous spacing before next element a'}
+ {
+ message: 'Ambiguous spacing before next element a',
+ line: 4,
+ column: 3
+ }
]
}, {
code: `
-
- Some loops
and some
- if
statements.
-
+
+ Some loops
and some
+ if
statements.
+
`,
errors: [
- {message: 'Ambiguous spacing before next element code'}
+ {
+ message: 'Ambiguous spacing before next element code',
+ line: 4,
+ column: 3
+ }
]
}, {
code: `
-
- Here is
- a link and here is
- another
-
+
+ Here is
+ a link and here is
+ another
+
`,
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
+ }
]
}]
});