add new check for pipe per line
Some style guide proposes:
# not preferred
1 |> Integer.to_string() |> String.to_integer()
# preferred
1
|> Integer.to_string()
|> String.to_integer()
This PR provides a check for that.
--
Credits by @bamorim
@rrrene ping
This looks good.
The last thing I am wondering is if we covered all edge cases in the tests though.
Are there things we could be missing? Like "exotic" combinations of single line and multi line pipes?
String.to_integer(1 |> Integer.to_string())
|> Integer.to_string()
@rrrene that is a good point. The current approach just count pipes per line, so something like
value
|> do_something(:a |> to_string())
|> do_something_else()
Would fail. If we want this to be accepted, we would need to change. If we don't mind that much, we could suggest that this is changed either to an extracted variable or to something like
value
|> do_something(
:a
|> to_string()
)
|> do_seomthing_else()
The implementation to support that case would require us parsing the AST and counting |> per line per tree depth, which is harder to implement and I'm not sure worth it.
This is part of Credo v1.7.0-rc.1 :+1: