Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Handle unnamed default exports like anonymous functions (fixes #3040) (
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionMH authored and jkillian committed Jul 19, 2017
1 parent 45a4b47 commit fcd0b98
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/rules/spaceBeforeFunctionParenRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions test/rules/space-before-function-paren/always/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -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
() => {};
Expand Down
4 changes: 4 additions & 0 deletions test/rules/space-before-function-paren/always/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
() => {};
Expand Down
2 changes: 2 additions & 0 deletions test/rules/space-before-function-paren/mixed/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/rules/space-before-function-paren/mixed/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/rules/space-before-function-paren/never/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/rules/space-before-function-paren/never/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fcd0b98

Please sign in to comment.