Skip to content

Commit

Permalink
Use the new function also in jsx-indent-props
Browse files Browse the repository at this point in the history
Although the logic is quite different here, the new function seems to work (tests are passing)
  • Loading branch information
jseminck committed Nov 16, 2017
1 parent c51087c commit acc4f24
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions lib/rules/jsx-indent-props.js
Expand Up @@ -29,6 +29,8 @@
*/
'use strict';

const astUtil = require('../util/ast');

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -136,20 +138,6 @@ module.exports = {
return indent ? indent[0].length : 0;
}

/**
* Checks node is the first in its own start line. By default it looks by start line.
* @param {ASTNode} node The node to check
* @param {Boolean} [byEndLocation] Lookup based on start position or end
* @return {Boolean} true if its the first in the its start line
*/
function isNodeFirstInLine(node, byEndLocation) {
const firstToken = byEndLocation === true ? sourceCode.getLastToken(node, 1) : sourceCode.getTokenBefore(node);
const startLine = byEndLocation === true ? node.loc.end.line : node.loc.start.line;
const endLine = firstToken ? firstToken.loc.end.line : -1;

return startLine !== endLine;
}

/**
* Check indent for nodes list
* @param {ASTNode[]} nodes list of node objects
Expand All @@ -161,7 +149,7 @@ module.exports = {
const nodeIndent = getNodeIndent(node, false, excludeCommas);
if (
node.type !== 'ArrayExpression' && node.type !== 'ObjectExpression' &&
nodeIndent !== indent && isNodeFirstInLine(node)
nodeIndent !== indent && astUtil.isNodeFirstInLine(context, node)
) {
report(node, indent, nodeIndent);
}
Expand Down

0 comments on commit acc4f24

Please sign in to comment.