Skip to content

Commit

Permalink
require-array-join-separator: Check optional member (#1569)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 2, 2021
1 parent ff43745 commit 15f9028
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rules/require-array-join-separator.js
Expand Up @@ -9,7 +9,11 @@ const messages = {

const selector = matches([
// `foo.join()`
methodCallSelector({method: 'join', argumentsLength: 0}),
methodCallSelector({
method: 'join',
argumentsLength: 0,
includeOptionalMember: true,
}),
// `[].join.call(foo)` and `Array.prototype.join.call(foo)`
[
methodCallSelector({method: 'call', argumentsLength: 1}),
Expand Down
4 changes: 3 additions & 1 deletion test/require-array-join-separator.mjs
Expand Up @@ -8,7 +8,8 @@ test.snapshot({
'foo.join(",")',
'join()',
'foo.join(...[])',
'foo?.join()',
'foo.join?.()',
'foo?.join?.()',
'foo[join]()',
'foo["join"]()',
'[].join.call(foo, ",")',
Expand Down Expand Up @@ -71,5 +72,6 @@ test.snapshot({
)/**/
)
`,
'foo?.join()',
],
});
16 changes: 16 additions & 0 deletions test/snapshots/require-array-join-separator.mjs.md
Expand Up @@ -192,3 +192,19 @@ Generated by [AVA](https://avajs.dev).
| ^^^^ Missing the separator argument.␊
26 | )␊
`

## Invalid #8
1 | foo?.join()

> Output
`␊
1 | foo?.join(',')␊
`

> Error 1/1
`␊
> 1 | foo?.join()␊
| ^^ Missing the separator argument.␊
`
Binary file modified test/snapshots/require-array-join-separator.mjs.snap
Binary file not shown.

0 comments on commit 15f9028

Please sign in to comment.