Skip to content

Commit

Permalink
Add quasiquote-to-append rule (#328)
Browse files Browse the repository at this point in the history
Closes #326.
  • Loading branch information
jackfirth authored Sep 25, 2024
1 parent be4ae49 commit 69fb819
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions default-recommendations/list-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ test: "unnecessary quasiquotation with constants refactorable to list"
------------------------------


test: "unnecessary splicing quasiquotation refactorable to append"
------------------------------
(define (f xs ys zs)
`(,@xs ,@ys ,@zs))
------------------------------
------------------------------
(define (f xs ys zs)
(append xs ys zs))
------------------------------


test: "splicing quasiquotation with other subterms not refactorable to append"
------------------------------
(define (f xs ys zs)
`(a ,@xs b ,@ys c ,@zs d))
------------------------------


test: "ignored map expression refactorable to for-each"
------------------------------
(define (f func xs ys zs)
Expand Down
10 changes: 9 additions & 1 deletion default-recommendations/list-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,18 @@

(define-refactoring-rule quasiquote-to-list
#:description "This quasiquotation is equialent to a simple `list` call."
#:literals (quasiquote unquote)
#:literals (quasiquote)
(quasiquote (arg:unquoted ...))
(list arg.expr ...))


(define-refactoring-rule quasiquote-to-append
#:description "This quasiquotation is equialent to calling `append`."
#:literals (quasiquote unquote-splicing)
(quasiquote ((unquote-splicing arg) ...))
(append arg ...))


(define-definition-context-refactoring-rule ignored-map-to-for-each
#:description "The result of this `map` expression is unused. Consider using `for-each` instead."
#:literals (map)
Expand All @@ -134,5 +141,6 @@
filter-to-remv*
first-reverse-to-last
ignored-map-to-for-each
quasiquote-to-append
quasiquote-to-list
sort-with-keyed-comparator-to-sort-by-key))

0 comments on commit 69fb819

Please sign in to comment.