Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect line breaks due to parentheses #320

Open
jrogov opened this issue Oct 11, 2021 · 0 comments
Open

Incorrect line breaks due to parentheses #320

jrogov opened this issue Oct 11, 2021 · 0 comments

Comments

@jrogov
Copy link

jrogov commented Oct 11, 2021

Here's a formatting issue I've encountered a few times. The distilled code with default settings is the following:

%% No 100-col overflow: oneliner.
ok() ->
    #{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvvvv}.

%% 100-col overflow: formatted map.
ok_overflow() ->
    #{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvvvv}.

%% Same 100-col overflow, but not handled correctly (assumably due to parens): no reformatting at all
not_ok_overflow() ->
    (#{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvv}).

%% Same 100-col overflow, but handled correctly because of additional "v" char
plus_one_char_ok_overflow() ->
    (#{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvvv}).

It's pretty explanatory, but the problem is that not_ok_overflow/0's body is not properly formatted. Hypothesis is that it happens because of how parens are treated. Took a quick dive into the code, so can't say for sure.

I do acknowledge that width-enforcement is "best-effort", but this case seems like there is something that can be improved.

Steps to reproduce

(as a shell script)

rebar3 new lib name=efmt_parens_issue
cd efmt_parens_issue/
cat >>src/efmt_parens_issue.erl <<EOF
%% No 100-col overflow: oneliner.

%% No 100-col overflow: oneliner.
ok() ->
    #{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvvvv}.

%% 100-col overflow: formatted map.
ok_overflow() ->
    #{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvvvv}.

%% Same 100-col overflow, but not handled correctly (assumably due to parens)
not_ok_overflow() ->
    (#{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvv}).

%% Same 100-col overflow, but handled correctly because of additional "v" char
plus_one_char_ok_overflow() ->
    (#{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvvv}).
EOF

echo -e '\n{plugins, [{erlfmt, "1.0.0"}]}.' >> rebar.config
cat src/efmt_parens_issue.erl | tail -n5 | head -n1 | wc -c
# Outputs 102, yet this line had to be split into multiple lines
rebar3 fmt -w

# To demonstrate how it looks
tail -n10 src/efmt_parens_issue.erl
# Yet not_ok_overflow/0 wasn't properly formatted:
# %% Same 100-col overflow, but not handled correctly (assumably due to parens): no reformatting at all
# not_ok_overflow() ->
#     (#{k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvv}).
#
# %% Same 100-col overflow, but handled correctly because of additional "v" char
# plus_one_char_ok_overflow() ->
#     (#{
#         k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => v, k => vvvvvvv
#     }).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant