From 9f506cd3308cb42989caa527d2801a074f475aca Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 8 Jun 2016 17:36:29 -0700 Subject: [PATCH] chore(lint): remove unused lint checks Now that we have --noImplicitAny we don't need these checks for explicit types in specific locations. Also re-enable the check to disallow keywords as variable names. --- tools/tslint/requireParameterTypeRule.ts | 40 --------------- tools/tslint/requireReturnTypeRule.ts | 62 ------------------------ tslint.json | 2 +- 3 files changed, 1 insertion(+), 103 deletions(-) delete mode 100644 tools/tslint/requireParameterTypeRule.ts delete mode 100644 tools/tslint/requireReturnTypeRule.ts diff --git a/tools/tslint/requireParameterTypeRule.ts b/tools/tslint/requireParameterTypeRule.ts deleted file mode 100644 index e7c5118925..0000000000 --- a/tools/tslint/requireParameterTypeRule.ts +++ /dev/null @@ -1,40 +0,0 @@ -import {RuleWalker} from 'tslint/lib/language/walker'; -import {RuleFailure} from 'tslint/lib/lint'; -import {AbstractRule} from 'tslint/lib/rules'; -import * as ts from 'typescript'; - -export class Rule extends AbstractRule { - public static FAILURE_STRING = 'missing type declaration'; - - public apply(sourceFile: ts.SourceFile): RuleFailure[] { - const typedefWalker = new TypedefWalker(sourceFile, this.getOptions()); - return this.applyWithWalker(typedefWalker); - } -} - -class TypedefWalker extends RuleWalker { - public visitMethodDeclaration(node: ts.MethodDeclaration) { - if (node.name.getText().charAt(0) !== '_') { - node.parameters.forEach((p: ts.ParameterDeclaration) => { - // a parameter's "type" could be a specific string value, for example `fn(option: - // "someOption", anotherOption: number)` - if (p.type == null || p.type.kind !== ts.SyntaxKind.StringLiteral) { - this.checkTypeAnnotation(p.getEnd(), p.type, p.name); - } - }); - } - super.visitMethodDeclaration(node); - } - - private checkTypeAnnotation(location: number, typeAnnotation: ts.TypeNode, name?: ts.Node) { - if (typeAnnotation == null) { - let ns = ''; - if (name != null && name.kind === ts.SyntaxKind.Identifier) { - ns = (name).text; - } - if (ns.charAt(0) === '_') return; - let failure = this.createFailure(location, 1, 'expected parameter ' + ns + ' to have a type'); - this.addFailure(failure); - } - } -} diff --git a/tools/tslint/requireReturnTypeRule.ts b/tools/tslint/requireReturnTypeRule.ts deleted file mode 100644 index 84784e01bc..0000000000 --- a/tools/tslint/requireReturnTypeRule.ts +++ /dev/null @@ -1,62 +0,0 @@ -import {RuleWalker} from 'tslint/lib/language/walker'; -import {RuleFailure} from 'tslint/lib/lint'; -import {AbstractRule} from 'tslint/lib/rules'; -import * as ts from 'typescript'; - -export class Rule extends AbstractRule { - public static FAILURE_STRING = 'missing type declaration'; - - public apply(sourceFile: ts.SourceFile): RuleFailure[] { - const typedefWalker = new TypedefWalker(sourceFile, this.getOptions()); - return this.applyWithWalker(typedefWalker); - } -} - -class TypedefWalker extends RuleWalker { - hasReturnStatement: boolean; - - public visitFunctionDeclaration(node: ts.FunctionDeclaration) { - this.hasReturnStatement = false; - super.visitFunctionDeclaration(node); - if (this.hasReturnStatement) { - this.handleCallSignature(node); - } - } - public visitFunctionExpression(node: ts.FunctionExpression) { - let orig = this.hasReturnStatement; - super.visitFunctionExpression(node); - this.hasReturnStatement = orig; - } - public visitMethodDeclaration(node: ts.MethodDeclaration) { - this.hasReturnStatement = false; - super.visitMethodDeclaration(node); - if (this.hasReturnStatement) { - this.handleCallSignature(node); - } - } - public visitReturnStatement(node: ts.ReturnStatement) { - if (node.expression) { - this.hasReturnStatement = true; - } - super.visitReturnStatement(node); - } - - private handleCallSignature(node: ts.SignatureDeclaration) { - // set accessors can't have a return type. - if (node.kind !== ts.SyntaxKind.SetAccessor) { - this.checkTypeAnnotation(node.type, node.name, node.getStart()); - } - } - - private checkTypeAnnotation(typeAnnotation: ts.TypeNode, name: ts.Node, start: number) { - if (typeAnnotation == null) { - let ns = ''; - if (name != null && name.kind === ts.SyntaxKind.Identifier) { - ns = (name).text; - } - if (ns.charAt(0) === '_') return; - let failure = this.createFailure(start, 1, 'expected ' + ns + ' to have a return type'); - this.addFailure(failure); - } - } -} diff --git a/tslint.json b/tslint.json index 40fc1b87aa..79d65cd341 100644 --- a/tslint.json +++ b/tslint.json @@ -3,6 +3,6 @@ "requireInternalWithUnderscore": true, "duplicateModuleImport": true, "semicolon": true, - "variable-name": false + "variable-name": [true, "ban-keywords"] } }