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
Called by record
Tested by
Calls none
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
Requirements
render
str clew.guard.report_formats.ViolationRenderer.render(self, list[Violation] violations)
Render every violation as one document.
clew/guard/report_formats.py:79
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
str clew.guard.report_formats.render(list[Violation] violations, str fmt)
Render violations in a machine format.
clew/guard/report_formats.py:265
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