Skip to content

Commit

Permalink
Fix false negative in Dbg check
Browse files Browse the repository at this point in the history
Refs #1087
  • Loading branch information
rrrene committed Dec 11, 2023
1 parent ba29ca1 commit 7c33dc1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/credo/check/warning/dbg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ defmodule Credo.Check.Warning.Dbg do
{ast, issues_for_call(meta, issues, issue_meta)}
end

defp traverse(
{:|>, _, [_, {:dbg, meta, nil}]} = ast,
issues,
issue_meta
) do
{ast, issues_for_call(meta, issues, issue_meta)}
end

defp traverse(ast, issues, _issue_meta) do
{ast, issues}
end
Expand Down
14 changes: 14 additions & 0 deletions test/credo/check/warning/dbg_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,18 @@ defmodule Credo.Check.Warning.DbgTest do
|> run_check(@described_check)
|> assert_issue()
end

test "it should report a violation /10" do
~S'''
defmodule CredoSampleModule do
def headers_to_strings(headers) do
:x |> dbg
Enum.map(headers, fn {key, value} -> "#{key}: #{value}" end)
end
end
'''
|> to_source_file
|> run_check(@described_check)
|> assert_issue()
end
end

0 comments on commit 7c33dc1

Please sign in to comment.