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

Commit

Permalink
rename no-multiple-var to no-multiple-variable-declaration (#1194)
Browse files Browse the repository at this point in the history
* remove stray line in README, simplify code a little

* rename rule to no-multiple-variable-declaration
  • Loading branch information
jkillian committed May 2, 2016
1 parent e41bddd commit a1071e6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ A sample configuration file with all options is available [here](https://github.
* `no-internal-module` disallows internal `module` (use `namespace` instead).
* `no-invalid-this` disallows using the `this` keyword outside of classes.
* `no-this-in-function-in-method` disallows using the `this` keyword in functions within class methods.
* `no-multiple-var` disallows multiple variable definitions in the same statement.
* `no-use-before-declare` disallows usage of variables before their declaration.
* `no-multiple-variable-declaration` disallows multiple variable definitions in the same statement.
* `no-namespace` disallows both internal `module`s and `namespace`, but allows ES6-style external modules.
* `allow-declarations` allows `declare namespace ... {}` to describe external APIs.
* `no-null-keyword` disallows use of the `null` keyword literal.
Expand Down
2 changes: 1 addition & 1 deletion docs/sample.tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
true,
"no-this-in-function-in-method"
],
"no-multiple-var": true,
"no-multiple-variable-declaration": true,
"no-null-keyword": true,
"no-reference": true,
"no-require-imports": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "Forbidden multiple variable definitions in the same statement";

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const noMultipleVarWalker = new NoMultipleVarWalker(sourceFile, this.getOptions());
const noMultipleVarWalker = new NoMultipleVariableDeclarationWalker(sourceFile, this.getOptions());
return this.applyWithWalker(noMultipleVarWalker);
}
}

class NoMultipleVarWalker extends Lint.RuleWalker {
class NoMultipleVariableDeclarationWalker extends Lint.RuleWalker {
public visitVariableStatement(node: ts.VariableStatement) {
const declarationList = node.declarationList;
const { declarationList } = node;

if (declarationList.declarations.length > 1) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
Expand All @@ -39,12 +39,13 @@ class NoMultipleVarWalker extends Lint.RuleWalker {
}

public visitForStatement(node: ts.ForStatement) {
let initializer = node.initializer;
if (initializer && initializer.kind === ts.SyntaxKind.VariableDeclarationList &&
(<ts.VariableDeclarationList>initializer).declarations.length > 1) {
const declarationList = <ts.VariableDeclarationList>initializer;
this.addFailure(this.createFailure(declarationList.getStart(), declarationList.getWidth(), Rule.FAILURE_STRING));
const initializer = node.initializer as ts.VariableDeclarationList;

if (initializer != null && initializer.kind === ts.SyntaxKind.VariableDeclarationList &&
initializer.declarations.length > 1) {
this.addFailure(this.createFailure(initializer.getStart(), initializer.getWidth(), Rule.FAILURE_STRING));
}

super.visitForStatement(node);
}
}
2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"rules/noInferrableTypesRule.ts",
"rules/noInternalModuleRule.ts",
"rules/noInvalidThisRule.ts",
"rules/noMultipleVarRule.ts",
"rules/noMultipleVariableDeclarationRule.ts",
"rules/noNamespaceRule.ts",
"rules/noNullKeywordRule.ts",
"rules/noReferenceRule.ts",
Expand Down
5 changes: 0 additions & 5 deletions test/rules/no-multiple-var/tslint.json

This file was deleted.

5 changes: 5 additions & 0 deletions test/rules/no-multiple-variable-declaration/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-multiple-variable-declaration": true
}
}
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"../src/rules/noInferrableTypesRule.ts",
"../src/rules/noInternalModuleRule.ts",
"../src/rules/noInvalidThisRule.ts",
"../src/rules/noMultipleVarRule.ts",
"../src/rules/noMultipleVariableDeclarationRule.ts",
"../src/rules/noNamespaceRule.ts",
"../src/rules/noNullKeywordRule.ts",
"../src/rules/noReferenceRule.ts",
Expand Down

0 comments on commit a1071e6

Please sign in to comment.