.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / noImportSideEffectRule.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 _a;
21 var utils = require("tsutils");
22 var Lint = require("../index");
23 var OPTION_IGNORE_MODULE = "ignore-module";
24 var Rule = /** @class */ (function (_super) {
25     tslib_1.__extends(Rule, _super);
26     function Rule() {
27         return _super !== null && _super.apply(this, arguments) || this;
28     }
29     Rule.prototype.apply = function (sourceFile) {
30         var patternConfig = this.ruleArguments[this.ruleArguments.length - 1];
31         var ignorePattern = patternConfig === undefined
32             ? undefined
33             : new RegExp(patternConfig[OPTION_IGNORE_MODULE]);
34         return this.applyWithFunction(sourceFile, walk, ignorePattern);
35     };
36     Rule.metadata = {
37         description: "Avoid import statements with side-effect.",
38         optionExamples: [true, [true, (_a = {}, _a[OPTION_IGNORE_MODULE] = "(\\.html|\\.css)$", _a)]],
39         options: {
40             items: {
41                 properties: {
42                     "ignore-module": {
43                         type: "string",
44                     },
45                 },
46                 type: "object",
47             },
48             maxLength: 1,
49             minLength: 0,
50             type: "array",
51         },
52         optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            One argument may be optionally provided:\n\n            * `", "` allows to specify a regex and ignore modules which it matches."], ["\n            One argument may be optionally provided:\n\n            * \\`", "\\` allows to specify a regex and ignore modules which it matches."])), OPTION_IGNORE_MODULE),
53         rationale: "Imports with side effects may have behavior which is hard for static verification.",
54         ruleName: "no-import-side-effect",
55         type: "typescript",
56         typescriptOnly: false,
57     };
58     Rule.FAILURE_STRING = "import with explicit side-effect";
59     return Rule;
60 }(Lint.Rules.AbstractRule));
61 exports.Rule = Rule;
62 function walk(ctx) {
63     var ignorePattern = ctx.options, sourceFile = ctx.sourceFile;
64     for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
65         var statement = _a[_i];
66         if (!utils.isImportDeclaration(statement)) {
67             continue;
68         }
69         var importClause = statement.importClause, moduleSpecifier = statement.moduleSpecifier;
70         if (importClause !== undefined || !utils.isStringLiteral(moduleSpecifier)) {
71             continue;
72         }
73         if (ignorePattern === undefined || !ignorePattern.test(moduleSpecifier.text)) {
74             ctx.addFailureAtNode(statement, Rule.FAILURE_STRING);
75         }
76     }
77 }
78 var templateObject_1;