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

Commit

Permalink
Make semi-colon rule laxer with bound-method properties
Browse files Browse the repository at this point in the history
Methods declared like:

```
class Foo {
      bar = () => { }
}
```

shouldn't be marked as requiring a trailing semi-colon for the closing `}`
  • Loading branch information
AndyMoreland committed Apr 4, 2016
1 parent 3281470 commit 79201cb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules/semicolonRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class SemicolonWalker extends Lint.RuleWalker {
}

public visitPropertyDeclaration(node: ts.PropertyDeclaration) {
this.checkSemicolonAt(node);
const initializer = node.initializer;
if (this.hasOption(OPTION_ALWAYS) || this.hasOption(OPTION_NEVER) ||
!(initializer && initializer.kind === ts.SyntaxKind.ArrowFunction)) {
this.checkSemicolonAt(node);
}
super.visitPropertyDeclaration(node);
}

Expand Down
5 changes: 5 additions & 0 deletions test/rules/semicolon/always/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class MyClass {
private index : number
~nil [missing semicolon]
private email : string;

public initializedProperty = 6
~nil [missing semicolon]
public initializedMethodProperty = () => { return "hi"; }
~nil [missing semicolon]
}

interface ITest {
Expand Down
3 changes: 3 additions & 0 deletions test/rules/semicolon/enabled/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class MyClass {
private index : number
~nil [missing semicolon]
private email : string;
public initializedProperty = 6
~nil [missing semicolon]
public initializedMethodProperty = () => { return "hi"; }
}

interface ITest {
Expand Down
4 changes: 4 additions & 0 deletions test/rules/semicolon/never/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class MyClass {
private index : number;
~ [unnecessary semicolon]
private email : string
public initializedProperty = 6
public initializedMethodProperty = () => { return "hi" };
~ [unnecessary semicolon]

}

interface ITest {
Expand Down

0 comments on commit 79201cb

Please sign in to comment.