Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions default-recommendations/exception-suggestions-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,18 @@ test: "error with ~a at end of string"
(define (end-tilde x)
(raise-arguments-error 'end-tilde "value is" "x" x))
--------------------


no-change-test: "error with ~a in quotes should not be refactored"
--------------------
(define (find-output-radio-box label)
(error 'find-output-radio-box "could not find `~a' radio box"
label))
--------------------


no-change-test: "error with ~a in parentheses should not be refactored"
--------------------
(define (f x y)
(error 'f "bad point (~a, ~a)" x y))
--------------------
14 changes: 12 additions & 2 deletions default-recommendations/exception-suggestions.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,18 @@ conventions."
(error sym:expr message:str arg:id ...+)

#:do [(define message-str (syntax-e (attribute message)))
(define args-list (attribute arg))]
#:when (= (length (regexp-match* #rx"~a" message-str)) (length args-list))
(define args-list (attribute arg))
(define tilde-a-matches (regexp-match-positions* #rx"~a" message-str))]
#:when (= (length tilde-a-matches) (length args-list))
;; Check that all ~a occurrences are surrounded by spaces or at string boundaries
#:when (for/and ([match (in-list tilde-a-matches)])
(define start (car match))
(define end (cdr match))
(define before-ok? (or (= start 0)
(char-whitespace? (string-ref message-str (- start 1)))))
(define after-ok? (or (= end (string-length message-str))
(char-whitespace? (string-ref message-str end))))
(and before-ok? after-ok?))
#:do [(define cleaned-message (string-replace message-str "~a" ""))
;; Clean up extra spaces and trailing punctuation from placeholder removal
(define cleaned-message-normalized
Expand Down