chore(lint): replace duplicate-module-import rule with no-duplicate-imports

This commit is contained in:
Joao Dias 2016-10-27 20:48:47 +02:00 committed by vsavkin
parent 262bd23b84
commit 0a94845435
3 changed files with 12 additions and 58 deletions

View File

@ -156,7 +156,6 @@ gulp.task('lint', ['check-tests', 'format:enforce', 'tools:build'], () => {
.pipe(tslint({ .pipe(tslint({
tslint: require('tslint').default, tslint: require('tslint').default,
configuration: tslintConfig, configuration: tslintConfig,
rulesDirectory: 'dist/tools/tslint',
formatter: 'prose', formatter: 'prose',
})) }))
.pipe(tslint.report({emitError: true})); .pipe(tslint.report({emitError: true}));

View File

@ -1,49 +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 = '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);
}
}

View File

@ -1,10 +1,14 @@
{ {
"rules": { "rulesDirectory": [
"requireInternalWithUnderscore": true, "dist/tools/tslint",
"duplicateModuleImport": true, "node_modules/vrsource-tslint-rules/rules"
"enforce-copyright-header": true, ],
"no-duplicate-variable": true, "rules": {
"semicolon": [true], "enforce-copyright-header": true,
"variable-name": [true, "ban-keywords"] "no-duplicate-imports": true,
} "no-duplicate-variable": true,
"require-internal-with-underscore": true,
"semicolon": [true],
"variable-name": [true, "ban-keywords"]
}
} }