Skip to content

Commit

Permalink
Don't emit warnings for parsed code
Browse files Browse the repository at this point in the history
At least on newer versions of Elixir
  • Loading branch information
rrrene committed May 2, 2024
1 parent 3612dc2 commit 90b83e8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/credo/code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,24 @@ defmodule Credo.Code do

@doc false
def ast(source, filename \\ "nofilename") when is_binary(source) do
case Code.string_to_quoted(source, line: 1, columns: true, file: filename) do
{:ok, value} ->
{:ok, value}

{:error, error} ->
{:error, [issue_for(error, filename)]}
case string_to_quoted(source, filename) do
{:ok, value} -> {:ok, value}
{:error, error} -> {:error, [issue_for(error, filename)]}
end
rescue
e in UnicodeConversionError ->
{:error, [issue_for({1, e.message, nil}, filename)]}
end

defp string_to_quoted(source, filename) do
Code.string_to_quoted(source,
line: 1,
columns: true,
file: filename,
emit_warnings: false
)
end

defp issue_for({line_no, error_message, _}, filename) do
%Credo.Issue{
check: ParserError,
Expand Down

0 comments on commit 90b83e8

Please sign in to comment.