简体   繁体   中英

Elixir's mix format ignores line length option

I have an Elixir project .formatter.exs file in my project 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.

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
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM