UNPKG

@abaplint/core

Version:
107 lines 5.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RulesRunner = void 0; const syntax_1 = require("./abap/5_syntax/syntax"); const artifacts_rules_1 = require("./artifacts_rules"); const _abap_object_1 = require("./objects/_abap_object"); const skip_logic_1 = require("./skip_logic"); const excludeHelper_1 = require("./utils/excludeHelper"); class RulesRunner { constructor(reg) { this.reg = reg; } objectsToCheck(objects) { const check = []; const skipLogic = new skip_logic_1.SkipLogic(this.reg); for (const obj of objects) { if (skipLogic.skip(obj) || this.reg.isDependency(obj)) { continue; } check.push(obj); } return check; } runRules(objects, input) { var _a, _b, _c, _d, _e, _f; const rulePerformance = {}; const issues = []; const rules = this.reg.getConfig().getEnabledRules(); const check = this.objectsToCheck(objects); // note: SyntaxLogic is cached, logic is run as first step in order // not to penalize the performance of the first rule using SyntaxLogic information (_a = input === null || input === void 0 ? void 0 : input.progress) === null || _a === void 0 ? void 0 : _a.set(check.length, "Run Syntax"); for (const obj of check) { (_b = input === null || input === void 0 ? void 0 : input.progress) === null || _b === void 0 ? void 0 : _b.tick("Run Syntax - " + obj.getName()); if (obj instanceof _abap_object_1.ABAPObject) { new syntax_1.SyntaxLogic(this.reg, obj).run(); } } (_c = input === null || input === void 0 ? void 0 : input.progress) === null || _c === void 0 ? void 0 : _c.set(rules.length, "Initialize Rules"); for (const rule of rules) { (_d = input === null || input === void 0 ? void 0 : input.progress) === null || _d === void 0 ? void 0 : _d.tick("Initialize Rules - " + rule.getMetadata().key); if (rule.initialize === undefined) { throw new Error(rule.getMetadata().key + " missing initialize method"); } rule.initialize(this.reg); rulePerformance[rule.getMetadata().key] = 0; } (_e = input === null || input === void 0 ? void 0 : input.progress) === null || _e === void 0 ? void 0 : _e.set(check.length, "Finding Issues"); for (const obj of check) { (_f = input === null || input === void 0 ? void 0 : input.progress) === null || _f === void 0 ? void 0 : _f.tick("Finding Issues - " + obj.getType() + " " + obj.getName()); for (const rule of rules) { const before = Date.now(); issues.push(...rule.run(obj)); const runtime = Date.now() - before; rulePerformance[rule.getMetadata().key] = rulePerformance[rule.getMetadata().key] + runtime; } } if ((input === null || input === void 0 ? void 0 : input.outputPerformance) === true) { const perf = []; for (const p in rulePerformance) { if (rulePerformance[p] > 100) { // ignore rules if it takes less than 100ms perf.push({ name: p, time: rulePerformance[p] }); } } perf.sort((a, b) => { return b.time - a.time; }); for (const p of perf) { process.stderr.write("\t" + p.time + "ms\t" + p.name + "\n"); } } return this.excludeIssues(issues); } excludeIssues(issues) { var _a; const ret = issues; const globalNoIssues = this.reg.getConfig().getGlobal().noIssues || []; const globalNoIssuesPatterns = globalNoIssues.map(x => new RegExp(x, "i")); if (globalNoIssuesPatterns.length > 0) { for (let i = ret.length - 1; i >= 0; i--) { const filename = ret[i].getFilename(); if (excludeHelper_1.ExcludeHelper.isExcluded(filename, globalNoIssuesPatterns)) { ret.splice(i, 1); } } } // exclude issues, as now we know both the filename and issue key for (const rule of artifacts_rules_1.ArtifactsRules.getRules()) { const key = rule.getMetadata().key; const ruleExclude = (_a = this.reg.getConfig().readByKey(key, "exclude")) !== null && _a !== void 0 ? _a : []; if (ruleExclude.length === 0) { continue; } const ruleExcludePatterns = ruleExclude.map(x => new RegExp(x, "i")); for (let i = ret.length - 1; i >= 0; i--) { if (ret[i].getKey() !== key) { continue; } const filename = ret[i].getFilename(); if (excludeHelper_1.ExcludeHelper.isExcluded(filename, ruleExcludePatterns)) { ret.splice(i, 1); } } } return ret; } } exports.RulesRunner = RulesRunner; //# sourceMappingURL=rules_runner.js.map