Skip to content

Commit

Permalink
Fix jsx-indent indentation calculation with nested JSX (fixes #1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Mar 19, 2017
1 parent ab03af8 commit 41bdb58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ module.exports = {
prevToken = prevToken.type === 'JSXExpressionContainer' ? prevToken.expression : prevToken;

var parentElementIndent = getNodeIndent(prevToken);
if (prevToken.type === 'JSXElement') {
if (prevToken.type === 'JSXElement' && (!prevToken.parent || prevToken.parent.type !== 'LogicalExpression')) {
parentElementIndent = getOpeningElementIndent(prevToken.openingElement);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,22 @@ ruleTester.run('jsx-indent', rule, {
].join('\n'),
options: [2],
parserOptions: parserOptions
}, {
code: [
'function foo() {',
' return (',
' <div>',
' {bar &&',
' <Div>',
' <span />',
' </Div>',
' }',
' </div>',
' );',
'}'
].join('\n'),
options: [2],
parserOptions: parserOptions
}],

invalid: [{
Expand Down

0 comments on commit 41bdb58

Please sign in to comment.