Skip to content

Commit

Permalink
Fix jsx-indent in multi-line function calls (fixes #895)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Croissant committed Oct 9, 2016
1 parent e2f72f1 commit b70cc33
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,15 @@ module.exports = {

return {
JSXOpeningElement: function(node) {
if (!node.parent || !node.parent.parent) {
var prevToken = sourceCode.getTokenBefore(node);
if (!prevToken) {
return;
}
var parentElementIndent = getNodeIndent(node.parent.parent);
var indent = node.parent.parent.loc.start.line === node.loc.start.line ? 0 : indentSize;
if (prevToken.type === 'JSXText') {
prevToken = sourceCode.getNodeByRangeIndex(prevToken.start).parent;
}
var parentElementIndent = getNodeIndent(prevToken);
var indent = prevToken.loc.start.line === node.loc.start.line ? 0 : indentSize;
checkNodesIndent(node, parentElementIndent + indent);
},
JSXClosingElement: function(node) {
Expand Down
36 changes: 35 additions & 1 deletion tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ ruleTester.run('jsx-indent', rule, {
].join('\n'),
options: [2],
parserOptions: parserOptions
}, {
code: [
'it(\n',
' (\n',
' <div>\n',
' <span />\n',
' </div>\n',
' )\n',
')'
].join('\n'),
parserOptions: parserOptions,
options: [2]
}, {
code: [
'(\n',
' <div>\n',
' <span />\n',
' </div>\n',
')'
].join('\n'),
parserOptions: parserOptions,
options: [2]
}, {
code: `
it('passes', () => assertPasses(
foo('bar'),
(<div>
<span />
<span />
<span />
</div>),
'baz'
));`,
parserOptions: parserOptions,
options: [2]
}],

invalid: [{
Expand Down Expand Up @@ -289,4 +324,3 @@ ruleTester.run('jsx-indent', rule, {
]
}*/]
});

0 comments on commit b70cc33

Please sign in to comment.