Skip to content

Commit

Permalink
no-array-callback-reference: Only ignore Boolean in reasonable pl…
Browse files Browse the repository at this point in the history
…aces (#1570)
  • Loading branch information
fisker committed Nov 2, 2021
1 parent 15f9028 commit 46f8638
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
64 changes: 53 additions & 11 deletions rules/no-array-callback-reference.js
Expand Up @@ -15,54 +15,96 @@ const messages = {
};

const iteratorMethods = [
['every'],
[
'every',
{
ignore: [
'Boolean',
],
},
],
[
'filter', {
extraSelector: '[callee.object.name!="Vue"]',
ignore: [
'Boolean',
],
},
],
[
'find',
{
ignore: [
'Boolean',
],
},
],
[
'findIndex',
{
ignore: [
'Boolean',
],
},
],
[
'flatMap',
{
ignore: [
'Boolean',
],
},
],
['find'],
['findIndex'],
['flatMap'],
[
'forEach', {
returnsUndefined: true,
},
],
[
'map', {
'map',
{
extraSelector: '[callee.object.name!="types"]',
ignore: [
'Boolean',
],
},
],
[
'reduce', {
'reduce',
{
parameters: [
'accumulator',
'element',
'index',
'array',
],
minParameters: 2,
ignore: [],
},
],
[
'reduceRight', {
'reduceRight',
{
parameters: [
'accumulator',
'element',
'index',
'array',
],
minParameters: 2,
ignore: [],
},
],
['some'],
[
'some',
{
ignore: [
'Boolean',
],
},
],
].map(([method, options]) => {
options = {
parameters: ['element', 'index', 'array'],
ignore: ['Boolean'],
ignore: [],
minParameters: 1,
extraSelector: '',
returnsUndefined: false,
Expand Down
14 changes: 12 additions & 2 deletions test/no-array-callback-reference.mjs
Expand Up @@ -57,7 +57,7 @@ test({
...reduceLikeMethods.map(method => `this.${method}(fn)`),

// `Boolean`
...simpleMethods.map(method => `foo.${method}(Boolean)`),
'foo.map(Boolean)',

// Not `CallExpression`
'new foo.map(fn);',
Expand Down Expand Up @@ -207,7 +207,7 @@ test({
}),
),

// `Boolean` is not ignored on `reduce` and `reduceRight`
// `Boolean` is only ignored on reasonable places
...reduceLikeMethods.map(
method => invalidTestCase({
code: `foo.${method}(Boolean, initialValue)`,
Expand All @@ -220,6 +220,16 @@ test({
],
}),
),
invalidTestCase({
code: 'foo.forEach(Boolean)',
method: 'forEach',
name: 'Boolean',
suggestions: [
'foo.forEach((element) => { Boolean(element); })',
'foo.forEach((element, index) => { Boolean(element, index); })',
'foo.forEach((element, index, array) => { Boolean(element, index, array); })',
],
}),

// Not `Identifier`
...simpleMethodsExceptForEach.map(
Expand Down

0 comments on commit 46f8638

Please sign in to comment.