Skip to content

Commit

Permalink
add same option
Browse files Browse the repository at this point in the history
  • Loading branch information
bormilan committed Dec 15, 2024
1 parent c073ad2 commit 9f1c988
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc_rules/elvis_style/max_function_arity.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ but it applies to regular functions only (not anonymous ones).

- `max_arity :: non_neg_integer()`.
- default: `8`.
- `non_exported_max_arity :: non_neg_integer()`.
- `non_exported_max_arity :: non_neg_integer() | same`.
- default: `8`.

## Example
Expand Down
4 changes: 3 additions & 1 deletion src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,9 @@ max_anonymous_function_arity(Config, Target, RuleConfig) ->
[elvis_result:item()].
max_function_arity(Config, Target, RuleConfig) ->
ExportedMaxArity = option(max_arity, RuleConfig, max_function_arity),
NonExportedMaxArity = option(non_exported_max_arity, RuleConfig, max_function_arity),
NonExportedMaxArity =
specific_or_default(option(non_exported_max_arity, RuleConfig, max_function_arity),
ExportedMaxArity),
Root = get_root(Config, Target, RuleConfig),
IsFunction = fun(Node) -> ktn_code:type(Node) == function end,
Functions = elvis_code:find(IsFunction, Root),
Expand Down
7 changes: 7 additions & 0 deletions test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,13 @@ verify_max_function_arity(Config) ->
max_function_arity,
#{max_arity => 1, non_exported_max_arity => 2},
PathNonExportedFail),

[_, _, _, _, _] =
elvis_core_apply_rule(Config,
elvis_style,
max_function_arity,
#{max_arity => 3, non_exported_max_arity => same},
PathNonExportedPass),
ok.

-spec verify_max_anonymous_function_arity(config()) -> any().
Expand Down

0 comments on commit 9f1c988

Please sign in to comment.