Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:palantir/tslint into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
#	src/linter.ts
  • Loading branch information
Noah Chen committed Dec 23, 2016
2 parents ad405d5 + 9f72565 commit 1d521bc
Show file tree
Hide file tree
Showing 67 changed files with 1,012 additions and 226 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Change Log
===

v4.2.0
---

* [new-rule] `no-string-throw` (#1878)
* [new-rule] `no-empty-interface` (#1889)
* [new-rule] `interface-over-type-literal` (#1890)
* [new-rule] `callable-types` (#1891)
* [new-rule] `no-void-expression` (#1903)
* [new-rule-option] `ban-single-arg-parens` added to `arrow-parens` (#1893)
* [bugfix] `prefer-const` handles destructuring arrays (#1894), destructuring objects (#1906), and forward references (#1908)
* [bugfix] Don't error for misplaced braces for 'else' in `one-line` rule (#1866)
* [bugfix] `no-shadowed-variable` now identifies shadowed `for` iterator (#1816)
* [bugfix] `object-literal-key-quotes` now includes function names (#1874)
* [bugfix] error when EOF comes after `disable-next-line` comment (#1902)

v4.1.1
---

Expand Down
56 changes: 47 additions & 9 deletions docs/_data/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
]
},
"optionExamples": [
"[true, array]",
"[true, generic]",
"[true, array-simple]"
"[true, \"array\"]",
"[true, \"generic\"]",
"[true, \"array-simple\"]"
],
"type": "style",
"typescriptOnly": true
Expand All @@ -59,10 +59,16 @@
"ruleName": "arrow-parens",
"description": "Requires parentheses around the parameters of arrow function definitions.",
"rationale": "Maintains stylistic consistency with other arrow function definitions.",
"optionsDescription": "Not configurable.",
"options": null,
"optionsDescription": "\nif `ban-single-arg-parens` is specified, then arrow functions with one parameter \nmust not have parentheses if removing them is allowed by TypeScript.",
"options": {
"type": "string",
"enum": [
"ban-single-arg-parens"
]
},
"optionExamples": [
"true"
"true",
"[true, ban-single-arg-parens]"
],
"type": "style",
"typescriptOnly": false
Expand All @@ -88,6 +94,15 @@
"type": "functionality",
"typescriptOnly": false
},
{
"ruleName": "callable-types",
"description": "An interface or literal type with just a call signature can be written as a function type.",
"rationale": "style",
"optionsDescription": "Not configurable.",
"options": null,
"type": "style",
"typescriptOnly": true
},
{
"ruleName": "class-name",
"description": "Enforces PascalCased class and interface names.",
Expand Down Expand Up @@ -269,6 +284,15 @@
"type": "style",
"typescriptOnly": true
},
{
"ruleName": "interface-over-type-literal",
"description": "Prefer an interface declaration over a type literal (`type T = { ... }`)",
"rationale": "style",
"optionsDescription": "Not configurable.",
"options": null,
"type": "style",
"typescriptOnly": true
},
{
"ruleName": "jsdoc-format",
"description": "Enforces basic format rules for JSDoc comments.",
Expand Down Expand Up @@ -606,9 +630,6 @@
"rationale": "An empty interface is equivalent to its supertype (or `{}`).",
"optionsDescription": "Not configurable.",
"options": null,
"optionExamples": [
"true"
],
"type": "typescript",
"typescriptOnly": true
},
Expand Down Expand Up @@ -846,6 +867,14 @@
"type": "functionality",
"typescriptOnly": false
},
{
"ruleName": "no-string-throw",
"description": "Flags throwing plain strings or concatenations of strings because only Errors produce proper stack traces.",
"options": null,
"optionsDescription": "",
"type": "functionality",
"typescriptOnly": false
},
{
"ruleName": "no-switch-case-fall-through",
"description": "Disallows falling through case statements.",
Expand Down Expand Up @@ -983,6 +1012,15 @@
"type": "typescript",
"typescriptOnly": true
},
{
"ruleName": "no-void-expression",
"description": "Requires expressions of type `void` to appear in statement position.",
"optionsDescription": "Not configurable.",
"options": null,
"requiresTypeInfo": true,
"type": "functionality",
"typescriptOnly": false
},
{
"ruleName": "object-literal-key-quotes",
"description": "Enforces consistent object literal property quote style.",
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/array-type/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"array-simple"
]
}
---
---
19 changes: 16 additions & 3 deletions docs/rules/arrow-parens/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
ruleName: arrow-parens
description: Requires parentheses around the parameters of arrow function definitions.
rationale: Maintains stylistic consistency with other arrow function definitions.
optionsDescription: Not configurable.
options: null
optionsDescription: |-

if `ban-single-arg-parens` is specified, then arrow functions with one parameter
must not have parentheses if removing them is allowed by TypeScript.
options:
type: string
enum:
- ban-single-arg-parens
optionExamples:
- 'true'
- '[true, ban-single-arg-parens]'
type: style
typescriptOnly: false
layout: rule
title: 'Rule: arrow-parens'
optionsJSON: 'null'
optionsJSON: |-
{
"type": "string",
"enum": [
"ban-single-arg-parens"
]
}
---
12 changes: 12 additions & 0 deletions docs/rules/callable-types/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
ruleName: callable-types
description: An interface or literal type with just a call signature can be written as a function type.
rationale: style
optionsDescription: Not configurable.
options: null
type: style
typescriptOnly: true
layout: rule
title: 'Rule: callable-types'
optionsJSON: 'null'
---
12 changes: 12 additions & 0 deletions docs/rules/interface-over-type-literal/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
ruleName: interface-over-type-literal
description: 'Prefer an interface declaration over a type literal (`type T = { ... }`)'
rationale: style
optionsDescription: Not configurable.
options: null
type: style
typescriptOnly: true
layout: rule
title: 'Rule: interface-over-type-literal'
optionsJSON: 'null'
---
2 changes: 0 additions & 2 deletions docs/rules/no-empty-interface/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
rationale: 'An empty interface is equivalent to its supertype (or `{}`).'
optionsDescription: Not configurable.
options: null
optionExamples:
- 'true'
type: typescript
typescriptOnly: true
layout: rule
Expand Down
11 changes: 11 additions & 0 deletions docs/rules/no-string-throw/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
ruleName: no-string-throw
description: Flags throwing plain strings or concatenations of strings because only Errors produce proper stack traces.
options: null
optionsDescription: ''
type: functionality
typescriptOnly: false
layout: rule
title: 'Rule: no-string-throw'
optionsJSON: 'null'
---
12 changes: 12 additions & 0 deletions docs/rules/no-void-expression/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
ruleName: no-void-expression
description: Requires expressions of type `void` to appear in statement position.
optionsDescription: Not configurable.
options: null
requiresTypeInfo: true
type: functionality
typescriptOnly: false
layout: rule
title: 'Rule: no-void-expression'
optionsJSON: 'null'
---
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": "4.1.0-dev.0",
"version": "4.2.0-dev.0",
"description": "An extensible static analysis linter for the TypeScript language",
"bin": {
"tslint": "./bin/tslint"
Expand Down
10 changes: 7 additions & 3 deletions src/enableDisableRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker {
}

private getStartOfLinePosition(node: ts.SourceFile, position: number, lineOffset = 0) {
return node.getPositionOfLineAndCharacter(
node.getLineAndCharacterOfPosition(position).line + lineOffset, 0,
);
const line = ts.getLineAndCharacterOfPosition(node, position).line + lineOffset;
const lineStarts = node.getLineStarts();
if (line >= lineStarts.length) {
// next line ends with eof or there is no next line
return node.getFullWidth();
}
return lineStarts[line];
}

private switchRuleState(ruleName: string, isEnabled: boolean, start: number, end?: number): void {
Expand Down
18 changes: 18 additions & 0 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ export function isNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean
/* tslint:enable:no-bitwise */
}

/**
* Bitwise check for combined node flags.
*/
export function isCombinedNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean {
/* tslint:disable:no-bitwise */
return (ts.getCombinedNodeFlags(node) & flagToCheck) !== 0;
/* tslint:enable:no-bitwise */
}

/**
* Bitwise check for combined modifier flags.
*/
export function isCombinedModifierFlagSet(node: ts.Node, flagToCheck: ts.ModifierFlags): boolean {
/* tslint:disable:no-bitwise */
return (ts.getCombinedModifierFlags(node) & flagToCheck) !== 0;
/* tslint:enable:no-bitwise */
}

/**
* Bitwise check for type flags.
*/
Expand Down
21 changes: 10 additions & 11 deletions src/language/walker/blockScopeAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export abstract class BlockScopeAwareRuleWalker<T, U> extends ScopeAwareRuleWalk
super(sourceFile, options);

// initialize with global scope if file is not a module
this.blockScopeStack = this.fileIsModule ? [] : [this.createBlockScope()];
this.blockScopeStack = this.fileIsModule ? [] : [this.createBlockScope(sourceFile)];
}

public abstract createBlockScope(): U;
public abstract createBlockScope(node: ts.Node): U;

// get all block scopes available at this depth
public getAllBlockScopes(): U[] {
Expand Down Expand Up @@ -62,7 +62,7 @@ export abstract class BlockScopeAwareRuleWalker<T, U> extends ScopeAwareRuleWalk
const isNewBlockScope = this.isBlockScopeBoundary(node);

if (isNewBlockScope) {
this.blockScopeStack.push(this.createBlockScope());
this.blockScopeStack.push(this.createBlockScope(node));
this.onBlockScopeStart();
}

Expand All @@ -76,20 +76,19 @@ export abstract class BlockScopeAwareRuleWalker<T, U> extends ScopeAwareRuleWalk

private isBlockScopeBoundary(node: ts.Node): boolean {
return super.isScopeBoundary(node)
|| node.kind === ts.SyntaxKind.Block
|| node.kind === ts.SyntaxKind.DoStatement
|| node.kind === ts.SyntaxKind.WhileStatement
|| node.kind === ts.SyntaxKind.ForStatement
|| node.kind === ts.SyntaxKind.ForInStatement
|| node.kind === ts.SyntaxKind.ForOfStatement
|| node.kind === ts.SyntaxKind.WithStatement
|| node.kind === ts.SyntaxKind.SwitchStatement
|| (node.parent != null
&& (node.parent.kind === ts.SyntaxKind.TryStatement
|| node.parent.kind === ts.SyntaxKind.IfStatement)
)
|| (node.kind === ts.SyntaxKind.Block && node.parent != null
&& (node.parent.kind === ts.SyntaxKind.Block
|| node.parent.kind === ts.SyntaxKind.SourceFile)
);
|| isParentKind(node, ts.SyntaxKind.TryStatement)
|| isParentKind(node, ts.SyntaxKind.IfStatement);
}
}

function isParentKind(node: ts.Node, kind: ts.SyntaxKind) {
return node.parent != null && node.parent.kind === kind;
}
4 changes: 4 additions & 0 deletions src/language/walker/ruleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class RuleWalker extends SyntaxWalker {
return this.sourceFile;
}

public getLineAndCharacterOfPosition(position: number): ts.LineAndCharacter {
return this.sourceFile.getLineAndCharacterOfPosition(position);
}

public getFailures(): RuleFailure[] {
return this.failures;
}
Expand Down
2 changes: 1 addition & 1 deletion src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { arrayify, dedent } from "./utils";
* Linter that can lint multiple files in consecutive runs.
*/
class Linter {
public static VERSION = "4.1.0-dev.0";
public static VERSION = "4.2.0-dev.0";

public static findConfiguration = findConfiguration;
public static findConfigurationPath = findConfigurationPath;
Expand Down
14 changes: 2 additions & 12 deletions src/rules/alignRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ export class Rule extends Lint.Rules.AbstractRule {
}
}

type SourcePosition = {
line: number;
character: number;
};

class AlignWalker extends Lint.RuleWalker {
public visitConstructorDeclaration(node: ts.ConstructorDeclaration) {
this.checkAlignment(Rule.PARAMETERS_OPTION, node.parameters);
Expand Down Expand Up @@ -104,22 +99,17 @@ class AlignWalker extends Lint.RuleWalker {
return;
}

let prevPos = getPosition(nodes[0]);
let prevPos = this.getLineAndCharacterOfPosition(nodes[0].getStart());
const alignToColumn = prevPos.character;

// skip first node in list
for (let node of nodes.slice(1)) {
const curPos = getPosition(node);
const curPos = this.getLineAndCharacterOfPosition(node.getStart());
if (curPos.line !== prevPos.line && curPos.character !== alignToColumn) {
this.addFailureAtNode(node, kind + Rule.FAILURE_STRING_SUFFIX);
break;
}
prevPos = curPos;
}
}

}

function getPosition(node: ts.Node): SourcePosition {
return node.getSourceFile().getLineAndCharacterOfPosition(node.getStart());
}
Loading

0 comments on commit 1d521bc

Please sign in to comment.