Elixir's mix format ignores line length option in umbrella project
Asked Answered
L

1

9

I have an Elixir project .formatter.exs file in my umbrella app's root that looks like this:

[
  line_length: 120,
  inputs: ["mix.exs", "config/*.exs"],
  subdirectories: ["apps/*"]
]

But as best I can tell, the line_length parameter is being ignored.

Given the following code, the longest line (whose length is 102 characters) is always being split into two lines (with the when clause wrapped to the new line):

defmodule SomeModule do
  def lookup_data(parameter1, parameter2) when is_integer(parameter1) and is_integer(parameter2) do
    :not_implemented
  end
end

In contrast, if I copy & paste the module into the online Elixir formatter and set the line length option to 120, I get no changes to the text (as expected).

I must have screwed up the .formatter.exs somehow, but for the life of me I can't figure out how.

Lorilee answered 30/12, 2019 at 19:1 Comment(0)
L
13

In the mix format docs, it notes that if your top-level .formatter.exs lists subdirectories (mine has "apps/*"), the rules from the top-level formatter won't be used in those subdirectories.

The solution was to edit apps/[my_app]/.formatter.exs (which had been auto-generated by mix new previously) with the line length parameter:

[
  line_length: 120
]
Lorilee answered 30/12, 2019 at 19:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.