1 The Resyntax Command-Line Interface
Resyntax provides a command-line resyntax tool for analyzing and refactoring code. The tool has two commands: resyntax analyze for analyzing code without changing it, and 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 .rkt extension where #lang racket/base is the first line in the file.
Each of the target flags accepted by these commands constructs a source group describing which files to operate on. See Source Groups in The Resyntax Grimoire for the API underlying these flags.
1.1 Installation
Use the Racket package manager to install Resyntax in the installation scope:
% raco pkg install --installation resyntax |
The --installation flag (shorthand for --scope installation) installs packages for all users of a Racket installation, ensuring resyntax is in your PATH.
% resyntax analyze --file example.rkt |
resyntax: --- analyzing code --- |
resyntax: --- displaying results --- |
% |
1.2 Running resyntax analyze
The 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:
--file ‹file-path› —
A file to analyze. --directory ‹directory-path› —
A directory to analyze, including subdirectories. --package ‹package-name› —
An installed package to analyze. --local-git-repository ‹repository-path› ‹base-ref› —
A local Git repository to analyze the changed files of. Only files which have changed relative to ‹base-ref› are analyzed. Base references must be given in the form remotename/branchname, for example origin/main or upstream/my-feature-branch. --refactoring-suite ‹module-path› ‹suite-name› —
A refactoring suite to use instead of Resyntax’s default recommendations. Custom refactoring suites can be created with define-refactoring-suite.
1.3 Running resyntax fix
The resyntax fix command accepts the same flags as resyntax analyze for specifying what modules to fix. After analysis, fixes are applied and a summary is printed.
--file ‹file-path› —
A file to fix. --directory ‹directory-path› —
A directory to fix, including subdirectories. --package ‹package-name› —
An installed package to fix. --local-git-repository ‹repository-path› ‹base-ref› —
A local Git repository to fix the changed files of. Only files which have changed relative to ‹base-ref› are fixed. Base references must be given in the form remotename/branchname, for example origin/main or upstream/my-feature-branch. --refactoring-suite ‹module-path› ‹suite-name› —
A refactoring suite to use instead of Resyntax’s default recommendations. Custom refactoring suites can be created with define-refactoring-suite.
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.