Skip to content

Commit

Permalink
prefer-array-some: Ignore filter calls with literal argument (#2097)
Browse files Browse the repository at this point in the history
Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
thorn0 and fisker committed May 15, 2023
1 parent 7895e5d commit 7a32edb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rules/prefer-array-some.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {methodCallSelector, matches, memberExpressionSelector} = require('./selec
const {checkVueTemplate} = require('./utils/rule.js');
const {isBooleanNode} = require('./utils/boolean.js');
const {getParenthesizedRange} = require('./utils/parentheses.js');
const {isNodeValueNotFunction} = require('./utils/index.js');
const {removeMemberExpressionProperty} = require('./fix/index.js');
const {isLiteral, isUndefined} = require('./ast/index.js');

Expand Down Expand Up @@ -94,6 +95,11 @@ const create = context => ({
};
},
[arrayFilterCallSelector](filterCall) {
const [firstArgument] = filterCall.arguments;
if (!firstArgument || isNodeValueNotFunction(firstArgument)) {
return;
}

const filterProperty = filterCall.callee.property;
return {
node: filterProperty,
Expand Down
3 changes: 3 additions & 0 deletions test/prefer-array-some.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ test.snapshot({
'array?.filter(fn).length > 0',
'array.notFilter(fn).length > 0',
'array.filter.length > 0',

// `jQuery#filter`
'$element.filter(":visible").length > 0',
],
invalid: [
'array.filter(fn).length > 0',
Expand Down

0 comments on commit 7a32edb

Please sign in to comment.