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

Support tab indentation #909

Merged
merged 6 commits into from
Oct 12, 2016
Merged
Changes from 1 commit
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
22 changes: 20 additions & 2 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ module.exports = {
}
}

/**
* Get the characters used for indentation on the line to be matched
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
* @param {String} expectedLocation Expected location for the closing bracket
* @return {String} The characters used for indentation
*/
function getIndentation(tokens, expectedLocation) {
switch (expectedLocation) {
case 'props-aligned':
return /^\s*/.exec(sourceCode[tokens.lastProp.lastLine])[0];
case 'tag-aligned':
return /^\s*/.exec(sourceCode[tokens.opening.line])[0];
case 'line-aligned':
return /^\s*/.exec(sourceCode[tokens.openingStartOfLine.line])[0];
default:
return '';
}
}

/**
* Get the locations of the opening bracket, closing bracket, last prop, and
* start of opening line.
Expand Down Expand Up @@ -244,9 +263,8 @@ module.exports = {
case 'props-aligned':
case 'tag-aligned':
case 'line-aligned':
var spaces = new Array(+correctColumn + 1);
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.end],
'\n' + spaces.join(' ') + closingTag);
'\n' + getIndentation(tokens, expectedLocation) + closingTag);
default:
return true;
}
Expand Down