chore(tslint): disallow variable names that look like keywords.

We've had issues such as the one I documented: https://github.com/Microsoft/TypeScript/issues/5187
This tslint check prevents this happening again.
This change also updates to the newest tslint which gets typings from npm.

Closes #4970
This commit is contained in:
Alex Eagle
2015-10-27 20:51:03 -07:00
committed by Alex Eagle
parent 25ddd8718d
commit c90e1920f5
7 changed files with 708 additions and 275 deletions
+7 -5
View File
@@ -1,16 +1,18 @@
/// <reference path="../../node_modules/typescript/lib/typescriptServices.d.ts" />
/// <reference path="../../node_modules/tslint/lib/tslint.d.ts" />
import {RuleFailure} from 'tslint/lib/lint';
import {AbstractRule} from 'tslint/lib/rules';
import {RuleWalker} from 'tslint/lib/language/walker';
import * as ts from 'tslint/node_modules/typescript';
export class Rule extends Lint.Rules.AbstractRule {
export class Rule extends AbstractRule {
public static FAILURE_STRING = "missing type declaration";
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
const typedefWalker = new TypedefWalker(sourceFile, this.getOptions());
return this.applyWithWalker(typedefWalker);
}
}
class TypedefWalker extends Lint.RuleWalker {
class TypedefWalker extends RuleWalker {
public visitMethodDeclaration(node: ts.MethodDeclaration) {
if (node.name.getText().charAt(0) !== '_') {
node.parameters.forEach((p: ts.ParameterDeclaration) => {
+7 -5
View File
@@ -1,16 +1,18 @@
/// <reference path="../../node_modules/typescript/lib/typescriptServices.d.ts" />
/// <reference path="../../node_modules/tslint/lib/tslint.d.ts" />
import {RuleFailure} from 'tslint/lib/lint';
import {AbstractRule} from 'tslint/lib/rules';
import {RuleWalker} from 'tslint/lib/language/walker';
import * as ts from 'tslint/node_modules/typescript';
export class Rule extends Lint.Rules.AbstractRule {
export class Rule extends AbstractRule {
public static FAILURE_STRING = "missing type declaration";
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
const typedefWalker = new TypedefWalker(sourceFile, this.getOptions());
return this.applyWithWalker(typedefWalker);
}
}
class TypedefWalker extends Lint.RuleWalker {
class TypedefWalker extends RuleWalker {
hasReturnStatement: boolean;
public visitFunctionDeclaration(node: ts.FunctionDeclaration) {