chore(lint): re-enable linter and fix violations

fixes #7798
This commit is contained in:
Alex Eagle 2016-03-28 14:25:22 -07:00 committed by Misko Hevery
parent 830aecd1a7
commit e9332c66d2
3 changed files with 60 additions and 11 deletions

View File

@ -329,17 +329,7 @@ gulp.task('lint', ['build.tools'], function() {
var tslint = require('gulp-tslint'); var tslint = require('gulp-tslint');
// Built-in rules are at // Built-in rules are at
// https://github.com/palantir/tslint#supported-rules // https://github.com/palantir/tslint#supported-rules
var tslintConfig = { var tslintConfig = require('./tslint.json');
"rules": {
"requireInternalWithUnderscore": true,
"requireParameterType": true,
"requireReturnType": true,
"semicolon": true,
// TODO: find a way to just screen for reserved names
"variable-name": false
}
};
return gulp.src(['modules/angular2/src/**/*.ts', '!modules/angular2/src/testing/**']) return gulp.src(['modules/angular2/src/**/*.ts', '!modules/angular2/src/testing/**'])
.pipe(tslint({ .pipe(tslint({
tslint: require('tslint').default, tslint: require('tslint').default,

View File

@ -0,0 +1,49 @@
import {RuleFailure} from 'tslint/lib/lint';
import {AbstractRule} from 'tslint/lib/rules';
import {RuleWalker} from 'tslint/lib/language/walker';
import * as ts from 'typescript';
export class Rule extends AbstractRule {
public static FAILURE_STRING = "duplicate module import";
public apply(sourceFile: ts.SourceFile): RuleFailure[] {
const typedefWalker = new ModuleImportWalker(sourceFile, this.getOptions());
return this.applyWithWalker(typedefWalker);
}
}
class ModuleImportWalker extends RuleWalker {
importModulesSeen: string[] = [];
protected visitImportDeclaration(node: ts.ImportDeclaration): void {
this.visitModuleSpecifier(node.moduleSpecifier);
super.visitImportDeclaration(node);
}
protected visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration): void {
this.visitModuleSpecifier(node.moduleReference);
super.visitImportEqualsDeclaration(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);
}
}
private visitModuleSpecifier(moduleSpecifier: ts.Node) {
var text = moduleSpecifier.getText();
if (this.importModulesSeen.indexOf(text) >= 0) {
let failure =
this.createFailure(moduleSpecifier.getEnd(), 1, "Duplicate imports from module " + text);
this.addFailure(failure);
}
this.importModulesSeen.push(text);
}
}

10
tslint.json Normal file
View File

@ -0,0 +1,10 @@
{
"rules": {
"requireInternalWithUnderscore": true,
"requireParameterType": true,
"requireReturnType": true,
"duplicateModuleImport": false,
"semicolon": true,
"variable-name": false
}
}