Skip to content

Commit

Permalink
phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinr committed Dec 9, 2013
1 parent d2ec389 commit 33254a8
Show file tree
Hide file tree
Showing 159 changed files with 31,646 additions and 34,030 deletions.
6,263 changes: 3,462 additions & 2,801 deletions lib/tslint.d.ts

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/language/languageServiceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

module Lint {

export class LanguageServiceHost extends TypeScript.NullLogger implements Services.ILanguageServiceHost {
export class LanguageServiceHost extends TypeScript.NullLogger implements TypeScript.Services.ILanguageServiceHost {
private compilationSettings: TypeScript.CompilationSettings;
private diagnostics: Services.ILanguageServicesDiagnostics;
private diagnostics: TypeScript.Services.ILanguageServicesDiagnostics;
private fileName: string;
private scriptSnapshot: TypeScript.IScriptSnapshot;

Expand Down Expand Up @@ -55,11 +55,11 @@ module Lint {
return this.scriptSnapshot;
}

public getScriptByteOrderMark(fileName: string): ByteOrderMark {
return ByteOrderMark.None;
public getScriptByteOrderMark(fileName: string): TypeScript.ByteOrderMark {
return TypeScript.ByteOrderMark.None;
}

public getDiagnosticsObject(): Services.ILanguageServicesDiagnostics {
public getDiagnosticsObject(): TypeScript.Services.ILanguageServicesDiagnostics {
return this.diagnostics;
}

Expand Down Expand Up @@ -95,7 +95,7 @@ module Lint {
}
}

class LanguageServicesDiagnostics implements Services.ILanguageServicesDiagnostics {
class LanguageServicesDiagnostics implements TypeScript.Services.ILanguageServicesDiagnostics {
private logger;

constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/language/rule/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/// <reference path='../../typescript/src/compiler/syntax/syntaxTree.ts'/>
/// <reference path='../../typescript/src/compiler/text/linePosition.ts'/>
/// <reference path='../../typescript/src/compiler/core/linePosition.ts'/>

module Lint {

Expand Down
2 changes: 1 addition & 1 deletion src/rules/curlyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CurlyWalker extends Lint.RuleWalker {
super.visitWhileStatement(node);
}

private isStatementBraced(node: TypeScript.IExpressionSyntax): boolean {
private isStatementBraced(node: TypeScript.IStatementSyntax): boolean {
var childCount = node.childCount();
if (childCount === 3) {
if (node.childAt(0).kind() === TypeScript.SyntaxKind.FirstPunctuation &&
Expand Down
2 changes: 1 addition & 1 deletion src/rules/indentRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class IndentWalker extends Lint.RuleWalker {
public visitModuleDeclaration(node: TypeScript.ModuleDeclarationSyntax): void {
this.visitList(node.modifiers);
this.visitToken(node.moduleKeyword);
this.visitOptionalNodeOrToken(node.moduleName);
this.visitOptionalNodeOrToken(node.name);
if (node.stringLiteral !== null) {
this.visitToken(node.stringLiteral);
}
Expand Down
12 changes: 0 additions & 12 deletions src/rules/noConsoleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,3 @@

/// <reference path='../../lib/tslint.d.ts' />

import BanRule = require("banRule");

export class Rule extends BanRule.Rule {
public apply(syntaxTree: TypeScript.SyntaxTree): Lint.RuleFailure[] {
var options = this.getOptions();
var consoleBanWalker = new BanRule.BanFunctionWalker(syntaxTree, this.getOptions());
options.forEach((option) => {
consoleBanWalker.addBannedFunction(["console", option]);
});
return this.applyWithWalker(consoleBanWalker);
}
}
8 changes: 4 additions & 4 deletions src/rules/noDuplicateVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class NoDuplicateVariableWalker extends Lint.ScopeAwareRuleWalker<ScopeInfo> {
}

public visitVariableDeclarator(node: TypeScript.VariableDeclaratorSyntax): void {
var identifier = node.identifier,
variableName = identifier.text(),
position = this.position() + identifier.leadingTriviaWidth(),
var propertyName = node.propertyName,
variableName = propertyName.text(),
position = this.position() + propertyName.leadingTriviaWidth(),
currentScope = this.getCurrentScope();

if (currentScope.variableNames.indexOf(variableName) >= 0) {
var failureString = Rule.FAILURE_STRING + variableName + "'";
this.addFailure(this.createFailure(position, identifier.width(), failureString));
this.addFailure(this.createFailure(position, propertyName.width(), failureString));
} else {
currentScope.variableNames.push(variableName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noStringLiteralRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NoStringLiteralWalker extends Lint.RuleWalker {

var unquotedString = id.substring(1, id.length - 1);
var simpleText = TypeScript.SimpleText.fromString(unquotedString);
var isValidIdentifier = TypeScript.Scanner.isValidIdentifier(simpleText, TypeScript.LanguageVersion);
var isValidIdentifier = TypeScript.Scanner.isValidIdentifier(simpleText, TypeScript.LanguageVersion.EcmaScript5);

// only create a failure if the identifier is valid, in which case there's no need to use string literals
if (isValidIdentifier) {
Expand Down
35 changes: 9 additions & 26 deletions src/rules/typedefRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ class TypedefWalker extends Lint.RuleWalker {
super.visitCatchClause(node);
}

public visitGetAccessorPropertyAssignment(node: TypeScript.GetAccessorPropertyAssignmentSyntax): void {
this.checkTypeAnnotation("getAccessorPropertyAssignment", node, node.typeAnnotation, node.propertyName);

super.visitGetAccessorPropertyAssignment(node);
}

public visitGetMemberAccessorDeclaration(node: TypeScript.GetMemberAccessorDeclarationSyntax): void {
this.checkTypeAnnotation("getMemberAccessorDeclaration", node, node.typeAnnotation, node.propertyName);

super.visitGetMemberAccessorDeclaration(node);
}

public visitIndexSignature(node: TypeScript.IndexSignatureSyntax): void {
this.checkTypeAnnotation("indexSignature", node, node.typeAnnotation);

Expand All @@ -68,25 +56,20 @@ class TypedefWalker extends Lint.RuleWalker {
}

public visitVariableDeclarator(node: TypeScript.VariableDeclaratorSyntax): void {
this.checkTypeAnnotation("variableDeclarator", node, node.typeAnnotation, node.identifier);
this.checkTypeAnnotation("variableDeclarator", node, node.typeAnnotation, node.propertyName);

super.visitVariableDeclarator(node);
}

public checkTypeAnnotation(
option: string,
node: TypeScript.SyntaxNode,
typeAnnotation: TypeScript.TypeAnnotationSyntax,
name?: TypeScript.ISyntaxToken) : void {
public checkTypeAnnotation(option: string,
node: TypeScript.SyntaxNode,
typeAnnotation: TypeScript.TypeAnnotationSyntax,
name?: TypeScript.ISyntaxToken): void {

if (this.hasOption(option) && !typeAnnotation) {
var name = name ? ": '" + name.text() + "'" : "";
this.addFailure(
this.createFailure(
this.positionAfter(node),
1,
"expected " + option + name + " to have a typedef."
)
);
var ns = name ? ": '" + name.text() + "'" : "";
var failure = this.createFailure(this.positionAfter(node), 1, "expected " + ns + " to have a typedef.");
this.addFailure(failure);
}
}
}
38 changes: 8 additions & 30 deletions src/rules/typedefWhitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,6 @@ class TypedefWhitespaceWalker extends Lint.RuleWalker {
super.visitCatchClause(node);
}

public visitGetAccessorPropertyAssignment(node: TypeScript.GetAccessorPropertyAssignmentSyntax): void {
// TODO: The following check was not accurate/working. Since the notation
// is esoteric, this subrule is marked as not implemented until
// the functionality is needed and the bugs worked out.
//this.checkSpace("getAccessorPropertyAssignment", node, node.typeAnnotation);

this.addNotImplementedFailure("getAccessorPropertyAssignment");

super.visitGetAccessorPropertyAssignment(node);
}

public visitGetMemberAccessorDeclaration(node: TypeScript.GetMemberAccessorDeclarationSyntax): void {
// TODO: The following check was not accurate/working. Since the notation
// is esoteric, this subrule is marked as not implemented until
// the functionality is needed and the bugs worked out.
//this.checkSpace("getMemberAccessorDeclaration", node, node.typeAnnotation);

this.addNotImplementedFailure("getMemberAccessorDeclaration");

super.visitGetMemberAccessorDeclaration(node);
}

public visitIndexSignature(node: TypeScript.IndexSignatureSyntax): void {
this.checkSpace("indexSignature", node, node.typeAnnotation);

Expand Down Expand Up @@ -87,13 +65,13 @@ class TypedefWhitespaceWalker extends Lint.RuleWalker {
public checkSpace(option: string, node: TypeScript.SyntaxNode, typeAnnotation: TypeScript.TypeAnnotationSyntax) : void {
if (this.hasOption(option) && typeAnnotation) {
var typeAnnotationChildIndex = this.getTypeAnnotationIndex(node),
preceedingChild = this.findPreceedingChild(node, typeAnnotationChildIndex),
hasLeadingWhitespace = this.hasLeadingWhitespace(preceedingChild.trailingTrivia());
precedingChild = this.findPrecedingChild(node, typeAnnotationChildIndex),
hasLeadingWhitespace = this.hasLeadingWhitespace(precedingChild.trailingTrivia());

if (hasLeadingWhitespace !== (this.getOption(option) === "space")) {
this.addFailure(
this.createFailure(
this.positionAfter(preceedingChild),
this.positionAfter(precedingChild),
1,
"expected " + this.getOption(option) + " in " + option + "."
)
Expand Down Expand Up @@ -145,15 +123,15 @@ class TypedefWhitespaceWalker extends Lint.RuleWalker {
return index;
}

private findPreceedingChild(node: TypeScript.SyntaxNode, startIndex: number): TypeScript.ISyntaxElement {
var preceedingChild,
private findPrecedingChild(node: TypeScript.SyntaxNode, startIndex: number): TypeScript.ISyntaxElement {
var precedingChild,
offset = 0;

while (!preceedingChild) {
while (!precedingChild) {
offset++;
preceedingChild = node.childAt(startIndex - offset);
precedingChild = node.childAt(startIndex - offset);
}
return preceedingChild;
return precedingChild;
}

private hasLeadingWhitespace(trivia: TypeScript.ISyntaxTriviaList): boolean {
Expand Down
8 changes: 4 additions & 4 deletions src/rules/variableNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export class Rule extends Lint.Rules.AbstractRule {

class VariableNameWalker extends Lint.RuleWalker {
public visitVariableDeclarator(node: TypeScript.VariableDeclaratorSyntax): void {
var identifier = node.identifier;
var variableName = identifier.text();
var position = this.position() + identifier.leadingTriviaWidth();
var propertyName = node.propertyName;
var variableName = propertyName.text();
var position = this.position() + propertyName.leadingTriviaWidth();

if (!this.isCamelCase(variableName) && !this.isUpperCase(variableName)) {
this.addFailure(this.createFailure(position, identifier.width(), Rule.FAILURE_STRING));
this.addFailure(this.createFailure(position, propertyName.width(), Rule.FAILURE_STRING));
}

super.visitVariableDeclarator(node);
Expand Down
4 changes: 2 additions & 2 deletions src/rules/whitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class WhitespaceWalker extends Lint.RuleWalker {

// check for spaces in variable declarations
public visitVariableDeclarator(node: TypeScript.VariableDeclaratorSyntax): void {
var position = this.positionAfter(node.identifier, node.typeAnnotation);
var position = this.positionAfter(node.propertyName, node.typeAnnotation);

if (this.hasOption(OPTION_DECL) && node.equalsValueClause !== null) {
if (node.typeAnnotation !== null) {
this.checkForLeadingSpace(position, node.typeAnnotation.trailingTrivia());
} else {
this.checkForLeadingSpace(position, node.identifier.trailingTrivia());
this.checkForLeadingSpace(position, node.propertyName.trailingTrivia());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tslint-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if (argv.o !== undefined) {
outputStream = fs.createWriteStream(argv.o, {
end: false,
flags: "w+",
mode: 0644
mode: 420
});
} else {
outputStream = process.stdout;
Expand Down
2 changes: 1 addition & 1 deletion src/tslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module Lint {
var i, failures = [];

var languageServiceHost = new Lint.LanguageServiceHost(this.fileName, this.source);
var languageService = new Services.LanguageService(languageServiceHost);
var languageService = new TypeScript.Services.LanguageService(languageServiceHost);
var syntaxTree = languageService.getSyntaxTree(this.fileName);

var rulesDirectory = this.getRelativePath(this.options.rulesDirectory);
Expand Down
Loading

0 comments on commit 33254a8

Please sign in to comment.