Sebb

Sebb

Credo: how to exclude functions?

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

https://hexdocs.pm/credo/Credo.Check.Refactor.PipeChainStart.html

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

al2o3cr

al2o3cr

Looks like Pipe has similar functionality, for similar reasons:

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:

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

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
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 42633 214
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement