Elixir的混合格式忽略行长选项

问题描述 投票:1回答:1

我的项目根目录中有一个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,但对于我的一生,我不知道该怎么做。

elixir code-formatting
1个回答
1
投票

mix format docs中,它指出,如果您的顶层.formatter.exs列出了子目录(我的有"apps/*"),则顶层格式化程序的规则将不会在这些子目录中使用。

解决方案是使用行长参数编辑apps/[my_app]/.formatter.exs(先前由mix new自动生成):

[
  line_length: 120
]
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.