Skip to content

Commit f081f0f

Browse files
authored
Fix false negatives for typed array in no-array-prototype-findlast-findlastindex rule (#35)
1 parent 173fc9a commit f081f0f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/rules/no-array-prototype-findlast-findlastindex.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ module.exports = {
3131
create(context) {
3232
return definePrototypeMethodHandler(context, {
3333
Array: ["findLast", "findLastIndex"],
34+
Int8Array: ["findLast", "findLastIndex"],
35+
Uint8Array: ["findLast", "findLastIndex"],
36+
Uint8ClampedArray: ["findLast", "findLastIndex"],
37+
Int16Array: ["findLast", "findLastIndex"],
38+
Uint16Array: ["findLast", "findLastIndex"],
39+
Int32Array: ["findLast", "findLastIndex"],
40+
Uint32Array: ["findLast", "findLastIndex"],
41+
Float32Array: ["findLast", "findLastIndex"],
42+
Float64Array: ["findLast", "findLastIndex"],
43+
BigInt64Array: ["findLast", "findLastIndex"],
44+
BigUint64Array: ["findLast", "findLastIndex"],
3445
})
3546
},
3647
}

tests/lib/rules/no-array-prototype-findlast-findlastindex.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,25 @@ new RuleTester({ parser, parserOptions: { tsconfigRootDir, project } }).run(
204204
],
205205
settings: { "es-x": { aggressive: true } },
206206
},
207+
...[
208+
"Int8Array",
209+
"Uint8Array",
210+
"Uint8ClampedArray",
211+
"Int16Array",
212+
"Uint16Array",
213+
"Int32Array",
214+
"Uint32Array",
215+
"Float32Array",
216+
"Float64Array",
217+
"BigInt64Array",
218+
"BigUint64Array",
219+
].map((className) => ({
220+
filename,
221+
code: `let foo = new ${className}(10); foo.findLast(predicate)`,
222+
errors: [
223+
`ES2023 '${className}.prototype.findLast' method is forbidden.`,
224+
],
225+
})),
207226
],
208227
},
209228
)

0 commit comments

Comments
 (0)