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

Require semicolon for function declaration with no body #1447

Merged
merged 3 commits into from Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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