Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 1x 1x 1x 1x 1x 1x 1x 22292x 22292x 22292x 1x 11147x 11147x 11147x 11147x 11147x 33242x 33242x 33242x 33242x 33242x 33242x 33242x 11147x 11147x 10583x 10583x 11147x 11147x 266x 266x 266x 11147x 11147x 268x 268x 11147x 11147x 334x 334x 334x 334x 334x 51x 1x 1x 1x 1x 51x 334x 334x 11147x 11147x | import {BasicRuleConfig} from "./_basic_rule_config"; import {Issue} from "../issue"; import {IRule, IRuleMetadata, RuleTag} from "./_irule"; import {IRegistry} from "../_iregistry"; import {IObject} from "../objects/_iobject"; import {CyclomaticComplexityStats} from "../utils/cyclomatic_complexity_stats"; export class CyclomaticComplexityConf extends BasicRuleConfig { public max: number = 20; } export class CyclomaticComplexity implements IRule { private conf = new CyclomaticComplexityConf(); public getMetadata(): IRuleMetadata { return { key: "cyclomatic_complexity", title: "Cyclomatic Complexity", shortDescription: `Cyclomatic complexity, only reported for methods`, tags: [RuleTag.SingleFile], }; } public getConfig() { return this.conf; } public setConfig(conf: CyclomaticComplexityConf): void { this.conf = conf; if (this.conf.max === undefined) { this.conf.max = new CyclomaticComplexityConf().max; } } public initialize(_reg: IRegistry) { return this; } public run(obj: IObject): Issue[] { const issues: Issue[] = []; const stats = 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.atPosition(s.file, s.pos, message, this.getMetadata().key, this.conf.severity); issues.push(issue); } } return issues; } } |