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.
This commit is contained in:
Alex Eagle 2016-06-08 17:36:29 -07:00
parent 729dc3b764
commit 9f506cd330
3 changed files with 1 additions and 103 deletions

View File

@ -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(), <ts.TypeNode>p.type, p.name);
}
});
}
super.visitMethodDeclaration(node);
}
private checkTypeAnnotation(location: number, typeAnnotation: ts.TypeNode, name?: ts.Node) {
if (typeAnnotation == null) {
let ns = '<name missing>';
if (name != null && name.kind === ts.SyntaxKind.Identifier) {
ns = (<ts.Identifier>name).text;
}
if (ns.charAt(0) === '_') return;
let failure = this.createFailure(location, 1, 'expected parameter ' + ns + ' to have a type');
this.addFailure(failure);
}
}
}

View File

@ -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 = '<name missing>';
if (name != null && name.kind === ts.SyntaxKind.Identifier) {
ns = (<ts.Identifier>name).text;
}
if (ns.charAt(0) === '_') return;
let failure = this.createFailure(start, 1, 'expected ' + ns + ' to have a return type');
this.addFailure(failure);
}
}
}

View File

@ -3,6 +3,6 @@
"requireInternalWithUnderscore": true,
"duplicateModuleImport": true,
"semicolon": true,
"variable-name": false
"variable-name": [true, "ban-keywords"]
}
}