Skip to content

Commit

Permalink
Account for &dbg/1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nezteb committed Nov 3, 2024
1 parent 6b84f3f commit 677e47c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/credo/check/warning/dbg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ defmodule Credo.Check.Warning.Dbg do
{ast, [issue_for(issue_meta, meta, "dbg") | issues]}
end

defp traverse(
{:&, _, [{:/, _, [{:dbg, meta, _}, 1]}]} = ast,
issues,
issue_meta
) do
dbg(ast)
{ast, [issue_for(issue_meta, meta, "dbg/1") | issues]}
end

defp traverse(ast, issues, _issue_meta) do
{ast, issues}
end
Expand Down
17 changes: 17 additions & 0 deletions test/credo/check/warning/dbg_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,21 @@ defmodule Credo.Check.Warning.DbgTest do
assert issue.trigger == "dbg"
end)
end

test "it should report a violation /11" do
~S'''
defmodule CredoSampleModule do
def some_function(params) do
params
|> tap(&dbg/1)
end
end
'''
|> to_source_file
|> run_check(@described_check)
|> assert_issue(fn issue ->
assert issue.line_no == 4
assert issue.trigger == "dbg/1"
end)
end
end

0 comments on commit 677e47c

Please sign in to comment.