Skip to content

Add -W/--strict flag and shared suppress_warnings to codelinks analyse#93

Draft
ubmarco wants to merge 10 commits into
mainfrom
feat/analyse-strict-90
Draft

Add -W/--strict flag and shared suppress_warnings to codelinks analyse#93
ubmarco wants to merge 10 commits into
mainfrom
feat/analyse-strict-90

Conversation

@ubmarco

@ubmarco ubmarco commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

Implements the agreed proposal in #90 (comment 4967873974): a -W / --strict flag for codelinks analyse that turns warnings into a non-zero exit, plus a shared, suppressible warning-slug system so CI can enforce traceability quality gates.

Closes #90.

What changed

-W / --strict flag. Without it, behaviour is unchanged (exit 0). With it, analyse exits 1 if any non-suppressed warning was emitted — mirroring sphinx-build -W.

Situation (standalone) without -W with -W
Completed, no warnings 0 0
Completed, ≥1 non-suppressed warning 0 1
Uncaught exception / crash 1 1
Usage / config error (BadParameter) 2 2

One suppression list, both frontends. A new [codelinks] suppress_warnings config field (on CodeLinksConfig) is read by both the CLI and the Sphinx extension:

  • Standalone drops matching warnings — not printed, not counted for -W.
  • Sphinx folds the slugs into its native suppress_warnings at config-inited, so sphinx-build / sphinx-build -W honour the same list; existing conf.py entries are preserved (additive).

Hierarchical, normalized slugs. All warnings now live under one namespace, matched hierarchically (codelinks → all, codelinks.git → the git family, codelinks.git.root → one):

  • git metadata: codelinks.git.{root,config,remote,head,ref,host} (was codelinks.git_*)
  • one-line marker: codelinks.marker.{too_many_fields,too_few_fields,missing_square_brackets,not_start_or_end_with_square_brackets,newline_in_field} (was need.*)

Single choke point. All standalone warnings now flow through the logging facade's CLI backend, which is where suppression + counting happen. Previously git warnings dropped their subtype and one-line warnings bypassed the facade entirely.

Design note — Sphinx's matcher is flat

The proposal assumed Sphinx's suppress_warnings matches hierarchically. It doesn't: Sphinx 8.2 matches only an exact type, type.*, or type.subtype. So a family entry like codelinks.git would silence nothing under Sphinx on its own. To keep the same list working in both frontends, the fold expands hierarchical entries to the concrete slugs Sphinx understands (via a single slug registry in logger.py). The standalone matcher is genuinely hierarchical.

Out of scope (follow-ups)

  • Ad-hoc --suppress-warning CLI override (proposal marked "optional").
  • A dedicated exit code (3) for -W failures — proposal decided to reuse 1.
  • Activating the (currently dormant) Sphinx marker-warning path.

Backwards compatibility

Default behaviour is unchanged; -W is strictly opt-in. The only behavioural change is the slug rename, and those slugs were effectively undocumented, so the blast radius is small. The one-line WarningSubTypeEnum values are unchanged (the marker. prefix is added only where warnings are surfaced), so this needs no ubCode parser change.

The docs' own src_trace.toml now sets suppress_warnings = ["codelinks.git"], dogfooding the feature and keeping the strict (-nW) docs build green when built from a git worktree (packed refs would otherwise emit a spurious codelinks.git.ref).

Testing

  • New/updated tests for the matcher, the CLI backend's suppress+count, git/marker slug surfacing, the config field + schema, the full exit-code contract (both flag spellings, exact-leaf vs family suppression, precision, git arm), the expand_suppress_for_sphinx helper, and a real Sphinx build asserting the fold is additive.
  • Verified end-to-end via the real codelinks binary (help text + exit codes).
  • Full suite green (298 passed, 1 pre-existing skip), mypy clean, pre-commit (ruff lint+format) clean, strict docs build succeeds.

ubmarco added 10 commits July 14, 2026 15:30
… matcher

Introduce CODELINKS_WARNING_SLUGS (the canonical set of warning slugs the
analyse layer can emit) and is_suppressed(), a dot-boundary hierarchical
matcher so a parent slug silences the family below it. Groundwork for the
-W/--strict flag (#90).
_CliBackend now drops warnings matching its suppress_warnings list and counts
the survivors, appending each slug to the message so users know what to
suppress. Adds configure_cli(suppress_warnings=), set_cli_suppress_warnings()
and cli_warning_count() so the CLI can apply suppression once the TOML config
is parsed and later gate the exit code on the count (#90).
…git.*

Emit the six git-metadata warnings with dotted subtypes (git.root, git.config,
git.remote, git.head, git.ref, git.host) so they share the hierarchical
codelinks.git.* namespace with marker warnings and are suppressible as a
family. These slugs are effectively undocumented today, so the blast radius is
small (#90).
The CLI previously printed marker warnings via the rich logger directly,
bypassing the suppress/count choke point and dropping the subtype. Route them
through get_logger().warning(subtype="marker.<subtype>") so they surface as
codelinks.marker.* on stderr, are suppressible, and are counted for --strict
(#90).
A list of hierarchical warning slugs, read by both frontends from the single
[codelinks] config. Registered as src_trace_suppress_warnings for conf.py and
schema-validated as an array of strings. Default empty, so behavior is
unchanged (#90).
With -W/--strict, analyse exits 1 if any non-suppressed warning was emitted
(git-metadata or marker), mirroring sphinx-build -W; crashes stay 1 and
BadParameter stays 2. Suppression comes from the shared [codelinks]
suppress_warnings, applied once the config is parsed. Default (no flag) is
unchanged. Closes #90.
…arnings

At config-inited the shared [codelinks] suppress_warnings is merged into
Sphinx's native suppress_warnings so sphinx-build and sphinx-build -W honour
the same list. Sphinx's matcher is flat (exact type/type.subtype or type.*),
so expand_suppress_for_sphinx() expands hierarchical slugs to the concrete
tokens it understands; the merge is additive so conf.py entries survive.
emit_warnings now uses the codelinks.marker.* slug for consistency (#90).
Add a suppress_warnings config reference (slug table, hierarchy, both frontends),
a 'Treating warnings as errors' CLI section with the exit-code contract, and a
changelog entry. The docs' own src_trace.toml now sets
suppress_warnings = ["codelinks.git"] so the strict -nW build is not tripped by
best-effort git-metadata warnings when building from a worktree (#90).
Combine PLR0913 into the analyse command's noqa (a CLI command legitimately
takes many options), simplify the .* suffix strip with str.removesuffix, and
apply ruff-format to the new tests.
A per-user Claude Code permissions file was accidentally committed via
git add -A. Untrack it and gitignore it.
@codecov-commenter

codecov-commenter commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.48187% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.38%. Comparing base (43927d0) to head (eecf387).

Files with missing lines Patch % Lines
src/sphinx_codelinks/logger.py 97.05% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   91.40%   92.38%   +0.98%     
==========================================
  Files          34       34              
  Lines        3012     3193     +181     
  Branches      322      333      +11     
==========================================
+ Hits         2753     2950     +197     
+ Misses        160      149      -11     
+ Partials       99       94       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --strict/-W flag to codelinks analyse command for treating warnings as errors

2 participants