1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const Lint = require("tslint");
|
4 | class Rule extends Lint.Rules.AbstractRule {
|
5 | apply(sourceFile) {
|
6 | const walker = new ImportsWalker(sourceFile, this.getOptions());
|
7 | this.applyWithWalker(walker);
|
8 | return walker.getFailures();
|
9 | }
|
10 | }
|
11 |
|
12 | Rule.FAILURE_STRING = "do not import from invalid folder like 'DISALLOWED_TEXT' (tsf-folders-import-from-disallowed-folders)";
|
13 | exports.Rule = Rule;
|
14 | class ImportsWalker extends Lint.RuleWalker {
|
15 | visitImportDeclaration(node) {
|
16 | this.validate(node, node.moduleSpecifier.getText());
|
17 | }
|
18 | visitImportEqualsDeclaration(node) {
|
19 | this.validate(node, node.moduleReference.getText());
|
20 | super.visitImportEqualsDeclaration(node);
|
21 | }
|
22 | validate(node, text) {
|
23 | const options = this.getOptions();
|
24 | if (options.length !== 1) {
|
25 | throw new Error("tslint rule is misconfigured (tsf-folders-import-from-disallowed-folders)");
|
26 | }
|
27 | const disallowedTexts = this.getOptions()[0].disallowed;
|
28 | for (const disallowed of disallowedTexts) {
|
29 | if (text.indexOf(disallowed) >= 0) {
|
30 | this.addFailureAtNode(node, Rule.FAILURE_STRING.replace("DISALLOWED_TEXT", disallowed));
|
31 |
|
32 | return;
|
33 | }
|
34 | }
|
35 | }
|
36 | }
|
37 |
|
\ | No newline at end of file |