Skip to content

Commit

Permalink
prefer-native-coercion-functions: Check .findLast and `.findLastI…
Browse files Browse the repository at this point in the history
…ndex` (#1893)
  • Loading branch information
fisker committed Sep 17, 2022
1 parent 3bc28ad commit f2c6acc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rules/prefer-native-coercion-functions.js
Expand Up @@ -8,7 +8,7 @@ const messages = {
};

const nativeCoercionFunctionNames = new Set(['String', 'Number', 'BigInt', 'Boolean', 'Symbol']);
const arrayMethodsWithBooleanCallback = new Set(['every', 'filter', 'find', 'findIndex', 'some']);
const arrayMethodsWithBooleanCallback = new Set(['every', 'filter', 'find', 'findLast', 'findIndex', 'findLastIndex', 'some']);

const isNativeCoercionFunctionCall = (node, firstArgumentName) =>
node
Expand Down
2 changes: 2 additions & 0 deletions test/prefer-native-coercion-functions.mjs
Expand Up @@ -185,8 +185,10 @@ test.snapshot({
'array.every(v => v)',
'array.filter(v => v)',
'array.find(v => v)',
'array.findLast(v => v)',
'array.some(v => v)',
'array.findIndex(v => v)',
'array.findLastIndex(v => v)',
'array.some(v => v)',
outdent`
array.some(v => {
Expand Down
44 changes: 38 additions & 6 deletions test/snapshots/prefer-native-coercion-functions.mjs.md
Expand Up @@ -441,6 +441,22 @@ Generated by [AVA](https://avajs.dev).
`

## Invalid #4
1 | array.findLast(v => v)

> Output
`␊
1 | array.findLast(Boolean)␊
`

> Error 1/1
`␊
> 1 | array.findLast(v => v)␊
| ^^ arrow function is equivalent to \`Boolean\`. Use \`Boolean\` directly.␊
`

## Invalid #5
1 | array.some(v => v)

> Output
Expand All @@ -456,7 +472,7 @@ Generated by [AVA](https://avajs.dev).
| ^^ arrow function is equivalent to \`Boolean\`. Use \`Boolean\` directly.␊
`

## Invalid #5
## Invalid #6
1 | array.findIndex(v => v)

> Output
Expand All @@ -472,7 +488,23 @@ Generated by [AVA](https://avajs.dev).
| ^^ arrow function is equivalent to \`Boolean\`. Use \`Boolean\` directly.␊
`

## Invalid #6
## Invalid #7
1 | array.findLastIndex(v => v)

> Output
`␊
1 | array.findLastIndex(Boolean)␊
`

> Error 1/1
`␊
> 1 | array.findLastIndex(v => v)␊
| ^^ arrow function is equivalent to \`Boolean\`. Use \`Boolean\` directly.␊
`

## Invalid #8
1 | array.some(v => v)

> Output
Expand All @@ -488,7 +520,7 @@ Generated by [AVA](https://avajs.dev).
| ^^ arrow function is equivalent to \`Boolean\`. Use \`Boolean\` directly.␊
`

## Invalid #7
## Invalid #9
1 | array.some(v => {
2 | return v;
3 | })
Expand All @@ -508,7 +540,7 @@ Generated by [AVA](https://avajs.dev).
3 | })␊
`

## Invalid #8
## Invalid #10
1 | array.some(function (v) {
2 | return v;
3 | })
Expand All @@ -528,7 +560,7 @@ Generated by [AVA](https://avajs.dev).
3 | })␊
`

## Invalid #9
## Invalid #11
1 | array.some((v, extra) => v)

> Error 1/1
Expand All @@ -538,7 +570,7 @@ Generated by [AVA](https://avajs.dev).
| ^^ arrow function is equivalent to \`Boolean\`. Use \`Boolean\` directly.␊
`

## Invalid #10
## Invalid #12
1 | array.some((v, ) => /* comment */ v)

> Error 1/1
Expand Down
Binary file modified test/snapshots/prefer-native-coercion-functions.mjs.snap
Binary file not shown.

0 comments on commit f2c6acc

Please sign in to comment.