chloro
chloro is a minimal Rust code formatter.
Motivation
For when you want to format two source files in a consistent way, as fast as possible.
How it works
Using rowan from the rust-analyzer project, which can give both green and red trees. The latter are notoriously expensive, but a formatter should only need the former.
Proof of concept library/CLI to explore a fast and low memory code formatter [WIP], with use cases of code diffing in mind.
Rustfmt Conformance
Diff 'leaderboard' for how well formatting with chloro matches rustfmt, as tested on rust-analyzer's crates:
| Top 5 Removed Lines | Top 5 Added Lines |
|---|---|
- } × 154- { × 135- }, × 93- ); × 87- /// × 72 |
+ &self, × 1,157+ &mut self, × 652+ self, × 518+ ) { × 463+ db: &dyn HirDatabase, × 351 |
Top 20 Most Impacted Files
| Rank | Size Rank | Diff Rank | Impact | + | - | File |
|---|---|---|---|---|---|---|
| 1 | 3 | 1 | 28.1% | 2,107 | 7,496 | hir/src_lib |
| 2 | 7 | 2 | 47.2% | 1,829 | 3,876 | rust_analyzer/src_config |
| 3 | 4 | 10 | 7.7% | 473 | 6,129 | ide_assists/src_handlers_extract_function |
| 4 | 2 | 28 | 2.5% | 276 | 11,104 | ide/src_hover_tests |
| 5 | 18 | 5 | 25.7% | 700 | 2,728 | hir/src_semantics |
| 6 | 27 | 4 | 30.2% | 747 | 2,472 | hir_ty/src_next_solver_interner |
| 7 | 16 | 9 | 16.4% | 487 | 2,964 | rust_analyzer/src_lsp_to_proto |
| 8 | 11 | 17 | 9.4% | 337 | 3,577 | hir_def/src_expr_store_lower |
| 9 | 64 | 3 | 56.2% | 835 | 1,486 | hir_expand/src_builtin_derive_macro |
| 10 | 8 | 30 | 6.9% | 266 | 3,865 | ide/src_goto_definition |
| 11 | 13 | 29 | 8.3% | 272 | 3,267 | hir_ty/src_mir_eval |
| 12 | 65 | 6 | 44.8% | 648 | 1,447 | hir_def/src_lib |
| 13 | 38 | 12 | 19.9% | 415 | 2,088 | hir_ty/src_infer |
| 14 | 63 | 8 | 32.7% | 489 | 1,496 | hir_ty/src_next_solver_ty |
| 15 | 9 | 56 | 5.2% | 195 | 3,767 | ide/src_rename |
| 16 | 1 | 540 | 0.1% | 12 | 19,633 | ide_db/src_generated_lints |
| 17 | 14 | 40 | 7.5% | 231 | 3,074 | ide_assists/src_handlers_generate_function |
| 18 | 89 | 7 | 47.7% | 558 | 1,171 | ide/src_navigation_target |
| 19 | 12 | 69 | 5.5% | 179 | 3,277 | ide_completion/src_render |
| 20 | 97 | 11 | 38.8% | 430 | 1,109 | hir_def/src_expr_store |
Installation
Add chloro to your Cargo.toml:
[]
= "0.5"
CLI Installation
- pre-built binary:
cargo binstall chloro(requires cargo-binstall), - build from source:
cargo install chloro --features cli
License
This project is licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.