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

Commit

Permalink
Merge pull request #575 from palantir/refactor-use-member-ordering
Browse files Browse the repository at this point in the history
Turn on member-ordering rule
  • Loading branch information
gscshoyru committed Aug 21, 2015
2 parents 3ea7a21 + 2fd802a commit 551f9ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
26 changes: 13 additions & 13 deletions src/rules/forinRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ForInWalker extends Lint.RuleWalker {

// if this "if" statement has a single continue block
const ifStatement = (<ts.IfStatement> firstBlockStatement).thenStatement;
if (ForInWalker.nodeIsContinue(ifStatement)) {
if (nodeIsContinue(ifStatement)) {
return;
}
}
Expand All @@ -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 = (<ts.Block> node).statements;
if (blockStatements.length === 1 && blockStatements[0].kind === ts.SyntaxKind.ContinueStatement) {
return true;
}
if (kind === ts.SyntaxKind.Block) {
const blockStatements = (<ts.Block> node).statements;
if (blockStatements.length === 1 && blockStatements[0].kind === ts.SyntaxKind.ContinueStatement) {
return true;
}

return false;
}

return false;
}
18 changes: 9 additions & 9 deletions src/rules/oneLineRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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];
}
4 changes: 2 additions & 2 deletions src/tslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 551f9ca

Please sign in to comment.