UNPKG

@abaplint/core

Version:
53 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CyclomaticComplexity = exports.CyclomaticComplexityConf = void 0; const _basic_rule_config_1 = require("./_basic_rule_config"); const issue_1 = require("../issue"); const _irule_1 = require("./_irule"); const cyclomatic_complexity_stats_1 = require("../utils/cyclomatic_complexity_stats"); class CyclomaticComplexityConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); this.max = 20; } } exports.CyclomaticComplexityConf = CyclomaticComplexityConf; class CyclomaticComplexity { constructor() { this.conf = new CyclomaticComplexityConf(); } getMetadata() { return { key: "cyclomatic_complexity", title: "Cyclomatic Complexity", shortDescription: `Cyclomatic complexity, only reported for methods`, tags: [_irule_1.RuleTag.SingleFile], }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; if (this.conf.max === undefined) { this.conf.max = new CyclomaticComplexityConf().max; } } initialize(_reg) { return this; } run(obj) { const issues = []; const stats = cyclomatic_complexity_stats_1.CyclomaticComplexityStats.run(obj); for (const s of stats) { if (s.count > this.conf.max) { const message = "Max cyclomatic complexity reached, " + s.count + ", " + s.name; const issue = issue_1.Issue.atPosition(s.file, s.pos, message, this.getMetadata().key, this.conf.severity); issues.push(issue); } } return issues; } } exports.CyclomaticComplexity = CyclomaticComplexity; //# sourceMappingURL=cyclomatic_complexity.js.map