From f782b703b58b044924c47f7f610191a73d54b48f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 17:05:19 +0000 Subject: [PATCH 1/3] Initial plan From ac58fb74cdf8cbbe4f09efbebd31cd6f331f8c66 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 17:17:53 +0000 Subject: [PATCH 2/3] Fix error-to-raise-arguments-error rule to check ~a context Co-authored-by: jackfirth <8175575+jackfirth@users.noreply.github.com> --- .../exception-suggestions-test.rkt | 15 +++++++++++++++ default-recommendations/exception-suggestions.rkt | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/default-recommendations/exception-suggestions-test.rkt b/default-recommendations/exception-suggestions-test.rkt index 81eb2d1b..ef44b33c 100644 --- a/default-recommendations/exception-suggestions-test.rkt +++ b/default-recommendations/exception-suggestions-test.rkt @@ -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)) +-------------------- diff --git a/default-recommendations/exception-suggestions.rkt b/default-recommendations/exception-suggestions.rkt index 98aa585e..1ef8ddd1 100644 --- a/default-recommendations/exception-suggestions.rkt +++ b/default-recommendations/exception-suggestions.rkt @@ -45,6 +45,16 @@ conventions." #:do [(define message-str (syntax-e (attribute message))) (define args-list (attribute arg))] #:when (= (length (regexp-match* #rx"~a" message-str)) (length args-list)) + ;; Check that all ~a occurrences are surrounded by spaces or at string boundaries + #:when (let ([matches (regexp-match-positions* #rx"~a" message-str)]) + (for/and ([match (in-list 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 From 7f0331cc3703325addf54e0b3855f8b25883bb7e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 17:22:51 +0000 Subject: [PATCH 3/3] Optimize to avoid duplicate regex computation Co-authored-by: jackfirth <8175575+jackfirth@users.noreply.github.com> --- .../exception-suggestions.rkt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/default-recommendations/exception-suggestions.rkt b/default-recommendations/exception-suggestions.rkt index 1ef8ddd1..c125acd3 100644 --- a/default-recommendations/exception-suggestions.rkt +++ b/default-recommendations/exception-suggestions.rkt @@ -43,18 +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 (let ([matches (regexp-match-positions* #rx"~a" message-str)]) - (for/and ([match (in-list 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?))) + #: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