UNPKG

tslint-folders

Version:

Custom TSLint rules for checking imports between packages and their folders, and generating relevant diagrams.

55 lines (54 loc) 2.4 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Rule = void 0; var Lint = require("tslint"); var ts = require("typescript"); var ConfigFactory_1 = require("./config/ConfigFactory"); var RuleId_1 = require("./RuleId"); var GeneralRuleUtils_1 = require("./utils/GeneralRuleUtils"); // note: MUST be named exactly 'Rule' to be picked up by tslint var Rule = /** @class */ (function (_super) { __extends(Rule, _super); function Rule() { return _super !== null && _super.apply(this, arguments) || this; } Rule.prototype.apply = function (sourceFile) { var config = ConfigFactory_1.ConfigFactory.createForDisabledTestRule(this.getOptions()); if (!GeneralRuleUtils_1.GeneralRuleUtils.isFileInPaths(sourceFile.fileName, config.includePaths)) { return []; } return this.applyWithFunction(sourceFile, walk, config); }; return Rule; }(Lint.Rules.AbstractRule)); exports.Rule = Rule; var walk = function (ctx) { return ts.forEachChild(ctx.sourceFile, checkNode); function checkNode(node) { if (node.kind === ts.SyntaxKind.CallExpression) { visitCallExpression(node, ctx); } return ts.forEachChild(node, checkNode); } }; function visitCallExpression(node, ctx) { var text = node.getText(); if (ctx.options.ban.some(function (token) { return text.startsWith(token); })) { ctx.addFailureAtNode(node.getFirstToken() || node, GeneralRuleUtils_1.GeneralRuleUtils.buildFailureString("do not disable or enable only some tests", RuleId_1.RuleId.TsfFoldersDisabledTest)); } }