Skip to content

Commit

Permalink
Merge pull request palantir#359 from palantir/upgrade-1.5.0
Browse files Browse the repository at this point in the history
Upgrade 1.5.0
  • Loading branch information
ashwinr committed Apr 9, 2015
2 parents 430dfec + 200c1fa commit 9d88b47
Show file tree
Hide file tree
Showing 34 changed files with 825 additions and 594 deletions.
4 changes: 3 additions & 1 deletion lib/tslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ declare module Lint {
protected visitIdentifier(node: ts.Identifier): void;
protected visitIfStatement(node: ts.IfStatement): void;
protected visitImportDeclaration(node: ts.ImportDeclaration): void;
protected visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration): void;
protected visitIndexSignatureDeclaration(node: ts.IndexSignatureDeclaration): void;
protected visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void;
protected visitLabeledStatement(node: ts.LabeledStatement): void;
protected visitMethodDeclaration(node: ts.MethodDeclaration): void;
protected visitMethodSignature(node: ts.SignatureDeclaration): void;
protected visitModuleDeclaration(node: ts.ModuleDeclaration): void;
protected visitNewExpression(node: ts.NewExpression): void;
protected visitObjectLiteralExpression(node: ts.ObjectLiteralExpression): void;
Expand All @@ -92,14 +94,14 @@ declare module Lint {
protected visitPropertyAccessExpression(node: ts.PropertyAccessExpression): void;
protected visitPropertyAssignment(node: ts.PropertyAssignment): void;
protected visitPropertyDeclaration(node: ts.PropertyDeclaration): void;
protected visitPropertySignature(node: ts.Node): void;
protected visitRegularExpressionLiteral(node: ts.Node): void;
protected visitReturnStatement(node: ts.ReturnStatement): void;
protected visitSetAccessor(node: ts.AccessorDeclaration): void;
protected visitSourceFile(node: ts.SourceFile): void;
protected visitSwitchStatement(node: ts.SwitchStatement): void;
protected visitTemplateExpression(node: ts.TemplateExpression): void;
protected visitThrowStatement(node: ts.ThrowStatement): void;
protected visitTryBlock(node: ts.Block): void;
protected visitTryStatement(node: ts.TryStatement): void;
protected visitTypeAssertionExpression(node: ts.TypeAssertion): void;
protected visitTypeLiteral(node: ts.TypeLiteralNode): void;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"grunt-mocha-test": "~0.6.2",
"grunt-ts": "~1.12.1",
"grunt-tslint": "~2.0.0",
"typescript": "1.4.1"
"typescript": "1.5.0-alpha"
},
"license": "Apache 2.0"
}
4 changes: 2 additions & 2 deletions src/formatters/pmdFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class Formatter extends Lint.Formatters.AbstractFormatter {
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();

output += "<file name=\"" + failure.getFileName();
output += "\"><violation begincolumn=\"" + lineAndCharacter.character;
output += "\" beginline=\"" + lineAndCharacter.line;
output += "\"><violation begincolumn=\"" + (lineAndCharacter.character + 1);
output += "\" beginline=\"" + (lineAndCharacter.line + 1);
output += "\" priority=\"1\"";
output += " rule=\"" + failureString + "\"> </violation></file>";
});
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/proseFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Formatter extends Lint.Formatters.AbstractFormatter {
var failureString = failure.getFailure();

var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var positionTuple = "[" + lineAndCharacter.line + ", " + lineAndCharacter.character + "]";
var positionTuple = "[" + (lineAndCharacter.line + 1) + ", " + (lineAndCharacter.character + 1) + "]";

return fileName + positionTuple + ": " + failureString;
});
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/verboseFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Formatter extends Lint.Formatters.AbstractFormatter {
var ruleName = failure.getRuleName();

var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var positionTuple = "[" + lineAndCharacter.line + ", " + lineAndCharacter.character + "]";
var positionTuple = "[" + (lineAndCharacter.line + 1) + ", " + (lineAndCharacter.character + 1) + "]";

return "(" + ruleName + ") " + fileName + positionTuple + ": " + failureString;
});
Expand Down
2 changes: 1 addition & 1 deletion src/language/languageServiceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Lint {
getCurrentDirectory: () => "",
getScriptIsOpen: () => true,
getCompilationSettings: () => Lint.createCompilerOptions(),
getDefaultLibFilename: (options) => "lib.d.ts",
getDefaultLibFileName: () => "lib.d.ts",
log: (message) => { /* */ }
};

Expand Down
4 changes: 2 additions & 2 deletions src/language/rule/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module Lint {
ruleName: string) {

this.sourceFile = sourceFile;
this.fileName = sourceFile.filename;
this.fileName = sourceFile.fileName;
this.startPosition = this.createFailurePosition(start);
this.endPosition = this.createFailurePosition(end);
this.failure = failure;
Expand Down Expand Up @@ -131,7 +131,7 @@ module Lint {
}

private createFailurePosition(position: number): RuleFailurePosition {
var lineAndCharacter = this.sourceFile.getLineAndCharacterFromPosition(position);
var lineAndCharacter = this.sourceFile.getLineAndCharacterOfPosition(position);
var failurePosition = new RuleFailurePosition(position, lineAndCharacter);
return failurePosition;
}
Expand Down
8 changes: 3 additions & 5 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@ module Lint {
var compilerHost = {
getSourceFile: function (filenameToGet: string) {
if (filenameToGet === normalizedName) {
return ts.createSourceFile(filenameToGet, source, compilerOptions.target, "1", true);
return ts.createSourceFile(filenameToGet, source, compilerOptions.target, true);
}
},
writeFile: () => null,
getDefaultLibFilename: () => "lib.d.ts",
getDefaultLibFileName: () => "lib.d.ts",
useCaseSensitiveFileNames: () => true,
getCanonicalFileName: (filename: string) => filename,
getCurrentDirectory: () => "",
getNewLine: () => "\n"
};

var program = ts.createProgram([normalizedName], compilerOptions, compilerHost);
// this will force the binder to properly set up parent pointers, which will allow getSourceFile to work on all nodes,
// and will therefore allow our code to work even if the source doesn't compile
program.getTypeChecker(true);

return program.getSourceFile(normalizedName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/walker/scopeAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module Lint {
|| node.kind === ts.SyntaxKind.FunctionExpression
|| node.kind === ts.SyntaxKind.PropertyAssignment
|| node.kind === ts.SyntaxKind.ShorthandPropertyAssignment
|| node.kind === ts.SyntaxKind.Method
|| node.kind === ts.SyntaxKind.MethodDeclaration
|| node.kind === ts.SyntaxKind.Constructor
|| node.kind === ts.SyntaxKind.ModuleDeclaration
|| node.kind === ts.SyntaxKind.ArrowFunction
Expand Down
36 changes: 26 additions & 10 deletions src/language/walker/syntaxWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ module Lint {
this.walkChildren(node);
}

protected visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration) {
this.walkChildren(node);
}

protected visitIndexSignatureDeclaration(node: ts.IndexSignatureDeclaration) {
this.walkChildren(node);
}
Expand All @@ -154,6 +158,10 @@ module Lint {
this.walkChildren(node);
}

protected visitMethodSignature(node: ts.SignatureDeclaration) {
this.walkChildren(node);
}

protected visitModuleDeclaration(node: ts.ModuleDeclaration) {
this.walkChildren(node);
}
Expand Down Expand Up @@ -190,6 +198,10 @@ module Lint {
this.walkChildren(node);
}

protected visitPropertySignature(node: ts.Node) {
this.walkChildren(node);
}

protected visitRegularExpressionLiteral(node: ts.Node) {
this.walkChildren(node);
}
Expand Down Expand Up @@ -218,10 +230,6 @@ module Lint {
this.walkChildren(node);
}

protected visitTryBlock(node: ts.Block) {
this.walkChildren(node);
}

protected visitTryStatement(node: ts.TryStatement) {
this.walkChildren(node);
}
Expand Down Expand Up @@ -364,6 +372,10 @@ module Lint {
this.visitImportDeclaration(<ts.ImportDeclaration> node);
break;

case ts.SyntaxKind.ImportEqualsDeclaration:
this.visitImportEqualsDeclaration(<ts.ImportEqualsDeclaration> node);
break;

case ts.SyntaxKind.IndexSignature:
this.visitIndexSignatureDeclaration(<ts.IndexSignatureDeclaration> node);
break;
Expand All @@ -376,10 +388,14 @@ module Lint {
this.visitLabeledStatement(<ts.LabeledStatement> node);
break;

case ts.SyntaxKind.Method:
case ts.SyntaxKind.MethodDeclaration:
this.visitMethodDeclaration(<ts.MethodDeclaration> node);
break;

case ts.SyntaxKind.MethodSignature:
this.visitMethodSignature(<ts.SignatureDeclaration> node);
break;

case ts.SyntaxKind.ModuleDeclaration:
this.visitModuleDeclaration(<ts.ModuleDeclaration> node);
break;
Expand Down Expand Up @@ -412,10 +428,14 @@ module Lint {
this.visitPropertyAssignment(<ts.PropertyAssignment> node);
break;

case ts.SyntaxKind.Property:
case ts.SyntaxKind.PropertyDeclaration:
this.visitPropertyDeclaration(<ts.PropertyDeclaration> node);
break;

case ts.SyntaxKind.PropertySignature:
this.visitPropertySignature(node);
break;

case ts.SyntaxKind.RegularExpressionLiteral:
this.visitRegularExpressionLiteral(node);
break;
Expand Down Expand Up @@ -444,10 +464,6 @@ module Lint {
this.visitThrowStatement(<ts.ThrowStatement> node);
break;

case ts.SyntaxKind.TryBlock:
this.visitTryBlock(<ts.Block> node);
break;

case ts.SyntaxKind.TryStatement:
this.visitTryStatement(<ts.TryStatement> node);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/alignRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ class AlignWalker extends Lint.RuleWalker {
}

private getPosition(node: ts.Node): SourcePosition {
return node.getSourceFile().getLineAndCharacterFromPosition(node.getStart());
return node.getSourceFile().getLineAndCharacterOfPosition(node.getStart());
}
}
3 changes: 1 addition & 2 deletions src/rules/jsdocFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class JsdocWalker extends Lint.RuleWalker {
}
return;
}
// the -1 is necessary because character is 1-indexed, but indexOf is 0-indexed
var indexToMatch = firstLine.indexOf("**") + sourceFile.getLineAndCharacterFromPosition(currentPosition).character - 1;
var indexToMatch = firstLine.indexOf("**") + sourceFile.getLineAndCharacterOfPosition(currentPosition).character;
// all lines but the first and last
var otherLines = lines.splice(1, lines.length - 2);
jsdocPosition += firstLine.length + 1; // + 1 for the splitted-out newline
Expand Down
13 changes: 12 additions & 1 deletion src/rules/memberOrderingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,22 @@ export class MemberOrderingWalker extends Lint.RuleWalker {
super.visitMethodDeclaration(node);
}

public visitMethodSignature(node: ts.SignatureDeclaration): void {
this.checkAndSetModifiers(node, getModifiers(true, node.modifiers));
super.visitMethodSignature(node);
}

public visitPropertyDeclaration(node: ts.PropertyDeclaration): void {
this.checkAndSetModifiers(node, getModifiers(false, node.modifiers));
super.visitPropertyDeclaration(node);
}

public visitPropertySignature(node: ts.Node): void {
this.checkAndSetModifiers(node, getModifiers(false, node.modifiers));
super.visitPropertySignature(node);
}


public visitTypeLiteral(node: ts.TypeLiteralNode) {
// don't call super from here -- we want to skip the property declarations in type literals
}
Expand All @@ -93,7 +104,7 @@ export class MemberOrderingWalker extends Lint.RuleWalker {
};
}

private checkAndSetModifiers(node: ts.Declaration, current: IModifiers): void {
private checkAndSetModifiers(node: ts.Node, current: IModifiers): void {
if (!this.canAppearAfter(this.previous, current)) {
var message = "Declaration of " + toString(current) +
" not allowed to appear after declaration of " + toString(this.previous);
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noBitwiseRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Rule extends Lint.Rules.AbstractRule {

class NoBitwiseWalker extends Lint.RuleWalker {
public visitBinaryExpression(node: ts.BinaryExpression): void {
switch (node.operator) {
switch (node.operatorToken.kind) {
case ts.SyntaxKind.AmpersandToken:
case ts.SyntaxKind.AmpersandEqualsToken:
case ts.SyntaxKind.BarToken:
Expand Down
8 changes: 6 additions & 2 deletions src/rules/noConstructorVarsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ export class NoConstructorVariableDeclarationsWalker extends Lint.RuleWalker {
var parameters = node.parameters;
parameters.forEach((parameter) => {
if (parameter.modifiers != null && parameter.modifiers.length > 0) {
var name = <ts.Identifier> parameter.name;
var errorMessage = "'" + name.text + "'" + Rule.FAILURE_STRING_PART;

var lastModifier = parameter.modifiers[parameter.modifiers.length - 1];
this.addFailure(this.createFailure(parameter.getStart(), lastModifier.getEnd() - parameter.getStart(),
"'" + parameter.name.text + "'" + Rule.FAILURE_STRING_PART));
var position = lastModifier.getEnd() - parameter.getStart();

this.addFailure(this.createFailure(parameter.getStart(), position, errorMessage));
}
});
super.visitConstructorDeclaration(node);
Expand Down
10 changes: 5 additions & 5 deletions src/rules/noDuplicateVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class NoDuplicateVariableWalker extends Lint.ScopeAwareRuleWalker<ScopeInfo> {

public visitParameterDeclaration(node: ts.ParameterDeclaration): void {
// Treat parameters as var.
var propertyName = node.name;
var propertyName = <ts.Identifier> node.name;
var variableName = propertyName.text;
var currentScope = this.getCurrentScope();

if (currentScope.varNames.indexOf(variableName) >= 0) {
this.addFailureOnIdentifier(node.name);
this.addFailureOnIdentifier(<ts.Identifier> node.name);
} else {
currentScope.varNames.push(variableName);
}
Expand All @@ -43,11 +43,11 @@ class NoDuplicateVariableWalker extends Lint.ScopeAwareRuleWalker<ScopeInfo> {
}

public visitVariableDeclaration(node: ts.VariableDeclaration): void {
var propertyName = node.name;
var propertyName = <ts.Identifier> node.name;
var variableName = propertyName.text;
var currentScope = this.getCurrentScope();
// determine if the appropriate bit is set, which indicates this is a "let"
var declarationIsLet = (Math.floor(node.flags / ts.NodeFlags.Let) % 2) === 1;
// determine if the appropriate bit in the parent (VariableDeclarationList) is set, which indicates this is a "let"
var declarationIsLet = (Math.floor(node.parent.flags / ts.NodeFlags.Let) % 2) === 1;

if (currentScope.varNames.indexOf(variableName) >= 0) {
// if there was a previous var declaration with the same name, this declaration is invalid
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noSwitchCaseFallThroughRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class NoSwitchCaseFallThroughWalker extends Lint.RuleWalker {
var isFallingThrough = false;
// get the position for the first case statement

var switchClauses = node.clauses;
var switchClauses = node.caseBlock.clauses;
switchClauses.forEach((child, i) => {
var kind = child.kind;
if (kind === ts.SyntaxKind.CaseClause) {
Expand Down
5 changes: 0 additions & 5 deletions src/rules/noUnreachableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ class UnreachableWalker extends Lint.RuleWalker {
this.hasReturned = false;
}

public visitTryBlock(node: ts.Block): void {
super.visitTryBlock(node);
this.hasReturned = false;
}

public visitCaseClause(node: ts.CaseClause): void {
super.visitCaseClause(node);
this.hasReturned = false;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUnusedExpressionRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class UnusedExpressionWalker extends Lint.RuleWalker {

public visitBinaryExpression(node: ts.BinaryExpression) {
super.visitBinaryExpression(node);
switch (node.operator) {
switch (node.operatorToken.kind) {
case ts.SyntaxKind.EqualsToken:
case ts.SyntaxKind.PlusEqualsToken:
case ts.SyntaxKind.MinusEqualsToken:
Expand Down
Loading

0 comments on commit 9d88b47

Please sign in to comment.