A library to format Clojure code following Simple Clojure Formatting Rules.
This project is under active development and I do not recommend using it for your codebase at this time unless you are very adventurous. I will publish a release to npm when the project is stable enough for Alpha usage.
Please see Issue #1 for an explanation of this project's genesis.
rtrim
every line)\n
) at the end of the file:remove-surrounding-whitespace?
= true:remove-trailing-whitespace?
= true:insert-missing-whitespace?
= true:remove-consecutive-blank-lines?
= truens
forms according to Stuart Sierra's how to nsclojurefmt:ignore
cause the next form to be ignored by the formatter"It is not the goal of the project to provide a one-to-one mapping between a Clojure syntax tree and formatted text; rather the intent is to correct formatting errors with minimal changes to the existing structure of the text. If you want format completely unstructured Clojure code, the zprint project may be more suitable.
let
forms and map literals are allowed
:remove-multiple-non-indenting-spaces?
= false:indents
optionThe coding style for this library is intentionally very simple in order to make porting the algorithm to multiple languages easier. This is informed by my experience porting parinfer.js to multiple languages (parinfer-lua, parinfer.py, and others).
Here are some rules to follow:
for
loops, only use while
++
or --
operators (wrap with function calls)Note: this should not be considered a definitive list. I will add to this as I come across additional cases.
## run unit tests
bun test
## test a single file
bun run jest format.test.js
## lint JS
bun run lint
:refer-clojure
:require-macros
:require
:import
:require-macros
:default
(if it exists), which is last