Skip to content

Commit

Permalink
Remove some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pfhayes committed Nov 15, 2017
1 parent 9de7c73 commit 5b2e1d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
14 changes: 1 addition & 13 deletions lib/rules/jsx-child-element-spacing.js
Expand Up @@ -64,8 +64,6 @@ module.exports = {
INLINE_ELEMENTS.includes(elementName(node))
);

const TRAILING_WHITESPACE_PATTERN = /\n +$/;
const LEADING_WHITESPACE_PATTERN = /^ +\n/;
const TEXT_FOLLOWING_ELEMENT_PATTERN = /^\s*\n\s*\S/;
const TEXT_PRECEDING_ELEMENT_PATTERN = /\S\s*\n\s*$/;

Expand All @@ -81,17 +79,7 @@ module.exports = {
(!nextChild || isInlineElement(nextChild)) &&
true
) {
if (
lastChild &&
nextChild &&
(child.value.match(LEADING_WHITESPACE_PATTERN) || child.value.match(TRAILING_WHITESPACE_PATTERN))
) {
context.report({
node: child,
loc: child.loc,
message: `Ambiguous spacing between elements ${elementName(lastChild)} and ${elementName(nextChild)}`
});
} else if (lastChild && child.value.match(TEXT_FOLLOWING_ELEMENT_PATTERN)) {
if (lastChild && child.value.match(TEXT_FOLLOWING_ELEMENT_PATTERN)) {
context.report({
node: child,
loc: child.loc,
Expand Down
63 changes: 38 additions & 25 deletions tests/lib/rules/jsx-child-element-spacing.js
Expand Up @@ -9,9 +9,6 @@ const parserOptions = {
}
};

// const ERROR_MESSAGE = [{message: 'Ambiguous spacing between child elements.'}];
const ERROR_MESSAGE = [{}];

const ruleTester = new RuleTester({parserOptions});
ruleTester.run('jsx-child-element-spacing', rule, {
valid: [{
Expand Down Expand Up @@ -108,6 +105,22 @@ ruleTester.run('jsx-child-element-spacing', rule, {
<p>A</p><p>B</p>
</App>
`
}, {
code: `
<App>
<a>foo</a>
<a>bar</a>
</App>
`
}, {
code: `
<App>
<a>
<b>nested1</b>
<b>nested2</b>
</a>
</App>
`
}, {
code: `
<App>
Expand All @@ -124,60 +137,60 @@ ruleTester.run('jsx-child-element-spacing', rule, {
<a>bar</a>
</App>
`,
errors: ERROR_MESSAGE
}, {
code: `
<App>
<a>foo</a>
<a>bar</a>
</App>
`,
errors: ERROR_MESSAGE
errors: [
{message: 'Ambiguous spacing before next element a'}
]
}, {
code: `
<App>
<a>bar</a>
baz
</App>
`,
errors: ERROR_MESSAGE
errors: [
{message: 'Ambiguous spacing after previous element a'}
]
}, {
code: `
<App>
{' '}<a>bar</a>
baz
</App>
`,
errors: ERROR_MESSAGE
errors: [
{message: 'Ambiguous spacing after previous element a'}
]
}, {
code: `
<App>
Please take a look at
<a href="https://js.org">this link</a>.
</App>
`,
errors: ERROR_MESSAGE
errors: [
{message: 'Ambiguous spacing before next element a'}
]
}, {
code: `
<App>
Here is
<a href="https://js.org">a link</a> and here is
<a href="https://js.org">another</a>
Some <code>loops</code> and some
<code>if</code> statements.
</App>
`,
errors: [
ERROR_MESSAGE,
ERROR_MESSAGE
{message: 'Ambiguous spacing before next element code'}
]
}, {
code: `
<App>
<a>
<b>nested1</b>
<b>nested2</b>
</a>
Here is
<a href="https://js.org">a link</a> and here is
<a href="https://js.org">another</a>
</App>
`,
errors: ERROR_MESSAGE
errors: [
{message: 'Ambiguous spacing before next element a'},
{message: 'Ambiguous spacing before next element a'}
]
}]
});

0 comments on commit 5b2e1d4

Please sign in to comment.