File tree Expand file tree Collapse file tree 3 files changed +95
-0
lines changed
Expand file tree Collapse file tree 3 files changed +95
-0
lines changed Original file line number Diff line number Diff line change @@ -429,6 +429,38 @@ guide Resyntax's internal comment preservation system when the default behavior
429429 because such rules often touch only a small series of forms in a much larger definition context.}
430430
431431
432+ @subsection{Suppressing Specific Suggestions}
433+
434+ @defform[(resyntax-suppress rule-id body ...+)]{
435+ Suppresses the application of a specific @tech{refactoring rule} to the code in @racket[body]. The
436+ @racket[rule-id] must be the name of a refactoring rule. This form is useful when a refactoring
437+ suggestion makes sense generally, but is unhelpful in a specific context.
438+
439+ For example, suppose you have code that maintains visual symmetry by using similar comparisons with
440+ zero:
441+
442+ @(racketblock
443+ (and (= (- x y) 0 )
444+ (> (- x y) 0 )
445+ (< (- x y) 0 )))
446+
447+ While Resyntax would normally suggest simplifying @racket[(> (- x y) 0 )] to @racket[(> x y)], doing
448+ so would break the visual pattern. You can suppress this specific suggestion while still allowing
449+ other refactorings:
450+
451+ @(racketblock
452+ (resyntax-suppress comparison-of-difference-and-zero-to-direct-comparison
453+ (and (= (- x y) 0 )
454+ (> (- x y) 0 )
455+ (< (- x y) 0 ))))
456+
457+ The suppression applies to all code within the @racket[body] forms. Multiple expressions can be
458+ suppressed together, and suppression works with nested forms.
459+
460+ Note that @racket[resyntax-suppress] must be @racket[require ]d from @racket[resyntax/base] before
461+ use.}
462+
463+
432464@subsection{Resyntax's Default Rules}
433465@defmodule[resyntax/default-recommendations]
434466
Original file line number Diff line number Diff line change 1+ #lang resyntax/test
2+
3+
4+ require: resyntax/default-recommendations comparison-shortcuts
5+
6+
7+ header:
8+ ------------------------------
9+ #lang racket/base
10+ (require resyntax/base)
11+ (define x 1 )
12+ (define y 2 )
13+ ------------------------------
14+
15+
16+ no-change-test: "suppressing comparison rule prevents refactoring "
17+ ------------------------------
18+ (resyntax-suppress comparison-of-difference-and-zero-to-direct-comparison
19+ (> (- x y) 0 ))
20+ ------------------------------
21+
22+
23+ test: "unsuppressed comparison is refactored "
24+ - (> (- x y) 0 )
25+ - (> x y)
26+
27+
28+ no-change-test: "specific comparison in symmetrical context can be suppressed "
29+ ------------------------------
30+ ;; Example from the issue - maintaining visual symmetry
31+ (resyntax-suppress comparison-of-difference-and-zero-to-direct-comparison
32+ (and (= (- x y) 0 )
33+ (> (- x y) 0 )
34+ (< (- x y) 0 )))
35+ ------------------------------
Original file line number Diff line number Diff line change @@ -38,3 +38,31 @@ test: "suppression is specific to the rule name"
3838(resyntax-suppress nested-or-to-flat-or
3939 (and 1 2 3 ))
4040------------------------------
41+
42+
43+ no-change-test: "multiple expressions can be suppressed in one form "
44+ ------------------------------
45+ (resyntax-suppress nested-and-to-flat-and
46+ (and 1 (and 2 3 ))
47+ (and 4 (and 5 6 )))
48+ ------------------------------
49+
50+
51+ no-change-test: "suppression works with nested forms "
52+ ------------------------------
53+ (resyntax-suppress nested-and-to-flat-and
54+ (define x (and 1 (and 2 3 )))
55+ (define y (and 4 (and 5 6 ))))
56+ ------------------------------
57+
58+
59+ test: "suppression outside a form doesn't affect it "
60+ ------------------------------
61+ (resyntax-suppress nested-and-to-flat-and
62+ (define x 1 ))
63+ (and 1 (and 2 3 ))
64+ ==============================
65+ (resyntax-suppress nested-and-to-flat-and
66+ (define x 1 ))
67+ (and 1 2 3 )
68+ ------------------------------
You can’t perform that action at this time.
0 commit comments