Skip to content

Commit d73ee9f

Browse files
committed
no-unused-array-method-return: Cover computed method names
Fixes #3549
1 parent 38fbb85 commit d73ee9f

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

rules/no-unused-array-method-return.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ function getVariableValue(node, context) {
9898

9999
// Supported variable inference boundary:
100100
// - exactly one binding definition
101-
// - unannotated plain parameters and explicitly array-typed plain parameters or variables
101+
// - unannotated or explicitly array-typed plain parameters
102+
// - explicitly array-typed variables
102103
// - a `VariableDeclarator` whose id is the same identifier we are resolving
103104
// - the original declarator initializer for unannotated variables only
104105
//

test/no-unused-array-method-return.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {test} = getTester(import.meta);
55

66
test.snapshot({
77
valid: [
8-
'new array.map(fn);',
98
'map(fn);',
109
'array.notMap(fn);',
1110
'array[map](fn);',
@@ -279,6 +278,7 @@ test.snapshot({
279278
'const assertion = expectation(value); assertion.includes(expected);',
280279
'expect.custom(value).includes(expected);',
281280
'function Symbol(value) { return value; } Symbol([]).slice(1);',
281+
'const method = "map"; array[method](fn);',
282282
],
283283
});
284284

test/snapshots/no-unused-array-method-return.js.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,3 +881,19 @@ Generated by [AVA](https://avajs.dev).
881881
> 1 | function Symbol(value) { return value; } Symbol([]).slice(1);␊
882882
| ^^^^^ Do not ignore the return value of \`.slice(…)\`.␊
883883
`
884+
885+
## invalid(54): const method = "map"; array[method](fn);
886+
887+
> Input
888+
889+
`␊
890+
1 | const method = "map"; array[method](fn);␊
891+
`
892+
893+
> Error 1/1
894+
895+
`␊
896+
Message:␊
897+
> 1 | const method = "map"; array[method](fn);␊
898+
| ^^^^^^ Do not ignore the return value of \`.map(…)\`.␊
899+
`
42 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)