Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSXExpressionContainer support for jsx-indent rule #838

Merged
merged 2 commits into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ module.exports = {
}
var peerElementIndent = getNodeIndent(node.parent.openingElement);
checkNodesIndent(node, peerElementIndent);
},
JSXExpressionContainer: function(node) {
if (!node.parent) {
return;
}
var parentNodeIndent = getNodeIndent(node.parent);
checkNodesIndent(node, parentNodeIndent + indentSize);
}
};

Expand Down
51 changes: 51 additions & 0 deletions tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,56 @@ ruleTester.run('jsx-indent', rule, {
options: [2],
parserOptions: parserOptions,
errors: [{message: 'Expected indentation of 4 space characters but found 0.'}]
}, {
code: [
'<App>',
' {test}',
'</App>'
].join('\n'),
parserOptions: parserOptions,
errors: [
{message: 'Expected indentation of 4 space characters but found 3.'}
]
}, {
code: [
'<App>',
' {options.map((option, index) => (',
' <option key={index} value={option.key}>',
' {option.name}',
' </option>',
' ))}',
'</App>'
].join('\n'),
parserOptions: parserOptions,
errors: [
{message: 'Expected indentation of 12 space characters but found 11.'}
]
}, {
code: [
'<App>',
'{test}',
'</App>'
].join('\n'),
parserOptions: parserOptions,
options: ['tab'],
errors: [
{message: 'Expected indentation of 1 tab character but found 0.'}
]
}, {
code: [
'<App>',
'\t{options.map((option, index) => (',
'\t\t<option key={index} value={option.key}>',
'\t\t{option.name}',
'\t\t</option>',
'\t))}',
'</App>'
].join('\n'),
parserOptions: parserOptions,
options: ['tab'],
errors: [
{message: 'Expected indentation of 3 tab characters but found 2.'}
]
}]
});