credo icon indicating copy to clipboard operation
credo copied to clipboard

False positive on Credo.Check.Refactor.Apply when piped

Open halostatue opened this issue 3 years ago • 1 comments

I had false positives on this when I had changed from apply(module, fun, [arg1, arg2]) to a piped version (because there was another call around it).

I decided to make a verification in tests rather than try to specify it otherwise.

Environment

  • Credo version (mix credo -v): 1.6.6 / master
  • Erlang/Elixir version (elixir -v): 1.13.4 / OTP 24
  • Operating system: macOS

What were you trying to do?

  test "it should NOT report violation for piped apply/3 when fun is a var" do
    """
    defmodule Test do
      def some_function(module, fun, arg1, arg2) do
        module
        |> apply(fun, [arg1, arg2])
      end
    end
    """
    |> to_source_file
    |> run_check(@described_check)
    |> refute_issues()
  end

Expected outcome

.

Actual outcome

  1) test it should NOT report violation for piped apply/3 when fun is a var (Credo.Check.Refactor.ApplyTest)
     test/credo/check/refactor/apply_test.exs:110
     There should be no issues, got 1: [
       %Credo.Issue{
         category: :refactor,
         check: Credo.Check.Refactor.Apply,
         column: nil,
         diff_marker: nil,
         exit_status: 8,
         filename: "test-untitled-576460752303404795.ex",
         line_no: 4,
         message: "Avoid `apply/2` and `apply/3` when the number of arguments is known",
         meta: [],
         priority: -7,
         scope: "Test.some_function",
         severity: 1,
         trigger: nil
       }
     ]
     code: |> refute_issues()
     stacktrace:
       (credo 1.6.6) lib/credo/test/assertions.ex:17: Credo.Test.Assertions.refute_issues/1
       test/credo/check/refactor/apply_test.exs:121: (test)

halostatue avatar Aug 30 '22 03:08 halostatue

Thx for reporting! 👍

rrrene avatar Aug 30 '22 04:08 rrrene