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 #622 from palantir/release-2.5.0-dev.5
Browse files Browse the repository at this point in the history
Prepare release 2.5.0-dev.5
  • Loading branch information
adidahiya committed Aug 28, 2015
2 parents e40bb19 + 14374da commit 0e61cfb
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/tslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/language/walker/syntaxWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module Lint {
this.walkChildren(node);
}

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

Expand Down Expand Up @@ -124,7 +124,7 @@ module Lint {
this.walkChildren(node);
}

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

Expand Down Expand Up @@ -331,7 +331,7 @@ module Lint {
break;

case ts.SyntaxKind.ConstructorType:
this.visitConstructorType(node);
this.visitConstructorType(<ts.FunctionOrConstructorTypeNode> node);
break;

case ts.SyntaxKind.ContinueStatement:
Expand Down Expand Up @@ -387,7 +387,7 @@ module Lint {
break;

case ts.SyntaxKind.FunctionType:
this.visitFunctionType(node);
this.visitFunctionType(<ts.FunctionOrConstructorTypeNode> node);
break;

case ts.SyntaxKind.GetAccessor:
Expand Down
4 changes: 4 additions & 0 deletions src/rules/noShadowedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class NoShadowedVariableWalker extends Lint.BlockScopeAwareRuleWalker<ScopeInfo,
this.visitBlock(node.block);
}

public visitFunctionType(node: ts.FunctionOrConstructorTypeNode) {
// don't call super, we don't need to check names in function types
}

public visitMethodSignature(node: ts.SignatureDeclaration) {
// don't call super, we don't want to walk method signatures either
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
this.skipVariableDeclaration = false;
}

public visitFunctionType(node: ts.Node) {
public visitFunctionType(node: ts.FunctionOrConstructorTypeNode) {
this.skipParameterDeclaration = true;
super.visitFunctionType(node);
this.skipParameterDeclaration = false;
Expand Down
13 changes: 9 additions & 4 deletions src/rules/variableNameRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

const OPTION_LEADING_UNDERSCORE = "allow-leading-underscore";
const OPTION_TRAILING_UNDERSCORE = "allow-trailing-underscore";

export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "variable name must be in camelcase or uppercase";
Expand Down Expand Up @@ -71,15 +72,19 @@ class VariableNameWalker extends Lint.RuleWalker {

private isCamelCase(name: string) {
const firstCharacter = name.charAt(0);
const rest = name.substring(1);
const lastCharacter = name.charAt(name.length - 1);
const middle = name.substr(1, name.length - 2);

if (name.length <= 0) {
return true;
} else if (!this.hasOption(OPTION_LEADING_UNDERSCORE) && firstCharacter === "_") {
}
if (!this.hasOption(OPTION_LEADING_UNDERSCORE) && firstCharacter === "_") {
return false;
}

return firstCharacter === firstCharacter.toLowerCase() && rest.indexOf("_") === -1;
if (!this.hasOption(OPTION_TRAILING_UNDERSCORE) && lastCharacter === "_") {
return false;
}
return firstCharacter === firstCharacter.toLowerCase() && middle.indexOf("_") === -1;
}

private isUpperCase(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/whitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class WhitespaceWalker extends Lint.SkippableTokenAwareRuleWalker {
super.visitConditionalExpression(node);
}

public visitConstructorType(node: ts.Node) {
public visitConstructorType(node: ts.FunctionOrConstructorTypeNode) {
this.checkEqualsGreaterThanTokenInNode(node);
super.visitConstructorType(node);
}
Expand All @@ -140,7 +140,7 @@ class WhitespaceWalker extends Lint.SkippableTokenAwareRuleWalker {
super.visitExportAssignment(node);
}

public visitFunctionType(node: ts.Node) {
public visitFunctionType(node: ts.FunctionOrConstructorTypeNode) {
this.checkEqualsGreaterThanTokenInNode(node);
super.visitFunctionType(node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Lint {
}

export class Linter {
public static VERSION = "2.5.0-dev.4";
public static VERSION = "2.5.0-dev.5";

private fileName: string;
private source: string;
Expand Down
12 changes: 12 additions & 0 deletions test/files/rules/no-shadowed-variable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ function testDestructuring(x: number) {
var [...z] = [1, 2, 3, 4]; // failure
}
}

function falsePositive1(bar: (okay1: any) => void) {
let okay1 = 1;
}

function falsePositive2(okay2: any, done: (okay2: any) => void) { }

interface FalsePositive3 {
diffuse: (pos: number) => number;
specular: (pos: number) => number;
pos: number;
}
3 changes: 3 additions & 0 deletions test/files/rules/varname.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
35 changes: 35 additions & 0 deletions test/rules/variableNameRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ describe("<variable-name>", () => {
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);
Expand All @@ -56,4 +58,37 @@ describe("<variable-name>", () => {
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));
}));
});
});
4 changes: 3 additions & 1 deletion typings/typescriptServices.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ declare namespace ts {
diagnostics?: boolean;
emitBOM?: boolean;
help?: boolean;
init?: boolean;
inlineSourceMap?: boolean;
inlineSources?: boolean;
jsx?: JsxEmit;
Expand All @@ -1328,6 +1329,7 @@ declare namespace ts {
rootDir?: string;
sourceMap?: boolean;
sourceRoot?: string;
suppressExcessPropertyErrors?: boolean;
suppressImplicitAnyIndexErrors?: boolean;
target?: ScriptTarget;
version?: boolean;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0e61cfb

Please sign in to comment.