Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d69fbb

Browse files
authored
fix(eslint-plugin): [comma-spacing] handle empty type params (typescript-eslint#2915)
1 parent 85c2720 commit 4d69fbb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/eslint-plugin/src/rules/comma-spacing.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ export default createRule<Options, MessageIds>({
9090
function addTypeParametersTrailingCommaToIgnoreList(
9191
node: TSESTree.TSTypeParameterDeclaration,
9292
): void {
93-
const param = node.params[node.params.length - 1];
94-
const afterToken = sourceCode.getTokenAfter(param);
95-
if (afterToken && isCommaToken(afterToken)) {
96-
ignoredTokens.add(afterToken);
93+
const paramLength = node.params.length;
94+
if (paramLength) {
95+
const param = node.params[paramLength - 1];
96+
const afterToken = sourceCode.getTokenAfter(param);
97+
if (afterToken && isCommaToken(afterToken)) {
98+
ignoredTokens.add(afterToken);
99+
}
97100
}
98101
}
99102

packages/eslint-plugin/tests/rules/comma-spacing.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ ruleTester.run('comma-spacing', rule, {
280280
'function foo<T,>() {}',
281281
'class Foo<T, T1> {}',
282282
'interface Foo<T, T1,>{}',
283+
'interface A<> {}',
283284
],
284285

285286
invalid: [

0 commit comments

Comments
 (0)