A certain line where print_width is not respected
eproxus opened this issue · 4 comments
There's a bug where {print_width, 80}
is not respected when formatting the following module (doesn't compile because I tried to make a minimal example):
-module(hello).
% API
-export([start/2]).
start(_Opts, Routes) ->
App = foo,
AllRoutes = routes(App, [{"/hello", hello_static, #{app => hello}}|Routes]).
Line 8 is exactly 80 characters wide.
Actual outcome
-module(hello).
% API
-export([start/2]).
start(_Opts, Routes) ->
App = foo,
AllRoutes = routes(App, [{"/hello", hello_static, #{app => hello}} | Routes]). % width = 82
Line 8 is now 82 characters wide.
Expected outcome
-module(hello).
% API
-export([start/2]).
start(_Opts, Routes) ->
App = foo,
AllRoutes = routes(App, [
{"/hello", hello_static, #{app => hello}}
| Routes
]).
Additional Information
If I set the width to 79 it works, but of course changes formatting elsewhere in other files.
The bug happens when running rebar3 fmt --write src/hello.erl
and also via rebar3_formatter
.
Unfortunately this is a side effect of the underlying algorithm.
It tries its best to respect the print_width, but will sometimes overflow.
So this is working as expected.
Thank you for the very thorough report though and sorry for the delay in answering.
Maybe this should be documented somewhere? I guess as part of the design principles?
That being said, it is easy to fix by introducing a variable or a manual line break.
Good idea, how about #303
@awalterschulze Great, thanks! 🙇