Skip to content

Commit 611e365

Browse files
committed
Rebase branch
1 parent 241c38b commit 611e365

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ module.exports = {
9999
return;
100100
}
101101

102-
countNewLinesBeforeContent = (child.raw.match(/^\s*\n/g) || []).length;
103-
countNewLinesAfterContent = (child.raw.match(/\n\s*$/g) || []).length;
102+
countNewLinesBeforeContent = (child.raw.match(/^\s*(\r?\n)/g) || []).length;
103+
countNewLinesAfterContent = (child.raw.match(/(\r?\n)\s*$/g) || []).length;
104104
}
105105

106106
const startLine = child.loc.start.line + countNewLinesBeforeContent;
@@ -201,7 +201,7 @@ module.exports = {
201201

202202
const nodeToReport = details.node;
203203
const descriptor = details.descriptor;
204-
const source = details.source.replace(/(^ +| +(?=\n)*$)/g, '');
204+
const source = details.source.replace(/(^ +| +(?=(\r?\n))*$)/g, '');
205205

206206
const leadingSpaceString = details.leadingSpace ? '\n{\' \'}' : '';
207207
const trailingSpaceString = details.trailingSpace ? '{\' \'}\n' : '';

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

+48
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ ruleTester.run('jsx-one-expression-per-line', rule, {
7676
' <Foo />',
7777
'</App>'
7878
].join('\n')
79+
}, {
80+
code: [
81+
'<App>',
82+
' <Foo />',
83+
'</App>'
84+
].join('\r\n')
85+
}, {
86+
code: [
87+
'<App>',
88+
' <Foo />',
89+
'</App>'
90+
].join('\r')
7991
}, {
8092
code: [
8193
'<App>',
@@ -110,6 +122,22 @@ ruleTester.run('jsx-one-expression-per-line', rule, {
110122
'<Foo />',
111123
'</App>'
112124
].join('\n')
125+
}, {
126+
code: [
127+
'<App',
128+
' foo="bar"',
129+
'>',
130+
'<Foo />',
131+
'</App>'
132+
].join('\r\n')
133+
}, {
134+
code: [
135+
'<App',
136+
' foo="bar"',
137+
'>',
138+
'<Foo />',
139+
'</App>'
140+
].join('\r')
113141
}, {
114142
code: [
115143
'<',
@@ -1250,5 +1278,25 @@ ruleTester.run('jsx-one-expression-per-line', rule, {
12501278
],
12511279
parser: parsers.BABEL_ESLINT,
12521280
parserOptions
1281+
}, {
1282+
code: [
1283+
'<div>',
1284+
' foo {"bar"}',
1285+
'</div>'
1286+
].join('\r\n'),
1287+
output: [
1288+
'<div>\r\n',
1289+
' foo \n',
1290+
'{\' \'}\n',
1291+
'{"bar"}\r\n',
1292+
'</div>'
1293+
].join(''),
1294+
errors: [
1295+
{
1296+
messageId: 'moveToNewLine',
1297+
data: {descriptor: '{"bar"}'}
1298+
}
1299+
],
1300+
parserOptions
12531301
}]
12541302
});

0 commit comments

Comments
 (0)