From eb039b865c70caee37cd4836587cccfbd3a3d92c Mon Sep 17 00:00:00 2001 From: Eugene Alanev Date: Fri, 11 Aug 2017 18:33:50 +0300 Subject: [PATCH 01/13] Add new line before/after parentheses when wrap --- lib/rules/jsx-wrap-multilines.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index ca12f033e6..172c12754d 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -76,7 +76,7 @@ module.exports = { node: node, message: 'Missing parentheses around multilines JSX', fix: function(fixer) { - return fixer.replaceText(node, `(${sourceCode.getText(node)})`); + return fixer.replaceText(node, `(\n${sourceCode.getText(node)}\n)`); } }); } From 04f3b9f9e96e8dd1c173dc57c8d3084a5e4b94c6 Mon Sep 17 00:00:00 2001 From: Eugene Alanev Date: Fri, 11 Aug 2017 18:34:41 +0300 Subject: [PATCH 02/13] Add new nodes for wrap Add ConditionalExpression, LogicalExpression and JSXAttribute --- lib/rules/jsx-wrap-multilines.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index 172c12754d..984cb60925 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -133,6 +133,21 @@ module.exports = { check(arrowBody); } } + + ConditionalExpression: function(node) { + check(node.consequent); + check(node.alternate); + }, + + LogicalExpression: function(node) { + check(node.right); + }, + + JSXAttribute: function (node) { + if (node.value && node.value.type === 'JSXExpressionContainer') { + check(node.value.expression); + } + } }; } }; From ed319dccdb92597d8278f51eb1772e39f1d76780 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Sat, 19 Aug 2017 20:54:56 +0300 Subject: [PATCH 03/13] [jsx-wrap-multilines] Fix typo --- lib/rules/jsx-wrap-multilines.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index 984cb60925..0fc56e9829 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -132,7 +132,7 @@ module.exports = { if (isEnabled('arrow') && arrowBody.type !== 'BlockStatement') { check(arrowBody); } - } + }, ConditionalExpression: function(node) { check(node.consequent); @@ -144,9 +144,9 @@ module.exports = { }, JSXAttribute: function (node) { - if (node.value && node.value.type === 'JSXExpressionContainer') { - check(node.value.expression); - } + if (node.value && node.value.type === 'JSXExpressionContainer') { + check(node.value.expression); + } } }; } From 2bbd79cb864e0b6d7a58a3497805538ea8115788 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Sat, 19 Aug 2017 22:53:46 +0300 Subject: [PATCH 04/13] [jsx-wrap-multilines] Add tests --- lib/rules/jsx-wrap-multilines.js | 33 ++++-- tests/lib/rules/jsx-wrap-multilines.js | 144 ++++++++++++++----------- 2 files changed, 102 insertions(+), 75 deletions(-) diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index 0fc56e9829..7984df0855 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -14,7 +14,10 @@ const DEFAULTS = { declaration: true, assignment: true, return: true, - arrow: true + arrow: true, + condition: false, + logical: false, + attr: false }; // ------------------------------------------------------------------------------ @@ -44,6 +47,15 @@ module.exports = { }, arrow: { type: 'boolean' + }, + condition: { + type: 'boolean' + }, + logical: { + type: 'boolean' + }, + attr: { + type: 'boolean' } }, additionalProperties: false @@ -76,7 +88,7 @@ module.exports = { node: node, message: 'Missing parentheses around multilines JSX', fix: function(fixer) { - return fixer.replaceText(node, `(\n${sourceCode.getText(node)}\n)`); + return fixer.replaceText(node, `(${sourceCode.getText(node)})`); } }); } @@ -100,11 +112,6 @@ module.exports = { if (!isEnabled('declaration')) { return; } - if (node.init && node.init.type === 'ConditionalExpression') { - check(node.init.consequent); - check(node.init.alternate); - return; - } check(node.init); }, @@ -135,16 +142,20 @@ module.exports = { }, ConditionalExpression: function(node) { - check(node.consequent); - check(node.alternate); + if (isEnabled('condition')) { + check(node.consequent); + check(node.alternate); + } }, LogicalExpression: function(node) { - check(node.right); + if (isEnabled('logical')) { + check(node.right); + } }, JSXAttribute: function (node) { - if (node.value && node.value.type === 'JSXExpressionContainer') { + if (isEnabled('attr') && node.value && node.value.type === 'JSXExpressionContainer') { check(node.value.expression); } } diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 3d3b7bdc1d..dda5c2b359 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -52,84 +52,92 @@ const RETURN_NO_PAREN = ` }); `; -const DECLARATION_TERNARY_SINGLE_LINE = 'var hello = foo ?

Hello

:

Hi

;'; +const DECLARATION_SINGLE_LINE = 'var hello =

Hello

;'; -const DECLARATION_TERNARY_PAREN = ` - var hello = foo ? (
+const DECLARATION_PAREN = ` + var hello = (

Hello

-
) : (
-

Hi

); `; -const DECLARATION_TERNARY_NO_PAREN = ` - var hello = foo ?
+const DECLARATION_NO_PAREN = ` + var hello =

Hello

-
:
-

Hi

; `; -const ASSIGNMENT_TERNARY_SINGLE_LINE = 'var hello; hello = foo ?

Hello

:

Hi

;'; +const ASSIGNMENT_SINGLE_LINE = 'var hello; hello =

Hello

;'; -const ASSIGNMENT_TERNARY_PAREN = ` +const ASSIGNMENT_PAREN = ` var hello; - hello = foo ? (
+ hello = (

Hello

-
) : (
-

Hi

); `; -const ASSIGNMENT_TERNARY_NO_PAREN = ` +const ASSIGNMENT_NO_PAREN = ` var hello; - hello = foo ?
+ hello =

Hello

-
:
-

Hi

; `; -const DECLARATION_SINGLE_LINE = 'var hello =

Hello

;'; +const ARROW_SINGLE_LINE = 'var hello = () =>

Hello

;'; -const DECLARATION_PAREN = ` - var hello = (
+const ARROW_PAREN = ` + var hello = () => (

Hello

); `; -const DECLARATION_NO_PAREN = ` - var hello =
+const ARROW_NO_PAREN = ` + var hello = () =>

Hello

; `; -const ASSIGNMENT_SINGLE_LINE = 'var hello; hello =

Hello

;'; +const CONDITION_SINGLE_LINE = 'foo ?

Hello

: null;'; -const ASSIGNMENT_PAREN = ` - var hello; - hello = (
+const CONDITION_PAREN = ` + foo ? (
+

Hello

+
) : null; +`; + +const CONDITION_NO_PAREN = ` + foo ?
+

Hello

+
: null; +`; + +const LOGICAL_SINGLE_LINE = 'foo &&

Hello

;'; + +const LOGICAL_PAREN = ` + foo && (

Hello

); `; -const ASSIGNMENT_NO_PAREN = ` - var hello; - hello =
+const LOGICAL_NO_PAREN = ` + foo &&

Hello

; `; -const ARROW_SINGLE_LINE = 'var hello = () =>

Hello

;'; +const ATTR_SINGLE_LINE = '
Hello

}>
'; -const ARROW_PAREN = ` - var hello = () => (
+const ATTR_PAREN = ` +
+

Hello

+
)}>

Hello

-
); +
; `; -const ARROW_NO_PAREN = ` - var hello = () =>
+const ATTR_NO_PAREN = ` +
+

Hello

+
}>

Hello

; `; @@ -149,20 +157,6 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: RETURN_NO_PAREN, options: [{return: false}] - }, { - code: DECLARATION_TERNARY_SINGLE_LINE - }, { - code: DECLARATION_TERNARY_PAREN - }, { - code: DECLARATION_TERNARY_NO_PAREN, - options: [{declaration: false}] - }, { - code: ASSIGNMENT_TERNARY_SINGLE_LINE - }, { - code: ASSIGNMENT_TERNARY_PAREN - }, { - code: ASSIGNMENT_TERNARY_NO_PAREN, - options: [{assignment: false}] }, { code: DECLARATION_SINGLE_LINE }, { @@ -187,6 +181,27 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: ARROW_NO_PAREN, options: [{arrow: false}] + }, { + code: CONDITION_SINGLE_LINE + }, { + code: CONDITION_NO_PAREN + }, { + code: CONDITION_PAREN, + options: [{condition: true}] + }, { + code: LOGICAL_SINGLE_LINE + }, { + code: LOGICAL_NO_PAREN + }, { + code: LOGICAL_PAREN, + options: [{logical: true}] + }, { + code: ATTR_SINGLE_LINE + }, { + code: ATTR_NO_PAREN + }, { + code: ATTR_PAREN, + options: [{attr: true}] } ], @@ -200,20 +215,6 @@ ruleTester.run('jsx-wrap-multilines', rule, { output: RETURN_PAREN, options: [{return: true}], errors: [{message: 'Missing parentheses around multilines JSX'}] - }, { - code: DECLARATION_TERNARY_NO_PAREN, - output: DECLARATION_TERNARY_PAREN, - errors: [ - {message: 'Missing parentheses around multilines JSX'}, - {message: 'Missing parentheses around multilines JSX'} - ] - }, { - code: ASSIGNMENT_TERNARY_NO_PAREN, - output: ASSIGNMENT_TERNARY_PAREN, - errors: [ - {message: 'Missing parentheses around multilines JSX'}, - {message: 'Missing parentheses around multilines JSX'} - ] }, { code: DECLARATION_NO_PAREN, output: DECLARATION_PAREN, @@ -237,6 +238,21 @@ ruleTester.run('jsx-wrap-multilines', rule, { output: ARROW_PAREN, options: [{arrow: true}], errors: [{message: 'Missing parentheses around multilines JSX'}] + }, { + code: CONDITION_NO_PAREN, + output: CONDITION_PAREN, + options: [{condition: true}], + errors: [{message: 'Missing parentheses around multilines JSX'}] + }, { + code: LOGICAL_NO_PAREN, + output: LOGICAL_PAREN, + options: [{logical: true}], + errors: [{message: 'Missing parentheses around multilines JSX'}] + }, { + code: ATTR_NO_PAREN, + output: ATTR_PAREN, + options: [{attr: true}], + errors: [{message: 'Missing parentheses around multilines JSX'}] } ] }); From 21d9a20268e8f43980031997e48f08ea97fc8116 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Sat, 19 Aug 2017 23:21:46 +0300 Subject: [PATCH 05/13] [jsx-wrap-multilines] Better tests --- tests/lib/rules/jsx-wrap-multilines.js | 36 +++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index dda5c2b359..0f91e3a8d9 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -99,29 +99,41 @@ const ARROW_NO_PAREN = ` const CONDITION_SINGLE_LINE = 'foo ?

Hello

: null;'; const CONDITION_PAREN = ` - foo ? (
-

Hello

-
) : null; +
+ {foo ? (
+

Hello

+
) : null} +
`; const CONDITION_NO_PAREN = ` - foo ?
-

Hello

-
: null; +
+ {foo ?
+

Hello

+
: null} +
`; const LOGICAL_SINGLE_LINE = 'foo &&

Hello

;'; const LOGICAL_PAREN = ` - foo && (
-

Hello

-
); +
+ {foo && + (
+

Hello World

+
) + } +
`; const LOGICAL_NO_PAREN = ` - foo &&
-

Hello

-
; +
+ {foo && +
+

Hello World

+
+ } +
`; const ATTR_SINGLE_LINE = '
Hello

}>
'; From 657e77e373181b17ed88e5d32a1be67277894633 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Sun, 20 Aug 2017 15:31:45 +0300 Subject: [PATCH 06/13] [jsx-wrap-multilines] Better tests for attributes --- tests/lib/rules/jsx-wrap-multilines.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 0f91e3a8d9..5515a56dae 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -139,19 +139,23 @@ const LOGICAL_NO_PAREN = ` const ATTR_SINGLE_LINE = '
Hello

}>
'; const ATTR_PAREN = ` -
+

Hello

-
)}> +
) + }>

Hello

-
; +
`; const ATTR_NO_PAREN = ` -
+

Hello

-
}> +
+ }>

Hello

-
; +
`; // ------------------------------------------------------------------------------ From 252c3baf52163ab4acceeb7a7e3349042dc61f4f Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Sun, 20 Aug 2017 15:35:45 +0300 Subject: [PATCH 07/13] [jsx-wrap-multilines] Add docs --- docs/rules/jsx-wrap-multilines.md | 64 ++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/docs/rules/jsx-wrap-multilines.md b/docs/rules/jsx-wrap-multilines.md index d80bf70d04..68ff544e21 100644 --- a/docs/rules/jsx-wrap-multilines.md +++ b/docs/rules/jsx-wrap-multilines.md @@ -6,7 +6,7 @@ Wrapping multiline JSX in parentheses can improve readability and/or convenience ## Rule Details -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, but these can be explicitly disabled. Any syntax type missing in the object will follow the default behavior (become enabled). +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 conditional expressions, 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). There are the possible syntax available: @@ -14,6 +14,9 @@ There are the possible syntax available: * `assignment` * `return` * `arrow` +* `condition` (not enabled by default) +* `logical` (not enabled by default) +* `attr` (not enabled by default) The following patterns are considered warnings: @@ -118,3 +121,62 @@ var hello = () => (
); ``` + +The following patterns are considered warnings when configured `{condition: true}`. + +```jsx +
+ {foo ?
+

Hello

+
: null} +
+``` + +The following patterns are not considered warnings when configured `{condition: true}`. + +```jsx +
+ {foo ? (
+

Hello

+
) : null} +
+``` + + +The following patterns are considered warnings when configured `{logical: true}`. + +```jsx +
+ {foo && +
+

Hello World

+
+ } +
+``` + +The following patterns are not considered warnings when configured `{logical: true}`. + +```jsx +
not +``` + +The following patterns are considered warnings when configured `{attr: true}`. + +```jsx +
+

Hello

+
}> +

Hello

+
; +``` + +The following patterns are not considered warnings when configured `{attr: true}`. + +```jsx +
+

Hello

+
)}> +

Hello

+
; +``` From cea83052b7f180768ff666f477698d082e82c648 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Tue, 22 Aug 2017 11:10:42 +0300 Subject: [PATCH 08/13] [jsx-wrap-multilines] Fix example --- docs/rules/jsx-wrap-multilines.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/rules/jsx-wrap-multilines.md b/docs/rules/jsx-wrap-multilines.md index 68ff544e21..82ab84bfd4 100644 --- a/docs/rules/jsx-wrap-multilines.md +++ b/docs/rules/jsx-wrap-multilines.md @@ -158,7 +158,13 @@ The following patterns are considered warnings when configured `{logical: true}` The following patterns are not considered warnings when configured `{logical: true}`. ```jsx -
not +
+ {foo && + (
+

Hello World

+
) + } +
``` The following patterns are considered warnings when configured `{attr: true}`. From a05c589f5a15a4936466d3849fd2b9d2f7ecc50f Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Tue, 22 Aug 2017 11:37:24 +0300 Subject: [PATCH 09/13] [jsx-wrap-multilines] Return tests --- tests/lib/rules/jsx-wrap-multilines.js | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 5515a56dae..261251bf4e 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -51,6 +51,43 @@ const RETURN_NO_PAREN = ` } }); `; +const DECLARATION_TERNARY_SINGLE_LINE = 'var hello = foo ?

Hello

:

Hi

;'; + +const DECLARATION_TERNARY_PAREN = ` + var hello = foo ? (
+

Hello

+
) : (
+

Hi

+
); +`; + +const DECLARATION_TERNARY_NO_PAREN = ` + var hello = foo ?
+

Hello

+
:
+

Hi

+
; +`; + +const ASSIGNMENT_TERNARY_SINGLE_LINE = 'var hello; hello = foo ?

Hello

:

Hi

;'; + +const ASSIGNMENT_TERNARY_PAREN = ` + var hello; + hello = foo ? (
+

Hello

+
) : (
+

Hi

+
); +`; + +const ASSIGNMENT_TERNARY_NO_PAREN = ` + var hello; + hello = foo ?
+

Hello

+
:
+

Hi

+
; +`; const DECLARATION_SINGLE_LINE = 'var hello =

Hello

;'; @@ -173,6 +210,20 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: RETURN_NO_PAREN, options: [{return: false}] + }, { + code: DECLARATION_TERNARY_SINGLE_LINE + }, { + code: DECLARATION_TERNARY_PAREN + }, { + code: DECLARATION_TERNARY_NO_PAREN, + options: [{declaration: false}] + }, { + code: ASSIGNMENT_TERNARY_SINGLE_LINE + }, { + code: ASSIGNMENT_TERNARY_PAREN + }, { + code: ASSIGNMENT_TERNARY_NO_PAREN, + options: [{assignment: false}] }, { code: DECLARATION_SINGLE_LINE }, { From dc729fa388e0eb0ae57801af6f84ae4516ca3128 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Tue, 22 Aug 2017 11:49:00 +0300 Subject: [PATCH 10/13] [jsx-wrap-multilines] Return invalid tests --- tests/lib/rules/jsx-wrap-multilines.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 261251bf4e..ec16fbce99 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -51,6 +51,7 @@ const RETURN_NO_PAREN = ` } }); `; + const DECLARATION_TERNARY_SINGLE_LINE = 'var hello = foo ?

Hello

:

Hi

;'; const DECLARATION_TERNARY_PAREN = ` @@ -282,6 +283,20 @@ ruleTester.run('jsx-wrap-multilines', rule, { output: RETURN_PAREN, options: [{return: true}], errors: [{message: 'Missing parentheses around multilines JSX'}] + }, { + code: DECLARATION_TERNARY_NO_PAREN, + output: DECLARATION_TERNARY_PAREN, + errors: [ + {message: 'Missing parentheses around multilines JSX'}, + {message: 'Missing parentheses around multilines JSX'} + ] + }, { + code: ASSIGNMENT_TERNARY_NO_PAREN, + output: ASSIGNMENT_TERNARY_PAREN, + errors: [ + {message: 'Missing parentheses around multilines JSX'}, + {message: 'Missing parentheses around multilines JSX'} + ] }, { code: DECLARATION_NO_PAREN, output: DECLARATION_PAREN, From 41a29c6f4fbec863482557fdb6f292c17cf6f06b Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Tue, 22 Aug 2017 11:54:31 +0300 Subject: [PATCH 11/13] [jsx-wrap-multilines] Fix tests. Check conditions by default --- docs/rules/jsx-wrap-multilines.md | 4 ++-- lib/rules/jsx-wrap-multilines.js | 7 +------ tests/lib/rules/jsx-wrap-multilines.js | 11 +++++------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/docs/rules/jsx-wrap-multilines.md b/docs/rules/jsx-wrap-multilines.md index 82ab84bfd4..a012f4041c 100644 --- a/docs/rules/jsx-wrap-multilines.md +++ b/docs/rules/jsx-wrap-multilines.md @@ -6,7 +6,7 @@ Wrapping multiline JSX in parentheses can improve readability and/or convenience ## Rule Details -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 conditional expressions, 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). +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). There are the possible syntax available: @@ -14,7 +14,7 @@ There are the possible syntax available: * `assignment` * `return` * `arrow` -* `condition` (not enabled by default) +* `condition` * `logical` (not enabled by default) * `attr` (not enabled by default) diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index 7984df0855..7e3b563738 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -15,7 +15,7 @@ const DEFAULTS = { assignment: true, return: true, arrow: true, - condition: false, + condition: true, logical: false, attr: false }; @@ -119,11 +119,6 @@ module.exports = { if (!isEnabled('assignment')) { return; } - if (node.right.type === 'ConditionalExpression') { - check(node.right.consequent); - check(node.right.alternate); - return; - } check(node.right); }, diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index ec16fbce99..a705e0d0b0 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -217,14 +217,14 @@ ruleTester.run('jsx-wrap-multilines', rule, { code: DECLARATION_TERNARY_PAREN }, { code: DECLARATION_TERNARY_NO_PAREN, - options: [{declaration: false}] + options: [{condition: false}] }, { code: ASSIGNMENT_TERNARY_SINGLE_LINE }, { code: ASSIGNMENT_TERNARY_PAREN }, { code: ASSIGNMENT_TERNARY_NO_PAREN, - options: [{assignment: false}] + options: [{condition: false}] }, { code: DECLARATION_SINGLE_LINE }, { @@ -252,10 +252,10 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: CONDITION_SINGLE_LINE }, { - code: CONDITION_NO_PAREN + code: CONDITION_NO_PAREN, + options: [{condition: false}] }, { - code: CONDITION_PAREN, - options: [{condition: true}] + code: CONDITION_PAREN }, { code: LOGICAL_SINGLE_LINE }, { @@ -323,7 +323,6 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: CONDITION_NO_PAREN, output: CONDITION_PAREN, - options: [{condition: true}], errors: [{message: 'Missing parentheses around multilines JSX'}] }, { code: LOGICAL_NO_PAREN, From ccb91328c92da06142d2a977109950d6b8f6ba16 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Fri, 1 Sep 2017 16:07:28 +0300 Subject: [PATCH 12/13] [jsx-wrap-multilines] Rename attr to prop --- docs/rules/jsx-wrap-multilines.md | 2 +- lib/rules/jsx-wrap-multilines.js | 6 +++--- tests/lib/rules/jsx-wrap-multilines.js | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/rules/jsx-wrap-multilines.md b/docs/rules/jsx-wrap-multilines.md index a012f4041c..69692ebef0 100644 --- a/docs/rules/jsx-wrap-multilines.md +++ b/docs/rules/jsx-wrap-multilines.md @@ -16,7 +16,7 @@ There are the possible syntax available: * `arrow` * `condition` * `logical` (not enabled by default) -* `attr` (not enabled by default) +* `prop` (not enabled by default) The following patterns are considered warnings: diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index 7e3b563738..6a35d1fc32 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -17,7 +17,7 @@ const DEFAULTS = { arrow: true, condition: true, logical: false, - attr: false + prop: false }; // ------------------------------------------------------------------------------ @@ -54,7 +54,7 @@ module.exports = { logical: { type: 'boolean' }, - attr: { + prop: { type: 'boolean' } }, @@ -150,7 +150,7 @@ module.exports = { }, JSXAttribute: function (node) { - if (isEnabled('attr') && node.value && node.value.type === 'JSXExpressionContainer') { + if (isEnabled('prop') && node.value && node.value.type === 'JSXExpressionContainer') { check(node.value.expression); } } diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index a705e0d0b0..9f18813e4e 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -174,10 +174,10 @@ const LOGICAL_NO_PAREN = `
`; -const ATTR_SINGLE_LINE = '
Hello

}>
'; +const ATTR_SINGLE_LINE = '
Hello

}>
'; const ATTR_PAREN = ` -

Hello

) @@ -187,7 +187,7 @@ const ATTR_PAREN = ` `; const ATTR_NO_PAREN = ` -

Hello

@@ -269,7 +269,7 @@ ruleTester.run('jsx-wrap-multilines', rule, { code: ATTR_NO_PAREN }, { code: ATTR_PAREN, - options: [{attr: true}] + options: [{prop: true}] } ], @@ -332,7 +332,7 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: ATTR_NO_PAREN, output: ATTR_PAREN, - options: [{attr: true}], + options: [{prop: true}], errors: [{message: 'Missing parentheses around multilines JSX'}] } ] From cfcb2bbfcbb10d7681cec91fa17d48d8efee5d95 Mon Sep 17 00:00:00 2001 From: Evgeny Petukhov Date: Mon, 4 Sep 2017 18:38:02 +0300 Subject: [PATCH 13/13] =?UTF-8?q?[jsx-wrap-multilines]=20=D0=A1ompatibilit?= =?UTF-8?q?y=20with=20current=20default=20parametrs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/rules/jsx-wrap-multilines.md | 4 ++-- lib/rules/jsx-wrap-multilines.js | 12 +++++++++++- tests/lib/rules/jsx-wrap-multilines.js | 14 +++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/rules/jsx-wrap-multilines.md b/docs/rules/jsx-wrap-multilines.md index 69692ebef0..f88db9b0b9 100644 --- a/docs/rules/jsx-wrap-multilines.md +++ b/docs/rules/jsx-wrap-multilines.md @@ -6,7 +6,7 @@ Wrapping multiline JSX in parentheses can improve readability and/or convenience ## Rule Details -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). +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). There are the possible syntax available: @@ -14,7 +14,7 @@ There are the possible syntax available: * `assignment` * `return` * `arrow` -* `condition` +* `condition` (not enabed by default, by default only conditions in declaraiton or assignment) * `logical` (not enabled by default) * `prop` (not enabled by default) diff --git a/lib/rules/jsx-wrap-multilines.js b/lib/rules/jsx-wrap-multilines.js index 6a35d1fc32..b4e7bbc005 100644 --- a/lib/rules/jsx-wrap-multilines.js +++ b/lib/rules/jsx-wrap-multilines.js @@ -15,7 +15,7 @@ const DEFAULTS = { assignment: true, return: true, arrow: true, - condition: true, + condition: false, logical: false, prop: false }; @@ -112,6 +112,11 @@ module.exports = { if (!isEnabled('declaration')) { return; } + if (!isEnabled('condition') && node.init && node.init.type === 'ConditionalExpression') { + check(node.init.consequent); + check(node.init.alternate); + return; + } check(node.init); }, @@ -119,6 +124,11 @@ module.exports = { if (!isEnabled('assignment')) { return; } + if (!isEnabled('condition') && node.right.type === 'ConditionalExpression') { + check(node.right.consequent); + check(node.right.alternate); + return; + } check(node.right); }, diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 9f18813e4e..59ad236d51 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -217,14 +217,14 @@ ruleTester.run('jsx-wrap-multilines', rule, { code: DECLARATION_TERNARY_PAREN }, { code: DECLARATION_TERNARY_NO_PAREN, - options: [{condition: false}] + options: [{declaration: false}] }, { code: ASSIGNMENT_TERNARY_SINGLE_LINE }, { code: ASSIGNMENT_TERNARY_PAREN }, { code: ASSIGNMENT_TERNARY_NO_PAREN, - options: [{condition: false}] + options: [{assignment: false}] }, { code: DECLARATION_SINGLE_LINE }, { @@ -252,10 +252,13 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: CONDITION_SINGLE_LINE }, { - code: CONDITION_NO_PAREN, - options: [{condition: false}] + code: CONDITION_SINGLE_LINE, + options: [{condition: true}] + }, { + code: CONDITION_NO_PAREN }, { - code: CONDITION_PAREN + code: CONDITION_PAREN, + options: [{condition: true}] }, { code: LOGICAL_SINGLE_LINE }, { @@ -323,6 +326,7 @@ ruleTester.run('jsx-wrap-multilines', rule, { }, { code: CONDITION_NO_PAREN, output: CONDITION_PAREN, + options: [{condition: true}], errors: [{message: 'Missing parentheses around multilines JSX'}] }, { code: LOGICAL_NO_PAREN,