vscode/build/lib/tslint/duplicateImportsRule.js

33 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-05-15 13:59:14 +00:00
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const Lint = require("tslint");
class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile) {
2017-05-15 13:59:14 +00:00
return this.applyWithWalker(new ImportPatterns(sourceFile, this.getOptions()));
}
}
2017-05-15 13:59:14 +00:00
exports.Rule = Rule;
class ImportPatterns extends Lint.RuleWalker {
constructor(file, opts) {
super(file, opts);
this.imports = Object.create(null);
2017-05-15 13:59:14 +00:00
}
visitImportDeclaration(node) {
let path = node.moduleSpecifier.getText();
2017-05-15 13:59:14 +00:00
// remove quotes
path = path.slice(1, -1);
if (path[0] === '.') {
path = path_1.join(path_1.dirname(node.getSourceFile().fileName), path);
}
if (this.imports[path]) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), `Duplicate imports for '${path}'.`));
2017-05-15 13:59:14 +00:00
}
this.imports[path] = true;
}
}