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 7c52468
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/rules/semicolonRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ class SemicolonWalker extends Lint.RuleWalker {
}

public visitPropertyDeclaration(node: ts.PropertyDeclaration) {
this.checkSemicolonAt(node);
const initializer = node.initializer;
if (this.hasOption(OPTION_ALWAYS) || !initializer
|| (initializer.kind !== ts.SyntaxKind.FunctionExpression
&& 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

0 comments on commit 7c52468

Please sign in to comment.