/
no-array-method-this-argument.mjs
79 lines (76 loc) · 2.54 KB
/
no-array-method-this-argument.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {getTester, parsers} from './utils/test.mjs';
const {test} = getTester(import.meta);
// Arrow functions
test.snapshot({
valid: [
'array.unknownMethod(() => {}, thisArgument)',
'new array.map(() => {}, thisArgument)',
'array.map?.(() => {}, thisArgument)',
'array?.map(() => {}, thisArgument)',
// More or less arguments
'array.map()',
'array.map(() => {},)',
'array.map(() => {}, ...thisArgument)',
'array.map(...() => {}, thisArgument)',
'array.map(() => {}, thisArgument, extraArgument)',
// Ignored
'lodash.every(array, () => {})',
'lodash.find(array, () => {})',
'jQuery.map(array, () => {})',
'$.map(array, () => {})',
'React.Children.map(children, () => {})',
'Children.map(children, () => {})',
'React.Children.forEach(children, () => {})',
'Children.forEach(children, () => {})',
'Vue.filter("capitalize", () => {})',
'R.filter(() => {}, [])',
'R.find(() => {}, [])',
'R.findIndex(() => {}, [])',
'R.forEach(() => {}, [])',
'R.map(() => {}, [])',
// `jQuery.find` and `jQuery.filter` don't accept second argument
'$( "li" ).filter( ":nth-child(2n)" ).css( "background-color", "red" );',
'$( "li.item-ii" ).find( "li" ).css( "background-color", "red" );',
// First argument is not function
'array.map(new Callback, thisArgument)',
'array.map(1, thisArgument)',
'async () => array.map(await callback, thisArgument)',
],
invalid: [
'array.every(() => {}, thisArgument)',
'array.filter(() => {}, thisArgument)',
'array.find(() => {}, thisArgument)',
'array.findIndex(() => {}, thisArgument)',
'array.flatMap(() => {}, thisArgument)',
'array.forEach(() => {}, thisArgument)',
'array.map(() => {}, thisArgument)',
// Comma
'array.map(() => {}, thisArgument,)',
'array.map(() => {}, (0, thisArgument),)',
// Side effect
'array.map(() => {}, thisArgumentHasSideEffect())',
],
});
// Non-arrow functions
test.snapshot({
valid: [],
invalid: [
'array.map(callback, thisArgument)',
'array.map(callback, (0, thisArgument))',
'array.map(function () {}, thisArgument)',
'array.map(function callback () {}, thisArgument)',
{
code: 'array.map( foo as bar, (( thisArgument )),)',
parser: parsers.typescript,
},
{
code: 'array.map( (( foo as bar )), (( thisArgument )),)',
parser: parsers.typescript,
},
'array.map( (( 0, callback )), (( thisArgument )),)',
// This callback is actually arrow function, but we don't know
'array.map((0, () => {}), thisArgument)',
// This callback is a bound function, but we don't know
'array.map(callback.bind(foo), thisArgument)',
],
});