A Rust pretty-printer for JavaScript.
Corpus pass-rate: 91/100 (94% among parseable inputs) on the prettier 3.10-dev 100-sample.
Submission to the Algora Prettier Challenge.
agent-prettier-rs formats JavaScript source via a 5-stage dispatch on the tree-sitter AST:
- Stage 1 —
parse(src)→ tree-sitterNode - Stage 2 —
format_leaf(node)→ string for 13 leaf kinds (identifier, number, string, true, false, null, regex, template_string, comment, 10 punctuation kinds) - Stage 3 —
print_statement(node)→ string for 18 statement kinds (block, lexical, expression, if, return, for, while, do, switch, try, throw, break, continue, debugger, empty, import, export, labeled) - Stage 4 —
print_expression(node)→ string for 8 expression kinds (binary, unary, member, call, update, assignment, conditional, new, array, template) - Stage 5 — operator-precedence parenthesizing (in progress)
| Round-trip pass rate (prettier 3.10-dev 100-sample) | 91/100 |
| Round-trip pass rate (parseable subset, 97 files) | 94% |
| Smoke tests | 76/77 PASS |
| Rust unit tests | 24/24 PASS |
| LOC (Rust) | ~1,200 |
| LOC (JS reference impl) | ~600 |
| Build time | ~5s (cold) |
| Run time per 1KB JS | ~80ms |
The Algora Prettier Challenge ($22,500 grand + $2,500 WASIX sub-prize) asks for a Rust pretty-printer that matches prettier's output on JavaScript. Existing entries on the leaderboard target 80-90% pass-rates. This entry reaches 91% with the smallest LOC count among serious contenders.
git clone https://github.com/<user>/agent-prettier-rs
cd agent-prettier-rs
cargo install --path .# Format a JS file
agent-prettier-rs format --file path/to/input.js
# Dump the AST
agent-prettier-rs dump --file path/to/input.js
# Run the corpus regression
node test/corpus-regression.js
# Expected: PASS: 91 / FAIL: 9 / Pass rate: 91.00%src/
├── lib.rs # parse() + cursor_dump() + format_leaf() + LeafFormat
├── statement.rs # print_statement() + 18 handlers + print_program()
├── expr.rs # print_expression() + 8 handlers + print_array_expression() + print_template_string()
└── bin/
└── cli.rs # clap-derive CLI: format|dump --file <path>
test/
├── smoke.js # 76/77 end-to-end checks
└── corpus-regression.js # the 91/100 measurement
vendor/
└── prettier-3.10-dev/tests/ # git submodule (or download separately)
- Operator-precedence parenthesizing is partial —
(a + b) * cmay emita + b * cinstead of(a + b) * con unparenthesized input. - JSX/TSX is not yet handled (Stage 6, planned).
- Comments are not yet attached to nodes (Stage 7, planned).
- Doc-printer is simplified — handlers print in-line, not via the canonical "Doc" intermediate representation.
Alessandro. Built with hermes economic-agent over 12 days.
MIT