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

Commit

Permalink
Handle get/set accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson committed May 7, 2017
1 parent 4207cb1 commit 7e28339
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/rules/spaceBeforeFunctionParenRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function walk(ctx: Lint.WalkContext<Options>): void {
const option = getOption(node, options);
if (option !== undefined) {
const openParen = Lint.childOfKind(node, ts.SyntaxKind.OpenParenToken)!;
const hasSpace = sourceFile.text[openParen.pos] !== "(";
const hasSpace = ts.isWhiteSpaceLike(sourceFile.text.charCodeAt(openParen.end - 2));

if (hasSpace && option === "never") {
const pos = openParen.getStart() - 1;
Expand Down Expand Up @@ -116,6 +116,8 @@ function getOption(node: ts.Node, options: Options): Option | undefined {

case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.MethodSignature:
case ts.SyntaxKind.SetAccessor:
case ts.SyntaxKind.GetAccessor:
return options.method;

default:
Expand Down
3 changes: 3 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 @@ -42,6 +42,9 @@ class MyClass {
two(): void {
}
three(a: string, cb: ()=>{}): void {}

get a() {}
set a() {}
}


Expand Down
53 changes: 29 additions & 24 deletions test/rules/space-before-function-paren/never/test.ts.lint
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
// Anonymous
function () {}
~ [space-before-function-paren]
~ [0]
function (): void {
~ [space-before-function-paren]
~ [0]
}
function (a: string, cb: ()=>{}): void {}
~ [space-before-function-paren]
~ [0]

var f = function () {};
~ [space-before-function-paren]
~ [0]
var f = function (): void {
~ [space-before-function-paren]
~ [0]
};
var f = function (a: string, cb: ()=>{}): void {};
~ [space-before-function-paren]
~ [0]


// Named
function foobar (){}
~ [space-before-function-paren]
~ [0]
function foobar (): void{
~ [space-before-function-paren]
~ [0]
}
function foobar (a: string, cb: ()=>{}): void{}
~ [space-before-function-paren]
~ [0]

var f = function foobar (){};
~ [space-before-function-paren]
~ [0]
var f = function foobar (): void{
~ [space-before-function-paren]
~ [0]
};
var f = function foobar (a: string, cb: ()=>{}): void{};
~ [space-before-function-paren]
~ [0]


// Async Arrow
Expand All @@ -40,44 +40,49 @@ var f = function foobar (a: string, cb: ()=>{}): void{};
var arrow = () => {};

async () => {};
~ [space-before-function-paren]
~ [0]
var arrow = async () => {};
~ [space-before-function-paren]
~ [0]


// Method
interface IMyInterface {
one ();
~ [space-before-function-paren]
~ [0]
two (): void;
~ [space-before-function-paren]
~ [0]
three (a: string, cb: ()=>{}): void;
~ [space-before-function-paren]
~ [0]
}
class MyClass {
one () {}
~ [space-before-function-paren]
~ [0]
two (): void {
~ [space-before-function-paren]
~ [0]
}
three (a: string, cb: ()=>{}): void {}
~ [space-before-function-paren]
~ [0]

get a () {}
~ [0]
set a () {}
~ [0]
}


// Constructor
class MyClass {
constructor () {}
~ [space-before-function-paren]
~ [0]
}
class MyClass {
constructor (): void {
~ [space-before-function-paren]
~ [0]
}
}
class MyClass {
constructor (a: string, cb: ()=>{}): void {}
~ [space-before-function-paren]
~ [0]
}

[space-before-function-paren]: Spaces before function parens are disallowed
[0]: Spaces before function parens are disallowed

0 comments on commit 7e28339

Please sign in to comment.