chloro 0.6.2

A minimal Rust code formatter
Documentation

chloro

crates.io documentation MIT/Apache-2.0 licensed pre-commit.ci status free of syn Dependencies: 32 Binary Size: 1.6M

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 +} × 75+/// × 75+ }, × 65+ } × 65+}; × 44

Top 20 Most Impacted Files

Rank Size Rank Diff Rank Impact + - File
1 9 1 43.1% 1,617 3,748 rust_analyzer/src_config
2 2 17 2.2% 241 11,083 ide/src_hover_tests
3 4 9 4.7% 281 6,011 ide_assists/src_handlers_extract_function
4 3 19 3.7% 235 6,366 hir/src_lib
5 16 4 15.0% 444 2,951 rust_analyzer/src_lsp_to_proto
6 7 12 6.6% 256 3,859 ide/src_goto_definition
7 62 2 55.0% 808 1,469 hir_expand/src_builtin_derive_macro
8 31 5 17.7% 400 2,259 hir_ty/src_next_solver_interner
9 8 34 4.8% 180 3,758 ide/src_rename
10 95 3 42.2% 473 1,120 ide/src_navigation_target
11 76 6 28.1% 357 1,272 hir_def/src_lib
12 1 516 0.1% 12 19,633 ide_db/src_generated_lints
13 47 11 15.0% 260 1,739 ide_assists/src_handlers_auto_import
14 14 44 5.4% 163 3,036 ide_assists/src_handlers_generate_function
15 34 20 10.2% 221 2,174 ide_assists/src_handlers_add_missing_match_arms
16 15 50 4.9% 149 3,018 ide/src_references
17 20 42 6.6% 167 2,534 ide_assists/src_handlers_extract_variable
18 23 39 6.9% 172 2,506 rust_analyzer/src_handlers_request
19 45 22 12.0% 217 1,804 ide_assists/src_handlers_generate_delegate_trait
20 12 84 3.5% 114 3,238 ide_completion/src_render

Installation

Add chloro to your Cargo.toml:

[dependencies]
chloro = "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:

at your option.