From 0a948454351d9e4b657acd644abee28ebc09415f Mon Sep 17 00:00:00 2001 From: Joao Dias Date: Thu, 27 Oct 2016 20:48:47 +0200 Subject: [PATCH] chore(lint): replace duplicate-module-import rule with no-duplicate-imports --- gulpfile.js | 1 - tools/tslint/duplicateModuleImportRule.ts | 49 ----------------------- tslint.json | 20 +++++---- 3 files changed, 12 insertions(+), 58 deletions(-) delete mode 100644 tools/tslint/duplicateModuleImportRule.ts diff --git a/gulpfile.js b/gulpfile.js index cd536663cc..44cc262cd4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -156,7 +156,6 @@ gulp.task('lint', ['check-tests', 'format:enforce', 'tools:build'], () => { .pipe(tslint({ tslint: require('tslint').default, configuration: tslintConfig, - rulesDirectory: 'dist/tools/tslint', formatter: 'prose', })) .pipe(tslint.report({emitError: true})); diff --git a/tools/tslint/duplicateModuleImportRule.ts b/tools/tslint/duplicateModuleImportRule.ts deleted file mode 100644 index c2d7c12321..0000000000 --- a/tools/tslint/duplicateModuleImportRule.ts +++ /dev/null @@ -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 = ''; - 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); - } - } - - 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); - } -} diff --git a/tslint.json b/tslint.json index c28db5ea6d..60af906968 100644 --- a/tslint.json +++ b/tslint.json @@ -1,10 +1,14 @@ { - "rules": { - "requireInternalWithUnderscore": true, - "duplicateModuleImport": true, - "enforce-copyright-header": true, - "no-duplicate-variable": true, - "semicolon": [true], - "variable-name": [true, "ban-keywords"] - } + "rulesDirectory": [ + "dist/tools/tslint", + "node_modules/vrsource-tslint-rules/rules" + ], + "rules": { + "enforce-copyright-header": true, + "no-duplicate-imports": true, + "no-duplicate-variable": true, + "require-internal-with-underscore": true, + "semicolon": [true], + "variable-name": [true, "ban-keywords"] + } }