jack-format ⚡
An opinionated, fast, and robust code formatter for the Jack programming language from the popular Nand2Tetris course (Projects 9, 10, and 11).
Standard Java/C formatters (like google-java-format or clang-format) fail or corrupt Jack programs due to Jack's unique grammar (function, method, constructor, var int x;, let x = ..., and do SubroutineCall;). jack-format solves this by providing a dedicated parser and formatter designed specifically for Jack.
Features
- 🚀 Zero external dependencies: Pure Python standard library.
- 📐 Standard Nand2Tetris indentation: Clean 4-space indentation for classes, subroutines, loops, and branching.
- 🛡️ Safe & non-destructive: Preserves string literals, line comments (
//), block comments (/* ... */), and doc comments (/** ... */). - 🔄 In-place formatting: Reformat individual files or entire project directories recursively with
-i. - 🔍 CI/CD Check Mode: Returns exit code
1if unformatted code is detected (--check), perfect for grading scripts and CI pipelines. - 🔌 Universal Editor Integration: Works seamlessly with Neovim, VS Code, Vim, and terminal workflows.
Installation
pip install jack-format
Verify installation:
jack-format --version
Usage
1. Format a single file (prints to stdout)
jack-format Main.jack
2. Format files in-place (-i)
jack-format -i Main.jack Square.jack
3. Format an entire project directory recursively
jack-format -i src/
4. Format from standard input (stdin)
cat Main.jack | jack-format
5. Check if code is properly formatted (CI mode)
Exits with code 0 if formatted, or 1 if any file needs formatting:
jack-format --check *.jack
6. View unified diff of changes
jack-format --diff Main.jack
7. Custom indentation size (e.g. 2 spaces instead of 4)
jack-format -s 2 -i Main.jack
Editor Integration
Neovim (conform.nvim)
Add jack-format to your conform.nvim configuration:
require("conform").setup({
formatters_by_ft = {
jack = { "jack_format" },
},
formatters = {
jack_format = {
command = "jack-format",
stdin = true,
},
},
})
VS Code
You can use the popular Run on Save extension or configure a custom task:
Add to your .vscode/settings.json:
{
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.jack$",
"cmd": "jack-format -i ${file}"
}
]
}
}
Vim
Add this to your .vimrc to format on <leader>f or before saving:
autocmd FileType jack setlocal equalprg=jack-format
Example
Before
class Main {
function void main() {
var int x;
let x=5;
if (x>0){
do Output.printInt(x);
}else{
do Output.printString("zero");
}
return;
}
}
After (jack-format)
class Main {
function void main() {
var int x;
let x = 5;
if (x > 0) {
do Output.printInt(x);
} else {
do Output.printString("zero");
}
return;
}
}
Development & Testing
Run unit tests:
python3 -m unittest discover -s tests
Build distribution packages:
python3 -m pip install build twine
python3 -m build
twine check dist/*
License
MIT License. See LICENSE for details.
Metadata
Release files for jack-format 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jack_format-0.1.0.tar.gz | 7.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jack_format-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.4 kB
Release files / jack_format-0.1.0.tar.gz
| Download URL | jack_format-0.1.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36c50b9042b537d23c6c46aff5b047f1eff7edd238cd3d05723927966ae0d1e5
|
|
BLAKE2b-256 checksum How to use checksums |
a04c520c827b8be9adea8cfb3dd5aff4c7075bb7d65cebfab463df431f9e78de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / jack_format-0.1.0-py3-none-any.whl
| Download URL | jack_format-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d281fbd3bc6da475e39e18c217008b6b6810c8f8c5ee51c1b883f7871a3d044
|
|
BLAKE2b-256 checksum How to use checksums |
91e623ef88f1dd8bba158d6f4c1e1d24ba65e6ff2136e768a916d2c3e2e33c81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency log