Skip to content

Commit 507b18b

Browse files
authored
Refactor options for selector functions (#1423)
1 parent 3dc2f77 commit 507b18b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+227
-157
lines changed

rules/better-regex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const messages = {
1010
};
1111

1212
const newRegExp = [
13-
newExpressionSelector({name: 'RegExp', min: 1}),
13+
newExpressionSelector({name: 'RegExp', minimumArguments: 1}),
1414
'[arguments.0.type="Literal"]',
1515
].join('');
1616

rules/catch-error-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const selector = matches([
2222
// - `promise.catch(function(foo) {})`
2323
[
2424
matches([
25-
methodCallSelector({name: 'then', length: 2}),
26-
methodCallSelector({name: 'catch', length: 1}),
25+
methodCallSelector({method: 'then', argumentsLength: 2}),
26+
methodCallSelector({method: 'catch', argumentsLength: 1}),
2727
]),
2828
' > ',
2929
':matches(FunctionExpression, ArrowFunctionExpression).arguments:last-child',

rules/error-message.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@ const messages = {
1111
[MESSAGE_ID_NOT_STRING]: 'Error message should be a string.',
1212
};
1313

14-
const selector = callOrNewExpressionSelector({
15-
names: [
16-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
17-
'Error',
18-
'EvalError',
19-
'RangeError',
20-
'ReferenceError',
21-
'SyntaxError',
22-
'TypeError',
23-
'URIError',
24-
'InternalError',
25-
'AggregateError',
26-
],
27-
});
14+
const selector = callOrNewExpressionSelector([
15+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
16+
'Error',
17+
'EvalError',
18+
'RangeError',
19+
'ReferenceError',
20+
'SyntaxError',
21+
'TypeError',
22+
'URIError',
23+
'InternalError',
24+
'AggregateError',
25+
]);
2826

2927
const create = context => {
3028
return {

rules/import-style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ const create = context => {
281281
visitor = {
282282
...visitor,
283283

284-
[`ExpressionStatement > ${callExpressionSelector({name: 'require', length: 1})}.expression`](node) {
284+
[`ExpressionStatement > ${callExpressionSelector({name: 'require', argumentsLength: 1})}.expression`](node) {
285285
const moduleName = getStringIfConstant(node.arguments[0], context.getScope());
286286
const allowedImportStyles = styles.get(moduleName);
287287
const actualImportStyles = ['unassigned'];

rules/no-array-callback-reference.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ const create = context => {
147147
const selector = [
148148
method === 'reduce' || method === 'reduceRight' ? '' : ':not(AwaitExpression) > ',
149149
methodCallSelector({
150-
name: method,
151-
min: 1,
152-
max: 2,
150+
method,
151+
minimumArguments: 1,
152+
maximumArguments: 2,
153153
}),
154154
options.extraSelector,
155155
ignoredFirstArgumentSelector,

rules/no-array-for-each.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const messages = {
2222
};
2323

2424
const arrayForEachCallSelector = methodCallSelector({
25-
name: 'forEach',
25+
method: 'forEach',
2626
includeOptionalCall: true,
2727
includeOptionalMember: true,
2828
});

rules/no-array-method-this-argument.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const ignored = [
5656

5757
const selector = [
5858
methodCallSelector({
59-
names: [
59+
methods: [
6060
'every',
6161
'filter',
6262
'find',
@@ -66,7 +66,7 @@ const selector = [
6666
'map',
6767
'some',
6868
],
69-
length: 2,
69+
argumentsLength: 2,
7070
}),
7171
notFunctionSelector('arguments.0'),
7272
].join('');

rules/no-array-push-push.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const messages = {
1414

1515
const arrayPushExpressionStatement = [
1616
'ExpressionStatement',
17-
methodCallSelector({path: 'expression', name: 'push'}),
17+
methodCallSelector({path: 'expression', method: 'push'}),
1818
].join('');
1919

2020
const selector = `${arrayPushExpressionStatement} + ${arrayPushExpressionStatement}`;

rules/no-array-reduce.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ const prototypeSelector = method => [
1111
methodCallSelector(method),
1212
arrayPrototypeMethodSelector({
1313
path: 'callee.object',
14-
names: ['reduce', 'reduceRight'],
14+
methods: ['reduce', 'reduceRight'],
1515
}),
1616
].join('');
1717
const selector = matches([
1818
// `array.{reduce,reduceRight}()`
1919
[
20-
methodCallSelector({names: ['reduce', 'reduceRight'], min: 1, max: 2}),
20+
methodCallSelector({methods: ['reduce', 'reduceRight'], minimumArguments: 1, maximumArguments: 2}),
2121
notFunctionSelector('arguments.0'),
2222
' > .callee > .property',
2323
].join(''),

rules/no-console-spaces.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const methods = [
1616
];
1717

1818
const selector = methodCallSelector({
19-
names: methods,
20-
min: 1,
19+
methods,
20+
minimumArguments: 1,
2121
object: 'console',
2222
});
2323

0 commit comments

Comments
 (0)