Skip to content

Commit 2c091dd

Browse files
Pavel Lysenkoljharb
Pavel Lysenko
authored andcommitted
[Fix] jsx-one-expression-per-line: fix when using tabs
Fixes jsx-eslint#2152.
1 parent d3dc4c8 commit 2c091dd

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/rules/jsx-one-expression-per-line.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ module.exports = {
9494
return;
9595
}
9696

97-
countNewLinesBeforeContent = (child.raw.match(/^ *\n/g) || []).length;
98-
countNewLinesAfterContent = (child.raw.match(/\n *$/g) || []).length;
97+
countNewLinesBeforeContent = (child.raw.match(/^\s*\n/g) || []).length;
98+
countNewLinesAfterContent = (child.raw.match(/\n\s*$/g) || []).length;
9999
}
100100

101101
const startLine = child.loc.start.line + countNewLinesBeforeContent;

tests/lib/rules/jsx-one-expression-per-line.js

+36
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,42 @@ const ruleTester = new RuleTester({parserOptions});
2828
ruleTester.run('jsx-one-expression-per-line', rule, {
2929
valid: [{
3030
code: '<App />'
31+
}, {
32+
code: `
33+
\t\t<AllTabs>
34+
\t\t\tFail
35+
\t\t</AllTabs>
36+
`
37+
}, {
38+
code: `
39+
\t\t<TagsWithTabs>
40+
Fail
41+
\t\t</TagsWithTabs>
42+
`
43+
}, {
44+
code: `
45+
<ClosedTagWithTabs>
46+
Fail
47+
\t\t</ClosedTagWithTabs>
48+
`
49+
}, {
50+
code: `
51+
\t\t<OpenTagWithTabs>
52+
OK
53+
</OpenTagWithTabs>
54+
`
55+
}, {
56+
code: `
57+
<TextWithTabs>
58+
\t\t\tOK
59+
</TextWithTabs>
60+
`
61+
}, {
62+
code: `
63+
<AllSpaces>
64+
OK
65+
</AllSpaces>
66+
`
3167
}, {
3268
code: '<App></App>'
3369
}, {

0 commit comments

Comments
 (0)