From 9168d5121029f2f2e5853134cf4705e50b480116 Mon Sep 17 00:00:00 2001 From: Noah Betzen Date: Sun, 3 Nov 2024 12:32:14 -0800 Subject: [PATCH] Account for &dbg/1 --- lib/credo/check/warning/dbg.ex | 8 ++++++++ test/credo/check/warning/dbg_test.exs | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/credo/check/warning/dbg.ex b/lib/credo/check/warning/dbg.ex index ac748aa40..45c73cc80 100644 --- a/lib/credo/check/warning/dbg.ex +++ b/lib/credo/check/warning/dbg.ex @@ -75,6 +75,14 @@ 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 + {ast, [issue_for(issue_meta, meta, "dbg/1") | issues]} + end + defp traverse(ast, issues, _issue_meta) do {ast, issues} end diff --git a/test/credo/check/warning/dbg_test.exs b/test/credo/check/warning/dbg_test.exs index 226f2207f..357047b4c 100644 --- a/test/credo/check/warning/dbg_test.exs +++ b/test/credo/check/warning/dbg_test.exs @@ -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