Skip to content

Commit 8a49143

Browse files
committed
Ensure backwards compat for jsx-wrap-multilines
Each test either uses the new string options or the old boolean options to be thorough.
1 parent b48c691 commit 8a49143

File tree

2 files changed

+85
-13
lines changed

2 files changed

+85
-13
lines changed

lib/rules/jsx-wrap-multilines.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ module.exports = {
3535

3636
schema: [{
3737
type: 'object',
38+
// true/false are for backwards compatibility
3839
properties: {
3940
declaration: {
40-
enum: ['ignore', 'parens', 'parens-new-line']
41+
enum: [true, false, 'ignore', 'parens', 'parens-new-line']
4142
},
4243
assignment: {
43-
enum: ['ignore', 'parens', 'parens-new-line']
44+
enum: [true, false, 'ignore', 'parens', 'parens-new-line']
4445
},
4546
return: {
46-
enum: ['ignore', 'parens', 'parens-new-line']
47+
enum: [true, false, 'ignore', 'parens', 'parens-new-line']
4748
},
4849
arrow: {
49-
enum: ['ignore', 'parens', 'parens-new-line']
50+
enum: [true, false, 'ignore', 'parens', 'parens-new-line']
5051
}
5152
},
5253
additionalProperties: false
@@ -66,7 +67,7 @@ module.exports = {
6667

6768
function isEnabled(type) {
6869
const option = getOption(type);
69-
return option !== 'ignore';
70+
return option && option !== 'ignore';
7071
}
7172

7273
function isParenthesised(node) {
@@ -106,7 +107,7 @@ module.exports = {
106107

107108
const option = getOption(type);
108109

109-
if (option === 'parens' && !isParenthesised(node) && isMultilines(node)) {
110+
if ((option === true || option === 'parens') && !isParenthesised(node) && isMultilines(node)) {
110111
report(node, MISSING_PARENS, fixer => fixer.replaceText(node, `(${sourceCode.getText(node)})`));
111112
}
112113

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

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,47 +215,99 @@ ruleTester.run('jsx-wrap-multilines', rule, {
215215
code: RETURN_SINGLE_LINE
216216
}, {
217217
code: RETURN_PAREN
218+
}, {
219+
code: RETURN_SINGLE_LINE,
220+
options: [{return: true}]
221+
}, {
222+
code: RETURN_PAREN,
223+
options: [{return: true}]
218224
}, {
219225
code: RETURN_NO_PAREN,
220226
options: [{return: 'ignore'}]
227+
}, {
228+
code: RETURN_NO_PAREN,
229+
options: [{return: false}]
221230
}, {
222231
code: DECLARATION_TERNARY_SINGLE_LINE
223232
}, {
224233
code: DECLARATION_TERNARY_PAREN
234+
}, {
235+
code: DECLARATION_TERNARY_SINGLE_LINE,
236+
options: [{declaration: true}]
237+
}, {
238+
code: DECLARATION_TERNARY_PAREN,
239+
options: [{declaration: true}]
225240
}, {
226241
code: DECLARATION_TERNARY_NO_PAREN,
227242
options: [{declaration: 'ignore'}]
243+
}, {
244+
code: DECLARATION_TERNARY_NO_PAREN,
245+
options: [{declaration: false}]
228246
}, {
229247
code: ASSIGNMENT_TERNARY_SINGLE_LINE
230248
}, {
231249
code: ASSIGNMENT_TERNARY_PAREN
250+
}, {
251+
code: ASSIGNMENT_TERNARY_SINGLE_LINE,
252+
options: [{assignment: true}]
253+
}, {
254+
code: ASSIGNMENT_TERNARY_PAREN,
255+
options: [{assignment: true}]
232256
}, {
233257
code: ASSIGNMENT_TERNARY_NO_PAREN,
234258
options: [{assignment: 'ignore'}]
259+
}, {
260+
code: ASSIGNMENT_TERNARY_NO_PAREN,
261+
options: [{assignment: false}]
235262
}, {
236263
code: DECLARATION_SINGLE_LINE
237264
}, {
238265
code: DECLARATION_PAREN
266+
}, {
267+
code: DECLARATION_SINGLE_LINE,
268+
options: [{declaration: true}]
269+
}, {
270+
code: DECLARATION_PAREN,
271+
options: [{declaration: true}]
239272
}, {
240273
code: DECLARATION_NO_PAREN,
241274
options: [{declaration: 'ignore'}]
275+
}, {
276+
code: DECLARATION_NO_PAREN,
277+
options: [{declaration: false}]
242278
}, {
243279
code: ASSIGNMENT_SINGLE_LINE,
244280
options: [{declaration: 'ignore'}]
281+
}, {
282+
code: ASSIGNMENT_SINGLE_LINE,
283+
options: [{declaration: false}]
245284
}, {
246285
code: ASSIGNMENT_PAREN
286+
}, {
287+
code: ASSIGNMENT_PAREN,
288+
options: [{assignment: true}]
247289
}, {
248290
code: ASSIGNMENT_NO_PAREN,
249291
options: [{assignment: 'ignore'}]
292+
}, {
293+
code: ASSIGNMENT_NO_PAREN,
294+
options: [{assignment: false}]
295+
}, {
296+
code: ARROW_PAREN
297+
}, {
298+
code: ARROW_SINGLE_LINE
250299
}, {
251300
code: ARROW_PAREN,
252-
options: []
301+
options: [{arrow: true}]
253302
}, {
254303
code: ARROW_SINGLE_LINE,
255-
options: []
304+
options: [{arrow: true}]
256305
}, {
257306
code: ARROW_NO_PAREN,
258307
options: [{arrow: 'ignore'}]
308+
}, {
309+
code: ARROW_NO_PAREN,
310+
options: [{arrow: false}]
259311
}, {
260312
code: RETURN_PAREN_NEW_LINE,
261313
options: [{return: 'parens-new-line'}]
@@ -285,7 +337,7 @@ ruleTester.run('jsx-wrap-multilines', rule, {
285337
}, {
286338
code: RETURN_NO_PAREN,
287339
output: RETURN_PAREN,
288-
options: [{return: 'parens'}],
340+
options: [{return: true}],
289341
errors: [{message: MISSING_PARENS}]
290342
}, {
291343
code: DECLARATION_TERNARY_NO_PAREN,
@@ -294,21 +346,37 @@ ruleTester.run('jsx-wrap-multilines', rule, {
294346
{message: MISSING_PARENS},
295347
{message: MISSING_PARENS}
296348
]
349+
}, {
350+
code: DECLARATION_TERNARY_NO_PAREN,
351+
output: DECLARATION_TERNARY_PAREN,
352+
options: [{declaration: true}],
353+
errors: [
354+
{message: MISSING_PARENS},
355+
{message: MISSING_PARENS}
356+
]
297357
}, {
298358
code: ASSIGNMENT_TERNARY_NO_PAREN,
299359
output: ASSIGNMENT_TERNARY_PAREN,
300360
errors: [
301361
{message: MISSING_PARENS},
302362
{message: MISSING_PARENS}
303363
]
364+
}, {
365+
code: ASSIGNMENT_TERNARY_NO_PAREN,
366+
output: ASSIGNMENT_TERNARY_PAREN,
367+
options: [{assignment: true}],
368+
errors: [
369+
{message: MISSING_PARENS},
370+
{message: MISSING_PARENS}
371+
]
304372
}, {
305373
code: DECLARATION_NO_PAREN,
306374
output: DECLARATION_PAREN,
307375
errors: [{message: MISSING_PARENS}]
308376
}, {
309377
code: DECLARATION_NO_PAREN,
310378
output: DECLARATION_PAREN,
311-
options: [{declaration: 'parens'}],
379+
options: [{declaration: true}],
312380
errors: [{message: MISSING_PARENS}]
313381
}, {
314382
code: ASSIGNMENT_NO_PAREN,
@@ -317,15 +385,18 @@ ruleTester.run('jsx-wrap-multilines', rule, {
317385
}, {
318386
code: ASSIGNMENT_NO_PAREN,
319387
output: ASSIGNMENT_PAREN,
320-
options: [{assignment: 'parens'}],
388+
options: [{assignment: true}],
321389
errors: [{message: MISSING_PARENS}]
322390
}, {
323391
code: ARROW_NO_PAREN,
324392
output: ARROW_PAREN,
325-
options: [{arrow: 'parens'}],
326393
errors: [{message: MISSING_PARENS}]
327394
}, {
328-
395+
code: ARROW_NO_PAREN,
396+
output: ARROW_PAREN,
397+
options: [{arrow: true}],
398+
errors: [{message: MISSING_PARENS}]
399+
}, {
329400
code: RETURN_NO_PAREN,
330401
output: addNewLineSymbols(RETURN_PAREN),
331402
options: [{return: 'parens-new-line'}],

0 commit comments

Comments
 (0)