Skip to content

Commit

Permalink
Change to not warn on calls to IO.inspect/3
Browse files Browse the repository at this point in the history
It seems unlikely that an inspect call with a specific file handler passed in would be
from a debugging session, so it makes sense to exclude these calls
  • Loading branch information
jisaacstone committed Sep 1, 2024
1 parent 1deaa53 commit c1fd419
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/credo/check/warning/io_inspect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ defmodule Credo.Check.Warning.IoInspect do
@impl true
def run(%SourceFile{} = source_file, params) do
issue_meta = IssueMeta.for(source_file, params)

Credo.Code.prewalk(source_file, &traverse(&1, &2, issue_meta))
end

defp traverse(
{{:., _, [{:__aliases__, meta, [:"Elixir", :IO]}, :inspect]}, _, _arguments} = ast,
{{:., _, [{:__aliases__, meta, [:"Elixir", :IO]}, :inspect]}, _, args} = ast,
issues,
issue_meta
) do
)
when length(args) < 3 do
{ast, issues_for_call(meta, "Elixir.IO.inspect", issues, issue_meta)}
end

defp traverse(
{{:., _, [{:__aliases__, meta, [:IO]}, :inspect]}, _meta, _arguments} = ast,
{{:., _, [{:__aliases__, meta, [:IO]}, :inspect]}, _, args} = ast,
issues,
issue_meta
) do
)
when length(args) < 3 do
{ast, issues_for_call(meta, "IO.inspect", issues, issue_meta)}
end

Expand Down
13 changes: 13 additions & 0 deletions test/credo/check/warning/io_inspect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ defmodule Credo.Check.Warning.IoInspectTest do
|> refute_issues()
end

test "it should NOT report Inspect/3" do
"""
defmodule CredoSampleModule do
def some_function(parameter1) do
IO.inspect(:stderr, parameter1, [])
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

#
# cases raising issues
#
Expand Down

0 comments on commit c1fd419

Please sign in to comment.