Skip to content

Commit 46f8638

Browse files
authored
no-array-callback-reference: Only ignore Boolean in reasonable places (#1570)
1 parent 15f9028 commit 46f8638

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

rules/no-array-callback-reference.js

+53-11
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,96 @@ const messages = {
1515
};
1616

1717
const iteratorMethods = [
18-
['every'],
18+
[
19+
'every',
20+
{
21+
ignore: [
22+
'Boolean',
23+
],
24+
},
25+
],
1926
[
2027
'filter', {
2128
extraSelector: '[callee.object.name!="Vue"]',
29+
ignore: [
30+
'Boolean',
31+
],
32+
},
33+
],
34+
[
35+
'find',
36+
{
37+
ignore: [
38+
'Boolean',
39+
],
40+
},
41+
],
42+
[
43+
'findIndex',
44+
{
45+
ignore: [
46+
'Boolean',
47+
],
48+
},
49+
],
50+
[
51+
'flatMap',
52+
{
53+
ignore: [
54+
'Boolean',
55+
],
2256
},
2357
],
24-
['find'],
25-
['findIndex'],
26-
['flatMap'],
2758
[
2859
'forEach', {
2960
returnsUndefined: true,
3061
},
3162
],
3263
[
33-
'map', {
64+
'map',
65+
{
3466
extraSelector: '[callee.object.name!="types"]',
67+
ignore: [
68+
'Boolean',
69+
],
3570
},
3671
],
3772
[
38-
'reduce', {
73+
'reduce',
74+
{
3975
parameters: [
4076
'accumulator',
4177
'element',
4278
'index',
4379
'array',
4480
],
4581
minParameters: 2,
46-
ignore: [],
4782
},
4883
],
4984
[
50-
'reduceRight', {
85+
'reduceRight',
86+
{
5187
parameters: [
5288
'accumulator',
5389
'element',
5490
'index',
5591
'array',
5692
],
5793
minParameters: 2,
58-
ignore: [],
5994
},
6095
],
61-
['some'],
96+
[
97+
'some',
98+
{
99+
ignore: [
100+
'Boolean',
101+
],
102+
},
103+
],
62104
].map(([method, options]) => {
63105
options = {
64106
parameters: ['element', 'index', 'array'],
65-
ignore: ['Boolean'],
107+
ignore: [],
66108
minParameters: 1,
67109
extraSelector: '',
68110
returnsUndefined: false,

test/no-array-callback-reference.mjs

+12-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test({
5757
...reduceLikeMethods.map(method => `this.${method}(fn)`),
5858

5959
// `Boolean`
60-
...simpleMethods.map(method => `foo.${method}(Boolean)`),
60+
'foo.map(Boolean)',
6161

6262
// Not `CallExpression`
6363
'new foo.map(fn);',
@@ -207,7 +207,7 @@ test({
207207
}),
208208
),
209209

210-
// `Boolean` is not ignored on `reduce` and `reduceRight`
210+
// `Boolean` is only ignored on reasonable places
211211
...reduceLikeMethods.map(
212212
method => invalidTestCase({
213213
code: `foo.${method}(Boolean, initialValue)`,
@@ -220,6 +220,16 @@ test({
220220
],
221221
}),
222222
),
223+
invalidTestCase({
224+
code: 'foo.forEach(Boolean)',
225+
method: 'forEach',
226+
name: 'Boolean',
227+
suggestions: [
228+
'foo.forEach((element) => { Boolean(element); })',
229+
'foo.forEach((element, index) => { Boolean(element, index); })',
230+
'foo.forEach((element, index, array) => { Boolean(element, index, array); })',
231+
],
232+
}),
223233

224234
// Not `Identifier`
225235
...simpleMethodsExceptForEach.map(

0 commit comments

Comments
 (0)