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 Single Clause Case Statements #290

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

New rule: No Single Clause Case Statements #290

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

Comments

@elbrujohalcon
Copy link
Member

No Single Clause Case Statements

Brief Description

The following code…

case do:something() of
    {ok, Result} -> do:something(else)
end

…should actually be written using pattern-matching:

{ok, Result} = do:something(),
do:something(else)

The case statement is unnecessary and the only difference between the two is that the exception raised in the case of error changes from case_clause to badmatch.

Should be on by default?

YES

Options

  • None.

Reasoning

Paraphrasing Elm-Review documentation:

[…] single-pattern case expressions […] may be written more concisely or removed entirely.

Origin (#281)

Inspired by the NoSinglePatternCase rule from elm-review

@elbrujohalcon elbrujohalcon added this to the 3.0.0 milestone Mar 1, 2023
@paulo-ferraz-oliveira
Copy link
Collaborator

Should there be an equivalent to maybe?

@elbrujohalcon
Copy link
Member Author

Probably… I had not thought much about maybe yet… mostly because I had never used it yet. 🤷🏻
But feel free to write another ticket for that rule.

@elbrujohalcon elbrujohalcon self-assigned this Mar 1, 2023
@paulo-ferraz-oliveira paulo-ferraz-oliveira changed the title No Single Clause Case Statements New rule: No Single Clause Case Statements Mar 1, 2023
elbrujohalcon added a commit that referenced this issue Mar 1, 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

2 participants