Skip to content

Commit

Permalink
Add ignored-map-to-for-each
Browse files Browse the repository at this point in the history
Closes #223.
  • Loading branch information
jackfirth committed Sep 2, 2024
1 parent dd2b543 commit 11ea393
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions default-recommendations/list-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,20 @@ test: "unnecessary quasiquotation with constants refactorable to list"
(define (f x y z)
(list x 1 y 2 z 3))
------------------------------


test: "ignored map expression refactorable to for-each"
------------------------------
(define (f func xs ys zs)
; comment before
(map func xs ys zs)
; comment after
(displayln "foo"))
------------------------------
------------------------------
(define (f func xs ys zs)
; comment before
(for-each func xs ys zs)
; comment after
(displayln "foo"))
------------------------------
9 changes: 9 additions & 0 deletions default-recommendations/list-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
resyntax/default-recommendations/private/lambda-by-any-name
resyntax/default-recommendations/private/literal-constant
resyntax/default-recommendations/private/syntax-identifier-sets
resyntax/private/syntax-neighbors
resyntax/refactoring-rule
resyntax/refactoring-suite
syntax/parse)
Expand Down Expand Up @@ -120,6 +121,13 @@
(list arg.expr ...)])


(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)
[(~seq body-before ... (~and map-expr (map proc list ...)) body-after ...)
(body-before ... (~replacement (for-each proc list ...) #:original map-expr) body-after ...)])


(define list-shortcuts
(refactoring-suite
#:name (name list-shortcuts)
Expand All @@ -131,5 +139,6 @@
filter-to-remq*
filter-to-remv*
first-reverse-to-last
ignored-map-to-for-each
quasiquote-to-list
sort-with-keyed-comparator-to-sort-by-key)))

0 comments on commit 11ea393

Please sign in to comment.