我的项目根目录中有一个Elixir项目.formatter.exs
文件,看起来像这样:
[
line_length: 120,
inputs: ["mix.exs", "config/*.exs"],
subdirectories: ["apps/*"]
]
但是据我所知,line_length
参数被忽略。
给出下面的代码,最长的行(其长度为102个字符)总是被分成两行(when
子句换成新行):
defmodule SomeModule do
def lookup_data(parameter1, parameter2) when is_integer(parameter1) and is_integer(parameter2) do
:not_implemented
end
end
相反,如果我将模块复制并粘贴到the online Elixir formatter并将行长选项设置为120,则对文本没有任何更改(如预期)。
我一定以某种方式弄坏了.formatter.exs
,但对于我的一生,我不知道该怎么做。
在mix format docs中,它指出,如果您的顶层.formatter.exs
列出了子目录(我的有"apps/*"
),则顶层格式化程序的规则将不会在这些子目录中使用。
解决方案是使用行长参数编辑apps/[my_app]/.formatter.exs
(先前由mix new
自动生成):
[
line_length: 120
]