Sebb

Sebb

Credo: how to exclude functions?

The checks PipeChainStart and ABC-Size allow a parameter excluded_functions.
This does not seem to work.

I have this function credo does not like:

def hello do
    Kernel.+(1, 1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
    |> Kernel.+(1)
  end

credo complains:

┃ [F] → Function is too complex (ABC size is 31, max is 30).
┃       lib/credo_check.ex:3:7 #(CredoCheck.hello)
┃ [F] → Pipe chain should start with a raw value.
┃       lib/credo_check.ex:5 #(CredoCheck.hello)

with this config:

{Credo.Check.Refactor.PipeChainStart, [excluded_functions: ["hello"]]},
{Credo.Check.Refactor.ABCSize, [excluded_functions: ["hello"]]},

I also tried

  • :hello
  • "CredoCheck.hello"
  • "hello/0"
  • ~r/hello/

Marked As Solved

Also Liked

al2o3cr

al2o3cr

Based on the tests for PipeChainStart, excluded_functions is a list of functions that are allowed to start a chain, not functions that are allowed to have a chain in them:

https://github.com/rrrene/credo/blob/61a91b0abf3b085f60a41703d2fbcf361b5c1481/test/credo/check/refactor/pipe_chain_start_test.exs#L219-L229

You likely want inline config comments on hello instead.

gregvaughn

gregvaughn

This may be an unwelcome tangent, but credo would not complain if you wrote this code in the more idiomatic way

Worms.Repo.get(Transaction, transaction_id)

Where Next?

Popular in Questions Top

greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement