diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index 374d0db5dc..2980a7652b 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -163,8 +163,8 @@ module.exports = { node, MISSING_PARENS, fixer => fixer.replaceTextRange( - [tokenBefore.range[0], tokenAfter ? tokenAfter.range[0] : node.range[1]], - `${trimTokenBeforeNewline(node, tokenBefore)}(\n${sourceCode.getText(node)}\n)` + [tokenBefore.range[0], tokenAfter && (tokenAfter.value === ';' || tokenAfter.value === '}') ? tokenAfter.range[0] : node.range[1]], + `${trimTokenBeforeNewline(node, tokenBefore)}(\n${' '.repeat(node.loc.start.column)}${sourceCode.getText(node)}\n${' '.repeat(node.loc.start.column - 2)})` ) ); } else { @@ -229,7 +229,7 @@ module.exports = { } }, - 'ArrowFunctionExpression:exit': function (node) { + 'ArrowFunctionExpression:exit': (node) => { const arrowBody = node.body; const type = 'arrow'; diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 19b94228ff..cdf0718689 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -464,20 +464,20 @@ const LOGICAL_NO_PAREN_FRAGMENT = ` const LOGICAL_PAREN_NEW_LINE_AUTOFIX = `
{foo && ( -
+

Hello World

-)} + )}
`; const LOGICAL_PAREN_NEW_LINE_AUTOFIX_FRAGMENT = `
{foo && ( -<> + <>

Hello World

-)} + )}
`; @@ -545,20 +545,20 @@ const ATTR_PAREN_NEW_LINE = ` const ATTR_PAREN_NEW_LINE_AUTOFIX = `
+

Hello

-)}> + )}>

Hello

`; const ATTR_PAREN_NEW_LINE_AUTOFIX_FRAGMENT = `
+ <>

Hello

-)}> + )}>

Hello

`; @@ -571,10 +571,53 @@ export default () => const SFC_NO_PARENS_AUTOFIX = ` export default () => ( -
+
with newline without parentheses eslint crashes
-)`; + )`; + +const ARROW_WITH_EXPORT = ` + const Component = () => +
+

Some text

+
+ + export { Component as default } +`; + +const ARROW_WITH_EXPORT_AUTOFIX = ` + const Component = () => ( +
+

Some text

+
+ ) + + export { Component as default } +`; + +const ARROW_WITH_LOGICAL = ` +const Component = props => ( +
+ {true && +
+

Some text

+
+ } +
+) +`; + +const ARROW_WITH_LOGICAL_AUTOFIX = ` +const Component = props => ( +
+ {true && ( +
+

Some text

+
+ )} +
+) +`; function addNewLineSymbols(code) { return code.replace(/\(\)/g, '>\n)'); @@ -1189,5 +1232,23 @@ ruleTester.run('jsx-wrap-multilines', rule, { output: SFC_NO_PARENS_AUTOFIX, options: [OPTIONS_ALL_NEW_LINES], errors: [{message: MISSING_PARENS}] + }, { + code: ARROW_WITH_EXPORT, + output: ARROW_WITH_EXPORT_AUTOFIX, + options: [{ + declaration: 'parens-new-line', + assignment: 'parens-new-line', + return: 'parens-new-line', + arrow: 'parens-new-line', + condition: 'parens-new-line', + logical: 'ignore', + prop: 'ignore' + }], + errors: [{message: MISSING_PARENS}] + }, { + code: ARROW_WITH_LOGICAL, + output: ARROW_WITH_LOGICAL_AUTOFIX, + options: [{logical: 'parens-new-line'}], + errors: [{message: MISSING_PARENS}] }] });