-
Notifications
You must be signed in to change notification settings - Fork 11
New rule: Shared else-value for if/case #784
Copy link
Copy link
Open
Labels
new lintIssues suggesting new lints or pull requests implementing new lintsIssues suggesting new lints or pull requests implementing new lints
Description
Rule summary
From:
(if (symbol? level)
(case level
[(warning) 'warning]
[(danger) 'danger]
[(info success warning danger
primary secondary light dark) level]
[else 'info])
'info)
To:
(case level
[(warning) 'warning]
[(danger) 'danger]
[(info success warning danger
primary secondary light dark) level]
[else 'info])
The observation is that the value return by the else-arm of the if-expression,
is the same as the expression returned in the else-expression of the case.
Test case
#lang resyntax/test
test: "original code should be refactorable to new code"
--------------------
#lang racket
(define level 'foo)
(if (symbol? level)
(case level
[(warning) 'warning]
[else 'info])
'info)
====================
#lang racket
(define level 'foo)
(case level
[(warning) 'warning]
[else 'info])
--------------------No-change test case
Additional context
Spotted here:
https://github.com/soegaard/webracket/blob/main/lib/web-easy/renderer.rkt#L892
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
new lintIssues suggesting new lints or pull requests implementing new lintsIssues suggesting new lints or pull requests implementing new lints