elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.3k stars 3.35k forks source link

Formatter ignores dot_formatter on stdin #7433

Closed lasseebert closed 6 years ago

lasseebert commented 6 years ago

Environment

Current behavior

The formatter mix task ignores .formatter.exs, even when parsed in as --dot-formatter when the input is from stdin (-).

Example:

# formatter_test.ex
defmodule FormatterTest do
  1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0
end
#.formatter.exs
[
  inputs: ["mix.exs", "apps/*/mix.exs", "apps/*/{config,lib,test}/**/*.{ex,exs}"],
  line_length: 119
]

When I run the mix format task with stdin:

$ cat formatter_test.ex | mix format - --dot-formatter .formatter.exs 
defmodule FormatterTest do
  1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 +
    5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 +
    9 + 0
end

it breaks the lines at column 99 and not column 119 as specified in the .formatter.exs.

If I format with mix format formatter_test.ex it changes the file as expected to:

defmodule FormatterTest do
  1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 +
    1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0
end

Expected behavior

cat file.ex | mix format - --dot-formatter .formatter.exs should format in the same way as mix format file.ex --dot-formatter .formatter.exs

I have tested also in 1.6.1, where it works as expected. I suspect that the change was introduced in this commit: https://github.com/elixir-lang/elixir/commit/d896f541f1ffff6677b56e5f0c0ad04b8ce447ed

Is the change from 1.6.1 to 1.6.2 on purpose?

josevalim commented 6 years ago

It has been fixed in master and v1.6. We plan to release v1.6.3 soon with a fix for this. Thanks!

lasseebert commented 6 years ago

Ah, didn't think to try on master.

Thanks for the quick reply! :)