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: No Match in Condition #289

Closed
elbrujohalcon opened this issue Mar 1, 2023 · 0 comments
Closed

New rule: No Match in Condition #289

elbrujohalcon opened this issue Mar 1, 2023 · 0 comments
Assignees
Labels
Milestone

Comments

@elbrujohalcon
Copy link
Member

No Match in Condition

Brief Description

Pattern-matching should not be used in case statement conditions, like this:

case #{a := A} = do:something() of
    #{b := good} -> {a, really, nice, A};
    #{b := bad} -> {"not", a, good, A}
end

Should be on by default?

YES

Options

  • None

Reasoning

While the code as written above is valid, it's much harder to understand (particularly for large statements) than the one below.

Refactoring Proposal

case do:something() of
    #{a := A, b := good} -> {a, really, nice, A};
    #{a := A, b := bad} -> {"not", a, good, A}
end

Origin (#281)

Inspired by the Refactor.MatchInCondition rule from Credo

@elbrujohalcon elbrujohalcon added this to the 3.0.0 milestone Mar 1, 2023
@paulo-ferraz-oliveira paulo-ferraz-oliveira changed the title No Match in Condition New rule: No Match in Condition Mar 1, 2023
@elbrujohalcon elbrujohalcon self-assigned this Mar 2, 2023
elbrujohalcon added a commit that referenced this issue Mar 2, 2023
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