Skip to content

Commit 5b2e1d4

Browse files
committed
Remove some cases
1 parent 9de7c73 commit 5b2e1d4

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ module.exports = {
6464
INLINE_ELEMENTS.includes(elementName(node))
6565
);
6666

67-
const TRAILING_WHITESPACE_PATTERN = /\n +$/;
68-
const LEADING_WHITESPACE_PATTERN = /^ +\n/;
6967
const TEXT_FOLLOWING_ELEMENT_PATTERN = /^\s*\n\s*\S/;
7068
const TEXT_PRECEDING_ELEMENT_PATTERN = /\S\s*\n\s*$/;
7169

@@ -81,17 +79,7 @@ module.exports = {
8179
(!nextChild || isInlineElement(nextChild)) &&
8280
true
8381
) {
84-
if (
85-
lastChild &&
86-
nextChild &&
87-
(child.value.match(LEADING_WHITESPACE_PATTERN) || child.value.match(TRAILING_WHITESPACE_PATTERN))
88-
) {
89-
context.report({
90-
node: child,
91-
loc: child.loc,
92-
message: `Ambiguous spacing between elements ${elementName(lastChild)} and ${elementName(nextChild)}`
93-
});
94-
} else if (lastChild && child.value.match(TEXT_FOLLOWING_ELEMENT_PATTERN)) {
82+
if (lastChild && child.value.match(TEXT_FOLLOWING_ELEMENT_PATTERN)) {
9583
context.report({
9684
node: child,
9785
loc: child.loc,

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

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ const parserOptions = {
99
}
1010
};
1111

12-
// const ERROR_MESSAGE = [{message: 'Ambiguous spacing between child elements.'}];
13-
const ERROR_MESSAGE = [{}];
14-
1512
const ruleTester = new RuleTester({parserOptions});
1613
ruleTester.run('jsx-child-element-spacing', rule, {
1714
valid: [{
@@ -108,6 +105,22 @@ ruleTester.run('jsx-child-element-spacing', rule, {
108105
<p>A</p><p>B</p>
109106
</App>
110107
`
108+
}, {
109+
code: `
110+
<App>
111+
<a>foo</a>
112+
<a>bar</a>
113+
</App>
114+
`
115+
}, {
116+
code: `
117+
<App>
118+
<a>
119+
<b>nested1</b>
120+
<b>nested2</b>
121+
</a>
122+
</App>
123+
`
111124
}, {
112125
code: `
113126
<App>
@@ -124,60 +137,60 @@ ruleTester.run('jsx-child-element-spacing', rule, {
124137
<a>bar</a>
125138
</App>
126139
`,
127-
errors: ERROR_MESSAGE
128-
}, {
129-
code: `
130-
<App>
131-
<a>foo</a>
132-
<a>bar</a>
133-
</App>
134-
`,
135-
errors: ERROR_MESSAGE
140+
errors: [
141+
{message: 'Ambiguous spacing before next element a'}
142+
]
136143
}, {
137144
code: `
138145
<App>
139146
<a>bar</a>
140147
baz
141148
</App>
142149
`,
143-
errors: ERROR_MESSAGE
150+
errors: [
151+
{message: 'Ambiguous spacing after previous element a'}
152+
]
144153
}, {
145154
code: `
146155
<App>
147156
{' '}<a>bar</a>
148157
baz
149158
</App>
150159
`,
151-
errors: ERROR_MESSAGE
160+
errors: [
161+
{message: 'Ambiguous spacing after previous element a'}
162+
]
152163
}, {
153164
code: `
154165
<App>
155166
Please take a look at
156167
<a href="https://js.org">this link</a>.
157168
</App>
158169
`,
159-
errors: ERROR_MESSAGE
170+
errors: [
171+
{message: 'Ambiguous spacing before next element a'}
172+
]
160173
}, {
161174
code: `
162175
<App>
163-
Here is
164-
<a href="https://js.org">a link</a> and here is
165-
<a href="https://js.org">another</a>
176+
Some <code>loops</code> and some
177+
<code>if</code> statements.
166178
</App>
167179
`,
168180
errors: [
169-
ERROR_MESSAGE,
170-
ERROR_MESSAGE
181+
{message: 'Ambiguous spacing before next element code'}
171182
]
172183
}, {
173184
code: `
174185
<App>
175-
<a>
176-
<b>nested1</b>
177-
<b>nested2</b>
178-
</a>
186+
Here is
187+
<a href="https://js.org">a link</a> and here is
188+
<a href="https://js.org">another</a>
179189
</App>
180190
`,
181-
errors: ERROR_MESSAGE
191+
errors: [
192+
{message: 'Ambiguous spacing before next element a'},
193+
{message: 'Ambiguous spacing before next element a'}
194+
]
182195
}]
183196
});

0 commit comments

Comments
 (0)