-
Notifications
You must be signed in to change notification settings - Fork 1
feat: redundant match arm preprocessing #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
294ed8c
c69485b
417da45
8747e7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Initial Plan: Remove redundant `Language::Json` match arms in preprocess.rs | ||
|
|
||
| ## Approach | ||
| Remove the redundant `Language::Json` match arms in `comment_syntax()` and `string_syntax()` methods in `crates/diffguard-domain/src/preprocess.rs`. | ||
|
|
||
| The fix consolidates language coverage by letting the catch-all `_ =>` handle what was being redundantly matched explicitly. | ||
|
|
||
| ### Step 1: Fix `comment_syntax()` (line 83) | ||
| Remove the redundant arm: | ||
| ```rust | ||
| // REMOVE this line: | ||
| Language::Json => CommentSyntax::CStyle, | ||
| ``` | ||
| The catch-all `_ => CommentSyntax::CStyle` already covers `Json`. | ||
|
|
||
| ### Step 2: Fix `string_syntax()` (line 108) | ||
| Change the grouped arm to exclude `Json`: | ||
| ```rust | ||
| // BEFORE: | ||
| Language::Yaml | Language::Toml | Language::Json => StringSyntax::CStyle, | ||
|
|
||
| // AFTER: | ||
| Language::Yaml | Language::Toml => StringSyntax::CStyle, | ||
| ``` | ||
| `Yaml` and `Toml` must remain explicit because they are NOT covered by the catch-all `_ => StringSyntax::CStyle` (which only covers the remaining languages: C, Cpp, CSharp, Java, Kotlin, JavaScript, TypeScript, Go, Ruby, Unknown). | ||
|
|
||
| ## Risks | ||
|
|
||
| 1. **Rustc warning vs error**: Removing the arm may change a warning into an error in strict builds or with `#[deny(dead_code))]` or `#[deny(unreachable_patterns)]` — verify the crate compiles cleanly after changes. | ||
|
|
||
| 2. **Mutation tests**: The `mutants.out.old` files suggest mutation testing was run. Removing dead code patterns may trigger different mutation coverage or new warnings from rustc. | ||
|
|
||
| 3. **Behavioral documentation**: The explicit `Language::Json` arm served as documentation that JSON intentionally uses C-style syntax even though JSON technically has no comments in its base spec. The comment `// JSON supports comments in jsonc/json5 dialects` on line 82 explains the intent. Removing the arm loses this documentation signal within the match. | ||
|
|
||
| ## Task Breakdown | ||
|
|
||
| 1. **Edit `comment_syntax()`**: Remove `Language::Json => CommentSyntax::CStyle,` at line 83 | ||
| 2. **Edit `string_syntax()`**: Change `Language::Yaml | Language::Toml | Language::Json` to `Language::Yaml | Language::Toml` at line 108 | ||
| 3. **Verify compilation**: `cargo build -p diffguard-domain` to ensure no new errors/warnings | ||
| 4. **Run tests**: `cargo test -p diffguard-domain` to confirm existing tests still pass | ||
| 5. **Optional**: Add a `#[allow(dead_code)]` or clarify the comment if the explicit `Json` arm was intentionally documented behavior | ||
|
|
||
| ## Verification Checklist | ||
| - [ ] `cargo build -p diffguard-domain` succeeds with no new warnings | ||
| - [ ] `cargo test -p diffguard-domain` passes | ||
| - [ ] `cargo clippy -p diffguard-domain` passes (if applicable) | ||
| - [ ] Mutation tests unchanged (existing test coverage for `Language::Json` remains) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Research Analysis: redundant match arm in preprocess.rs | ||
|
|
||
| ## Issue Summary | ||
| **Issue**: GitHub issue #136 — "preprocess.rs: redundant match arm — Language::Json is shadowed by wildcard" | ||
|
|
||
| In `crates/diffguard-domain/src/preprocess.rs`, the `Language` enum match arms in `comment_syntax()` and `string_syntax()` methods have redundant arms where `Language::Json` is explicitly matched but then also caught by the catch-all `_ =>` wildcard pattern. | ||
|
|
||
| ## Issue Details | ||
|
|
||
| ### Location 1: `comment_syntax()` (lines 69–86) | ||
|
|
||
| ```rust | ||
| pub fn comment_syntax(self) -> CommentSyntax { | ||
| match self { | ||
| Language::Python | Language::Ruby | Language::Shell => CommentSyntax::Hash, | ||
| Language::Rust | Language::Swift | Language::Scala => CommentSyntax::CStyleNested, | ||
| Language::Sql => CommentSyntax::Sql, | ||
| Language::Xml => CommentSyntax::Xml, | ||
| Language::Php => CommentSyntax::Php, | ||
| Language::Yaml | Language::Toml => CommentSyntax::Hash, | ||
| Language::Json => CommentSyntax::CStyle, // ← REDUNDANT | ||
| _ => CommentSyntax::CStyle, | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Location 2: `string_syntax()` (lines 89–111) | ||
|
|
||
| ```rust | ||
| pub fn string_syntax(self) -> CommentSyntax { | ||
| match self { | ||
| Language::Rust => StringSyntax::Rust, | ||
| Language::Python => StringSyntax::Python, | ||
| Language::JavaScript | Language::TypeScript | Language::Ruby => StringSyntax::JavaScript, | ||
| Language::Go => StringSyntax::Go, | ||
| Language::Shell => StringSyntax::Shell, | ||
| Language::Swift | Language::Scala => StringSyntax::SwiftScala, | ||
| Language::Sql => StringSyntax::Sql, | ||
| Language::Xml => StringSyntax::Xml, | ||
| Language::Php => StringSyntax::Php, | ||
| Language::Yaml | Language::Toml | Language::Json => StringSyntax::CStyle, // ← GROUP PARTIALLY REDUNDANT | ||
| _ => StringSyntax::CStyle, | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| In `string_syntax()`, the line `Language::Yaml | Language::Toml | Language::Json => StringSyntax::CStyle` is partially redundant because the catch-all `_ => StringSyntax::CStyle` already covers `Language::Json`. However, keeping `YAML` and `TOML` explicitly listed may be intentional for documentation purposes since they are not covered by the catch-all (the catch-all covers C, Cpp, CSharp, Java, Kotlin, JavaScript, TypeScript, Go, Ruby, and Unknown). | ||
|
|
||
| ## Relevant Codebase Areas | ||
|
|
||
| ### File: `crates/diffguard-domain/src/preprocess.rs` | ||
| - **Lines 9–31**: `Language` enum definition with 21 variants (Rust, Python, JavaScript, TypeScript, Go, Ruby, C, Cpp, CSharp, Java, Kotlin, Shell, Swift, Scala, Sql, Xml, Php, Yaml, Toml, Json, Unknown) | ||
| - **Lines 69–86**: `comment_syntax()` method — `Language::Json` arm (line 83) is fully redundant | ||
| - **Lines 89–111**: `string_syntax()` method — `Language::Json` within the group arm (line 108) is redundant (caught by catch-all) | ||
|
|
||
| ### Other Files | ||
| - `fuzz/fuzz_targets/preprocess.rs` — fuzzing target for the preprocessor | ||
| - `crates/diffguard-domain/src/rules.rs` — uses `Language` for rule matching | ||
| - `crates/diffguard-domain/src/preprocess.rs` tests (lines ~1015, ~1039, ~1083, ~2647) | ||
|
|
||
| ## Dependencies and Constraints | ||
| - **No I/O constraint**: diffguard-domain must not use `std::process`, `std::fs`, or `std::env` | ||
| - **Pure functions required**: All logic testable without mocks | ||
| - **Best-effort preprocessing**: Uses C-like syntax heuristics, not full language parsers | ||
| - **Mutation testing**: The crate runs `cargo mutants` for mutation testing | ||
|
|
||
| ## Key Findings | ||
|
|
||
| 1. **`comment_syntax()` redundancy**: The `Language::Json => CommentSyntax::CStyle` arm at line 83 is fully redundant — it produces the same output (`CStyle`) as the catch-all `_ => CommentSyntax::CStyle` at line 84. | ||
|
|
||
| 2. **`string_syntax()` partial redundancy**: In the arm `Language::Yaml | Language::Toml | Language::Json => StringSyntax::CStyle`, only `Json` is redundant since the catch-all already returns `CStyle` for `Json`. `Yaml` and `Toml` are NOT covered by the catch-all. | ||
|
|
||
| 3. **Rustc warning**: This generates E0017 (redundant match arm) or similar warning — the arms are unreachable or provably redundant. | ||
|
|
||
| 4. **Existing test coverage**: Tests exist for `Language::Json.comment_syntax()` (line 1083) and `jsonc_double_slash_comment_ignored` (line 2647), confirming `Json` should return `CStyle`. | ||
|
|
||
| ## Recommended Fix | ||
| - In `comment_syntax()`: Remove the `Language::Json => CommentSyntax::CStyle,` line (83) | ||
| - In `string_syntax()`: Change `Language::Yaml | Language::Toml | Language::Json` to `Language::Yaml | Language::Toml` (removing `Json` from the group) | ||
|
|
||
| ## Risk Assessment | ||
| - **Low risk**: The fix is a pure refactoring — no functional change since `Json` already returns `CStyle` via the catch-all | ||
| - **Test impact**: Existing tests should continue to pass since behavior is unchanged | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Plan: Fix Issue #136 — Remove Redundant `Language::Json` Match Arms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Goal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Fix clippy warning: `preprocess.rs: redundant match arm — Language::Json is shadowed by wildcard` in `crates/diffguard-domain/src/preprocess.rs`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Current Context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Issue:** #136 — `preprocess.rs: redundant match arm — Language::Json is shadowed by wildcard` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Location:** `crates/diffguard-domain/src/preprocess.rs` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Branch:** `main` with uncommitted working change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Build status:** Passing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Tests:** Passing (0 failures) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Related work item:** `work-59dfbec8` exists in conveyor with initial plan already written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Proposed Approach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Remove the redundant `Language::Json` match arms in `comment_syntax()` and `string_syntax()` methods. The wildcard `_ =>` already covers `Language::Json`, so the explicit arms are dead code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **Changes:** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1. `comment_syntax()` (line ~82-83): Remove `Language::Json => CommentSyntax::CStyle,` — covered by `_ =>` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2. `string_syntax()` (line ~107): Change `Language::Yaml | Language::Toml | Language::Json => StringSyntax::CStyle,` → `Language::Yaml | Language::Toml => StringSyntax::CStyle,` — `Json` covered by `_ =>` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Note: The working tree already shows this diff (1 insertion, 2 deletions). This plan verifies the correct approach and defines verification steps. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Step-by-Step Plan | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1. **Verify current diff** matches the intended fix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2. **Run full workspace build** (`cargo build --workspace`) — ensure no new errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3. **Run tests** (`cargo test --workspace`) — confirm no regressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4. **Run clippy** (`cargo clippy --workspace --all-targets`) — verify warning is resolved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5. **Commit** with message referencing issue #136 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Files Likely to Change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `crates/diffguard-domain/src/preprocess.rs` (1 file, ~3 lines changed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Tests / Validation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `cargo build -p diffguard-domain` — compiles cleanly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `cargo test -p diffguard-domain` — all tests pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `cargo clippy -p diffguard-domain` — no redundant match arm warning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Risks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1. **Strict compile mode:** If crate uses `#[deny(dead_code)]` or `#[deny(unreachable_patterns)]`, removing the arm could trigger an error. Verified: no such attributes present. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2. **Documentation signal:** The removed arm comment (`// JSON supports comments in jsonc/json5 dialects`) served as documentation. The updated comment on line 82 (`// JSON handled by wildcard (jsonc/json5 dialects use C-style comments)`) preserves intent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Verification Checklist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - [ ] `cargo build --workspace` succeeds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - [ ] `cargo test --workspace` passes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - [ ] `cargo clippy --all-targets` shows no redundant match arm warning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - [ ] `git diff` shows expected 1 insertion, 2 deletions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix markdownlint spacing violations (MD022/MD031). This file currently triggers markdownlint warnings for heading/code-fence spacing. Please add required blank lines so docs lint stays green. Suggested markdown adjustment pattern ## Goal
+
Fix clippy warning: `preprocess.rs: redundant match arm — Language::Json is shadowed by wildcard` in `crates/diffguard-domain/src/preprocess.rs`.
## Current Context
+
- **Issue:** `#136` — `preprocess.rs: redundant match arm — Language::Json is shadowed by wildcard`📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.22.0)[warning] 3-3: Headings should be surrounded by blank lines (MD022, blanks-around-headings) [warning] 8-8: Headings should be surrounded by blank lines (MD022, blanks-around-headings) [warning] 10-10: Fenced code blocks should be surrounded by blank lines (MD031, blanks-around-fences) [warning] 13-13: Fenced code blocks should be surrounded by blank lines (MD031, blanks-around-fences) [warning] 16-16: Headings should be surrounded by blank lines (MD022, blanks-around-headings) [warning] 18-18: Fenced code blocks should be surrounded by blank lines (MD031, blanks-around-fences) [warning] 24-24: Fenced code blocks should be surrounded by blank lines (MD031, blanks-around-fences) [warning] 43-43: Headings should be surrounded by blank lines (MD022, blanks-around-headings) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # ADR-011: Remove Unnecessary Result Wrapper from parse_blame_porcelain | ||
|
|
||
| **Status:** Accepted | ||
|
|
||
| **Date:** 2026-04-11 | ||
|
|
||
| **Work Item:** work-430b0729 | ||
|
|
||
| --- | ||
|
|
||
| ## Context | ||
|
|
||
| Issue #141 reports that `parse_blame_porcelain` in `crates/diffguard/src/main.rs` (line 1768) is typed to return `Result<BTreeMap<u32, BlameLineMeta>>` but never actually returns `Err`. This is dead code — the function silently skips invalid entries via `continue` rather than propagating errors, and always reaches `Ok(out)` at line 1818. | ||
|
|
||
| Clippy detects this pattern with the `unnecessary_result_bool` lint (or equivalent): *"this function's return value is unnecessarily wrapped by `Result`"*. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: The correct Rust Clippy lint name for functions that unnecessarily return Result (or Option) when they never return Err (or None) is clippy::unnecessary_wraps. Neither unnecessary_result_bool nor clippy::unnecessary_wraps (without the clippy:: prefix in the name itself) is correct; the full lint is clippy::unnecessary_wraps. This pedantic lint checks private functions that only return Ok or Some, suggesting to remove the unnecessary wrapper from the return type. It explicitly handles Result returning only Ok, as shown in the source code example: rust fn get_cool_number(a: bool, b: bool) -> Result<i32, !> { // or any Error type if a && b { return Ok(50); } Ok(10) } There is no lint named unnecessary_result_bool; that appears to be a misremembering. The lint originated from issues requesting detection of "needless/unnecessary Result" and was implemented as unnecessary_wraps in Clippy version 1.50.0. Citations:
Update the Clippy lint name from
🤖 Prompt for AI Agents |
||
|
|
||
| --- | ||
|
|
||
| ## Decision | ||
|
|
||
| Change `parse_blame_porcelain` to return `BTreeMap<u32, BlameLineMeta>` directly, removing the `Result` wrapper. | ||
|
|
||
| ### Changes Required | ||
|
|
||
| 1. **Function signature (line 1768):** | ||
| ```rust | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix markdownlint violations in ADR formatting. The reported Also applies to: 35-35, 44-44, 54-54, 73-73, 76-76, 79-79, 110-110 🧰 Tools🪛 markdownlint-cli2 (0.22.0)[warning] 26-26: Fenced code blocks should be surrounded by blank lines (MD031, blanks-around-fences) 🤖 Prompt for AI Agents |
||
| // Before | ||
| fn parse_blame_porcelain(blame_text: &str) -> Result<BTreeMap<u32, BlameLineMeta>> | ||
|
|
||
| // After | ||
| fn parse_blame_porcelain(blame_text: &str) -> BTreeMap<u32, BlameLineMeta> | ||
| ``` | ||
|
|
||
| 2. **Return expression (line 1818):** | ||
| ```rust | ||
| // Before | ||
| Ok(out) | ||
|
|
||
| // After | ||
| out | ||
| ``` | ||
|
|
||
| 3. **Caller in `collect_blame_allowed_lines` (lines 1861-1862):** | ||
| ```rust | ||
| // Before | ||
| let blame_map = parse_blame_porcelain(&blame_text) | ||
| .with_context(|| format!("parse git blame for {}", path))?; | ||
|
|
||
| // After | ||
| let blame_map = parse_blame_porcelain(&blame_text); | ||
| ``` | ||
|
|
||
| 4. **Test at line 4068:** | ||
| ```rust | ||
| // Before | ||
| let map = parse_blame_porcelain(porcelain).expect("parse"); | ||
|
|
||
| // After | ||
| let map = parse_blame_porcelain(porcelain); | ||
| ``` | ||
|
|
||
| ### Rationale for Silent-Skip Behavior | ||
|
|
||
| The parsing logic skips malformed entries rather than failing because: | ||
| - Git blame output for files with unusual content (binary, untrusted encoding) may contain partial/invalid entries | ||
| - The function is used to extract allowed-line metadata for diff checking — incomplete data is tolerable, hard failure is not | ||
| - This behavior is established and users depend on it | ||
|
|
||
| --- | ||
|
|
||
| ## Alternatives Considered | ||
|
|
||
| ### 1. Keep Result and document the never-err case | ||
| Adding a comment like `// SAFETY: this function never returns Err` would suppress the lint but leave unnecessary complexity for callers. | ||
|
|
||
| ### 2. Return Option instead of bare BTreeMap | ||
| `Option<BTreeMap<u32, BlameLineMeta>>` would allow `None` for parse failures, but no call site checks for `Err` so `None` would be equally unused. The bare type is cleaner. | ||
|
|
||
| ### 3. Make the function return Result and propagate real errors | ||
| Adding proper error propagation would be a breaking change to the call sites' logic and is out of scope for this fix. | ||
|
|
||
| --- | ||
|
|
||
| ## Consequences | ||
|
|
||
| **Positive:** | ||
| - Removes dead error-handling code from callers | ||
| - Eliminates Clippy lint | ||
| - Improves code clarity — readers know the function cannot fail | ||
| - Removes `.expect()` from test, making test failure messages cleaner | ||
|
|
||
| **Negative:** | ||
| - None — this is purely a refactor with no behavioral change | ||
|
|
||
| **Neutral:** | ||
| - The `anyhow::Result` type alias used throughout the crate remains; this only affects one function's return type | ||
|
|
||
| --- | ||
|
|
||
| ## Files Affected | ||
|
|
||
| - `crates/diffguard/src/main.rs` — function definition (line 1768), return (line 1818), caller (lines 1861-1862), test (line 4068) | ||
|
|
||
| --- | ||
|
|
||
| ## Verification | ||
|
|
||
| After applying changes: | ||
| 1. Run `cargo clippy -p diffguard` — confirm no lint warnings related to `parse_blame_porcelain` | ||
| 2. Run `cargo test -p diffguard` — confirm all tests pass, especially `parse_blame_porcelain_extracts_line_metadata` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve markdownlint heading spacing warnings (MD022).
Please normalize blank lines around headings in this document to satisfy markdownlint and avoid docs-lint noise.
🧰 Tools
🪛 markdownlint-cli2 (0.22.0)
[warning] 3-3: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
[warning] 51-51: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
[warning] 56-56: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
[warning] 61-61: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
[warning] 77-77: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
[warning] 81-81: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🤖 Prompt for AI Agents