diff --git a/CHANGELOG.md b/CHANGELOG.md index f1dd800f366..3ae218b2eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Change Log === +v2.5.0-dev.5 +--- +* Upgrade TypeScript compiler to v1.7.0-dev.20150828 +* [bugfix] Handle .tsx files appropriately (#597, #558) + v2.5.0-dev.4 --- * Upgrade TypeScript compiler to v1.6.0-dev.20150825 @@ -19,6 +24,11 @@ v2.5.0-dev.1 * Upgrade TypeScript compiler to v1.6.0-dev.20150805 * [enhancement] Support `.tsx` syntax (#490) +v2.4.5 +--- +* [bugfix] fix false positives on `no-shadowed-variable` rule (#500) +* [enhancement] add `allow-trailing-underscore` option to `variable-name` rule + v2.4.4 --- * [bugfix] remove "typescript" block from package.json (#606) diff --git a/README.md b/README.md index e57403382f0..ec56ea63e30 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,7 @@ A sample configuration file with all options is available [here](https://github. * `check-function` checks that all top-level functions are using strict mode * `variable-name` allows only camelCased or UPPER_CASED variable names. Rule options: * `"allow-leading-underscore"` allows underscores at the beginnning. + * `"allow-trailing-underscore"` allows underscores at the end. * `whitespace` enforces spacing whitespace. Rule options: * `"check-branch"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace * `"check-decl"`checks that variable declarations have whitespace around the equals token diff --git a/lib/tslint.d.ts b/lib/tslint.d.ts index 053822a825c..a1c460059af 100644 --- a/lib/tslint.d.ts +++ b/lib/tslint.d.ts @@ -13,7 +13,7 @@ declare module Lint { protected visitCatchClause(node: ts.CatchClause): void; protected visitConditionalExpression(node: ts.ConditionalExpression): void; protected visitConstructorDeclaration(node: ts.ConstructorDeclaration): void; - protected visitConstructorType(node: ts.Node): void; + protected visitConstructorType(node: ts.FunctionOrConstructorTypeNode): void; protected visitContinueStatement(node: ts.BreakOrContinueStatement): void; protected visitDebuggerStatement(node: ts.Statement): void; protected visitDefaultClause(node: ts.DefaultClause): void; @@ -27,7 +27,7 @@ declare module Lint { protected visitForOfStatement(node: ts.ForOfStatement): void; protected visitFunctionDeclaration(node: ts.FunctionDeclaration): void; protected visitFunctionExpression(node: ts.FunctionExpression): void; - protected visitFunctionType(node: ts.Node): void; + protected visitFunctionType(node: ts.FunctionOrConstructorTypeNode): void; protected visitGetAccessor(node: ts.AccessorDeclaration): void; protected visitIdentifier(node: ts.Identifier): void; protected visitIfStatement(node: ts.IfStatement): void; diff --git a/package.json b/package.json index 894a9cc6911..61f7c11f7bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tslint", - "version": "2.5.0-dev.4", + "version": "2.5.0-dev.5", "description": "a static analysis linter for TypeScript", "bin": { "tslint": "./bin/tslint" diff --git a/src/language/walker/syntaxWalker.ts b/src/language/walker/syntaxWalker.ts index 066a108a470..20fe515ce46 100644 --- a/src/language/walker/syntaxWalker.ts +++ b/src/language/walker/syntaxWalker.ts @@ -68,7 +68,7 @@ module Lint { this.walkChildren(node); } - protected visitConstructorType(node: ts.Node) { + protected visitConstructorType(node: ts.FunctionOrConstructorTypeNode) { this.walkChildren(node); } @@ -124,7 +124,7 @@ module Lint { this.walkChildren(node); } - protected visitFunctionType(node: ts.Node) { + protected visitFunctionType(node: ts.FunctionOrConstructorTypeNode) { this.walkChildren(node); } @@ -331,7 +331,7 @@ module Lint { break; case ts.SyntaxKind.ConstructorType: - this.visitConstructorType(node); + this.visitConstructorType( node); break; case ts.SyntaxKind.ContinueStatement: @@ -387,7 +387,7 @@ module Lint { break; case ts.SyntaxKind.FunctionType: - this.visitFunctionType(node); + this.visitFunctionType( node); break; case ts.SyntaxKind.GetAccessor: diff --git a/src/rules/noShadowedVariableRule.ts b/src/rules/noShadowedVariableRule.ts index a2adc7c9128..8fe02139a36 100644 --- a/src/rules/noShadowedVariableRule.ts +++ b/src/rules/noShadowedVariableRule.ts @@ -48,6 +48,10 @@ class NoShadowedVariableWalker extends Lint.BlockScopeAwareRuleWalker void) { + let okay1 = 1; +} + +function falsePositive2(okay2: any, done: (okay2: any) => void) { } + +interface FalsePositive3 { + diffuse: (pos: number) => number; + specular: (pos: number) => number; + pos: number; +} diff --git a/test/files/rules/varname.test.ts b/test/files/rules/varname.test.ts index d68d9b2287e..a7dc617d0ed 100644 --- a/test/files/rules/varname.test.ts +++ b/test/files/rules/varname.test.ts @@ -30,3 +30,6 @@ export function anotherFunctionWithInvalidParamNames ([first_element, SecondElem export function functionWithInvalidSpread(invalid_arg: ...number) { // 1 failure // } + +let optionallyValid_ = "bar"; +let _$httpBackend_ = "leading and trailing"; \ No newline at end of file diff --git a/test/rules/variableNameRuleTests.ts b/test/rules/variableNameRuleTests.ts index 920996e50b4..e36d1117b2f 100644 --- a/test/rules/variableNameRuleTests.ts +++ b/test/rules/variableNameRuleTests.ts @@ -35,6 +35,8 @@ describe("", () => { createFailure([26, 56], [26, 69]), createFailure([26, 71], [26, 84]), createFailure([30, 43], [30, 54]), + createFailure([34, 5], [34, 21]), + createFailure([35, 5], [35, 19]) ]; const actualFailures = Lint.Test.applyRuleOnFile(fileName, VariableNameRule); @@ -56,4 +58,37 @@ describe("", () => { return optionallyValidFailures.some((f) => f.equals(failure)); })); }); + + it("ensures trailing underscores can optionally be legal", () => { + const options = [true, + "allow-trailing-underscore" + ]; + + const actualFailures = Lint.Test.applyRuleOnFile(fileName, VariableNameRule, options); + const optionallyValidFailures = [ + createFailure([34, 5], [34, 21]) + ]; + + // none of the optionally valid names should appear in the failures list + assert.isFalse(actualFailures.some((failure) => { + return optionallyValidFailures.some((f) => f.equals(failure)); + })); + }); + + it("ensures leading & trailing underscores can optionally be legal", () => { + const options = [true, + "allow-leading-underscore", + "allow-trailing-underscore" + ]; + + const actualFailures = Lint.Test.applyRuleOnFile(fileName, VariableNameRule, options); + const optionallyValidFailures = [ + createFailure([35, 5], [35, 19]) + ]; + + // none of the optionally valid names should appear in the failures list + assert.isFalse(actualFailures.some((failure) => { + return optionallyValidFailures.some((f) => f.equals(failure)); + })); + }); }); diff --git a/typings/typescriptServices.d.ts b/typings/typescriptServices.d.ts index 7ea3324afe0..3d4418a9750 100644 --- a/typings/typescriptServices.d.ts +++ b/typings/typescriptServices.d.ts @@ -1304,6 +1304,7 @@ declare namespace ts { diagnostics?: boolean; emitBOM?: boolean; help?: boolean; + init?: boolean; inlineSourceMap?: boolean; inlineSources?: boolean; jsx?: JsxEmit; @@ -1328,6 +1329,7 @@ declare namespace ts { rootDir?: string; sourceMap?: boolean; sourceRoot?: string; + suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; target?: ScriptTarget; version?: boolean; @@ -1523,7 +1525,7 @@ declare namespace ts { function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { - function parseCommandLine(commandLine: string[]): ParsedCommandLine; + function parseCommandLine(commandLine: string[], readFile?: (path: string) => string): ParsedCommandLine; /** * Read tsconfig.json file * @param fileName The path to the config file