Skip to content

Commit cfcb2bb

Browse files
committed
[jsx-wrap-multilines] Сompatibility with current default parametrs
1 parent ccb9132 commit cfcb2bb

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

docs/rules/jsx-wrap-multilines.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Wrapping multiline JSX in parentheses can improve readability and/or convenience
66

77
## Rule Details
88

9-
This rule optionally takes a second parameter in the form of an object, containing places to apply the rule. By default, all the syntax listed below will be checked except the logical expressions and JSX attributes, but these can be explicitly disabled. Any syntax type missing in the object will follow the default behavior (become enabled).
9+
This rule optionally takes a second parameter in the form of an object, containing places to apply the rule. By default, all the syntax listed below will be checked except the conditions out of declaration or assignment, logical expressions and JSX attributes, but these can be explicitly disabled. Any syntax type missing in the object will follow the default behavior (become enabled).
1010

1111
There are the possible syntax available:
1212

1313
* `declaration`
1414
* `assignment`
1515
* `return`
1616
* `arrow`
17-
* `condition`
17+
* `condition` (not enabed by default, by default only conditions in declaraiton or assignment)
1818
* `logical` (not enabled by default)
1919
* `prop` (not enabled by default)
2020

lib/rules/jsx-wrap-multilines.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const DEFAULTS = {
1515
assignment: true,
1616
return: true,
1717
arrow: true,
18-
condition: true,
18+
condition: false,
1919
logical: false,
2020
prop: false
2121
};
@@ -112,13 +112,23 @@ module.exports = {
112112
if (!isEnabled('declaration')) {
113113
return;
114114
}
115+
if (!isEnabled('condition') && node.init && node.init.type === 'ConditionalExpression') {
116+
check(node.init.consequent);
117+
check(node.init.alternate);
118+
return;
119+
}
115120
check(node.init);
116121
},
117122

118123
AssignmentExpression: function(node) {
119124
if (!isEnabled('assignment')) {
120125
return;
121126
}
127+
if (!isEnabled('condition') && node.right.type === 'ConditionalExpression') {
128+
check(node.right.consequent);
129+
check(node.right.alternate);
130+
return;
131+
}
122132
check(node.right);
123133
},
124134

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ ruleTester.run('jsx-wrap-multilines', rule, {
217217
code: DECLARATION_TERNARY_PAREN
218218
}, {
219219
code: DECLARATION_TERNARY_NO_PAREN,
220-
options: [{condition: false}]
220+
options: [{declaration: false}]
221221
}, {
222222
code: ASSIGNMENT_TERNARY_SINGLE_LINE
223223
}, {
224224
code: ASSIGNMENT_TERNARY_PAREN
225225
}, {
226226
code: ASSIGNMENT_TERNARY_NO_PAREN,
227-
options: [{condition: false}]
227+
options: [{assignment: false}]
228228
}, {
229229
code: DECLARATION_SINGLE_LINE
230230
}, {
@@ -252,10 +252,13 @@ ruleTester.run('jsx-wrap-multilines', rule, {
252252
}, {
253253
code: CONDITION_SINGLE_LINE
254254
}, {
255-
code: CONDITION_NO_PAREN,
256-
options: [{condition: false}]
255+
code: CONDITION_SINGLE_LINE,
256+
options: [{condition: true}]
257+
}, {
258+
code: CONDITION_NO_PAREN
257259
}, {
258-
code: CONDITION_PAREN
260+
code: CONDITION_PAREN,
261+
options: [{condition: true}]
259262
}, {
260263
code: LOGICAL_SINGLE_LINE
261264
}, {
@@ -323,6 +326,7 @@ ruleTester.run('jsx-wrap-multilines', rule, {
323326
}, {
324327
code: CONDITION_NO_PAREN,
325328
output: CONDITION_PAREN,
329+
options: [{condition: true}],
326330
errors: [{message: 'Missing parentheses around multilines JSX'}]
327331
}, {
328332
code: LOGICAL_NO_PAREN,

0 commit comments

Comments
 (0)