Skip to content

Commit a752c8e

Browse files
Copilotjackfirth
andauthored
Consolidate legacy migration rules into default-recommendations/legacy/ (#665)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jackfirth <[email protected]>
1 parent c5e22b9 commit a752c8e

18 files changed

+236
-140
lines changed

default-recommendations.rkt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
resyntax/default-recommendations/function-definition-shortcuts
1919
resyntax/default-recommendations/function-shortcuts
2020
resyntax/default-recommendations/hash-shortcuts
21-
resyntax/default-recommendations/legacy-contract-migrations
22-
resyntax/default-recommendations/legacy-struct-migrations
23-
resyntax/default-recommendations/legacy-syntax-migrations
21+
resyntax/default-recommendations/legacy/define-simple-macro-migration
22+
resyntax/default-recommendations/legacy/legacy-contract-migrations
23+
resyntax/default-recommendations/legacy/legacy-struct-migrations
24+
resyntax/default-recommendations/legacy/legacy-syntax-migrations
25+
resyntax/default-recommendations/legacy/make-temporary-directory-migration
26+
resyntax/default-recommendations/legacy/provide-contract-migration
2427
resyntax/default-recommendations/let-binding-suggestions
2528
resyntax/default-recommendations/let-replacement/cond-let-replacement
2629
resyntax/default-recommendations/let-replacement/let-replacement
@@ -57,9 +60,12 @@
5760
resyntax/default-recommendations/function-definition-shortcuts
5861
resyntax/default-recommendations/function-shortcuts
5962
resyntax/default-recommendations/hash-shortcuts
60-
resyntax/default-recommendations/legacy-contract-migrations
61-
resyntax/default-recommendations/legacy-struct-migrations
62-
resyntax/default-recommendations/legacy-syntax-migrations
63+
resyntax/default-recommendations/legacy/define-simple-macro-migration
64+
resyntax/default-recommendations/legacy/legacy-contract-migrations
65+
resyntax/default-recommendations/legacy/legacy-struct-migrations
66+
resyntax/default-recommendations/legacy/legacy-syntax-migrations
67+
resyntax/default-recommendations/legacy/make-temporary-directory-migration
68+
resyntax/default-recommendations/legacy/provide-contract-migration
6369
resyntax/default-recommendations/let-binding-suggestions
6470
resyntax/default-recommendations/let-replacement/cond-let-replacement
6571
resyntax/default-recommendations/let-replacement/let-replacement
@@ -91,6 +97,7 @@
9197
cond-let-replacement
9298
console-io-suggestions
9399
contract-shortcuts
100+
define-simple-macro-migration
94101
definition-shortcuts
95102
dict-suggestions
96103
exception-suggestions
@@ -113,12 +120,14 @@
113120
let-replacement
114121
list-loopification
115122
list-shortcuts
123+
make-temporary-directory-migration
116124
match-let-replacement
117125
match-shortcuts
118126
miscellaneous-suggestions
119127
mutability-predicates
120128
named-let-loopification
121129
numeric-shortcuts
130+
provide-contract-migration
122131
require-and-provide-suggestions
123132
string-shortcuts
124133
syntax-shortcuts

default-recommendations/contract-shortcuts-test.rkt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,3 @@ test: "infix ->* contracts using #:rest (listof arg) can be replaced with -> and
9393
no-change-test:
9494
"->* contracts using #:rest and optional arguments not refactorable to -> and ellipses"
9595
- (void (->* () (string?) #:rest (listof symbol?) list?))
96-
97-
98-
test: "provide/contract refactorable to provide with contract-out"
99-
------------------------------
100-
(provide/contract [foo integer?])
101-
(define foo 42)
102-
==============================
103-
(provide (contract-out [foo integer?]))
104-
(define foo 42)
105-
------------------------------
106-
107-
108-
test: "provide/contract with unprotected submodule refactorable to provide with contract-out"
109-
------------------------------
110-
(provide/contract #:unprotected-submodule unsafe [foo integer?])
111-
(define foo 42)
112-
==============================
113-
(provide (contract-out #:unprotected-submodule unsafe [foo integer?]))
114-
(define foo 42)
115-
------------------------------

default-recommendations/contract-shortcuts.rkt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,8 @@
6060
result-contract))
6161

6262

63-
(define-splicing-syntax-class unprotected-submodule-option
64-
(pattern (~optional (~seq #:unprotected-submodule submodule-name))))
65-
66-
67-
(define-refactoring-rule provide/contract-to-contract-out
68-
#:description "The `provide/contract` form is a legacy form made obsolete by `contract-out`."
69-
#:literals (provide/contract)
70-
(provide/contract submod:unprotected-submodule-option item ...)
71-
(provide (contract-out (~@ . submod) item ...)))
72-
73-
7463
(define-refactoring-suite contract-shortcuts
7564
#:rules (arrow-contract-with-rest-to-arrow-contract-with-ellipses
7665
explicit-path-string?-to-path-string?
7766
nested-or/c-to-flat-or/c
78-
nested-and/c-to-flat-and/c
79-
provide/contract-to-contract-out))
67+
nested-and/c-to-flat-and/c))

default-recommendations/file-io-suggestions-test.rkt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ header:
1111
----------------------------------------
1212

1313

14-
test: "should migrate make-temporary-file with 'directory to make-temporary-directory"
15-
- (void (make-temporary-file #:copy-from 'directory))
16-
- (void (make-temporary-directory))
17-
18-
19-
test: "should migrate make-temporary-file with template and 'directory to make-temporary-directory"
20-
- (void (make-temporary-file "footmp~a" #:copy-from 'directory))
21-
- (void (make-temporary-file "footmp~a" 'directory))
22-
- (void (make-temporary-directory "footmp~a"))
23-
24-
25-
test: "should migrate make-temporary-file with base-dir and 'directory to make-temporary-directory"
26-
- (void (make-temporary-file #:base-dir #false #:copy-from 'directory))
27-
- (void (make-temporary-directory #:base-dir #false))
28-
29-
3014
no-change-test:
3115
"should not migrate make-temporary-file without 'directory to make-temporary-directory"
3216
- (make-temporary-file #:copy-from #false)

default-recommendations/file-io-suggestions.rkt

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,12 @@
99
[file-io-suggestions refactoring-suite?]))
1010

1111

12-
(require racket/file
13-
racket/list
14-
rebellion/private/static-name
15-
resyntax/base
16-
syntax/parse)
12+
(require rebellion/private/static-name
13+
resyntax/base)
1714

1815

1916
;@----------------------------------------------------------------------------------------------------
2017

2118

22-
(define-splicing-syntax-class function-call-argument
23-
#:attributes (keyword expr)
24-
(pattern (~seq expr:expr) #:attr keyword #false)
25-
(pattern (~seq keyword:keyword expr:expr)))
26-
27-
28-
(define-splicing-syntax-class function-call-arguments
29-
#:attributes ([positional 1] keyword)
30-
(pattern (~seq arg:function-call-argument ...)
31-
#:cut
32-
#:with (positional ...)
33-
(for/list ([expr (in-list (attribute arg.expr))]
34-
[keyword (in-list (attribute arg.keyword))]
35-
#:unless keyword)
36-
expr)
37-
38-
#:attr keyword
39-
(for/hasheq ([expr (in-list (attribute arg.expr))]
40-
[keyword (in-list (attribute arg.keyword))]
41-
#:when keyword)
42-
(values (syntax-e keyword) expr))))
43-
44-
45-
(define-refactoring-rule make-temporary-directory-migration
46-
#:description "Use `make-temporary-directory` to make directories instead of `make-temporary-file`."
47-
#:literals (make-temporary-file)
48-
#:datum-literals (quote directory)
49-
50-
(make-temporary-file args:function-call-arguments)
51-
#:with 'directory
52-
(or (and (>= (length (attribute args.positional)) 2)
53-
(second (attribute args.positional)))
54-
(hash-ref (attribute args.keyword) '#:copy-from #false))
55-
#:cut
56-
#:attr template-arg
57-
(and (not (empty? (attribute args.positional)))
58-
(first (attribute args.positional)))
59-
#:attr base-dir-arg
60-
(or (and (>= (length (attribute args.positional)) 3)
61-
(third (attribute args.positional)))
62-
(hash-ref (attribute args.keyword) '#:base-dir #false))
63-
64-
(make-temporary-directory (~? template-arg) (~? (~@ #:base-dir base-dir-arg))))
65-
66-
6719
(define-refactoring-suite file-io-suggestions
68-
#:rules (make-temporary-directory-migration))
20+
#:rules ())

default-recommendations/syntax-parse-shortcuts-test.rkt renamed to default-recommendations/legacy/define-simple-macro-migration-test.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#lang resyntax/test
22

33

4-
require: resyntax/default-recommendations syntax-parse-shortcuts
4+
require: resyntax/default-recommendations define-simple-macro-migration
55

66

77
header:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#lang racket/base
2+
3+
4+
(require racket/contract/base)
5+
6+
7+
(provide
8+
(contract-out
9+
[define-simple-macro-migration refactoring-suite?]))
10+
11+
12+
(require resyntax/base
13+
resyntax/default-recommendations/private/syntax-lines
14+
syntax/parse/define)
15+
16+
17+
;@----------------------------------------------------------------------------------------------------
18+
19+
20+
(define define-simple-macro-migration-name-length-increase
21+
(- (string-length "define-syntax-parse-rule") (string-length "define-simple-macro")))
22+
23+
(define-refactoring-rule define-simple-macro-to-define-syntax-parse-rule
24+
#:description "The `define-simple-macro` form has been renamed to `define-syntax-parse-rule`."
25+
#:literals (define-simple-macro)
26+
(original:define-simple-macro header form ...)
27+
28+
;; The define-simple-macro is a renamed alias of define-syntax-parse-rule, so it's
29+
;; free-identifier=?. As a result, we need to check the actual symbol of the identifier instead of
30+
;; just its binding. See https://github.com/jackfirth/resyntax/issues/106.
31+
#:when (equal? (syntax-e #'original) 'define-simple-macro)
32+
33+
#:do
34+
[(define should-reformat?
35+
(or (multiline-syntax? #'header)
36+
(not (equal? (syntax-line #'original) (syntax-line #'header)))
37+
(> (+ (syntax-column #'header)
38+
(syntax-span #'header)
39+
define-simple-macro-migration-name-length-increase)
40+
102)))]
41+
42+
#:with new-id (if should-reformat?
43+
#'define-syntax-parse-rule
44+
#'(~focus-replacement-on define-syntax-parse-rule))
45+
46+
(new-id header form ...))
47+
48+
49+
(define-refactoring-suite define-simple-macro-migration
50+
#:rules (define-simple-macro-to-define-syntax-parse-rule))

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

File renamed without changes.

default-recommendations/legacy-contract-migrations.rkt renamed to default-recommendations/legacy/legacy-contract-migrations.rkt

File renamed without changes.

default-recommendations/legacy-struct-migrations-test.rkt renamed to default-recommendations/legacy/legacy-struct-migrations-test.rkt

File renamed without changes.

0 commit comments

Comments
 (0)