Skip to content

Commit e1c24da

Browse files
jackfirthCopilot
andauthored
Improve ignored-map-to-for-each (#548)
Closes #546. Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jackfirth <[email protected]>
1 parent 440a28f commit e1c24da

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

default-recommendations/list-shortcuts-test.rkt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ test: "used map expression not refactorable to for-each"
175175
------------------------------
176176

177177

178+
test: "ignored map in begin0 refactorable to for-each"
179+
------------------------------
180+
(define (f xs)
181+
(begin0 42
182+
(map add1 xs)))
183+
==============================
184+
(define (f xs)
185+
(begin0 42
186+
(for-each add1 xs)))
187+
------------------------------
188+
189+
178190
test: "build-list with const refactorable to make-list"
179191
------------------------------
180192
(require racket/function

default-recommendations/list-shortcuts.rkt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@
128128
(append arg ...))
129129

130130

131-
(define-definition-context-refactoring-rule ignored-map-to-for-each
132-
#:description "The result of this `map` expression is unused. Consider using `for-each` instead."
131+
(define-refactoring-rule ignored-map-to-for-each
132+
#:description
133+
"The result of this `map` expression is unused. Make that explicit with `for-each` instead."
133134
#:literals (map)
134-
(~seq body-before ... (~and map-expr (map proc list ...)) body-after ...+)
135-
(body-before ... (~replacement (for-each proc list ...) #:original map-expr) body-after ...))
135+
(map proc list ...)
136+
#:when (equal? (syntax-property this-syntax 'expression-result) 'ignored)
137+
(for-each proc list ...))
136138

137139

138140
(define-refactoring-rule build-list-const-to-make-list

0 commit comments

Comments
 (0)