Skip to content

Commit

Permalink
Merge branch 'develop' into 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya committed May 6, 2015
2 parents 7016aef + dc74e0f commit f5cd8ca
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 398 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
Change Log
===
v2.2.0-beta
---
* Upgraded Typescript compiler to 1.5
* **BREAKING CHANGES**
* due to changes to the typescript compiler API, old custom rules may no longer work and may need to be rewritten
* the JSON formatter's line and character positions are now back to being 0-indexed instead of 1-indexed
* [bugs] #328 #334 #319 #351 #365 #254
* [bug] fixes for tslint behavior around template strings (fixes #357, #349, #332, and more)
* [new-rule] `align` rule now enforces vertical alignment on parameters, arguments, and statements
* [new-rule] `switch-default` enforces a `default` case in `switch` statements
* [feature] `no-duplicate-variable` rule now additionally checks if function parameters have been shadowed
* Additional fixes to existing rules to work as before with the typescript 1.5 compiler

===
v2.1.1
---
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tslint",
"version": "2.1.1",
"version": "2.2.0-beta",
"description": "a static analysis linter for TypeScript",
"bin": {
"tslint": "./bin/tslint"
Expand Down Expand Up @@ -32,7 +32,7 @@
"grunt-mocha-test": "~0.6.2",
"grunt-ts": "~1.12.1",
"grunt-tslint": "~2.0.0",
"typescript": "1.5.0-alpha"
"typescript": "1.5.0-beta"
},
"license": "Apache 2.0"
}
1 change: 1 addition & 0 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module Lint {

export function createCompilerOptions(): ts.CompilerOptions {
return {
noResolve: true,
target: ts.ScriptTarget.ES5
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/rules/noDuplicateVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class NoDuplicateVariableWalker extends Lint.ScopeAwareRuleWalker<ScopeInfo> {
// don't call super, we don't want to walk method signatures either
}

public visitFunctionType(node: ts.Node): void {
// don't call super, we don't want to walk function types as well
}

public visitCatchClause(node: ts.CatchClause): void {
// don't visit the catch clause variable declaration, just visit the block
// the catch clause variable declaration has its own special scoping rules
Expand Down
10 changes: 8 additions & 2 deletions src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
super.visitImportEqualsDeclaration(node);
}

public visitCatchClause(node: ts.CatchClause): void {
// don't visit the catch clause variable declaration, just visit the block
// the catch clause variable declaration needs to be there but doesn't need to be used
this.visitBlock(node.block);
}

// check variable declarations
public visitVariableDeclaration(node: ts.VariableDeclaration): void {
var propertyName = <ts.Identifier> node.name;
Expand Down Expand Up @@ -168,8 +174,8 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
}

private validateReferencesForVariable(name: string, position: number) {
var references = this.languageService.getReferencesAtPosition("file.ts", position);
if (references.length <= 1) {
var highlights = this.languageService.getDocumentHighlights("file.ts", position, ["file.ts"]);
if (highlights[0].highlightSpans.length <= 1) {
var failureString = Rule.FAILURE_STRING + "'" + name + "'";
var failure = this.createFailure(position, name.length, failureString);
this.addFailure(failure);
Expand Down
20 changes: 11 additions & 9 deletions src/rules/noUseBeforeDeclareRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ class NoUseBeforeDeclareWalker extends Lint.ScopeAwareRuleWalker<{}> {
}

private validateUsageForVariable(name: string, position: number) {
var references = this.languageService.getReferencesAtPosition("file.ts", position);
if (references) {
references.forEach((reference) => {
var referencePosition = reference.textSpan.start;
if (referencePosition < position) {
var failureString = Rule.FAILURE_STRING_PREFIX + name + Rule.FAILURE_STRING_POSTFIX;
var failure = this.createFailure(referencePosition, name.length, failureString);
this.addFailure(failure);
}
var highlights = this.languageService.getDocumentHighlights("file.ts", position, ["file.ts"]);
if (highlights) {
highlights.forEach((highlight) => {
highlight.highlightSpans.forEach((highlightSpan) => {
var referencePosition = highlightSpan.textSpan.start;
if (referencePosition < position) {
var failureString = Rule.FAILURE_STRING_PREFIX + name + Rule.FAILURE_STRING_POSTFIX;
var failure = this.createFailure(referencePosition, name.length, failureString);
this.addFailure(failure);
}
});
});
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/rules/semicolonRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ class SemicolonWalker extends Lint.RuleWalker {
super.visitDebuggerStatement(node);
}

public visitPropertyDeclaration(node: ts.PropertyDeclaration) {
this.checkSemicolonAt(node);

super.visitPropertyDeclaration(node);
}

public visitInterfaceDeclaration(node: ts.InterfaceDeclaration) {
node.members.forEach((member) => {
this.checkSemicolonAt(member);
});

super.visitInterfaceDeclaration(node);
}

private checkSemicolonAt(node: ts.Node) {
var children = node.getChildren(this.getSourceFile());
for (var i = 0; i < children.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"../../lib/tslint.d.ts",
"../../typings/node.d.ts",
"../../typings/typescriptServices.d.ts",
"../../typings/typescriptServicesScanner.d.ts",
"./alignRule.ts",
"./banRule.ts",
"./classNameRule.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/typedefWhitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class TypedefWhitespaceWalker extends Lint.RuleWalker {
super.visitVariableDeclaration(node);
}

public checkSpace(option: string, node: ts.Node, typeNode: ts.TypeNode | ts.StringLiteralExpression, positionBeforeColon: number) {
public checkSpace(option: string, node: ts.Node, typeNode: ts.TypeNode | ts.StringLiteral, positionBeforeColon: number) {
if (this.hasOption(option) && typeNode != null && positionBeforeColon != null) {
var hasLeadingWhitespace: boolean;
var scanner = ts.createScanner(ts.ScriptTarget.ES5, false, node.getText());
Expand Down
2 changes: 1 addition & 1 deletion src/rules/useStrictRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class UseStrictWalker extends Lint.ScopeAwareRuleWalker<{}> {
var firstChild = firstStatement.getChildAt(0);

if (firstChild.kind === ts.SyntaxKind.StringLiteral &&
(<ts.StringLiteralExpression> firstChild).text === UseStrictWalker.USE_STRICT_STRING) {
(<ts.StringLiteral> firstChild).text === UseStrictWalker.USE_STRICT_STRING) {
isFailure = false;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"files": [
"../typings/node.d.ts",
"../typings/typescriptServices.d.ts",
"../typings/typescriptServicesScanner.d.ts",
"./language/formatter/abstractFormatter.ts",
"./language/formatter/formatter.ts",
"./language/languageServiceHost.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/tslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Lint {
private source: string;
private options: ILinterOptions;

public static VERSION = "2.1.1";
public static VERSION = "2.2.0-beta";

constructor(fileName: string, source: string, options: ILinterOptions) {
this.fileName = fileName;
Expand Down
4 changes: 3 additions & 1 deletion test/files/rules/duplicate-variable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ function blah(arg1: {[key: string]: any, arg2: {[key:string]: any}) {
export interface IClipboard {
copy(key: string, state: any): void;
paste(key: string): any;
findMaxOrMin(values: any[], defaultValue: number, operation: (...values: any[]) => number)
findMaxOrMin(values: any[], defaultValue: number, operation: (...values: any[]) => number);
functionA: (value: string) => void;
functionB: (value: string) => void;
}

try {
Expand Down
6 changes: 6 additions & 0 deletions test/files/rules/nounusedvariable-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ import xyz = require("xyz");
export import a = require("a");

$(_.xyz());

/// <reference path="../externalFormatter.test.ts" />

module S {
var template = '';
}
6 changes: 6 additions & 0 deletions test/files/rules/nounusedvariable-var.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ class ABCD {
z = 3;
}
}

try {
// code here
} catch (e) {
// e is unused but that's still ok
}
12 changes: 12 additions & 0 deletions test/files/rules/semicolon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ function useStrictMissingSemicolon() {
"use strict"
return null;
}

class MyClass {
public name : string
private index : number
private email : string; // no error
}

interface ITest {
foo?: string
bar: number
baz: boolean; // no error
}
9 changes: 5 additions & 4 deletions test/rules/noUnusedVariableRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ describe("<no-unused-variable>", () => {
it("restricts unused imports", () => {
var fileName = "rules/nounusedvariable-imports.test.ts";
var Rule = Lint.Test.getRule("no-unused-variable");
var failureString = Rule.FAILURE_STRING + "'xyz'";
var failure = Lint.Test.createFailuresOnFile(fileName, failureString)([3, 9], [3, 12]);
var failure1 = Lint.Test.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'xyz'")([3, 9], [3, 12]);
var failure2 = Lint.Test.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'template'")([11, 7], [11, 15]);

var actualFailures = Lint.Test.applyRuleOnFile(fileName, Rule);

assert.lengthOf(actualFailures, 1);
Lint.Test.assertContainsFailure(actualFailures, failure);
assert.lengthOf(actualFailures, 2);
Lint.Test.assertContainsFailure(actualFailures, failure1);
Lint.Test.assertContainsFailure(actualFailures, failure2);
});

it("restricts unused variables", () => {
Expand Down
12 changes: 11 additions & 1 deletion test/rules/semicolonRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("<semicolon>", () => {
});

it("warns on all statements", () => {
assert.equal(actualFailures.length, 15);
assert.equal(actualFailures.length, 19);
});

it("warns on variable statements", () => {
Expand Down Expand Up @@ -75,4 +75,14 @@ describe("<semicolon>", () => {
it("warns on use strict statements", () => {
Lint.Test.assertContainsFailure(actualFailures, createFailure([36, 17], [36, 17]));
});

it("warns on property declarations", () => {
Lint.Test.assertContainsFailure(actualFailures, createFailure([41, 25], [41, 25]));
Lint.Test.assertContainsFailure(actualFailures, createFailure([42, 27], [42, 27]));
});

it("warns on interface declaration", () => {
Lint.Test.assertContainsFailure(actualFailures, createFailure([47, 17], [47, 17]));
Lint.Test.assertContainsFailure(actualFailures, createFailure([48, 16], [48, 16]));
});
});
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"files": [
"../typings/node.d.ts",
"../typings/typescriptServices.d.ts",
"../typings/typescriptServicesScanner.d.ts",
"../lib/tslint.d.ts",
"./typings/chai-assert.d.ts",
"./typings/chai.d.ts",
Expand Down
Loading

0 comments on commit f5cd8ca

Please sign in to comment.