Skip to content

Commit

Permalink
Set an explicit width limit on Inspect.Algebra. (#3)
Browse files Browse the repository at this point in the history
An explicit limit of 98 (equal to the value Mix formatter uses) prevents various formatting glitches that happened e.g. around comments and multiline lists.
  • Loading branch information
kzemek authored Apr 28, 2024
1 parent e89b2a6 commit ed0ce47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mix/tasks/es6_maps/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ defmodule Mix.Tasks.Es6Maps.Format do
escape: false,
locals_without_parens: opts.locals_without_parens
)
|> Inspect.Algebra.format(:infinity)
|> Inspect.Algebra.format(98)
|> then(&File.write!(filepath, &1))
end

Expand Down
25 changes: 25 additions & 0 deletions test/es6_maps_test/test/format_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,30 @@ defmodule Es6MapsTest.Format do
"""
end
'''

test_formatting "comments are not moved around",
original: """
defmodule Test do
use LoremIpsum,
lorem: [LoremIpsum],
ipsum: [
# Lorem Ipsum Dolor
LoremIpsumDolorSitAmetConsequaturAdipisciElit,
LoremIpsumDolorSitAmetConsequaturAdipisciElit,
LoremIpsumDolorSitAmetConsequaturAdipisciElit
]
end
"""

test_formatting "multiline list literals are not single-lined",
original: """
def test do
[
1,
2,
3
]
end
"""
end
end

0 comments on commit ed0ce47

Please sign in to comment.