Skip to content

Commit

Permalink
fix(eslint-plugin): [comma-spacing] handle empty type params (#2915)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan committed Jan 3, 2021
1 parent 85c2720 commit 4d69fbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/eslint-plugin/src/rules/comma-spacing.ts
Expand Up @@ -90,10 +90,13 @@ export default createRule<Options, MessageIds>({
function addTypeParametersTrailingCommaToIgnoreList(
node: TSESTree.TSTypeParameterDeclaration,
): void {
const param = node.params[node.params.length - 1];
const afterToken = sourceCode.getTokenAfter(param);
if (afterToken && isCommaToken(afterToken)) {
ignoredTokens.add(afterToken);
const paramLength = node.params.length;
if (paramLength) {
const param = node.params[paramLength - 1];
const afterToken = sourceCode.getTokenAfter(param);
if (afterToken && isCommaToken(afterToken)) {
ignoredTokens.add(afterToken);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/tests/rules/comma-spacing.test.ts
Expand Up @@ -280,6 +280,7 @@ ruleTester.run('comma-spacing', rule, {
'function foo<T,>() {}',
'class Foo<T, T1> {}',
'interface Foo<T, T1,>{}',
'interface A<> {}',
],

invalid: [
Expand Down

0 comments on commit 4d69fbb

Please sign in to comment.