a zip code crypto-currency system good for red ONLY

noImportSideEffectRule.js 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ? undefined : new RegExp(patternConfig[OPTION_IGNORE_MODULE]);
  32. return this.applyWithFunction(sourceFile, walk, ignorePattern);
  33. };
  34. Rule.metadata = {
  35. description: "Avoid import statements with side-effect.",
  36. optionExamples: [true, [true, (_a = {}, _a[OPTION_IGNORE_MODULE] = "(\\.html|\\.css)$", _a)]],
  37. options: {
  38. items: {
  39. properties: {
  40. "ignore-module": {
  41. type: "string",
  42. },
  43. },
  44. type: "object",
  45. },
  46. maxLength: 1,
  47. minLength: 0,
  48. type: "array",
  49. },
  50. 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),
  51. rationale: "Imports with side effects may have behavior which is hard for static verification.",
  52. ruleName: "no-import-side-effect",
  53. type: "typescript",
  54. typescriptOnly: false,
  55. };
  56. Rule.FAILURE_STRING = "import with explicit side-effect";
  57. return Rule;
  58. }(Lint.Rules.AbstractRule));
  59. exports.Rule = Rule;
  60. function walk(ctx) {
  61. var ignorePattern = ctx.options, sourceFile = ctx.sourceFile;
  62. for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
  63. var statement = _a[_i];
  64. if (!utils.isImportDeclaration(statement)) {
  65. continue;
  66. }
  67. var importClause = statement.importClause, moduleSpecifier = statement.moduleSpecifier;
  68. if (importClause !== undefined || !utils.isStringLiteral(moduleSpecifier)) {
  69. continue;
  70. }
  71. if (ignorePattern === undefined || !ignorePattern.test(moduleSpecifier.text)) {
  72. ctx.addFailureAtNode(statement, Rule.FAILURE_STRING);
  73. }
  74. }
  75. }
  76. var templateObject_1;