[AAASM-4757] ♻️ (examples): Clear 5 Sonar smells in generate_example_metadata#322
Conversation
The old ``(?:\s+//.*)?\s*`` tail let the comment's ``.*`` and the trailing ``\s*`` both consume trailing whitespace — a super-linear overlap static analysis flags as a ReDoS risk (python:S8786). Rewrite the tail as the disjoint alternation ``\s+//[^\n]*|\s*``; proven to match the same set and capture identical groups across ~0.4M fuzz inputs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TdxntF32Wi278LGD22dVS4
``(?:rc|beta|alpha|b|a)`` has ``b``/``a`` shadowing ``beta``/``alpha`` — an alternation overlap static analysis flags as super-linear (python:S8786). Fold the pairs into ``b(?:eta)?`` / ``a(?:lpha)?`` so no branch is a prefix of another. Proven equivalent (same token, span, findall) across ~0.5M fuzz inputs plus a structured version-string corpus. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TdxntF32Wi278LGD22dVS4
The operator audit only inspects the pin operator via _PY_PIN_AUDIT_RE and never reads the SoT versions (python:S1172). Remove the dead parameter and update its sole caller, audit(). Not a shared interface — the only caller is internal. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TdxntF32Wi278LGD22dVS4
process_prereq_rows nested two rewrite loops and a touched flag inside its per-README loop, pushing cognitive complexity to 16 (python:S3776, limit 15). Move the per-README alignment into _align_prereq_readme, leaving the outer function a flat collect loop. Behaviour identical. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TdxntF32Wi278LGD22dVS4
_audit_prose nested three checks inside a per-line loop inside a per-file loop, reaching cognitive complexity 45 (python:S3776, limit 15). Extract the label, backtick-row and install-hint checks into flat helpers, a per-line combiner (_audit_prose_line) and a per-file walker (_audit_prose_file); the outer function is now a flat collect loop. Emit order and message text are unchanged, so a generator-produced tree still audits identically. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TdxntF32Wi278LGD22dVS4
|
Claude Code — PR reviewVerdict: ready to approve & merge (pending required Pioneer approval).
Scope coverage — all 5 Sonar smells in
Side-effect analysis — the strongest possible proof: running the generator after the change leaves Validation: 39/39 unit tests pass; |



What changed
Clears all 5 SonarCloud maintainability smells in
scripts/generate_example_metadata.py, taking the examples repo's Maintainability rating debt on this file to zero. Every change is strictly behaviour-preserving — the generator's output stays byte-identical (verified against the CI metadata drift check), and the two regex simplifications were proven to match the same set as before._GO_PIN_REtail and_VERSION_TOKEN_REpre-release alternation rewritten as prefix-free forms that remove the flagged overlap._GO_PIN_RE:(?:\s+//.*)?\s*->\s+//[^\n]*|\s*(comment.*no longer competes with trailing\s*)._VERSION_TOKEN_RE:(?:rc|beta|alpha|b|a)->(?:rc|b(?:eta)?|a(?:lpha)?)(folds theb/betaanda/alphaprefix shadows).versionsargument from_audit_py_operatorand updated its sole calleraudit(). It is an internal helper, not a shared interface, so removal (not underscore-prefix) is the correct fix.process_prereq_rows(16 -> under limit) by extracting_align_prereq_readme;_audit_prose(45 -> under limit) by splitting into flat per-line helpers (_audit_prose_label/_backtick/_install/_line/_file). Emit order and message text are unchanged.Related ticket
Jira: https://lightning-dust-mite.atlassian.net/browse/AAASM-4757 (Epic AAASM-4754)
How to verify
Run locally from the repo root:
python3 -m py_compile scripts/generate_example_metadata.py— passes.python scripts/generate_example_metadata.pythengit diff— no diff (byte-identical output; the CI drift check stays green).python scripts/generate_example_metadata.py --check— every audited surface matches the SoT.python -m unittest scripts.test_generate_example_metadata— 39/39 pass.findall— IDENTICAL for both regexes.Checklist
[AAASM-XXXX] <GitEmoji> (<scope>): <summary>.envfiles committedREADME.mdwith prerequisites and run instructions🤖 Generated with Claude Code