# Resyntax: A Macro-Powered Refactoring Tool

**URL:** <https://racket.discourse.group/t/resyntax-a-macro-powered-refactoring-tool/835>\
**Category:** Show & Tell\
**Tags:** developer-tools\
**Created:** [March 31, 2022, 9:32pm UTC](https://racket.discourse.group/t/resyntax-a-macro-powered-refactoring-tool/835 "2022-03-31T21:32:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![notjack](https://avatars.discourse-cdn.com/v4/letter/n/e47774/32.png) [@notjack](https://racket.discourse.group/u/notjack)\
**Post date:** [March 31, 2022, 9:32pm UTC](https://racket.discourse.group/t/resyntax-a-macro-powered-refactoring-tool/835/1 "2022-03-31T21:32:06Z")

</div>

Some of you may already know this, but I've implemented a refactoring tool for Racket called [Resyntax](https://github.com/jackfirth/resyntax). It analyzes your code (must be written in `#lang racket/base`) and suggests ways you can improve it. Here's an [example](https://github.com/jackfirth/yaragg/commit/9d48ab7152003e39aa6c1bab11a601d3723143fa) of the changes it made when I ran it over a real-world package. To use Resyntax, install it in **installation scope** (this is very important!) using `raco pkg install --installation resyntax`. Then you can run it at the command line. Here are some example commands:

- Analyze a file and print suggestions in the terminal: `resyntax analyze --file foo.rkt`
- Analyze multiple files: `resyntax analyze --file foo.rkt --file bar.rkt`
- Fix a file: `resyntax fix --file foo.rkt`
- Fix a directory: `resyntax fix --directory path/to/some/dir`
- Fix a locally-installed package: `resyntax fix --package mypackage` (the package should be installed with `--link` option for this to work the way you expect)

---

<div class="post-metadata">

**Author:** ![Laurent.O](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/laurent.o/32/18_2.png) [@Laurent.O](https://racket.discourse.group/u/Laurent.O)\
**Post date:** [April 1, 2022, 12:15pm UTC](https://racket.discourse.group/t/resyntax-a-macro-powered-refactoring-tool/835/2 "2022-04-01T12:15:25Z")

</div>

Very nice! 👏

I love this one (click on the header starting with `github.com/jackfirth...`, not on `Run ...`):

> <https://github.com/jackfirth/yaragg/commit/9d48ab7152003e39aa6c1bab11a601d3723143fa#diff-b66019a7cfe33e8f238d16d84fa01fbd16d2f27b50294d3d4edef5180432bf5cL97>

A little more room for refactoring 🙂  
`(and ... (and ...) ...)` -\> `(and ...)`

> <https://github.com/jackfirth/yaragg/commit/9d48ab7152003e39aa6c1bab11a601d3723143fa#diff-6ea3d601e9cb23a0bd3ee16de36fe16f0d7d7b6e57ed7d631067d6c3300506a1R150>

Did it miss a let-\>define? Or is it because the internal definitions of the `let` may then be spliced? If the latter, then maybe suggest using `(block (define ...)...)`?

> <https://github.com/jackfirth/yaragg/commit/9d48ab7152003e39aa6c1bab11a601d3723143fa#diff-12674874407501f8a61ca64cf222446eb4b0fc678c830d93fd737c5c626c8803R66>

---

<div class="post-metadata">

**Author:** ![notjack](https://avatars.discourse-cdn.com/v4/letter/n/e47774/32.png) [@notjack](https://racket.discourse.group/u/notjack)\
**Post date:** [April 1, 2022, 7:56pm UTC](https://racket.discourse.group/t/resyntax-a-macro-powered-refactoring-tool/835/3 "2022-04-01T19:56:55Z")

</div>

The `(and ... (and ...) ...) -> (and ...)` case is normally refactored by Resyntax, but there's some logic to skip it for multiline ands so that this:

```scheme
(and (long-expr)
     (and a b c d e))

```

doesn't become this:

```scheme
(and (long-expr)
     a
     b
     c
     d
     e)

```

That logic is overly conservative though, and should be adjusted.

For that `let->define` case, `syntax-case` doesn't allow internal definitions. The better fix there is to replace `syntax-case` with `syntax-parse`.
