Skip to content

Commit f0fd75b

Browse files
eelyafilencioni
authored andcommitted
Add JSXExpressionContainer support for jsx-indent rule (#838)
* Add JSXExpressionContainer support for jsx-indent rule * Added tests for tabs
1 parent 0348173 commit f0fd75b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

lib/rules/jsx-indent.js

+7
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ module.exports = {
176176
}
177177
var peerElementIndent = getNodeIndent(node.parent.openingElement);
178178
checkNodesIndent(node, peerElementIndent);
179+
},
180+
JSXExpressionContainer: function(node) {
181+
if (!node.parent) {
182+
return;
183+
}
184+
var parentNodeIndent = getNodeIndent(node.parent);
185+
checkNodesIndent(node, parentNodeIndent + indentSize);
179186
}
180187
};
181188

tests/lib/rules/jsx-indent.js

+51
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,56 @@ ruleTester.run('jsx-indent', rule, {
162162
options: [2],
163163
parserOptions: parserOptions,
164164
errors: [{message: 'Expected indentation of 4 space characters but found 0.'}]
165+
}, {
166+
code: [
167+
'<App>',
168+
' {test}',
169+
'</App>'
170+
].join('\n'),
171+
parserOptions: parserOptions,
172+
errors: [
173+
{message: 'Expected indentation of 4 space characters but found 3.'}
174+
]
175+
}, {
176+
code: [
177+
'<App>',
178+
' {options.map((option, index) => (',
179+
' <option key={index} value={option.key}>',
180+
' {option.name}',
181+
' </option>',
182+
' ))}',
183+
'</App>'
184+
].join('\n'),
185+
parserOptions: parserOptions,
186+
errors: [
187+
{message: 'Expected indentation of 12 space characters but found 11.'}
188+
]
189+
}, {
190+
code: [
191+
'<App>',
192+
'{test}',
193+
'</App>'
194+
].join('\n'),
195+
parserOptions: parserOptions,
196+
options: ['tab'],
197+
errors: [
198+
{message: 'Expected indentation of 1 tab character but found 0.'}
199+
]
200+
}, {
201+
code: [
202+
'<App>',
203+
'\t{options.map((option, index) => (',
204+
'\t\t<option key={index} value={option.key}>',
205+
'\t\t{option.name}',
206+
'\t\t</option>',
207+
'\t))}',
208+
'</App>'
209+
].join('\n'),
210+
parserOptions: parserOptions,
211+
options: ['tab'],
212+
errors: [
213+
{message: 'Expected indentation of 3 tab characters but found 2.'}
214+
]
165215
}]
166216
});
217+

0 commit comments

Comments
 (0)