Skip to content

Commit

Permalink
Simplify getNodeIndent
Browse files Browse the repository at this point in the history
cut out unused vars based on feedback
  • Loading branch information
snowypowers committed Nov 2, 2016
1 parent 9834e7a commit f15b117
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions lib/rules/jsx-first-prop-new-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = {

create: function (context) {
var configuration = context.options[0];
var extraColumnStart = 0;
var indentType = 'space';
var indentSize = 2;
var sourceCode = context.getSourceCode();
Expand All @@ -40,27 +39,14 @@ module.exports = {
}
}

function getNodeIndent(node, byLastLine, excludeCommas) {
byLastLine = byLastLine || false;
excludeCommas = excludeCommas || false;

var src = sourceCode.getText(node, node.loc.start.column + extraColumnStart);
var lines = src.split('\n');
if (byLastLine) {
src = lines[lines.length - 1];
} else {
src = lines[0];
}

var skip = excludeCommas ? ',' : '';

function getNodeIndent(node) {
var src = sourceCode.getText(node, node.loc.start.column).split('\n')[0];
var regExp;
if (indentType === 'space') {
regExp = new RegExp('^[ ' + skip + ']+');
regExp = new RegExp('^[ ]+');
} else {
regExp = new RegExp('^[\t' + skip + ']+');
regExp = new RegExp('^[\t' + ']+');
}

var indent = regExp.exec(src);
return indent ? indent[0].length : 0;
}
Expand All @@ -82,8 +68,7 @@ module.exports = {
node: decl,
message: 'Property should be placed on a new line',
fix: function(fixer) {
var nodeIndent = getNodeIndent(node, false, false);
var neededIndent = nodeIndent + indentSize;
var neededIndent = getNodeIndent(node) + indentSize;
var insert = '\n' + Array(neededIndent + 1).join(indentType === 'space' ? ' ' : '\t');
return fixer.replaceTextRange([node.name.end, decl.start], insert);
}
Expand Down

0 comments on commit f15b117

Please sign in to comment.