.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / noSubmoduleImportsRule.js
1 "use strict";
2 /**
3  * @license
4  * Copyright 2017 Palantir Technologies, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var tsutils_1 = require("tsutils");
21 var ts = require("typescript");
22 var Lint = require("../index");
23 var Rule = /** @class */ (function (_super) {
24     tslib_1.__extends(Rule, _super);
25     function Rule() {
26         return _super !== null && _super.apply(this, arguments) || this;
27     }
28     Rule.prototype.apply = function (sourceFile) {
29         return this.applyWithFunction(sourceFile, walk, this.ruleArguments);
30     };
31     /* tslint:disable:object-literal-sort-keys */
32     Rule.metadata = {
33         ruleName: "no-submodule-imports",
34         description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            Disallows importing any submodule."], ["\n            Disallows importing any submodule."]))),
35         rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n            Submodules of some packages are treated as private APIs and the import\n            paths may change without deprecation periods. It's best to stick with\n            top-level package exports."], ["\n            Submodules of some packages are treated as private APIs and the import\n            paths may change without deprecation periods. It's best to stick with\n            top-level package exports."]))),
36         optionsDescription: "A list of whitelisted package or submodule names.",
37         options: {
38             type: "array",
39             items: {
40                 type: "string",
41             },
42         },
43         optionExamples: [
44             true,
45             [true, "rxjs", "@angular/platform-browser", "@angular/core/testing"],
46         ],
47         type: "functionality",
48         typescriptOnly: false,
49     };
50     Rule.FAILURE_STRING = "Submodule import paths from this package are disallowed; import from the root instead";
51     return Rule;
52 }(Lint.Rules.AbstractRule));
53 exports.Rule = Rule;
54 function walk(ctx) {
55     for (var _i = 0, _a = tsutils_1.findImports(ctx.sourceFile, 63 /* All */); _i < _a.length; _i++) {
56         var name = _a[_i];
57         if (!ts.isExternalModuleNameRelative(name.text) &&
58             isSubmodulePath(name.text) &&
59             !isWhitelisted(name.text, ctx.options)) {
60             ctx.addFailureAtNode(name, Rule.FAILURE_STRING);
61         }
62     }
63 }
64 function isWhitelisted(path, whitelist) {
65     for (var _i = 0, whitelist_1 = whitelist; _i < whitelist_1.length; _i++) {
66         var option = whitelist_1[_i];
67         if (path === option || path.startsWith(option + "/")) {
68             return true;
69         }
70     }
71     return false;
72 }
73 function isSubmodulePath(path) {
74     return path.split("/").length > (path[0] === "@" ? 2 : 1);
75 }
76 var templateObject_1, templateObject_2;