Skip to content

Commit

Permalink
feature(report): adds support for 'via' type rules in the azure-devop…
Browse files Browse the repository at this point in the history
…s reporter
  • Loading branch information
sverweij committed Jul 8, 2023
1 parent 360371d commit 83c7930
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
24 changes: 21 additions & 3 deletions src/report/azure-devops.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ const SEVERITY2VSO_TYPE = new Map([
]);

/**
*
* @param {import("../../types/shared-types.js").SeverityType} pSeverity
* @returns {string}
*/
function formatSeverity(pSeverity) {
return SEVERITY2VSO_TYPE.get(pSeverity) ?? "warning";
}

/**
* @param {import("../../types/violations.js").IViolation} pViolation
* @returns {string}
*/
function formatModuleViolation(pViolation) {
return `${pViolation.rule.name}: ${pViolation.from}`;
}
Expand All @@ -34,22 +38,36 @@ function formatDependencyViolation(pViolation) {
return `${pViolation.rule.name}: ${pViolation.from} -> ${pViolation.to}`;
}

/**
* @param {import("../../types/violations.js").IViolation} pViolation
* @returns {string}
*/
function formatCycleViolation(pViolation) {
return `${pViolation.rule.name}: ${
pViolation.from
} -> ${pViolation.cycle.join(" -> ")}`;
}

/**
*
* @param {import("../../types/violations.js").IViolation} pViolation
* @returns {string}
*/
function formatReachabilityViolation(pViolation) {
return `${pViolation.rule.name}: ${pViolation.from} -> ${
pViolation.to
} (via ${pViolation.via.join(" -> ")})`;
}

/**
* @param {import("../../types/violations.js").IViolation} pViolation
* @returns {string}
*/
function formatViolation(pViolation) {
const lViolationType2Formatter = {
module: formatModuleViolation,
dependency: formatDependencyViolation,
cycle: formatCycleViolation,
// reachability: formatReachabilityViolation,
reachability: formatReachabilityViolation,
// instability: formatInstabilityViolation,
};
let lFormattedViolators = _formatViolation(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##vso[task.logissue type=error;sourcepath=src/extract/index.js]some-via-rule: src/extract/index.js -> src/utl/array-util.js (via via-one -> via-another)
##vso[task.logissue type=error;sourcepath=src/extract/index.js]some-via-rule: src/extract/index.js -> src/utl/find-rule-by-name.js (via via-one -> via-another)
##vso[task.logissue type=error;sourcepath=src/utl/array-util.js]some-via-rule: src/utl/array-util.js
##vso[task.logissue type=error;sourcepath=src/utl/find-rule-by-name.js]some-via-rule: src/utl/find-rule-by-name.js
##vso[task.complete result=Failed;]4 dependency violations (4 error, 0 warning/ informational). 8 modules, 7 dependencies cruised
4 changes: 2 additions & 2 deletions test/report/azure-devops/__mocks__/via-deps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default {
severity: "error",
name: "some-via-rule",
},
via: ["(via via)"],
via: ["via-one", "via-another"],
},
{
type: "reachability",
Expand All @@ -213,7 +213,7 @@ export default {
severity: "error",
name: "some-via-rule",
},
via: ["(via via)"],
via: ["via-one", "via-another"],
},
{
type: "module",
Expand Down
18 changes: 10 additions & 8 deletions test/report/azure-devops/azure-devops.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import errdeps from "./__mocks__/there-are-errors.mjs";
import moduleErrs from "./__mocks__/module-errors.mjs";
import requiredErrs from "./__mocks__/required-errors.mjs";
import circulars from "./__mocks__/circular-deps.mjs";
// import vias from "./__mocks__/via-deps.mjs";
import vias from "./__mocks__/via-deps.mjs";
// import unsupportedErrorLevels from "./__mocks__/unsupported-severity.mjs";
// import knownViolations from "./__mocks__/known-violations.mjs";
// import instabilities from "./__mocks__/instabilities.mjs";
Expand Down Expand Up @@ -94,14 +94,16 @@ describe("[I] report/azure-devops", () => {
expect(lResult.exitCode).to.equal(3);
});

// it("renders via transgressions", () => {
// const lFixture = readFixture("__mocks__/via-deps-azure-devops-format.txt");
// const lResult = render(vias);
it("renders via transgressions", () => {
const lFixture = readFixture("__mocks__/via-deps-azure-devops-format.txt");
const lResult = render(vias);

// expect(lResult.output).to.equal(lFixture);
// // eslint-disable-next-line no-magic-numbers
// expect(lResult.exitCode).to.equal(4);
// });
expect(normalizeNewline(lResult.output)).to.equal(
normalizeNewline(lFixture)
);
// eslint-disable-next-line no-magic-numbers
expect(lResult.exitCode).to.equal(4);
});

// it("renders instability transgressions", () => {
// const lFixture = readFixture(
Expand Down

0 comments on commit 83c7930

Please sign in to comment.