Skip to content

Commit a223964

Browse files
author
Joachim Seminck
committed
Better fixer for conditional
1 parent 0ce122b commit a223964

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

lib/rules/jsx-wrap-multilines.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = {
7070
return node.loc.start.line !== node.loc.end.line;
7171
}
7272

73-
function check(node) {
73+
function check(node, fixerFn) {
7474
if (!node || node.type !== 'JSXElement') {
7575
return;
7676
}
@@ -79,7 +79,7 @@ module.exports = {
7979
context.report({
8080
node: node,
8181
message: 'Missing parentheses around multilines JSX',
82-
fix: function(fixer) {
82+
fix: fixerFn || function(fixer) {
8383
return fixer.replaceText(node, `(${sourceCode.getText(node)})`);
8484
}
8585
});
@@ -135,7 +135,14 @@ module.exports = {
135135
return;
136136
}
137137

138-
check(node.expression.right);
138+
const rightNode = node.expression.right;
139+
140+
check(rightNode, (fixer) => {
141+
return [
142+
fixer.insertTextAfterRange(sourceCode.getTokenBefore(rightNode).range, ' ('),
143+
fixer.insertTextBeforeRange(sourceCode.getLastToken(node).range, ')')
144+
];
145+
});
139146
},
140147

141148
'ArrowFunctionExpression:exit': function (node) {

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ const CONDITIONAL_SINGLE_LINE = `
141141
`;
142142

143143
const CONDITIONAL_PAREN = `
144-
<div>
145-
{unreadMessages.length > 0 &&
146-
(<h2>
147-
You have {unreadMessages.length} unread messages.
148-
</h2>)
149-
}
150-
</div>
151-
`;
152-
153-
const CONDITIONAL_PAREN_DIFFERENT_LINE = `
154144
<div>
155145
{unreadMessages.length > 0 && (
156146
<h2>
@@ -228,9 +218,6 @@ ruleTester.run('jsx-wrap-multilines', rule, {
228218
}, {
229219
code: CONDITIONAL_PAREN,
230220
options: [{conditional: true}]
231-
}, {
232-
code: CONDITIONAL_PAREN_DIFFERENT_LINE,
233-
options: [{conditional: true}]
234221
}, {
235222
code: CONDITIONAL_SINGLE_LINE,
236223
options: [{conditional: true}]

0 commit comments

Comments
 (0)