rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

Credo.Check.Design.SkipTestWithoutComment and many others, fail to run (Elixir 1.17 issue?) #1141

Closed joze144 closed 2 months ago

joze144 commented 2 months ago

Environment

What were you trying to do?

Expected outcome

Actual outcome

** (EXIT from #PID<0.98.0>) an exception was raised:
    ** (CaseClauseError) no case clause matching: {:ok, 9, 1, [], [{:eol, {8, 4, 1}}, {:end, {8, 1, nil}}, {:eol, {7, 6, 1}}, {:end, {7, 3, nil}}, {:eol, {6, 84, 1}}, {:bin_string, {6, 40, nil}, ["Peace of mind from prototype to production"]}, {:comp_op, {6, 37, nil}, :=~}, {:")", {6, 35, nil}}, {:int, {6, 32, 200}, ~c"200"}, {:",", {6, 30, 0}}, {:identifier, {6, 26, ~c"conn"}, :conn}, {:"(", {6, 25, nil}}, {:paren_identifier, {6, 12, ~c"html_response"}, :html_response}, {:identifier, {6, 5, ~c"assert"}, :assert}, {:eol, {5, 28, 1}}, {:")", {5, 27, nil}}, {:sigil, {5, 22, nil}, :sigil_p, ["/"], [], nil, "\""}, {:",", {5, 20, 0}}, {:identifier, {5, 16, ~c"conn"}, :conn}, {:"(", {5, 15, nil}}, {:paren_identifier, {5, 12, ~c"get"}, :get}, {:match_op, {5, 10, nil}, :=}, {:identifier, {5, 5, ~c"conn"}, :conn}, {:eol, {4, 33, 1}}, {:do, {4, 31, nil}}, {:"}", {4, 29, nil}}, {:identifier, {4, 25, ~c"conn"}, :conn}, {:kw_identifier, {4, 19, ~c"conn"}, :conn}, {:"{", {4, 17, nil}}, {:%{}, {4, 17, nil}}, {:",", {4, 15, 0}}, {:bin_string, {4, 8, nil}, ["GET /"]}, {:identifier, {4, 3, ~c"test"}, :test}, {:eol, {2, 31, 2}}, {:alias, {2, 23, ~c"ConnCase"}, :ConnCase}, {:., {2, 22, nil}}, {:alias, {2, 7, ~c"TestAppWeb"}, :TestAppWeb}, {:identifier, {2, 3, ~c"use"}, :use}, {:eol, {1, 48, 1}}, {:do, {1, 46, nil}}, {:alias, {1, 27, ...}, :PageControllerTest}, {:., {1, ...}}, {:alias, {...}, ...}, {:identifier, ...}], []}
        (credo 1.7.6) lib/credo/code.ex:138: Credo.Code.to_tokens/2
        (credo 1.7.6) lib/credo/code/interpolation_helper.ex:68: Credo.Code.InterpolationHelper.interpolation_positions/2
        (credo 1.7.6) lib/credo/code/interpolation_helper.ex:9: Credo.Code.InterpolationHelper.replace_interpolations/3
        (credo 1.7.6) lib/credo/code/sigils.ex:81: Credo.Code.Sigils.replace_with_spaces/5
        (credo 1.7.6) lib/credo/code.ex:176: Credo.Code.clean_charlists_strings_and_sigils/1
        (credo 1.7.6) lib/credo/check/design/skip_test_without_comment.ex:41: Credo.Check.Design.SkipTestWithoutComment.run/2
        (credo 1.7.6) lib/credo/check/design/skip_test_without_comment.ex:2: Credo.Check.Design.SkipTestWithoutComment.do_run_on_source_file/3
        (elixir 1.17.0) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2

It looks like there's an issue is in the function bellow. My result from :elixir_tokenizer.tokenize has one more parameter than expected. Not sure if that's a breaking change on Elixir 1.17 or is something wrong with my setup?

def to_tokens(source, filename \\ "nofilename") when is_binary(source) do
    source
    |> String.to_charlist()
    |> :elixir_tokenizer.tokenize(1, file: filename)
    |> case do
      # Elixir < 1.6
      {_, _, _, tokens} ->
        tokens

      # Elixir >= 1.6
      {:ok, tokens} ->
        tokens

      # Elixir >= 1.13
      {:ok, _, _, _, tokens} ->
        tokens

      {:error, _, _, _, tokens} ->
        tokens
    end
  end
joze144 commented 2 months ago

Saw that this is already fixed on the latest version, closing this issue