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 #683 from palantir/update-next
Browse files Browse the repository at this point in the history
Prepare release 2.6.0-dev.1
  • Loading branch information
adidahiya committed Sep 24, 2015
2 parents 0a4cb11 + 7fd165f commit 07aae95
Show file tree
Hide file tree
Showing 27 changed files with 248 additions and 65 deletions.
File renamed without changes.
File renamed without changes.
27 changes: 22 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
Change Log
===

v2.6.0-dev.1
---
* Upgrade TypeScript compiler to `v1.7.0-dev.20150924`

v2.5.0
---
* Use TypeScript compiler `v1.6.2`
* [bugfixes] #637, #642, #650, #652
* [bugfixes] fix various false positives in `no-unused-variable` rule (#570, #613, #663)
* Update project setup for latest VSCode (#662)

v2.5.0-beta
---
* Use TypeScript compiler `v1.6.0-beta`
* [bugfix] Fix `no-internal-module` false positives on nested namespaces (#600)
* [docs] Add documentation for `sort-object-literal-keys` rule

v2.5.0-dev.5
---
* Upgrade TypeScript compiler to v1.7.0-dev.20150828
* 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
* Upgrade TypeScript compiler to `v1.6.0-dev.20150825`

v2.5.0-dev.3
---
* Upgrade TypeScript compiler to v1.6.0-dev.20150821
* Upgrade TypeScript compiler to `v1.6.0-dev.20150821`

v2.5.0-dev.2
---
* Upgrade TypeScript compiler to v1.6.0-dev.20150811
* Upgrade TypeScript compiler to `v1.6.0-dev.20150811`
* [bug] fix `whitespace` false positive in JSX elements (#559)

v2.5.0-dev.1
---
* Upgrade TypeScript compiler to v1.6.0-dev.20150805
* Upgrade TypeScript compiler to `v1.6.0-dev.20150805`
* [enhancement] Support `.tsx` syntax (#490)

v2.4.5
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ A sample configuration file with all options is available [here](https://github.
* `"check-else"` checks that `else` is on the same line as the closing brace for `if`
* `"check-open-brace"` checks that an open brace falls on the same line as its preceding expression.
* `"check-whitespace"` checks preceding whitespace for the specified tokens.
* `quotemark` enforces consistent single or double quoted string literals. Rule options (one is required):
* `quotemark` enforces consistent single or double quoted string literals. Rule options (at least one of `"double"` or `"single"` is required):
* `"single"` enforces single quotes
* `"double"` enforces double quotes
* `"avoid-escape"` allows you to use the "other" quotemark in cases where escaping would normally be required. For example, `[true, "double", "avoid-escape"]` would not report a failure on the string literal `'Hello "World"'`.
* `radix` enforces the radix parameter of `parseInt`
* `semicolon` enforces semicolons at the end of every statement.
* `sort-object-literal-keys` checks that keys in object literals are declared in alphabetical order
Expand Down
2 changes: 1 addition & 1 deletion docs/sample.tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"check-else",
"check-whitespace"
],
"quotemark": [true, "double"],
"quotemark": [true, "double", "avoid-escape"],
"radix": true,
"semicolon": true,
"sort-object-literal-keys": true,
Expand Down
1 change: 1 addition & 0 deletions lib/tslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare module Lint {
protected visitBlock(node: ts.Block): void;
protected visitBreakStatement(node: ts.BreakOrContinueStatement): void;
protected visitCallExpression(node: ts.CallExpression): void;
protected visitCallSignature(node: ts.SignatureDeclaration): void;
protected visitCaseClause(node: ts.CaseClause): void;
protected visitClassDeclaration(node: ts.ClassDeclaration): void;
protected visitCatchClause(node: ts.CatchClause): 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.5",
"version": "2.6.0-dev.1",
"description": "a static analysis linter for TypeScript",
"bin": {
"tslint": "./bin/tslint"
Expand Down
5 changes: 2 additions & 3 deletions src/language/languageServiceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Lint {
getCurrentDirectory: () => "",
getDefaultLibFileName: () => "lib.d.ts",
getScriptFileNames: () => [fileName],
getScriptSnapshot: () => ts.ScriptSnapshot.fromString(source),
getScriptSnapshot: (name) => ts.ScriptSnapshot.fromString(name === fileName ? source : ""),
getScriptVersion: () => "1",
log: (message) => { /* */ }
};
Expand All @@ -30,8 +30,7 @@ module Lint {
}

export function createLanguageService(fileName: string, source: string) {
const documentRegistry = ts.createDocumentRegistry();
const languageServiceHost = Lint.createLanguageServiceHost(fileName, source);
return ts.createLanguageService(languageServiceHost, documentRegistry);
return ts.createLanguageService(languageServiceHost);
}
}
8 changes: 8 additions & 0 deletions src/language/walker/syntaxWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ module Lint {
this.walkChildren(node);
}

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

protected visitCaseClause(node: ts.CaseClause) {
this.walkChildren(node);
}
Expand Down Expand Up @@ -310,6 +314,10 @@ module Lint {
this.visitCallExpression(<ts.CallExpression> node);
break;

case ts.SyntaxKind.CallSignature:
this.visitCallSignature(<ts.SignatureDeclaration> node);
break;

case ts.SyntaxKind.CaseClause:
this.visitCaseClause(<ts.CaseClause> node);
break;
Expand Down
12 changes: 11 additions & 1 deletion src/rules/alignRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type SourcePosition = {
}

class AlignWalker extends Lint.RuleWalker {
public visitConstructorDeclaration(node: ts.ConstructorDeclaration) {
this.checkAlignment(Rule.PARAMETERS_OPTION, node.parameters);
super.visitConstructorDeclaration(node);
}

public visitFunctionDeclaration(node: ts.FunctionDeclaration) {
this.checkAlignment(Rule.PARAMETERS_OPTION, node.parameters);
super.visitFunctionDeclaration(node);
Expand All @@ -43,6 +48,11 @@ class AlignWalker extends Lint.RuleWalker {
super.visitFunctionExpression(node);
}

public visitMethodDeclaration(node: ts.MethodDeclaration) {
this.checkAlignment(Rule.PARAMETERS_OPTION, node.parameters);
super.visitMethodDeclaration(node);
}

public visitCallExpression(node: ts.CallExpression) {
this.checkAlignment(Rule.ARGUMENTS_OPTION, node.arguments);
super.visitCallExpression(node);
Expand All @@ -59,7 +69,7 @@ class AlignWalker extends Lint.RuleWalker {
}

private checkAlignment(kind: string, nodes: ts.Node[]) {
if (nodes.length === 0 || !this.hasOption(kind)) {
if (nodes == null || nodes.length === 0 || !this.hasOption(kind)) {
return;
}

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 visitCallSignature(node: ts.SignatureDeclaration) {
// don't call super, we don't need to check parameter names in call signatures
}

public visitFunctionType(node: ts.FunctionOrConstructorTypeNode) {
// don't call super, we don't need to check names in function types
}
Expand Down
5 changes: 5 additions & 0 deletions src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker {
}
}

// abstract methods can't have a body so their parameters are always unused
if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.AbstractKeyword)) {
this.skipParameterDeclaration = true;
}
super.visitMethodDeclaration(node);
this.skipParameterDeclaration = false;
}

private validateReferencesForVariable(name: string, position: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUseBeforeDeclareRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NoUseBeforeDeclareWalker extends Lint.ScopeAwareRuleWalker<VisitedVariable
// use-before-declare errors for block-scoped vars are caught by tsc
if (isSingleVariable && !isBlockScoped) {
const variableName = (<ts.Identifier> node.name).text;
this.validateUsageForVariable(variableName, node.getStart());
this.validateUsageForVariable(variableName, node.name.getStart());
}

super.visitBindingElement(node);
Expand Down
21 changes: 15 additions & 6 deletions src/rules/oneLineRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,12 @@ class OneLineWalker extends Lint.RuleWalker {
}

public visitInterfaceDeclaration(node: ts.InterfaceDeclaration) {
const nameNode = node.name;
const openBraceToken = getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken);
this.handleOpeningBrace(nameNode, openBraceToken);
this.handleClassLikeDeclaration(node);
super.visitInterfaceDeclaration(node);
}

public visitClassDeclaration(node: ts.ClassDeclaration) {
const nameNode = node.name;
const openBraceToken = getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken);
this.handleOpeningBrace(nameNode, openBraceToken);
this.handleClassLikeDeclaration(node);
super.visitClassDeclaration(node);
}

Expand Down Expand Up @@ -216,6 +212,19 @@ class OneLineWalker extends Lint.RuleWalker {
}
}

private handleClassLikeDeclaration(node: ts.ClassDeclaration | ts.InterfaceDeclaration) {
let lastNodeOfDeclaration: ts.Node = node.name;
const openBraceToken = getFirstChildOfKind(node, ts.SyntaxKind.OpenBraceToken);

if (node.heritageClauses != null) {
lastNodeOfDeclaration = node.heritageClauses[node.heritageClauses.length - 1];
} else if (node.typeParameters != null) {
lastNodeOfDeclaration = node.typeParameters[node.typeParameters.length - 1];
}

this.handleOpeningBrace(lastNodeOfDeclaration, openBraceToken);
}

private handleIterationStatement(node: ts.IterationStatement) {
// last child is the statement, second to last child is the close paren
const closeParenToken = node.getChildAt(node.getChildCount() - 2);
Expand Down
33 changes: 18 additions & 15 deletions src/rules/quotemarkRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ export class Rule extends Lint.Rules.AbstractRule {
}

class QuoteWalker extends Lint.RuleWalker {
private quoteMark: QuoteMark;
private quoteMark = QuoteMark.DOUBLE_QUOTES;
private avoidEscape: boolean;

constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) {
super(sourceFile, options);

const quoteMarkString = this.getOptions()[0];
const ruleArguments = this.getOptions();
const quoteMarkString = ruleArguments[0];
if (quoteMarkString === "single") {
this.quoteMark = QuoteMark.SINGLE_QUOTES;
} else {
this.quoteMark = QuoteMark.DOUBLE_QUOTES;
}

this.avoidEscape = ruleArguments.indexOf("avoid-escape") > 0;
}

public visitNode(node : ts.Node) {
Expand All @@ -57,8 +61,6 @@ class QuoteWalker extends Lint.RuleWalker {
}

private handleNode(node: ts.Node) {
let failure: Lint.RuleFailure;

if (node.kind === ts.SyntaxKind.StringLiteral) {
const text = node.getText();
const width = node.getWidth();
Expand All @@ -67,19 +69,20 @@ class QuoteWalker extends Lint.RuleWalker {
const firstCharacter = text.charAt(0);
const lastCharacter = text.charAt(text.length - 1);

if (this.quoteMark === QuoteMark.SINGLE_QUOTES) {
if (firstCharacter !== "'" || lastCharacter !== "'") {
failure = this.createFailure(position, width, Rule.SINGLE_QUOTE_FAILURE);
}
} else if (this.quoteMark === QuoteMark.DOUBLE_QUOTES) {
if (firstCharacter !== "\"" || lastCharacter !== "\"") {
failure = this.createFailure(position, width, Rule.DOUBLE_QUOTE_FAILURE);
const expectedQuoteMark = (this.quoteMark === QuoteMark.SINGLE_QUOTES) ? "'" : "\"";

if (firstCharacter !== expectedQuoteMark || lastCharacter !== expectedQuoteMark) {
// allow the "other" quote mark to be used, but only to avoid having to escape
const includesOtherQuoteMark = text.slice(1, -1).indexOf(expectedQuoteMark) !== -1;

if (!(this.avoidEscape && includesOtherQuoteMark)) {
const failureMessage = (this.quoteMark === QuoteMark.SINGLE_QUOTES)
? Rule.SINGLE_QUOTE_FAILURE
: Rule.DOUBLE_QUOTE_FAILURE;

this.addFailure(this.createFailure(position, width, failureMessage));
}
}
}

if (failure != null) {
this.addFailure(failure);
}
}
}
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.5";
public static VERSION = "2.6.0-dev.1";

private fileName: string;
private source: string;
Expand Down
Loading

0 comments on commit 07aae95

Please sign in to comment.