This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
forked from jackfirth/resyntax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.scrbl
114 lines (70 loc) · 4.25 KB
/
main.scrbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#lang scribble/manual
@(require (for-label racket/base
syntax/parse)
scribble/bnf)
@title{Resyntax}
@defmodule[resyntax]
Resyntax is a refactoring tool for Racket. The tool can be guided by @deftech{refactoring rules},
which are macro-like functions defined in terms of @racket[syntax-parse] that specify how to search
for and refactor different coding patterns. Resyntax comes with a standard set of refactoring rules
that improve code written in @racket[@#,hash-lang[] @#,racketmodname[racket/base]]. For example,
consider the following program:
@(racketmod
#:file "my-program.rkt"
racket/base
(define (swap x y)
(let ([t (unbox x)])
(set-box! x (unbox y))
(set-box! y t))))
This program uses @racket[let] unnecessarily. The @racket[let] expression can be replaced with a
@racket[define] form, reducing the indentation of the code. Resyntax is capable of detecting and
automatically fixing this issue. Running @exec{resyntax fix --file my-program.rkt} rewrites the above
to the following:
@(racketmod
#:file "my-program.rkt"
racket/base
(define (swap x y)
(define t (unbox x))
(set-box! x (unbox y))
(set-box! y t)))
To see a list of suggestions that Resyntax would apply, use @exec{resyntax analyze} instead of
@exec{resyntax fix}. Each suggestion includes an explanation of why the change is being recommended.
@bold{This tool is extremely experimental.} Do not attempt to incorporate it into your projects yet.
For now, the refactoring suggestions produced by @racketmodname[resyntax] are best viewed as glimpses
into one possible distant future of static analysis for Racket. Feedback, questions, and ideas are all
greatly appreciated and are best directed at the @hyperlink[github-repository-url]{GitHub repository}.
@table-of-contents[]
@(define github-repository-url "https://github.com/jackfirth/resyntax/")
@section[#:tag "cli"]{The Resyntax Command-Line Interface}
Resyntax provides a command-line @exec{resyntax} tool for analyzing and refactoring code. The tool has
two commands: @exec{resyntax analyze} for analyzing code without changing it, and @exec{resyntax fix}
for fixing code by applying Resyntax's suggestions.
Note that at present, Resyntax is limited in what files it can fix. Resyntax only analyzes files with
the @exec{.rkt} extension where @tt{#lang racket/base} is the first line in file.
@subsection{Running @exec{resyntax analyze}}
The @exec{resyntax analyze} command accepts flags for specifying what modules to analyze. After
analysis, suggestions are printed in the console. Any of the following flags can be specified any
number of times:
@itemlist[
@item{@exec{--file} @nonterm{file-path} --- A file to anaylze.}
@item{@exec{--directory} @nonterm{directory-path} --- A directory to anaylze, including
subdirectories.}
@item{@exec{--package} @nonterm{package-name} --- An installed package to analyze.}
@item{@exec{--local-git-repository} @nonterm{repository-path} @nonterm{base-ref} --- A local Git
repository to analyze the changed files of. Only files which have changed relative to
@nonterm{base-ref} are analyzed. Base references must be given in the form
@exec{remotename/branchname}, for example @exec{origin/main} or @exec{upstream/my-feature-branch}.}]
@subsection{Running @exec{resyntax fix}}
The @exec{resyntax fix} command accepts the same flags as @exec{resyntax analyze} for specifying what
modules to fix. After analysis, fixes are applied and a summary is printed.
@itemlist[
@item{@exec{--file} @nonterm{file-path} --- A file to fix.}
@item{@exec{--directory} @nonterm{directory-path} --- A directory to fix, including
subdirectories.}
@item{@exec{--package} @nonterm{package-name} --- An installed package to fix.}
@item{@exec{--local-git-repository} @nonterm{repository-path} @nonterm{base-ref} --- A local Git
repository to fix the changed files of. Only files which have changed relative to @nonterm{base-ref}
are fixed. Base references must be given in the form @exec{remotename/branchname}, for example
@exec{origin/main} or @exec{upstream/my-feature-branch}.}]
If two suggestions try to fix the same code, one of them will be rejected. At present, the best way to
handle overlapping fixes is to run Resyntax multiple times until no fixes are rejected.