Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): [comma-spacing] verify nextToken exists (#4868)
* eslint-plugin/rules/comma-spacing: add check to verify nextToken exists

* fix(eslint-plugin): run prettier and use builtin functions

* fix(eslint-plugin): [comma-spacing] add unit test
  • Loading branch information
comrem committed Apr 27, 2022
1 parent 5899164 commit 23746f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/comma-spacing.ts
Expand Up @@ -177,7 +177,7 @@ export default createRule<Options, MessageIds>({
isCommaToken(prevToken) || ignoredTokens.has(token)
? null
: prevToken,
isCommaToken(nextToken) || ignoredTokens.has(token)
(nextToken && isCommaToken(nextToken)) || ignoredTokens.has(token)
? null
: nextToken,
);
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-plugin/tests/rules/comma-spacing.test.ts
Expand Up @@ -281,6 +281,7 @@ ruleTester.run('comma-spacing', rule, {
'class Foo<T, T1> {}',
'interface Foo<T, T1,>{}',
'interface A<> {}',
'let foo,',
],

invalid: [
Expand Down Expand Up @@ -787,5 +788,17 @@ ruleTester.run('comma-spacing', rule, {
},
],
},
{
code: 'let foo ,',
output: 'let foo,',
errors: [
{
messageId: 'unexpected',
column: 9,
line: 1,
data: { loc: 'before' },
},
],
},
],
});

0 comments on commit 23746f8

Please sign in to comment.