diff --git a/src/rules/forinRule.ts b/src/rules/forinRule.ts index e13518cb8a0..017a8f44f81 100644 --- a/src/rules/forinRule.ts +++ b/src/rules/forinRule.ts @@ -51,7 +51,7 @@ class ForInWalker extends Lint.RuleWalker { // if this "if" statement has a single continue block const ifStatement = ( firstBlockStatement).thenStatement; - if (ForInWalker.nodeIsContinue(ifStatement)) { + if (nodeIsContinue(ifStatement)) { return; } } @@ -61,21 +61,21 @@ class ForInWalker extends Lint.RuleWalker { const failure = this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING); this.addFailure(failure); } +} - private static nodeIsContinue(node: ts.Node) { - const kind = node.kind; +function nodeIsContinue(node: ts.Node) { + const kind = node.kind; - if (kind === ts.SyntaxKind.ContinueStatement) { - return true; - } + if (kind === ts.SyntaxKind.ContinueStatement) { + return true; + } - if (kind === ts.SyntaxKind.Block) { - const blockStatements = ( node).statements; - if (blockStatements.length === 1 && blockStatements[0].kind === ts.SyntaxKind.ContinueStatement) { - return true; - } + if (kind === ts.SyntaxKind.Block) { + const blockStatements = ( node).statements; + if (blockStatements.length === 1 && blockStatements[0].kind === ts.SyntaxKind.ContinueStatement) { + return true; } - - return false; } + + return false; } diff --git a/src/rules/oneLineRule.ts b/src/rules/oneLineRule.ts index 3f9874b74f8..28be132a989 100644 --- a/src/rules/oneLineRule.ts +++ b/src/rules/oneLineRule.ts @@ -44,7 +44,7 @@ class OneLineWalker extends Lint.RuleWalker { const elseStatement = node.elseStatement; if (elseStatement != null) { // find the else keyword - const elseKeyword = OneLineWalker.getFirstChildOfKind(node, ts.SyntaxKind.ElseKeyword); + const elseKeyword = getFirstChildOfKind(node, ts.SyntaxKind.ElseKeyword); if (elseStatement.kind === ts.SyntaxKind.Block) { const elseOpeningBrace = elseStatement.getChildAt(0); this.handleOpeningBrace(elseKeyword, elseOpeningBrace); @@ -152,7 +152,7 @@ class OneLineWalker extends Lint.RuleWalker { public visitEnumDeclaration(node: ts.EnumDeclaration) { const nameNode = node.name; - const openBraceToken = OneLineWalker.getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken); + const openBraceToken = getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken); this.handleOpeningBrace(nameNode, openBraceToken); super.visitEnumDeclaration(node); } @@ -166,14 +166,14 @@ class OneLineWalker extends Lint.RuleWalker { public visitInterfaceDeclaration(node: ts.InterfaceDeclaration) { const nameNode = node.name; - const openBraceToken = OneLineWalker.getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken); + const openBraceToken = getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken); this.handleOpeningBrace(nameNode, openBraceToken); super.visitInterfaceDeclaration(node); } public visitClassDeclaration(node: ts.ClassDeclaration) { const nameNode = node.name; - const openBraceToken = OneLineWalker.getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken); + const openBraceToken = getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken); this.handleOpeningBrace(nameNode, openBraceToken); super.visitClassDeclaration(node); } @@ -196,7 +196,7 @@ class OneLineWalker extends Lint.RuleWalker { public visitArrowFunction(node: ts.FunctionLikeDeclaration) { const body = node.body; if (body != null && body.kind === ts.SyntaxKind.Block) { - const arrowToken = OneLineWalker.getFirstChildOfKind(node, ts.SyntaxKind.EqualsGreaterThanToken); + const arrowToken = getFirstChildOfKind(node, ts.SyntaxKind.EqualsGreaterThanToken); const openBraceToken = node.body.getChildAt(0); this.handleOpeningBrace(arrowToken, openBraceToken); } @@ -210,7 +210,7 @@ class OneLineWalker extends Lint.RuleWalker { if (node.type != null) { this.handleOpeningBrace(node.type, openBraceToken); } else { - const closeParenToken = OneLineWalker.getFirstChildOfKind(node, ts.SyntaxKind.CloseParenToken); + const closeParenToken = getFirstChildOfKind(node, ts.SyntaxKind.CloseParenToken); this.handleOpeningBrace(closeParenToken, openBraceToken); } } @@ -246,8 +246,8 @@ class OneLineWalker extends Lint.RuleWalker { this.addFailure(failure); } } +} - private static getFirstChildOfKind(node: ts.Node, kind: ts.SyntaxKind) { - return node.getChildren().filter((child) => child.kind === kind)[0]; - } +function getFirstChildOfKind(node: ts.Node, kind: ts.SyntaxKind) { + return node.getChildren().filter((child) => child.kind === kind)[0]; } diff --git a/src/tslint.ts b/src/tslint.ts index a888241498f..4eb4c097d25 100644 --- a/src/tslint.ts +++ b/src/tslint.ts @@ -33,12 +33,12 @@ module Lint { } export class Linter { + public static VERSION = "2.4.2"; + private fileName: string; private source: string; private options: ILinterOptions; - public static VERSION = "2.4.2"; - constructor(fileName: string, source: string, options: ILinterOptions) { this.fileName = fileName; this.source = source; diff --git a/tslint.json b/tslint.json index 0fa36d08c1d..bc8c2aefc91 100644 --- a/tslint.json +++ b/tslint.json @@ -9,6 +9,11 @@ "label-position": true, "label-undefined": true, "max-line-length": [true, 140], + "member-ordering": [true, + "public-before-private", + "static-before-instance", + "variables-before-functions" + ], "no-arg": true, "no-bitwise": true, "no-console": [true,