Skip to content

Commit 9eb7560

Browse files
Automated Resyntax fixes (#744)
Co-authored-by: resyntax-ci[bot] <181813515+resyntax-ci[bot]@users.noreply.github.com> Co-authored-by: Jack Firth <[email protected]>
1 parent f1f4f2e commit 9eb7560

File tree

7 files changed

+39
-45
lines changed

7 files changed

+39
-45
lines changed

cli.rkt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ For help on these, use 'analyze --help' or 'fix --help'."
302302

303303
(match (resyntax-analyze-options-output-destination options)
304304
['console
305-
(printf "resyntax: --- displaying results ---\n")
305+
(displayln "resyntax: --- displaying results ---")
306306
(display-results)]
307307
[(? path? output-path)
308-
(printf "resyntax: --- writing results to file ---\n")
308+
(displayln "resyntax: --- writing results to file ---")
309309
(with-output-to-file output-path display-results #:mode 'text)]))
310310

311311

@@ -347,7 +347,7 @@ For help on these, use 'analyze --help' or 'fix --help'."
347347
(define issue-string (if (> total-fixes 1) "issues" "issue"))
348348
(define file-string (if (> total-files 1) "files" "file"))
349349
(if (zero? total-fixes)
350-
(printf "Resyntax found no issues.\n")
350+
(displayln "Resyntax found no issues.")
351351
(printf "Resyntax fixed ~a ~a in ~a ~a.\n\n" total-fixes issue-string total-files file-string))
352352
(for ([rule+count (in-list fix-counts-by-rule)])
353353
(match-define (entry rule count) rule+count)
@@ -358,7 +358,7 @@ For help on these, use 'analyze --help' or 'fix --help'."
358358

359359

360360
(define (resyntax-fix-print-plain-text-summary analysis)
361-
(printf "resyntax: --- summary ---\n\n")
361+
(displayln "resyntax: --- summary ---\n")
362362
(define total-fixes (resyntax-analysis-total-fixes analysis))
363363
(define total-files (resyntax-analysis-total-sources-modified analysis))
364364
(define message
@@ -399,11 +399,11 @@ For help on these, use 'analyze --help' or 'fix --help'."
399399
(define issue-string (if (> total-fixes 1) "issues" "issue"))
400400
(define file-string (if (> total-files 1) "files" "file"))
401401
(if (zero? total-fixes)
402-
(printf "Resyntax found no issues.")
402+
(display "Resyntax found no issues.")
403403
(printf "Resyntax fixed ~a ~a in ~a ~a."
404404
total-fixes issue-string total-files file-string))
405405
(unless (zero? total-fixes)
406-
(printf "\n")
406+
(newline)
407407
(for ([rule+count (in-list fix-counts-by-rule)])
408408
(match-define (entry rule count) rule+count)
409409
(define occurrence-string (if (> count 1) "occurrences" "occurrence"))

default-recommendations/analyzers/private/expanded-id-table.rkt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@
5959
(define phase (expanded-identifier-phase id))
6060
(define stx (expanded-identifier-syntax id))
6161
(define phase-table (hash-ref (expanded-id-table-table table) phase #false))
62-
(if phase-table
63-
(free-id-table-ref phase-table stx failure-result)
64-
(if (procedure? failure-result)
65-
(failure-result)
66-
failure-result)))
62+
(cond
63+
[phase-table (free-id-table-ref phase-table stx failure-result)]
64+
[(procedure? failure-result) (failure-result)]
65+
[else failure-result]))
6766

6867

6968
(define (expanded-id-table-set! table id value)

default-recommendations/legacy/legacy-contract-migrations-test.rkt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,10 @@ test: "flat-contract in contract-out refactorable to predicate"
103103

104104

105105
test: "contract-struct refactorable to struct"
106-
------------------------------
107-
(contract-struct person (name age))
108-
==============================
109-
(struct person (name age))
110-
------------------------------
106+
- (contract-struct person (name age))
107+
- (struct person (name age))
111108

112109

113110
test: "define-contract-struct refactorable to struct with extra constructor"
114-
------------------------------
115-
(define-contract-struct point (x y))
116-
==============================
117-
(struct point (x y) #:extra-constructor-name make-point)
118-
------------------------------
111+
- (define-contract-struct point (x y))
112+
- (struct point (x y) #:extra-constructor-name make-point)

default-recommendations/let-binding-suggestions-test.rkt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ require: resyntax/default-recommendations let-binding-suggestions
77
header:
88
- #lang racket/base
99
test: "named lets which don't refer to the name are refactorable to unnamed lets"
10-
------------------------------
11-
(let loop ([x 1]) x)
12-
==============================
13-
(let ([x 1]) x)
14-
------------------------------
10+
- (let loop ([x 1]) x)
11+
- (let ([x 1]) x)
1512

1613

1714
no-change-test: "named lets which do refer to the name aren't refactorable to unnamed lets"

private/file-group.rkt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
(check-equal? (single-file-group-ranges group) (range-set (closed-open-range 1 10 #:comparator natural<=>))))
157157

158158
(test-case "file-group-resolve returns single file"
159-
(define test-dir (make-temporary-file "resyntax-test-~a" 'directory))
159+
(define test-dir (make-temporary-directory "resyntax-test-~a"))
160160
(define test-file (build-path test-dir "test.rkt"))
161161
(call-with-output-file test-file
162162
(λ (out) (displayln "#lang racket/base" out)))
@@ -175,7 +175,7 @@
175175
(check-equal? (directory-file-group-path group) (simple-form-path "/tmp")))
176176

177177
(test-case "file-group-resolve returns only .rkt files"
178-
(define test-dir (make-temporary-file "resyntax-test-~a" 'directory))
178+
(define test-dir (make-temporary-directory "resyntax-test-~a"))
179179
(define rkt-file1 (build-path test-dir "test1.rkt"))
180180
(define rkt-file2 (build-path test-dir "test2.rkt"))
181181
(define txt-file (build-path test-dir "test.txt"))
@@ -220,7 +220,7 @@
220220
(check-equal? (git-repository-file-group-ref group) "HEAD"))
221221

222222
(test-case "file-group-resolve with git repository"
223-
(define test-dir (make-temporary-file "resyntax-test-git-~a" 'directory))
223+
(define test-dir (make-temporary-directory "resyntax-test-git-~a"))
224224
(parameterize ([current-directory test-dir])
225225
(unless (system "git init -q")
226226
(fail "git init failed"))
@@ -246,7 +246,7 @@
246246

247247
(test-case "file-groups-resolve"
248248
(test-case "resolves multiple groups into hash"
249-
(define test-dir (make-temporary-file "resyntax-test-~a" 'directory))
249+
(define test-dir (make-temporary-directory "resyntax-test-~a"))
250250
(define test-file1 (build-path test-dir "test1.rkt"))
251251
(define test-file2 (build-path test-dir "test2.rkt"))
252252
(call-with-output-file test-file1
@@ -263,7 +263,7 @@
263263
(delete-directory/files test-dir))
264264

265265
(test-case "combines ranges for same file"
266-
(define test-dir (make-temporary-file "resyntax-test-~a" 'directory))
266+
(define test-dir (make-temporary-directory "resyntax-test-~a"))
267267
(define test-file (build-path test-dir "test.rkt"))
268268
(call-with-output-file test-file
269269
(λ (out) (displayln "#lang racket/base" out)))

private/syntax-delta.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
[(empty-syntax-path? start) #false]
8484
[(empty-syntax-path? next-start) #false]
8585
[(equal? (syntax-path-parent start) (syntax-path-parent next-start))
86-
(<= (+ (syntax-path-last-element start)) (syntax-path-last-element next-start))]
86+
(<= (syntax-path-last-element start) (syntax-path-last-element next-start))]
8787
[else #true]))
8888
(unless disjoint?
8989
(raise-arguments-error 'syntax-delta "overlapping splices"

private/syntax-path.rkt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,23 @@
277277
'string->syntax-path
278278
"syntax path string must not end with / (except for root path)"
279279
"given" str))
280-
(if (equal? str "/")
281-
empty-syntax-path
282-
(let* ([parts (string-split (substring str 1) "/")]
283-
[numbers (for/list ([part (in-list parts)])
284-
(define num (string->number part))
285-
(unless (and num (exact-nonnegative-integer? num))
286-
(raise-arguments-error
287-
'string->syntax-path
288-
"syntax path string contains invalid element (must be nonnegative integer)"
289-
"given" str
290-
"invalid element" part))
291-
num)])
292-
(syntax-path numbers))))
280+
(cond
281+
[(equal? str "/") empty-syntax-path]
282+
[else
283+
(define parts (string-split (substring str 1) "/"))
284+
(define numbers
285+
(for/list ([part (in-list parts)])
286+
(define num (string->number part))
287+
(unless (and num (exact-nonnegative-integer? num))
288+
(raise-arguments-error
289+
'string->syntax-path
290+
"syntax path string contains invalid element (must be nonnegative integer)"
291+
"given"
292+
str
293+
"invalid element"
294+
part))
295+
num))
296+
(syntax-path numbers)]))
293297

294298

295299
(module+ test

0 commit comments

Comments
 (0)