Skip to content

Commit 7a42dac

Browse files
committed
refactor: fix reach dead-code and smell findings
- Remove unused String.slice short-sha vars in format_unified_diff - Remove unused attachment_type case in attach_file - Drop redundant nil default in Map.get/3 calls - Replace Map.keys |> length with map_size/1 - Replace guard == :ok comparison with pattern-matched clauses - Remove redundant params assignment before return - Use iolist for WIQL string building
1 parent 32490e8 commit 7a42dac

4 files changed

Lines changed: 31 additions & 44 deletions

File tree

lib/ado_cli/cli/pipelines.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ defmodule AdoCli.CLI.Pipelines do
11121112
writeln(String.duplicate("─", 100))
11131113

11141114
Enum.each(groups, fn g ->
1115-
var_count = g["variables"] |> Map.keys() |> length()
1115+
var_count = map_size(g["variables"])
11161116

11171117
desc = String.slice(g["description"] || "", 0, 38)
11181118

lib/ado_cli/cli/pull_requests.ex

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,11 +1110,8 @@ defmodule AdoCli.CLI.PullRequests do
11101110
end
11111111
end
11121112

1113-
defp format_unified_diff(path, old_content, new_content, base_sha, target_sha) do
1114-
# Ensure path has a leading "/" for consistency
1113+
defp format_unified_diff(path, old_content, new_content, _base_sha, _target_sha) do
11151114
path = if String.starts_with?(path, "/"), do: path, else: "/#{path}"
1116-
_short_base = String.slice(base_sha, 0, 7)
1117-
_short_target = String.slice(target_sha, 0, 7)
11181115

11191116
header = """
11201117
diff --git a#{path} b#{path}
@@ -1940,20 +1937,23 @@ defmodule AdoCli.CLI.PullRequests do
19401937
defp do_delete_request(:delete, path), do: Client.delete(path)
19411938
defp do_delete_request(:patch, path), do: Client.patch(path, %{"status" => "closed"})
19421939

1943-
defp render_delete_result(result, target_label, json?, parsed) do
1944-
case result do
1945-
r when r == :ok or (is_tuple(r) and elem(r, 0) == :ok) ->
1946-
if json? do
1947-
IO.puts(JSON.encode!(%{ok: true, closed: target_label}))
1948-
else
1949-
success("Closed #{target_label}.")
1950-
end
1940+
defp render_delete_result(:ok, target_label, json?, _parsed),
1941+
do: render_delete_ok(target_label, json?)
19511942

1952-
halt_success("")
1943+
defp render_delete_result({:ok, _}, target_label, json?, _parsed),
1944+
do: render_delete_ok(target_label, json?)
19531945

1954-
{:error, reason} ->
1955-
Helpers.bail(reason, parsed)
1946+
defp render_delete_result({:error, reason}, _target_label, _json?, parsed),
1947+
do: Helpers.bail(reason, parsed)
1948+
1949+
defp render_delete_ok(target_label, json?) do
1950+
if json? do
1951+
IO.puts(JSON.encode!(%{ok: true, closed: target_label}))
1952+
else
1953+
success("Closed #{target_label}.")
19561954
end
1955+
1956+
halt_success("")
19571957
end
19581958

19591959
@doc """

lib/ado_cli/cli/test_results.ex

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,24 @@ defmodule AdoCli.CLI.TestResults do
133133
params = %{}
134134

135135
params =
136-
if top = Map.get(parsed.options, :top, nil) do
136+
if top = Map.get(parsed.options, :top) do
137137
Map.put(params, "$top", top)
138138
else
139139
params
140140
end
141141

142142
params =
143-
if build_id = Map.get(parsed.options, :"build-id", nil) do
143+
if build_id = Map.get(parsed.options, :"build-id") do
144144
Map.put(params, "buildIds", build_id)
145145
else
146146
params
147147
end
148148

149-
params =
150-
if min_date = Map.get(parsed.options, :"min-last-updated", nil) do
151-
Map.put(params, "minLastUpdatedDate", min_date)
152-
else
153-
params
154-
end
155-
156-
params
149+
if min_date = Map.get(parsed.options, :"min-last-updated") do
150+
Map.put(params, "minLastUpdatedDate", min_date)
151+
else
152+
params
153+
end
157154
end
158155

159156
defp find_stat(stats, label) do
@@ -270,7 +267,7 @@ defmodule AdoCli.CLI.TestResults do
270267
}
271268

272269
body =
273-
if build_id = Map.get(parsed.options, :"build-id", nil) do
270+
if build_id = Map.get(parsed.options, :"build-id") do
274271
Map.put(body, "build", %{"id" => build_id})
275272
else
276273
body
@@ -281,20 +278,6 @@ defmodule AdoCli.CLI.TestResults do
281278
end
282279

283280
defp attach_file(project, run_id, file_path, _content) do
284-
# Determine attachment type from file extension
285-
ext =
286-
file_path
287-
|> String.downcase()
288-
|> Path.extname()
289-
290-
_attachment_type =
291-
case ext do
292-
".xml" -> "CodeCoverage"
293-
".cobertura" -> "CodeCoverage"
294-
".trx" -> "TmiTestRunSummaryResult"
295-
_ -> "GeneralAttachment"
296-
end
297-
298281
# Mark the run as completed
299282
_ = Client.patch("/#{project}/_apis/test/runs/#{run_id}", %{"state" => "Completed"})
300283

lib/ado_cli/cli/work_items.ex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,14 @@ defmodule AdoCli.CLI.WorkItems do
271271
|> add_wiql_filter(Map.get(parsed.options, :state), "System.State")
272272

273273
wiql =
274-
"SELECT [System.Id], [System.Title], [System.State], [System.WorkItemType], [System.AssignedTo] " <>
275-
"FROM WorkItems " <>
276-
"WHERE #{Enum.join(where_clauses, " AND ")} " <>
274+
IO.iodata_to_binary([
275+
"SELECT [System.Id], [System.Title], [System.State], [System.WorkItemType], [System.AssignedTo] ",
276+
"FROM WorkItems ",
277+
"WHERE ",
278+
Enum.join(where_clauses, " AND "),
279+
" ",
277280
"ORDER BY [System.Id] DESC"
281+
])
278282

279283
run_wiql_query(project, wiql, parsed)
280284
end

0 commit comments

Comments
 (0)