Skip to content

6cdh/racket-fixw

Repository files navigation

Racket fixw

A Racket formatter that adjusts whitespace but respects newlines.

🔋 Status

It should work as expected, except some builtin 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

  • Fixes indentation
  • Respects existing newlines
  • Works on incorrect code
  • Enforces a trailing empty line at the end of file with -n or --newline
  • Ensures at least one trailing newline at end of file with --ensure-newline-eof
  • Enforces single spaces between tokens (with several exceptions)
  • Raco integration
  • Reads scmindent-compatible configuration files
  • Skips code surrounded by special comments
  • Supports range formatting

Planned Features:

  • Customizable formatting system (macro-like)
    • Sorting require clauses
    • Keyword arguments and default arguments support

📑 Todo

🚀 Run

# install
raco pkg install fixw
# show help
raco fixw -h
# read from stdin and print formatted text to stdout
raco fixw
# ensure the file ends with at least one newline
raco fixw --ensure-newline-eof some-file.rkt
# format all Racket files in current directory recursively
raco fixw .

🤔 Documentation

See the online documentation.

🖇️ See also

  • fmt - A Racket formatter that calculates 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

 
 
 

Contributors

Languages