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

New rule: Param Pattern-Matching #284

Closed
elbrujohalcon opened this issue Feb 28, 2023 · 0 comments
Closed

New rule: Param Pattern-Matching #284

elbrujohalcon opened this issue Feb 28, 2023 · 0 comments
Assignees
Labels
Milestone

Comments

@elbrujohalcon
Copy link
Member

elbrujohalcon commented Feb 28, 2023

Consistent Param Pattern-Matching

Brief Description

When capturing a parameter using pattern matching you can either put the parameter name on the left (Param = #{pattern := ToMatch}) or right (#{pattern := ToMatch} = Param) side of the pattern that you use in the function clause. This rule will make sure you are consistent through your code and use always the same style.

Should be on by default?

YES

Options

  • preferred_style :: left | right (default: left)

Reasoning

Paraphrasing Credo documentation:

When capturing a parameter using pattern matching you can either put the parameter name before or after the value i.e.

parse(#{ok := Values} = Pair) ->

…or…

parse(Pair = #{ok := Values}) ->

Neither of these is better than the other, but it seems a good idea not to mix the two patterns in the same codebase.
While this is not necessarily a concern for the correctness of your code, you should use a consistent style throughout your codebase.

Origin (#281)

Inspired by the Consistency.ParameterPatternMatching rule from Credo

@elbrujohalcon elbrujohalcon added this to the 3.0.0 milestone Feb 28, 2023
@paulo-ferraz-oliveira paulo-ferraz-oliveira changed the title Consistent Param Pattern-Matching New rule: Consistent Param Pattern-Matching Mar 1, 2023
@elbrujohalcon elbrujohalcon self-assigned this Mar 2, 2023
@elbrujohalcon elbrujohalcon changed the title New rule: Consistent Param Pattern-Matching New rule: Param Pattern-Matching Mar 2, 2023
elbrujohalcon added a commit that referenced this issue Mar 2, 2023
…_matching

Fix #284: New Rule: Param Pattern Matching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant