Skip to content

Commit 40d995d

Browse files
Copilotjackfirth
andauthored
Remove miscellaneous-suggestions suite (#669)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jackfirth <[email protected]>
1 parent cee1df8 commit 40d995d

File tree

6 files changed

+142
-85
lines changed

6 files changed

+142
-85
lines changed

default-recommendations.rkt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
resyntax/default-recommendations/loops/list-loopification
3434
resyntax/default-recommendations/loops/named-let-loopification
3535
resyntax/default-recommendations/match-shortcuts
36-
resyntax/default-recommendations/miscellaneous-suggestions
3736
resyntax/default-recommendations/mutability-predicates
3837
resyntax/default-recommendations/numeric-shortcuts
3938
resyntax/default-recommendations/require-and-provide-suggestions
@@ -75,7 +74,6 @@
7574
resyntax/default-recommendations/loops/list-loopification
7675
resyntax/default-recommendations/loops/named-let-loopification
7776
resyntax/default-recommendations/match-shortcuts
78-
resyntax/default-recommendations/miscellaneous-suggestions
7977
resyntax/default-recommendations/mutability-predicates
8078
resyntax/default-recommendations/numeric-shortcuts
8179
resyntax/default-recommendations/require-and-provide-suggestions
@@ -123,7 +121,6 @@
123121
make-temporary-directory-migration
124122
match-let-replacement
125123
match-shortcuts
126-
miscellaneous-suggestions
127124
mutability-predicates
128125
named-let-loopification
129126
numeric-shortcuts

default-recommendations/conditional-shortcuts-test.rkt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,49 @@ no-change-test: "cond with unshared tail expression not refactorable to when"
828828
[else
829829
(displayln "false tail")]))
830830
--------------------
831+
832+
833+
test: "if with else cond can be flattened to cond"
834+
- (if 'a 'b (cond ['c 'd] ['e 'f]))
835+
------------------------------
836+
(cond
837+
['a 'b]
838+
['c 'd]
839+
['e 'f])
840+
------------------------------
841+
842+
843+
test: "cond with else-if can be collapsed"
844+
- (cond ['a 'b] ['c 'd] [else (if 'e 'f 'g)])
845+
------------------------------
846+
(cond
847+
['a 'b]
848+
['c 'd]
849+
['e 'f]
850+
[else 'g])
851+
------------------------------
852+
853+
854+
test: "cond with begin in clause can be simplified"
855+
------------------------------
856+
(cond ['a (begin 'b 'c 'd)])
857+
==============================
858+
(cond
859+
['a
860+
'b
861+
'c
862+
'd])
863+
------------------------------
864+
865+
866+
test: "cond with begin in middle clause can be simplified"
867+
------------------------------
868+
(cond ['a 'b] ['c (begin 'd 'e)] ['f 'g])
869+
==============================
870+
(cond
871+
['a 'b]
872+
['c
873+
'd
874+
'e]
875+
['f 'g])
876+
------------------------------

default-recommendations/conditional-shortcuts.rkt

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,18 @@
9191
#:attributes (negated? condition [body 1])
9292
#:literals (cond void not begin let)
9393

94-
(pattern (cond [(not condition) (void)] [else :block-expression]) #:with negated? #false)
95-
(pattern (cond [(not condition) :block-expression] [else (void)]) #:with negated? #true)
96-
(pattern (cond [condition (void)] [else :block-expression]) #:with negated? #true)
97-
(pattern (cond [condition :block-expression] [else (void)]) #:with negated? #false))
94+
(pattern (cond [(not condition) (void)] [else block-expr:block-expression])
95+
#:with negated? #false
96+
#:with (body ...) #'(block-expr.body ...))
97+
(pattern (cond [(not condition) block-expr:block-expression] [else (void)])
98+
#:with negated? #true
99+
#:with (body ...) #'(block-expr.body ...))
100+
(pattern (cond [condition (void)] [else block-expr:block-expression])
101+
#:with negated? #true
102+
#:with (body ...) #'(block-expr.body ...))
103+
(pattern (cond [condition block-expr:block-expression] [else (void)])
104+
#:with negated? #false
105+
#:with (body ...) #'(block-expr.body ...)))
98106

99107

100108
(define-refactoring-rule cond-void-to-when-or-unless
@@ -236,13 +244,56 @@ tail expression outside `cond` lets you replace `cond` with `when`."
236244
body-after ...))
237245

238246

247+
(define if-begin-to-cond-message
248+
"The `cond` form supports multiple body expressions in each branch, making `begin` unnecessary.")
249+
250+
251+
(define-refactoring-rule if-else-cond-to-cond
252+
#:description if-begin-to-cond-message
253+
#:literals (if cond)
254+
(if condition then-branch (cond clause ...))
255+
(cond [condition then-branch] clause ...))
256+
257+
258+
(define-refactoring-rule cond-else-if-to-cond
259+
#:description "The `else`-`if` branch of this `cond` expression can be collapsed into the `cond`\
260+
expression."
261+
#:literals (cond else if)
262+
(cond clause ... [else (if inner-condition inner-then-branch else-branch)])
263+
(cond clause ... [inner-condition inner-then-branch] [else else-branch]))
264+
265+
266+
(define-refactoring-rule cond-begin-to-cond
267+
#:description "The bodies of `cond` clauses are already implicitly wrapped in `begin`."
268+
#:literals (cond begin else void)
269+
(cond clause-before ... [condition (begin body ...)] clause-after ...)
270+
;; Don't match if this is the else clause of a cond that could be converted to when/unless
271+
#:when (not (and (empty? (attribute clause-after))
272+
(= (length (attribute clause-before)) 1)
273+
(syntax-parse (first (attribute clause-before))
274+
#:literals (void not)
275+
[(~or [_ (void)]
276+
[(not _) (void)]) #true]
277+
[_ #false])))
278+
;; Also don't match if the clause after is [else (void)]
279+
#:when (or (empty? (attribute clause-after))
280+
(syntax-parse #'(clause-after ...)
281+
#:literals (else void)
282+
[(~not ([else (void)])) #true]
283+
[_ #false]))
284+
(cond clause-before ... [condition body ...] clause-after ...))
285+
286+
239287
(define-refactoring-suite conditional-shortcuts
240288
#:rules (always-throwing-cond-to-when
241289
always-throwing-if-to-when
290+
cond-begin-to-cond
242291
cond-else-cond-to-cond
292+
cond-else-if-to-cond
243293
cond-void-to-when-or-unless
244294
explicit-cond-else-void
245295
if-begin-to-cond
296+
if-else-cond-to-cond
246297
if-else-false-to-and
247298
if-void-to-when-or-unless
248299
if-x-else-x-to-and

default-recommendations/match-shortcuts-test.rkt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,34 @@ test: "refactoring list element variable definitions to match-define doesn't ref
474474
------------------------------
475475

476476

477+
test: "and with match on same identifier can be simplified"
478+
------------------------------
479+
(define (f x)
480+
(and x (match x [1 2])))
481+
==============================
482+
(define (f x)
483+
(match x
484+
[#f #f]
485+
[1 2]))
486+
------------------------------
487+
488+
489+
test: "and with match on same identifier preserves formatting"
490+
------------------------------
491+
(define (foo some-var)
492+
(and some-var
493+
(match some-var
494+
['first-case 'first-result]
495+
['second-case 'second-result])))
496+
==============================
497+
(define (foo some-var)
498+
(match some-var
499+
[#f #f]
500+
['first-case 'first-result]
501+
['second-case 'second-result]))
502+
------------------------------
503+
504+
505+
no-change-test: "and with match on different identifiers not refactorable"
506+
- (define (foo x y) (and x (match y ['a 'b] ['c 'd])))
477507

default-recommendations/match-shortcuts.rkt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,18 @@ elements than expected."
265265
(body-before ... (~focus-replacement-on match-definition) body-after ...))
266266

267267

268+
(define-refactoring-rule and-match-to-match
269+
#:description "This `and` expression can be turned into a clause of the inner `match` expression,\
270+
reducing nesting."
271+
#:literals (and match)
272+
(and and-subject:id (match match-subject:id match-clause ...))
273+
#:when (free-identifier=? #'and-subject #'match-subject)
274+
(match match-subject [#false #false] match-clause ...))
275+
276+
268277
(define-refactoring-suite match-shortcuts
269-
#:rules (list-element-definitions-to-match-define
278+
#:rules (and-match-to-match
279+
list-element-definitions-to-match-define
270280
match-conditional-to-when
271281
predicate-pattern-with-lambda-to-when
272282
remove-unnecessary-root-and-pattern

default-recommendations/miscellaneous-suggestions.rkt

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)