diff --git a/CODESMELL.md b/CODESMELL.md index a9a7296..ccc703c 100644 --- a/CODESMELL.md +++ b/CODESMELL.md @@ -414,9 +414,11 @@ --- -### CSM-027 — `if result == :ok` Instead of Pattern Matching -- **File:** `lib/bds/templates.ex:445` -- **Fix:** Use `case result do :ok -> ...; _ -> ... end`. +### ~~CSM-027 — `if result == :ok` Instead of Pattern Matching~~ ✅ FIXED +- **Fixed:** 2026-05-11 +- **What was done:** + - Replaced `if result == :ok and ...` in `rewrite_template_file/2` with a `case` expression using pattern matching and a `when` guard. + - `Persistence.atomic_write` result is now matched directly: `:ok when file_path changed` triggers old file cleanup, `other` (including `{:error, _}`) is returned as-is. --- diff --git a/lib/bds/templates.ex b/lib/bds/templates.ex index a15e0a1..790622c 100644 --- a/lib/bds/templates.ex +++ b/lib/bds/templates.ex @@ -448,13 +448,12 @@ defmodule BDS.Templates do body = published_template_body(original_template) new_full_path = full_file_path(updated_template.project_id, updated_template.file_path) - result = - Persistence.atomic_write(new_full_path, serialize_template_file(updated_template, body)) + case Persistence.atomic_write(new_full_path, serialize_template_file(updated_template, body)) do + :ok when original_template.file_path != updated_template.file_path -> + delete_file_if_present(original_template.project_id, original_template.file_path) - if result == :ok and original_template.file_path != updated_template.file_path do - delete_file_if_present(original_template.project_id, original_template.file_path) - else - result + other -> + other end end