Skip to main content

Module code_climate

Module code_climate 

Source
Expand description

GitLab Code Climate JSON writer for OffenderRecord batches.

GitLab’s merge-request Code Quality widget consumes a strict subset of the upstream Code Climate engine spec; this writer emits exactly that subset so a bca check artifact can drop straight into .gitlab-ci.yml’s artifacts.reports.codequality: slot. See the authoritative GitLab docs at https://docs.gitlab.com/ci/testing/code_quality/ for the consumer side.

§Fields emitted

JSON fieldSource
descriptionmetric_catalog long-form + OffenderRecord::default_message; bare default_message for unknown metrics
check_name"big-code-analysis/<metric>" (namespaced so multi-tool pipelines do not collide)
fingerprintSHA-256 of path \0 function.unwrap_or("") \0 metric, truncated to 32 hex chars. Deliberately excludes line / value so re-runs after upstream-line edits still dedup in the MR widget.
severityRatio-band mapping over value / limit (inverted for the mi.* family — lower is worse there). Falls back to a per-record Severity lookup when the ratio is ill-defined.
location.pathUTF-8 relative path, forward slashes, leading ./ stripped. Non-UTF-8 paths emit a stderr warning and the offender is skipped.
location.lines.begin, lines.endstart_line (clamped ≥ 1) and end_line (only when > start_line).
location.positions.begin{line, column} emitted only when start_col is Some(c) with c > 0.

§Not emitted

The upstream Code Climate spec defines type, categories, remediation_points, and content; GitLab ignores all of them, so we omit them to keep the artifact small. Adding them later is a purely additive change.

§Framing

Single JSON array of objects, no byte-order-mark, one trailing newline. The empty case emits the literal []\n so consumers that pipe through jq see a well-formed document even when no offenders triggered.

Functions§

write_code_climate
Write a GitLab Code Climate JSON report for offenders to writer.