Skip to content

Commit b75c01c

Browse files
author
Joachim Seminck
committed
Validate parenthesis in JSXExpressionContainers
1 parent 9e13ae2 commit b75c01c

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/rules/jsx-wrap-multilines.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const DEFAULTS = {
1414
declaration: true,
1515
assignment: true,
1616
return: true,
17-
arrow: true
17+
arrow: true,
18+
conditional: false
1819
};
1920

2021
// ------------------------------------------------------------------------------
@@ -44,6 +45,9 @@ module.exports = {
4445
},
4546
arrow: {
4647
type: 'boolean'
48+
},
49+
conditional: {
50+
type: 'boolean'
4751
}
4852
},
4953
additionalProperties: false
@@ -126,6 +130,14 @@ module.exports = {
126130
}
127131
},
128132

133+
JSXExpressionContainer: function(node) {
134+
if (!isEnabled('conditional')) {
135+
return;
136+
}
137+
138+
check(node.expression.right);
139+
},
140+
129141
'ArrowFunctionExpression:exit': function (node) {
130142
const arrowBody = node.body;
131143

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ const ARROW_NO_PAREN = `
134134
</div>;
135135
`;
136136

137+
const CONDITIONAL_PAREN = `
138+
<div>
139+
{unreadMessages.length > 0 &&
140+
(<h2>
141+
You have {unreadMessages.length} unread messages.
142+
</h2>)
143+
}
144+
</div>
145+
`;
146+
147+
const CONDITIONAL_NO_PAREN = `
148+
<div>
149+
{unreadMessages.length > 0 &&
150+
<h2>
151+
You have {unreadMessages.length} unread messages.
152+
</h2>
153+
}
154+
</div>
155+
`;
156+
137157
// ------------------------------------------------------------------------------
138158
// Tests
139159
// ------------------------------------------------------------------------------
@@ -187,6 +207,13 @@ ruleTester.run('jsx-wrap-multilines', rule, {
187207
}, {
188208
code: ARROW_NO_PAREN,
189209
options: [{arrow: false}]
210+
}, {
211+
code: CONDITIONAL_PAREN
212+
}, {
213+
code: CONDITIONAL_PAREN,
214+
options: [{conditional: true}]
215+
}, {
216+
code: CONDITIONAL_NO_PAREN
190217
}
191218
],
192219

@@ -237,6 +264,11 @@ ruleTester.run('jsx-wrap-multilines', rule, {
237264
output: ARROW_PAREN,
238265
options: [{arrow: true}],
239266
errors: [{message: 'Missing parentheses around multilines JSX'}]
267+
}, {
268+
code: CONDITIONAL_NO_PAREN,
269+
output: CONDITIONAL_PAREN,
270+
options: [{conditional: true}],
271+
errors: [{message: 'Missing parentheses around multilines JSX'}]
240272
}
241273
]
242274
});

0 commit comments

Comments
 (0)