Skip to content

Commit cc84a46

Browse files
committed
Fix jsx-indent to allow multi-line logical expressions with one level of indent
1 parent d0dfc07 commit cc84a46

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/rules/jsx-indent.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,6 @@ module.exports = {
190190
);
191191
}
192192

193-
/**
194-
* Check if the node is the parenthesized right member of a logical expression
195-
* @param {ASTNode} node The node to check
196-
* @return {Boolean} true if its the case, false if not
197-
*/
198-
function isParenthesizedInLogicalExp(node) {
199-
var token = sourceCode.getTokenBefore(node);
200-
return isRightInLogicalExp(node) && token.type === 'Punctuator' && token.value === '(';
201-
}
202-
203193
/**
204194
* Check indent for nodes list
205195
* @param {ASTNode} node The node to check
@@ -208,7 +198,8 @@ module.exports = {
208198
*/
209199
function checkNodesIndent(node, indent, excludeCommas) {
210200
var nodeIndent = getNodeIndent(node, false, excludeCommas);
211-
if (nodeIndent !== indent && isNodeFirstInLine(node) && !isParenthesizedInLogicalExp(node)) {
201+
var isCorrectRightInLogicalExp = isRightInLogicalExp(node) && (nodeIndent - indent) === indentSize;
202+
if (nodeIndent !== indent && isNodeFirstInLine(node) && !isCorrectRightInLogicalExp) {
212203
report(node, indent, nodeIndent);
213204
}
214205
}

tests/lib/rules/jsx-indent.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ ruleTester.run('jsx-indent', rule, {
144144
].join('\n'),
145145
parserOptions: parserOptions,
146146
options: [2]
147+
}, {
148+
code: [
149+
'{',
150+
' head.title &&',
151+
' <h1>',
152+
' {head.title}',
153+
' </h1>',
154+
'}'
155+
].join('\n'),
156+
parserOptions: parserOptions,
157+
options: [2]
147158
}, {
148159
code: [
149160
'{',

0 commit comments

Comments
 (0)