Skip to content

refactor: audit hygiene — shared constants, domain naming, idiom sweep - #95

Merged
pixincreate merged 4 commits into
masterfrom
chore/audit-hygiene
Sep 5, 2026
Merged

refactor: audit hygiene — shared constants, domain naming, idiom sweep#95
pixincreate merged 4 commits into
masterfrom
chore/audit-hygiene

Conversation

@pixincreate

Copy link
Copy Markdown
Owner

Summary

Lands all twelve findings from the constants/idiom/domain audit, one commit per group:

  • refactor(scanner): the git-config override list duplicated between --staged and --git-history is one GIT_DIFF_FRAMING_ARGS constant (a new override previously had to be added to both call sites — fix(scan): make git-history and staged modes behave like the others #88 did exactly that); the (?s multiline heuristic is now Detector::is_multiline() — production and the seven test partitions shared two divergent definitions, and the tests still carried the pre-fix: baseline integrity, clearer CLI errors, deterministic SARIF #92 form.
  • refactor: detectors.toml is DETECTORS_FILE_NAME across discovery and error messages; the hook-uninstall marker is pinned by a test (a template header edit would have silently broken hook uninstall); redact()'s 4-char prefix and 8-char threshold are named constants; config discovery uses utils::home_dir() instead of a third inline HOME/USERPROFILE fallback.
  • refactor: ScanArgs::default is derived (#[default] on ExitMode::Strict/OutputFormat::Json); collect_files returns named ScanTargets instead of anonymous tuples; scan_lines takes a BinaryHandling enum instead of a bare bool; CustomRule::description (parsed, never read) is dropped — configs carrying it keep parsing; stray mid-file imports moved to the top.
  • refactor(domain): Finding.plugin_namedetector_name in code — the JSON wire format still emits and accepts plugin_name (serde rename + alias), so report consumers are unaffected; BaselineEntry keeps the versioned on-disk name. undiffable_files/scan_undiffable_blobsunscannable_from_diff/scan_index_blobs, with comments keeping the cause/outcome distinction ('undiffable' = git cannot render it; 'unscannable' = we could not read it).

Tests

214 pass (one new: templates must carry the uninstall marker). fmt/clippy clean; self-scan clean and drift-free.

…etection

The git-config override list was duplicated between --staged and
--git-history, so adding the next override meant remembering both call
sites (#88 had to add diff.relative twice). GIT_DIFF_FRAMING_ARGS is now
one constant with the parser-dependency rationale attached.

The (?s heuristic likewise lived in run_scan and seven test partitions —
and the tests still carried the pre-#92 form that misses (?s:...).
Detector::is_multiline() is now the single definition.
…esolution

- detectors.toml was a literal at three discovery sites plus two error
  messages; DETECTORS_FILE_NAME is now the single spelling.
- hook uninstall trusts the '# Installed by KeyWatch' marker, which the
  templates carried as unpinned text; a test now fails if a template
  loses it.
- redact()'s prefix length (4) and short-match threshold (8) are named
  constants instead of magic numbers.
- config discovery resolved HOME/USERPROFILE inline; utils::home_dir()
  (which hooks and display_path already rely on) is now the one
  implementation. Hooks keeps its own XDG/APPDATA-first order.
- ScanArgs' Default is derived now: ExitMode::Strict and
  OutputFormat::Json carry #[default], so a new flag no longer means
  editing a 25-line hand-written impl.
- collect_files handed back anonymous (String, Option<String>) tuples
  whose second slot was 'the scan root'; a small ScanTarget struct names
  it.
- scan_lines took a bare binary_detection: bool; a BinaryHandling enum
  makes both call sites self-describing.
- CustomRule::description was parsed and never read (#[allow(dead_code)]);
  dropped. Configs carrying it keep parsing — serde ignores unknown keys.
- utils.rs and report.rs had use statements below their first code
  blocks; all imports now sit at the top.
Finding.plugin_name stored a detector's name, but the domain says
'detector' everywhere else — 'plugin' survived in one field and the
baseline schema. The in-code field is now detector_name; the JSON wire
format keeps the historical plugin_name key (serde rename + alias) so
report consumers are unaffected, and BaselineEntry keeps the versioned
on-disk name.

The staged parser's undiffable_files / scan_undiffable_blobs became
unscannable_from_diff / scan_index_blobs: 'undiffable' is the cause (git
cannot render the file), 'unscannable' is the outcome the report talks
about — a distinction the two previous names blurred.
@pixincreate
pixincreate merged commit 6820b66 into master Sep 5, 2026
7 checks passed
@pixincreate
pixincreate deleted the chore/audit-hygiene branch September 5, 2026 12:48
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.

1 participant