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

Rebar3 format #2996

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Rebar3 format #2996

wants to merge 2 commits into from

Conversation

vkatsuba
Copy link
Member

@vkatsuba vkatsuba commented Jun 1, 2022

Description

Add https://github.com/AdRoll/rebar3_format. For run formatting just call:

$ rebar3 format

For verify if need to run formatting plugin, just need to run:

$ rebar3 format --verify

@williamthome
Copy link
Contributor

There is also the erlfmt.

$ rebar3 fmt

Also have a check command:

$ rebar3 fmt --check

The erlfmt repository has a comparison table with other formatters, including the rebar3_format.
I have used it and liked the code formatting.

@vkatsuba
Copy link
Member Author

vkatsuba commented Jun 2, 2022

The erlfmt repository has a comparison table with other formatters, including the rebar3_format.
I have used it and liked the code formatting.

@williamthome yep, thanks, I know about this tool. But in big project the rebar3_format was recommended a little bit more better then erlfmt. Plus if some issue will be show with rebar3_format - we can always politely ask @elbrujohalcon about improvements. BTW the rebar3_format can use erlfmt formater too if this will be necessary. But still, I repeat, I integrated this formatter in several projects and it has proven itself quite well.

@vkatsuba
Copy link
Member Author

vkatsuba commented Jun 2, 2022

@williamthome another important point is that rebar3_format can be configured as you want. You can ignore specific module, provide specific rules that suit your project and apply them. Full control and flexibility in the operation of the formatter configuration. (C) that’s something you can’t do with any other formatter.

@williamthome
Copy link
Contributor

williamthome commented Jun 2, 2022

@vkatsuba thanks for the explanation. For my use case, the erlfmt has worked well, since I have not worked on big erlang projects and most of the projects are for study. I will give it a try to the rebar3_fmt as soon as I can.

@vkatsuba vkatsuba force-pushed the rebar3-format branch 2 times, most recently from b13f59d to 5fade52 Compare June 2, 2022 08:13
@vkatsuba
Copy link
Member Author

vkatsuba commented Jun 2, 2022

@williamthome here is described config https://github.com/AdRoll/rebar3_format#configuration. Also was created a great topic https://tech.nextroll.com/blog/dev/2020/02/25/erlang-rebar3-format.html. Enjoy!

}).

-record(z_msg_v1,
{qos = 0 :: 0 | 1 | 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this { on this position, as either it is not a tab stop, or the list below is not a tab stop.

That is why I normally add the { at the end of the previous line.

location :: binary()
}).

-record(filestore_credentials_lookup, {id :: integer(), path :: binary()}).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it fits on a single line, wouldn't it be better (and consistent) to have it on multiple lines, like the other record definitions?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add -format #{inline_fields => none}. to this module or the equivalent option to the rebar.config if you want it for all modules. But… that won't put { on the initial line.

logger:get_handler_config()),
IsLogstasherNeeded =
lists:any(fun(#{ module := Module }) -> Module =:= logstasher_h end,
logger:get_handler_config()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I find this less readable than the non-reformatted version, also because the arguments are not a tab stop anymore.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add -format #{inline_simple_funs => false}. to this module or the equivalent option to the rebar.config file if you want it for all modules.

path => MnesiaDir,
result => error,
reason => Reason
}),
Copy link
Member

@mworrell mworrell Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the extra indentation? Does it want to push it at the same indent as the #{ ?

I also like to have the closing }) on the same level as the ?LOG_ERROR, as it is easier to scan upwards to see to what it belongs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That, sadly, is not yet an option for rebar3_format. Feel free to open a ticket (or a PR ;)) to add it.

Processes =
[% Ring buffer for http request logs
{ringbuffer_normal,
{ringbuffer_process, start_link, [zotonic_http_metrics_normal, LogBufferSize]},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like to have indents of a singe space, makes this less readable.

Is there a setting to have all indents on tab stops? (aka 4 chars)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, no. That comes straight up from OTP's prettypr. It's really hard to change. I know, because I also like 4-space indentations and I tried my best at achieving that and failed. Without improvements on OTP's prettypr, I doubt that rebar3_format will ever be available to give you that option.

terminal_notifier/1
]).
-export([compile_all/0, compile_all_sync/0, reload_modules/0, reload_module/1,
load_module/1, compile_options/1, terminal_notifier/1]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I find it easier to see what is exported by having all functions on their own line.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add -format #{inline_attributes => none}. to this module or the equivalent option to the rebar.config file if you want it for all modules.

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

Successfully merging this pull request may close these issues.

None yet

4 participants