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
al2o3cr
Looks like Pipe has similar functionality, for similar reasons:
Also Liked
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
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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









