Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to not warn on calls to IO.inspect/3 #1149

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading