Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 19, 2020
1 parent 8dcdddc commit 6399b90
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions rules/prefer-array-find.js
Expand Up @@ -13,6 +13,12 @@ const MESSAGE_ID_DECLARATION = 'prefer-array-find-over-filter';
const MESSAGE_ID_USE_NULLISH_COALESCING_OPERATOR = 'use-nullish-coalescing-operator';
const MESSAGE_ID_USE_LOGICAL_OR_OPERATOR = 'use-logical-or-operator';

const filterMethodSelectorOptions = {
name: 'filter',
min: 1,
max: 2
};

const filterVariableSelector = [
'VariableDeclaration',
// Exclude `export const foo = [];`
Expand All @@ -27,9 +33,7 @@ const filterVariableSelector = [
'VariableDeclarator.declarations',
'[id.type="Identifier"]',
methodSelector({
name: 'filter',
min: 1,
max: 2,
...filterMethodSelectorOptions,
property: 'init'
})
].join('');
Expand All @@ -40,9 +44,7 @@ const zeroIndexSelector = [
'[property.type="Literal"]',
'[property.raw="0"]',
methodSelector({
name: 'filter',
min: 1,
max: 2,
...filterMethodSelectorOptions,
property: 'object'
})
].join('');
Expand All @@ -53,9 +55,7 @@ const shiftSelector = [
length: 0
}),
methodSelector({
name: 'filter',
min: 1,
max: 2,
...filterMethodSelectorOptions,
property: 'callee.object'
})
].join('');
Expand All @@ -66,9 +66,7 @@ const destructuringDeclaratorSelector = [
'[id.elements.length=1]',
'[id.elements.0.type!="RestElement"]',
methodSelector({
name: 'filter',
min: 1,
max: 2,
...filterMethodSelectorOptions,
property: 'init'
})
].join('');
Expand All @@ -79,9 +77,7 @@ const destructuringAssignmentSelector = [
'[left.elements.length=1]',
'[left.elements.0.type!="RestElement"]',
methodSelector({
name: 'filter',
min: 1,
max: 2,
...filterMethodSelectorOptions,
property: 'right'
})
].join('');
Expand Down

0 comments on commit 6399b90

Please sign in to comment.