Skip to content

Commit

Permalink
Merge pull request #1149 from jisaacstone/master
Browse files Browse the repository at this point in the history
Change to not warn on calls to IO.inspect/3
  • Loading branch information
rrrene authored Sep 22, 2024
2 parents 5af2172 + c1fd419 commit 8a03218
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 8a03218

Please sign in to comment.