Repository: rrrene/credo (elixir)

Issue:
PipeChainStart with :atom excluded fails on nil
The following code:
```elixir
foo(nil) |> bar()
```

will fail the `PipeChainStart` test even when `excluded_argument_types: [:atom]` is set. A logic issue with using `List.first()` and the list of arguments is the root cause of this.

Fixed in https://github.com/rrrene/credo/pull/713

Pull request description:
Fix logic issue with PipeChainStart, excluding :atoms, and nil. Fixes #712
Fixed logic issue with PipeChainStart when excluding `:atom` and using a `nil`. See #712.

Patch:
diff --git a/lib/credo/check/refactor/pipe_chain_start.ex b/lib/credo/check/refactor/pipe_chain_start.ex
index 00c7b788..3e5a7def 100644
--- a/lib/credo/check/refactor/pipe_chain_start.ex
+++ b/lib/credo/check/refactor/pipe_chain_start.ex
@@ -205,9 +205,10 @@ defmodule Credo.Check.Refactor.PipeChainStart do
     function_name = to_function_call_name(ast)
 
     found_argument_types =
-      arguments
-      |> List.first()
-      |> argument_type()
+      case arguments do
+        [nil | _] -> [:atom]
+        x -> x |> List.first() |> argument_type()
+      end
 
     Enum.member?(excluded_functions, function_name) ||
       Enum.any?(


Test patch:
diff --git a/test/credo/check/refactor/pipe_chain_start_test.exs b/test/credo/check/refactor/pipe_chain_start_test.exs
index f90a64e4..ce31e560 100644
--- a/test/credo/check/refactor/pipe_chain_start_test.exs
+++ b/test/credo/check/refactor/pipe_chain_start_test.exs
@@ -312,6 +312,22 @@ defmodule Credo.Check.Refactor.PipeChainStartTest do
     |> refute_issues(@described_check, excluded_argument_types: [:number])
   end
 
+  test "it should NOT report a violation for an excluded argument type /7" do
+    """
+    insert(:event) |> schedule_events()
+    """
+    |> to_source_file
+    |> refute_issues(@described_check, excluded_argument_types: [:atom])
+  end
+
+  test "it should NOT report a violation for an excluded argument type /8" do
+    """
+    foo(nil) |> bar()
+    """
+    |> to_source_file
+    |> refute_issues(@described_check, excluded_argument_types: [:atom])
+  end
+
   #
   # cases raising issues
   #