Skip to content

Commit

Permalink
Require semicolon for function declaration with no body (palantir#1447)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored and Nina Hartmann committed Aug 31, 2016
1 parent ded0407 commit f585cbc
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/rules/semicolonRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ class SemicolonWalker extends Lint.RuleWalker {
super.visitExportAssignment(node);
}

public visitFunctionDeclaration(node: ts.FunctionDeclaration) {
if (!node.body) {
this.checkSemicolonAt(node);
}
super.visitFunctionDeclaration(node);
}

private checkSemicolonAt(node: ts.Node) {
const sourceFile = this.getSourceFile();
const children = node.getChildren(sourceFile);
Expand Down
8 changes: 8 additions & 0 deletions test/rules/semicolon/always/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ debugger;
import v = require("i");
module M {
export var x;
export function f(s: string): string;
export function f(n: number): number;
export function f(x: any) { return x; }
}

declare module "M" {
function f(): number;
function g(): number;
}

function useStrictMissingSemicolon() {
Expand Down
10 changes: 10 additions & 0 deletions test/rules/semicolon/always/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ import v = require("i")
module M {
export var x
~nil [Missing semicolon]
export function f(s: string): string;
export function f(n: number): number
~nil [Missing semicolon]
export function f(x: any) { return x; }
}

declare module "M" {
function f(): number;
function g(): number
~nil [Missing semicolon]
}

function useStrictMissingSemicolon() {
Expand Down
8 changes: 8 additions & 0 deletions test/rules/semicolon/enabled/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ debugger;
import v = require("i");
module M {
export var x;
export function f(s: string): string;
export function f(n: number): number;
export function f(x: any) { return x; }
}

declare module "M" {
function f(): number;
function g(): number;
}

function useStrictMissingSemicolon() {
Expand Down
10 changes: 10 additions & 0 deletions test/rules/semicolon/enabled/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ import v = require("i")
module M {
export var x
~nil [Missing semicolon]
export function f(s: string): string;
export function f(n: number): number
~nil [Missing semicolon]
export function f(x: any) { return x; }
}

declare module "M" {
function f(): number;
function g(): number
~nil [Missing semicolon]
}

function useStrictMissingSemicolon() {
Expand Down
8 changes: 8 additions & 0 deletions test/rules/semicolon/ignore-interfaces/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ debugger;
import v = require("i");
module M {
export var x;
export function f(s: string): string;
export function f(n: number): number;
export function f(x: any) { return x; }
}

declare module "M" {
function f(): number;
function g(): number;
}

function useStrictMissingSemicolon() {
Expand Down
10 changes: 10 additions & 0 deletions test/rules/semicolon/ignore-interfaces/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ import v = require("i")
module M {
export var x
~nil [Missing semicolon]
export function f(s: string): string;
export function f(n: number): number
~nil [Missing semicolon]
export function f(x: any) { return x; }
}

declare module "M" {
function f(): number;
function g(): number
~nil [Missing semicolon]
}

function useStrictMissingSemicolon() {
Expand Down
8 changes: 8 additions & 0 deletions test/rules/semicolon/never/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ debugger
import v = require("i")
module M {
export var x
export function f(s: string): string
export function f(n: number): number
export function f(x: any) { return x }
}

declare module "M" {
function f(): number
function g(): number
}

function useStrictUnnecessarySemicolon() {
Expand Down
11 changes: 11 additions & 0 deletions test/rules/semicolon/never/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ import v = require("i");
module M {
export var x;
~ [Unnecessary semicolon]
export function f(s: string): string;
~ [Unnecessary semicolon]
export function f(n: number): number
export function f(x: any) { return x; }
~ [Unnecessary semicolon]
}

declare module "M" {
function f(): number;
~ [Unnecessary semicolon]
function g(): number
}

function useStrictUnnecessarySemicolon() {
Expand Down

0 comments on commit f585cbc

Please sign in to comment.