chore(lint): replace duplicate-module-import rule with no-duplicate-imports
This commit is contained in:
parent
262bd23b84
commit
0a94845435
|
@ -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}));
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,13 @@
|
||||||
{
|
{
|
||||||
|
"rulesDirectory": [
|
||||||
|
"dist/tools/tslint",
|
||||||
|
"node_modules/vrsource-tslint-rules/rules"
|
||||||
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"requireInternalWithUnderscore": true,
|
|
||||||
"duplicateModuleImport": true,
|
|
||||||
"enforce-copyright-header": true,
|
"enforce-copyright-header": true,
|
||||||
|
"no-duplicate-imports": true,
|
||||||
"no-duplicate-variable": true,
|
"no-duplicate-variable": true,
|
||||||
|
"require-internal-with-underscore": true,
|
||||||
"semicolon": [true],
|
"semicolon": [true],
|
||||||
"variable-name": [true, "ban-keywords"]
|
"variable-name": [true, "ban-keywords"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue