Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

agent-prettier-rs

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.

What

agent-prettier-rs formats JavaScript source via a 5-stage dispatch on the tree-sitter AST:

  1. Stage 1parse(src) → tree-sitter Node
  2. Stage 2format_leaf(node) → string for 13 leaf kinds (identifier, number, string, true, false, null, regex, template_string, comment, 10 punctuation kinds)
  3. Stage 3print_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)
  4. Stage 4print_expression(node) → string for 8 expression kinds (binary, unary, member, call, update, assignment, conditional, new, array, template)
  5. Stage 5 — operator-precedence parenthesizing (in progress)

Numbers

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

Why

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.

Install

git clone https://github.com/<user>/agent-prettier-rs
cd agent-prettier-rs
cargo install --path .

Run

# 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%

Architecture

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)

Honest limitations

  • Operator-precedence parenthesizing is partial — (a + b) * c may emit a + b * c instead of (a + b) * c on 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.

Author

Alessandro. Built with hermes economic-agent over 12 days.

License

MIT

About

Rust pretty-printer for JavaScript — Algora Prettier submission, 91% corpus pass-rate

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages