Skip to content

Commit

Permalink
fix false positives of complex comparison and computed properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ganimomer committed Oct 11, 2015
1 parent 00c24d2 commit 3a0878e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/prefer-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function (context) {
}

function shouldCheckDeeper(node, nodeRight, toCompare) {
return node.operator === '&&' && nodeRight && (!toCompare || astUtil.isEquivalentExp(nodeRight, toCompare));
return node.operator === '&&' && nodeRight && nodeRight.type === 'MemberExpression' && !astUtil.isComputed(nodeRight) && (!toCompare || astUtil.isEquivalentExp(nodeRight, toCompare));
}

return {
Expand Down
1 change: 1 addition & 0 deletions lib/util/astUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ module.exports = {
isNegationExpression: isNegationExpression,
getValueReturnedInFirstLine: getValueReturnedInFirstLine,
isCallFromObject: isCallFromObject,
isComputed: isComputed,
isEquivalentExp: isEquivalentExp
};
3 changes: 2 additions & 1 deletion tests/lib/rules/prefer-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ ruleTester.run('prefer-get', rule, {
'var x = _.has(a, "b.c");',
'var x = a && a.b',
'a && a.b && f()',
'a && a[v] && a[v].c'
'a && a[v] && a[v].c',
'a && a.b && typeof a.b === "number"'
],
invalid: [{
code: 'x = a && a.b && a.b.c === 8',
Expand Down

0 comments on commit 3a0878e

Please sign in to comment.