-
Notifications
You must be signed in to change notification settings - Fork 87
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
Use of defaults in code #525
Comments
Your concern is very valid. -spec default(module(), atom(), atom()) -> term().
default(elvis_style, line_length, limit) -> 100;
default(elvis_style, line_length, skip_comments) -> false;
… …or even… -spec default(module(), atom()) -> #{atom() => term()}.
default(elvis_style, line_length) -> #{limit => 100, skip_comments => false};
… So that it can be used directly in the rulesets. |
Thanks, @elbrujohalcon. I think I'll go with a mix of both. A function that allows for an easier to maintain |
Something like -spec default(module(), function(), Option :: atom()) -> DefaultValue :: term().
default(elvis_style, line_length, limit) -> 100;
default(elvis_style, line_length, skip_comments) -> false.
-spec default(module(), function()) -> DefaultOption :: term().
default(elvis_style = M, line_length = F) -> #{limit => default(M, F, limit),
skip_comments => default(M, F, limit)}. , perhaps? |
maps:get(skip_comments, RuleConfig, false) would become a more generic get_option(M, F, Option, RuleConfig) ->
maps:get(Option, RuleConfig, default(M, F, Option)). or is this too abstract? |
The way I'm looking at this now, which thus implied changes to two test cases, is that:
|
I don't really like having 2 |
I like this but it has to be properly documented. |
Where should it be documented? |
Sure, will do. It's an extra |
It shouldn't be performance degrading.
Probably here. |
Should this be enough:
|
Yeah! |
Done! |
Due to the fact that the defaults in
elvis_rulesets.erl
andelvis_style.erl
aren't always the same, the following might happen.My
elvis.config
file has{elvis_style, line_length, #{}}
. If I look at the Wiki, I might (wrongly assume the default is 100). The default being applied, in this case, isn't coming from the rulesets but from the style, since the option map is present but the key isn't, which meansmaps:get(limit, RuleConfig, 80)
evaluates to 80, not 100 (as expected).Do you think it's best to:
?
The text was updated successfully, but these errors were encountered: