From 3d9dae8294e267052f549d2d6310246b4ab3ae64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Sun, 20 Oct 2024 13:30:07 +0200 Subject: [PATCH] Do not count pin operator for ABC size Refs #1155 --- lib/credo/check/refactor/abc_size.ex | 2 +- test/credo/check/refactor/abc_size_test.exs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/credo/check/refactor/abc_size.ex b/lib/credo/check/refactor/abc_size.ex index ceafbdf1e..7c8a49fc2 100644 --- a/lib/credo/check/refactor/abc_size.ex +++ b/lib/credo/check/refactor/abc_size.ex @@ -27,7 +27,7 @@ defmodule Credo.Check.Refactor.ABCSize do @def_ops [:def, :defp, :defmacro] @branch_ops [:.] @condition_ops [:if, :unless, :for, :try, :case, :cond, :and, :or, :&&, :||] - @non_calls [:==, :fn, :__aliases__, :__block__, :if, :or, :|>, :%{}] + @non_calls [:==, :fn, :__aliases__, :__block__, :if, :or, :|>, :%{}, :^] @doc false @impl true diff --git a/test/credo/check/refactor/abc_size_test.exs b/test/credo/check/refactor/abc_size_test.exs index f5cf46f81..75112fbc3 100644 --- a/test/credo/check/refactor/abc_size_test.exs +++ b/test/credo/check/refactor/abc_size_test.exs @@ -336,6 +336,20 @@ defmodule Credo.Check.Refactor.ABCSizeTest do assert rounded_abc_size(source) == 3 end + test "it should NOT count pin operators (^) for abc size" do + source = """ + def test(param, foo) do + case param do + ^foo -> foo.bar + "bar" -> bar.baz + "baz" -> bux.bus + end + end + """ + + assert rounded_abc_size(source) == 6 + end + test "it should NOT count functions given to ignore for abc size" do source = """ def fun() do