简体   繁体   English

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

[英]Elixir's mix format ignores line length option

I have an Elixir project .formatter.exs file in my project root that looks like this:我的项目根目录中有一个 Elixir 项目.formatter.exs文件,如下所示:

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

But as best I can tell, the line_length parameter is being ignored.但据我所知, line_length参数被忽略了。

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):给定以下代码,最长的行(长度为 102 个字符)总是被分成两行( when子句包装到新行):

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).相比之下,如果我将模块复制并粘贴到在线 Elixir 格式化程序中并将行长度选项设置为 120,则不会对文本进行任何更改(如预期)。

I must have screwed up the .formatter.exs somehow, but for the life of me I can't figure out how.我一定是搞砸了.formatter.exs不知何故,但对于我的生活,我无法弄清楚如何。

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

The solution was to edit apps/[my_app]/.formatter.exs (which had been auto-generated by mix new previously) with the line length parameter:解决方案是使用apps/[my_app]/.formatter.exs编辑apps/[my_app]/.formatter.exs (之前由mix new自动生成):

[
  line_length: 120
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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