Skip to content

Commit ad27922

Browse files
authored
no-array-callback-reference: Fix optional chaining expressions being ignored (#2694)
1 parent a7864a3 commit ad27922

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

rules/no-array-callback-reference.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ const create = context => ({
234234
minimumArguments: 1,
235235
maximumArguments: 2,
236236
optionalCall: false,
237-
optionalMember: false,
238237
computed: false,
239238
})
240239
|| callExpression.callee.property.type !== 'Identifier'

test/no-array-callback-reference.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ test({
5757
...simpleMethods.map(method => `foo.${method}(element => fn(element))`),
5858
...reduceLikeMethods.map(method => `foo.${method}((accumulator, element) => fn(element))`),
5959

60+
// Optional chaining
61+
...simpleMethods.map(method => `foo?.${method}(element => fn(element))`),
62+
...reduceLikeMethods.map(method => `foo?.${method}((accumulator, element) => fn(element))`),
63+
6064
// `this.{map, filter, …}`
6165
...simpleMethods.map(method => `this.${method}(fn)`),
6266
...reduceLikeMethods.map(method => `this.${method}(fn)`),
@@ -160,6 +164,18 @@ test({
160164
],
161165
}),
162166
),
167+
...simpleMethodsExceptForEach.map(
168+
method => invalidTestCase({
169+
code: `foo?.${method}(fn)`,
170+
method,
171+
name: 'fn',
172+
suggestions: [
173+
`foo?.${method}((element) => fn(element))`,
174+
`foo?.${method}((element, index) => fn(element, index))`,
175+
`foo?.${method}((element, index, array) => fn(element, index, array))`,
176+
],
177+
}),
178+
),
163179
invalidTestCase({
164180
code: 'foo.forEach(fn)',
165181
method: 'forEach',

0 commit comments

Comments
 (0)