jononomo

jononomo

Can I use the formatter to indent with three spaces?

I see that Elixir now comes with a .formatter.exs file:

# Used by "mix format"
[
 inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

How can I adjust this file so that it formats my Elixir files using three spaces for an indent?

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

You cannot no. The purpose of the formatter is to produce standardized code formatting across the community, which would be undercut if massive things like spacing were configurable.

dimitarvp

dimitarvp

Sadly it doesn’t go far enough. There are things where the formatter allows you to do whatever, like various newlines between @spec, @doc, a function head (without a body; where you can specify default argument values) and the functions bodies themselves. I had other examples in the past but sadly never wrote them down.

I remember having CI fail on me just a few days ago because after a refactor there was an extra newline between @spec and a function body which I trusted mix format to fix but it didn’t. :frowning:

So if anything, I’d celebrate a complete dictator Elixir formatter!

Rust does this really well. When I contracted for a few companies with it I was kind of bummed out initially – some code got reformatted really weirdly for my taste – but their devs convinced me that they prefer to not fiddle with rustfmt configuration (because it can be huge if you go down that rabbit hole). I ended up getting used to the enforced format and even liking it because it was designed to make the (sometimes very cryptic) Rust code easier to read. It took some getting used to though, but that’s another discussion entirely – Rust code can get very weird looking.

Last Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

3 posts were split to a new topic: Mix formatter for tabs instead of spaces

Where Next?

Popular in Questions Top

New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
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

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement