Skip to content

a Racket formatter that only fixes whitespaces

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE-2.0
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

6cdh/racket-fixw

Repository files navigation

Racket fixw

A Racket formatter that add/remove some whitespaces but respects newline.

🔋 Status

It should work as expected, except some rules for macros and special forms are missing.

🖨️ Example

before

#lang racket

(define(fib n )
(if (<= n 1)
1
(+ (fib  (- n 1))
(fib (- n 2)) )))

after

#lang racket

(define (fib n)
  (if (<= n 1)
      1
      (+ (fib (- n 1))
         (fib (- n 2)))))

✈️ Performance

  • format a 5k lines file in 100ms on a 6 years old laptop

The biggest Racket file class-internal.rkt in racket/racket repo has almost 5k lines, so I think it's fast enough.

✨ Features

  • fix indent
  • respect newline
  • works for unbalanced code
  • remove trailing spaces
  • force only one space between two tokens with several exceptions
  • force only one empty line at the end of the file
    • make it configurable
  • raco integration
  • read scmindent compatible configuration file
  • skip code that surrounded by special comments
  • support range formatting
  • a configurable system looks like macro but allows user customize the formatting
    • support sort require
    • support keyword arguments and default arguments

📑 todo

  • refactor
    • isolate the lexer workarounds and special escape comments processing
    • simplify the core logic

🚀 Run

# install
raco pkg install fixw
# show help
raco fixw -h
# read from stdin and output formatted text to stdout
raco fixw
# format current directory recursively
raco fixw .

🤔 docs

See online docs.

🖇️ See also

  • fmt - a Racket formatter that calculate optimal layout
  • scmindent - a general lisp indenter

About

a Racket formatter that only fixes whitespaces

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE-2.0
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages