UNPKG

archunit

Version:

ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app

38 lines 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.gatherMetricViolations = exports.MetricViolation = void 0; const assertion_1 = require("../../common/assertion"); /** * Represents a class that violates a metric threshold */ class MetricViolation { constructor(className, filePath, metricName, metricValue, threshold, comparison) { this.className = className; this.filePath = filePath; this.metricName = metricName; this.metricValue = metricValue; this.threshold = threshold; this.comparison = comparison; } toString() { const comparisonText = this.comparison === 'below' ? 'not below' : 'not above'; return `Class '${this.className}' in file '${this.filePath}' has ${this.metricName} value of ${this.metricValue}, which is ${comparisonText} threshold ${this.threshold}`; } } exports.MetricViolation = MetricViolation; /** * Gathers violations from pre-computed metric results * @param metricResults The metric results to check for violations * @param allowEmptyTests Whether to allow empty tests (when no files match) */ function gatherMetricViolations(metricResults, allowEmptyTests, filters) { // Check for empty test condition if (metricResults.length === 0 && !allowEmptyTests) { return [new assertion_1.EmptyTestViolation(filters || [])]; } return metricResults .filter((result) => result.isViolation) .map((result) => new MetricViolation(result.className, result.filePath, result.metricName, result.metricValue, result.threshold, result.comparison)); } exports.gatherMetricViolations = gatherMetricViolations; //# sourceMappingURL=metric-thresholds.js.map