Skip to content

Commit

Permalink
Fix string-append-and-string-join-to-string-join (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfirth authored Jan 8, 2025
1 parent 2aba64a commit 3b85486
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
5 changes: 5 additions & 0 deletions default-recommendations/string-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ test: "string-append around string-join refactorable to string-join with keyword
- (string-join (list "fox" "hen" "dog") #:before-first "The " #:after-last " jumped")


test: "string-append before string-join with sep refactorable to string-join with #:before-first"
- (string-append "The " (string-join (list "fox" "hen" "dog") ", "))
- (string-join (list "fox" "hen" "dog") ", " #:before-first "The ")


test:
"multiline string-append around string-join refactorable to multiline string-join with keyword\
arguments"
Expand Down
22 changes: 8 additions & 14 deletions default-recommendations/string-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,23 @@
(~@ . after)))


(define-syntax-class keywordless-string-join-call
#:attributes ([original 1])
(define-splicing-syntax-class keywordless-string-join-call
#:literals (string-join)

(pattern ((~and id string-join) strs)
#:with (original ...) #'(id strs))

(pattern ((~and id string-join) strs sep)
#:with (original ...) #'(id sep)))
(pattern (~seq string-join strs (~optional sep))))


(define-syntax-class string-append-and-string-join-expression
#:attributes (refactored)
#:literals (string-append)

(pattern (string-append before join-call:keywordless-string-join-call)
#:with refactored #'(join-call.original ... #:before-first before))
(pattern (string-append before (join-call:keywordless-string-join-call))
#:with refactored #'((~@ . join-call) #:before-first before))

(pattern (string-append join-call:keywordless-string-join-call after)
#:with refactored #'(join-call.original ... #:after-last after))
(pattern (string-append (join-call:keywordless-string-join-call) after)
#:with refactored #'((~@ . join-call) #:after-last after))

(pattern (string-append before join-call:keywordless-string-join-call after)
#:with refactored #'(join-call.original ... #:before-first before #:after-last after)))
(pattern (string-append before (join-call:keywordless-string-join-call) after)
#:with refactored #'((~@ . join-call) #:before-first before #:after-last after)))


(define-refactoring-rule string-append-and-string-join-to-string-join
Expand Down

0 comments on commit 3b85486

Please sign in to comment.