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)

Last Post!

DavidRawk-Blake

DavidRawk-Blake

The example is contrived. I don’t understand how people can’t see this. It’s meant to be silly..

Sometimes a function is only complex if you can’t read. Which is perfectly sane for a linter to catch. But the OP code isn’t complex.

Where Next?

Popular in Questions Top

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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement