diff --git a/packages/eslint-plugin/src/rules/space-before-function-paren.ts b/packages/eslint-plugin/src/rules/space-before-function-paren.ts index f06327e2dd5..e2ccfa5182d 100644 --- a/packages/eslint-plugin/src/rules/space-before-function-paren.ts +++ b/packages/eslint-plugin/src/rules/space-before-function-paren.ts @@ -76,9 +76,10 @@ export default util.createRule({ | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression - | TSESTree.TSAbstractMethodDefinition, + | TSESTree.TSEmptyBodyFunctionExpression + | TSESTree.TSDeclareFunction, ): boolean { - if ('id' in node && node.id != null) { + if (node.id != null) { return true; } @@ -102,7 +103,8 @@ export default util.createRule({ | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression - | TSESTree.TSAbstractMethodDefinition, + | TSESTree.TSEmptyBodyFunctionExpression + | TSESTree.TSDeclareFunction, ): FuncOption { if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) { // Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar @@ -116,7 +118,7 @@ export default util.createRule({ return overrideConfig.named ?? baseConfig; // `generator-star-spacing` should warn anonymous generators. E.g. `function* () {}` - } else if (!('generator' in node) || node.generator === false) { + } else if (!node.generator) { return overrideConfig.anonymous ?? baseConfig; } @@ -133,7 +135,8 @@ export default util.createRule({ | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression - | TSESTree.TSAbstractMethodDefinition, + | TSESTree.TSEmptyBodyFunctionExpression + | TSESTree.TSDeclareFunction, ): void { const functionConfig = getConfigForFunction(node); @@ -165,7 +168,7 @@ export default util.createRule({ } else if ( !hasSpacing && functionConfig === 'always' && - (!node.typeParameters || ('id' in node && node != null)) + (!node.typeParameters || node.id) ) { context.report({ node, @@ -180,7 +183,8 @@ export default util.createRule({ ArrowFunctionExpression: checkFunction, FunctionDeclaration: checkFunction, FunctionExpression: checkFunction, - TSAbstractMethodDefinition: checkFunction, + TSEmptyBodyFunctionExpression: checkFunction, + TSDeclareFunction: checkFunction, }; }, }); diff --git a/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts b/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts index 5de3b0e6378..13c68b88bc7 100644 --- a/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts +++ b/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts @@ -153,6 +153,19 @@ ruleTester.run('space-before-function-paren', rule, { code: 'abstract class Foo { constructor() {} abstract method() }', options: ['never'], }, + { + code: 'abstract class Foo { constructor() {} abstract method() }', + options: [{ anonymous: 'always', named: 'never' }], + }, + 'function foo ();', + { + code: 'function foo();', + options: ['never'], + }, + { + code: 'function foo();', + options: [{ anonymous: 'always', named: 'never' }], + }, ], invalid: [