Skip to content

Commit

Permalink
Fix jsx-indent to allow multi-line logical expressions with one level…
Browse files Browse the repository at this point in the history
… of indent
  • Loading branch information
yannickcr committed Oct 10, 2016
1 parent d0dfc07 commit cc84a46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,6 @@ module.exports = {
);
}

/**
* Check if the node is the parenthesized right member of a logical expression
* @param {ASTNode} node The node to check
* @return {Boolean} true if its the case, false if not
*/
function isParenthesizedInLogicalExp(node) {
var token = sourceCode.getTokenBefore(node);
return isRightInLogicalExp(node) && token.type === 'Punctuator' && token.value === '(';
}

/**
* Check indent for nodes list
* @param {ASTNode} node The node to check
Expand All @@ -208,7 +198,8 @@ module.exports = {
*/
function checkNodesIndent(node, indent, excludeCommas) {
var nodeIndent = getNodeIndent(node, false, excludeCommas);
if (nodeIndent !== indent && isNodeFirstInLine(node) && !isParenthesizedInLogicalExp(node)) {
var isCorrectRightInLogicalExp = isRightInLogicalExp(node) && (nodeIndent - indent) === indentSize;
if (nodeIndent !== indent && isNodeFirstInLine(node) && !isCorrectRightInLogicalExp) {
report(node, indent, nodeIndent);
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ ruleTester.run('jsx-indent', rule, {
].join('\n'),
parserOptions: parserOptions,
options: [2]
}, {
code: [
'{',
' head.title &&',
' <h1>',
' {head.title}',
' </h1>',
'}'
].join('\n'),
parserOptions: parserOptions,
options: [2]
}, {
code: [
'{',
Expand Down

0 comments on commit cc84a46

Please sign in to comment.