Skip to content

Commit 64db1a5

Browse files
fix incorrect formatting in jsx-wrap-multilines
1 parent 97a9f39 commit 64db1a5

File tree

2 files changed

+74
-13
lines changed

2 files changed

+74
-13
lines changed

lib/rules/jsx-wrap-multilines.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ module.exports = {
163163
node,
164164
MISSING_PARENS,
165165
fixer => fixer.replaceTextRange(
166-
[tokenBefore.range[0], tokenAfter ? tokenAfter.range[0] : node.range[1]],
167-
`${trimTokenBeforeNewline(node, tokenBefore)}(\n${sourceCode.getText(node)}\n)`
166+
[tokenBefore.range[0], tokenAfter && (tokenAfter.value === ';' || tokenAfter.value === '}') ? tokenAfter.range[0] : node.range[1]],
167+
`${trimTokenBeforeNewline(node, tokenBefore)}(\n${' '.repeat(node.loc.start.column)}${sourceCode.getText(node)}\n${' '.repeat(node.loc.start.column - 2)})`
168168
)
169169
);
170170
} else {
@@ -229,7 +229,7 @@ module.exports = {
229229
}
230230
},
231231

232-
'ArrowFunctionExpression:exit': function (node) {
232+
'ArrowFunctionExpression:exit': (node) => {
233233
const arrowBody = node.body;
234234
const type = 'arrow';
235235

tests/lib/rules/jsx-wrap-multilines.js

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,20 +464,20 @@ const LOGICAL_NO_PAREN_FRAGMENT = `
464464
const LOGICAL_PAREN_NEW_LINE_AUTOFIX = `
465465
<div>
466466
{foo && (
467-
<div>
467+
<div>
468468
<p>Hello World</p>
469469
</div>
470-
)}
470+
)}
471471
</div>
472472
`;
473473

474474
const LOGICAL_PAREN_NEW_LINE_AUTOFIX_FRAGMENT = `
475475
<div>
476476
{foo && (
477-
<>
477+
<>
478478
<p>Hello World</p>
479479
</>
480-
)}
480+
)}
481481
</div>
482482
`;
483483

@@ -545,20 +545,20 @@ const ATTR_PAREN_NEW_LINE = `
545545

546546
const ATTR_PAREN_NEW_LINE_AUTOFIX = `
547547
<div prop={(
548-
<div>
548+
<div>
549549
<p>Hello</p>
550550
</div>
551-
)}>
551+
)}>
552552
<p>Hello</p>
553553
</div>
554554
`;
555555

556556
const ATTR_PAREN_NEW_LINE_AUTOFIX_FRAGMENT = `
557557
<div prop={(
558-
<>
558+
<>
559559
<p>Hello</p>
560560
</>
561-
)}>
561+
)}>
562562
<p>Hello</p>
563563
</div>
564564
`;
@@ -571,10 +571,53 @@ export default () =>
571571

572572
const SFC_NO_PARENS_AUTOFIX = `
573573
export default () => (
574-
<div>
574+
<div>
575575
with newline without parentheses eslint crashes
576576
</div>
577-
)`;
577+
)`;
578+
579+
const ARROW_WITH_EXPORT = `
580+
const Component = () =>
581+
<div>
582+
<p>Some text</p>
583+
</div>
584+
585+
export { Component as default }
586+
`;
587+
588+
const ARROW_WITH_EXPORT_AUTOFIX = `
589+
const Component = () => (
590+
<div>
591+
<p>Some text</p>
592+
</div>
593+
)
594+
595+
export { Component as default }
596+
`;
597+
598+
const ARROW_WITH_LOGICAL = `
599+
const Component = props => (
600+
<div>
601+
{true &&
602+
<div>
603+
<p>Some text</p>
604+
</div>
605+
}
606+
</div>
607+
)
608+
`;
609+
610+
const ARROW_WITH_LOGICAL_AUTOFIX = `
611+
const Component = props => (
612+
<div>
613+
{true && (
614+
<div>
615+
<p>Some text</p>
616+
</div>
617+
)}
618+
</div>
619+
)
620+
`;
578621

579622
function addNewLineSymbols(code) {
580623
return code.replace(/\(</g, '(\n<').replace(/>\)/g, '>\n)');
@@ -1189,5 +1232,23 @@ ruleTester.run('jsx-wrap-multilines', rule, {
11891232
output: SFC_NO_PARENS_AUTOFIX,
11901233
options: [OPTIONS_ALL_NEW_LINES],
11911234
errors: [{message: MISSING_PARENS}]
1235+
}, {
1236+
code: ARROW_WITH_EXPORT,
1237+
output: ARROW_WITH_EXPORT_AUTOFIX,
1238+
options: [{
1239+
declaration: 'parens-new-line',
1240+
assignment: 'parens-new-line',
1241+
return: 'parens-new-line',
1242+
arrow: 'parens-new-line',
1243+
condition: 'parens-new-line',
1244+
logical: 'ignore',
1245+
prop: 'ignore'
1246+
}],
1247+
errors: [{message: MISSING_PARENS}]
1248+
}, {
1249+
code: ARROW_WITH_LOGICAL,
1250+
output: ARROW_WITH_LOGICAL_AUTOFIX,
1251+
options: [{logical: 'parens-new-line'}],
1252+
errors: [{message: MISSING_PARENS}]
11921253
}]
11931254
});

0 commit comments

Comments
 (0)