report_formats.py

clew/guard/report_formats.py

Machine-readable renderings of guard violations: SARIF 2.1.0, GitLab Code Quality, GitHub workflow commands (S1; 2.0.0).

fingerprint

str clew.guard.report_formats.fingerprint(Violation v)

A violation's fingerprint: stable when lines move, distinct across overloads.

clew/guard/report_formats.py:54

Source · 10 lines
def fingerprint(v: Violation) -> str:
    """No line number goes in: see the module docstring.

    @brief Fingerprint one violation.
    @return Hex digest.
    """
    key = "\x1f".join((v.check, v.file, v.qualified, v.message))
    return hashlib.sha256(key.encode("utf-8")).hexdigest()

Activity · 2 steps
lines 60–60key = "\x1f".join((v.check, v.file, v.qualified, v.message))lines 61–61return hashlib.sha256(key.encode("utf-8")).hexdigest()

Requirements

REQ-DDB-GUARD-001

render

str clew.guard.report_formats.ViolationRenderer.render(self, list[Violation] violations)

Render every violation as one document.

clew/guard/report_formats.py:79

Show on the map →

Called by none

Calls record, record, wrap

Source · 10 lines
    def render(self, violations: list[Violation]) -> str:
        """Sorted by (file, line, check, message), so the same violations always render the
        same bytes.

        @brief Render a document.
        @return Text.
        """
        ordered = sorted(violations, key=lambda v: (v.file, v.line, v.check, v.message))
        return self.wrap([self.record(v) for v in ordered], ordered)
Activity · 2 steps
lines 86–86ordered = sorted(violations, key=lambda v: (v.file, v.line, v.check, v.message))lines 87–87return self.wrap([self.record(v) for v in ordered], ordered)
str clew.guard.report_formats.render(list[Violation] violations, str fmt)

Render violations in a machine format.

clew/guard/report_formats.py:265

Show on the map →

Called by none

Calls none

Source · 3 lines
def render(violations: list[Violation], fmt: str) -> str:
    """@brief Render in a named format. @return Text."""
    return RENDERERS[fmt]().render(violations)

1 more lines, not shown

Activity · 1 steps
lines 267–267return RENDERERS[fmt]().render(violations)

Requirements

REQ-DDB-GUARD-001