cd-slash

cd-slash

Formatter breaking code by adding new lines below `attr/3`

I’ve come across a few instances recently where the built-in formatter is breaking otherwise working code. As an example, take a Phoenix component with a moderately long default string attribute:

attr :text_color, :string, default: "text-gray-900 hover:text-primary-700 dark:text-gray-400 dark:hover:text-white"
attr :border, :string, default: "border focus:outline-none"

def button(assigns) do

end

This code works fine, except that with default settings the text_color attribute gets broken into 2 lines and a new line added below:

attr :text_color, :string,
    default: "text-gray-900 hover:text-primary-700 dark:text-gray-400 dark:hover:text-white"

attr :border, :string, default: "border focus:outline-none"

def button(assigns) do

end

The additional line between the two attr/3 statements breaks the component and results in a compiler error.

I’ve worked around this by adding line_length: 120 to my .formatter.exs file, but this is not an ideal workaround. I’m struggling to find a way to override the rule that’s causing this to break; can it be set to ignore attr/3 line length, for example, or even not apply the rule in this file type?

Most Liked

LostKobrakai

LostKobrakai

Newlines shouldn’t be a problem. E.g. the CoreComponents phoenix generates do have such attr defintions as well and I’ve not seen anyone have problems with that. By my understanding attr simply aggregates all attr invokations between functions, no matter the whitespace or other (valid) syntax between the individual attr calls.

If that’s a problem on your end I’d argue that’s a bug somewhere, not a problem with the formatter.

Can you post the error you’re getting?

Last Post!

cd-slash

cd-slash

You’re completely right, I seem to have made an error elsewhere and somehow thought it was a compiler error. My mistake, thanks for your inputs!

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
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

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 49084 226
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement