Skip to content

Commit 798f2ca

Browse files
committed
Fix jsx-indent to not check lines starting by literals (fixes #900)
1 parent c056489 commit 798f2ca

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/rules/jsx-indent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ module.exports = {
8484
function getFixerFunction(node, needed, gotten) {
8585
if (needed > gotten) {
8686
var spaces = indentChar.repeat(needed - gotten);
87-
8887
return function(fixer) {
8988
return fixer.insertTextBeforeRange([node.range[0], node.range[0]], spaces);
9089
};
@@ -169,7 +168,7 @@ module.exports = {
169168
var token = node;
170169
do {
171170
token = sourceCode.getTokenBefore(token);
172-
} while (token.type === 'JSXText');
171+
} while (token.type === 'JSXText' && /^\s*$/.test(token.value));
173172
var startLine = node.loc.start.line;
174173
var endLine = token ? token.loc.end.line : -1;
175174

tests/lib/rules/jsx-indent.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ ruleTester.run('jsx-indent', rule, {
187187
].join('\n'),
188188
parserOptions: parserOptions,
189189
options: [2]
190+
}, {
191+
// Literals indentation is not touched
192+
code: [
193+
'<div>',
194+
'bar <div>',
195+
' bar',
196+
' bar {foo}',
197+
'bar </div>',
198+
'</div>'
199+
].join('\n'),
200+
parserOptions: parserOptions
190201
}],
191202

192203
invalid: [{

0 commit comments

Comments
 (0)