diff --git a/src/rules/spaceBeforeFunctionParenRule.ts b/src/rules/spaceBeforeFunctionParenRule.ts index 283e90ec178..558d3e18371 100644 --- a/src/rules/spaceBeforeFunctionParenRule.ts +++ b/src/rules/spaceBeforeFunctionParenRule.ts @@ -116,8 +116,8 @@ function getOption(node: ts.Node, options: Options): Option | undefined { return options.constructor; case ts.SyntaxKind.FunctionDeclaration: - return options.named; - + // name is optional for function declaration which is default export (TS will emit error in other cases). + // Can be handled in the same way as function expression. case ts.SyntaxKind.FunctionExpression: return (node as ts.FunctionExpression).name !== undefined ? options.named : options.anonymous; diff --git a/test/rules/space-before-function-paren/always/test.ts.fix b/test/rules/space-before-function-paren/always/test.ts.fix index a297321de26..a6228929272 100644 --- a/test/rules/space-before-function-paren/always/test.ts.fix +++ b/test/rules/space-before-function-paren/always/test.ts.fix @@ -22,6 +22,9 @@ var f = function foobar (): void{ var f = function foobar (a: string, cb: ()=>{}): void{}; +// Default export (name ommited) +export default function () {} + // Async Arrow // ignore () => {}; diff --git a/test/rules/space-before-function-paren/always/test.ts.lint b/test/rules/space-before-function-paren/always/test.ts.lint index 134ce574a5f..e552e11524c 100644 --- a/test/rules/space-before-function-paren/always/test.ts.lint +++ b/test/rules/space-before-function-paren/always/test.ts.lint @@ -34,6 +34,10 @@ var f = function foobar(a: string, cb: ()=>{}): void{}; ~ [space-before-function-paren] +// Default export (name ommited) +export default function() {} + ~ [space-before-function-paren] + // Async Arrow // ignore () => {}; diff --git a/test/rules/space-before-function-paren/mixed/test.ts.fix b/test/rules/space-before-function-paren/mixed/test.ts.fix index 1546d57add6..115b10e7340 100644 --- a/test/rules/space-before-function-paren/mixed/test.ts.fix +++ b/test/rules/space-before-function-paren/mixed/test.ts.fix @@ -16,6 +16,8 @@ var f = function foobar(): void{ }; var f = function foobar(a: string, cb: ()=>{}): void{}; +// Default export (name ommited) +export default function () {} // Async Arrow // ignore diff --git a/test/rules/space-before-function-paren/mixed/test.ts.lint b/test/rules/space-before-function-paren/mixed/test.ts.lint index aa28f957418..09298386964 100644 --- a/test/rules/space-before-function-paren/mixed/test.ts.lint +++ b/test/rules/space-before-function-paren/mixed/test.ts.lint @@ -25,6 +25,9 @@ var f = function foobar (): void{ var f = function foobar (a: string, cb: ()=>{}): void{}; ~ [invalid-space] +// Default export (name ommited) +export default function() {} + ~ [missing-space] // Async Arrow // ignore diff --git a/test/rules/space-before-function-paren/never/test.ts.fix b/test/rules/space-before-function-paren/never/test.ts.fix index 237fc3a0d22..73856016928 100644 --- a/test/rules/space-before-function-paren/never/test.ts.fix +++ b/test/rules/space-before-function-paren/never/test.ts.fix @@ -21,6 +21,8 @@ var f = function foobar(): void{ }; var f = function foobar(a: string, cb: ()=>{}): void{}; +// Default export (name ommited) +export default function() {} // Async Arrow // ignore diff --git a/test/rules/space-before-function-paren/never/test.ts.lint b/test/rules/space-before-function-paren/never/test.ts.lint index fb34e87535f..dd67e06b713 100644 --- a/test/rules/space-before-function-paren/never/test.ts.lint +++ b/test/rules/space-before-function-paren/never/test.ts.lint @@ -33,6 +33,9 @@ var f = function foobar (): void{ var f = function foobar (a: string, cb: ()=>{}): void{}; ~ [0] +// Default export (name ommited) +export default function () {} + ~ [0] // Async Arrow // ignore