jackfirth / jackfirth/resyntax
New rule: `Shared else-value for if/case`
Nobody has claimed this yet.
- Dominant language
- Racket
- Stars
- 70
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing refactoring-rule implementations and their test suite; the issue provides a positive Racket test case and points to renderer.rkt in the webracket repository as the observation site. Done means the shown if/case form is transformed into the case form while unrelated code remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100