Skip to content

Commit

Permalink
no-array-method-this-argument: Check .findLast and `.findLastInde…
Browse files Browse the repository at this point in the history
…x` (#1890)
  • Loading branch information
fisker committed Sep 17, 2022
1 parent 37a5cda commit 3bc28ad
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/rules/no-array-method-this-argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ This rule checks following array methods accepts `thisArg`:
- [`Array#every()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/every)
- [`Array#filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/filter)
- [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/find)
- [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/findLast)
- [`Array#findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/findIndex)
- [`Array#findLastIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/findLastIndex)
- [`Array#flatMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/flatMap)
- [`Array#forEach()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/forEach)
- [`Array#map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Array/map)
Expand Down
2 changes: 2 additions & 0 deletions rules/no-array-method-this-argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const selector = [
'every',
'filter',
'find',
'findLast',
'findIndex',
'findLastIndex',
'flatMap',
'forEach',
'map',
Expand Down
2 changes: 2 additions & 0 deletions test/no-array-method-this-argument.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ test.snapshot({
'array.filter(() => {}, thisArgument)',
'array.find(() => {}, thisArgument)',
'array.findIndex(() => {}, thisArgument)',
'array.findLast(() => {}, thisArgument)',
'array.findLastIndex(() => {}, thisArgument)',
'array.flatMap(() => {}, thisArgument)',
'array.forEach(() => {}, thisArgument)',
'array.map(() => {}, thisArgument)',
Expand Down
42 changes: 37 additions & 5 deletions test/snapshots/no-array-method-this-argument.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,38 @@ Generated by [AVA](https://avajs.dev).
`

## Invalid #5
1 | array.findLast(() => {}, thisArgument)

> Output
`␊
1 | array.findLast(() => {})␊
`

> Error 1/1
`␊
> 1 | array.findLast(() => {}, thisArgument)␊
| ^^^^^^^^^^^^ Do not use the \`this\` argument in \`Array#findLast()\`.␊
`

## Invalid #6
1 | array.findLastIndex(() => {}, thisArgument)

> Output
`␊
1 | array.findLastIndex(() => {})␊
`

> Error 1/1
`␊
> 1 | array.findLastIndex(() => {}, thisArgument)␊
| ^^^^^^^^^^^^ Do not use the \`this\` argument in \`Array#findLastIndex()\`.␊
`

## Invalid #7
1 | array.flatMap(() => {}, thisArgument)

> Output
Expand All @@ -84,7 +116,7 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^ Do not use the \`this\` argument in \`Array#flatMap()\`.␊
`

## Invalid #6
## Invalid #8
1 | array.forEach(() => {}, thisArgument)

> Output
Expand All @@ -100,7 +132,7 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^ Do not use the \`this\` argument in \`Array#forEach()\`.␊
`

## Invalid #7
## Invalid #9
1 | array.map(() => {}, thisArgument)

> Output
Expand All @@ -116,7 +148,7 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^ Do not use the \`this\` argument in \`Array#map()\`.␊
`

## Invalid #8
## Invalid #10
1 | array.map(() => {}, thisArgument,)

> Output
Expand All @@ -132,7 +164,7 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^ Do not use the \`this\` argument in \`Array#map()\`.␊
`

## Invalid #9
## Invalid #11
1 | array.map(() => {}, (0, thisArgument),)

> Output
Expand All @@ -148,7 +180,7 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^^^^ Do not use the \`this\` argument in \`Array#map()\`.␊
`

## Invalid #10
## Invalid #12
1 | array.map(() => {}, thisArgumentHasSideEffect())

> Error 1/1
Expand Down
Binary file modified test/snapshots/no-array-method-this-argument.mjs.snap
Binary file not shown.

0 comments on commit 3bc28ad

Please sign in to comment.