chloro 0.7.1

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.7M

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:

Summary: +101,906 / -13,957

Top 5 Removed Lines Top 5 Added Lines
- ) × 219- r#" × 140- }, × 108- check( × 90- ); × 87 + }, × 137+"#) × 104+ } × 87+ check(r#" × 79+} × 75

Top 20 Most Impacted Files

Rank Size Rank Diff Rank Impact + - File
1 2 8 4.8% 312 6,475 hir/src_lib
2 7 3 9.8% 379 3,856 ide/src_goto_definition
3 3 10 4.3% 264 6,086 ide_assists/src_handlers_extract_function
4 1 38 1.4% 161 11,159 ide/src_hover_tests
5 55 1 46.9% 728 1,551 hir_expand/src_builtin_derive_macro
6 15 4 12.3% 371 3,014 rust_analyzer/src_lsp_to_proto
7 28 6 15.0% 353 2,346 hir_ty/src_next_solver_interner
8 10 17 6.3% 219 3,495 hir_def/src_expr_store_lower
9 5 37 4.0% 166 4,157 rust_analyzer/src_config
10 95 2 39.9% 448 1,123 ide/src_navigation_target
11 8 33 4.6% 175 3,769 ide/src_rename
12 41 7 18.4% 346 1,881 ide_assists/src_handlers_auto_import
13 58 5 23.7% 358 1,513 hir_def/src_lib
14 14 30 5.8% 178 3,067 ide/src_references
15 13 34 5.6% 172 3,087 ide_assists/src_handlers_generate_function
16 26 18 8.8% 215 2,446 ide/src_highlight_related
17 44 13 13.5% 241 1,788 ide_assists/src_handlers_generate_delegate_trait
18 11 62 3.8% 125 3,267 ide_completion/src_render
19 33 22 9.0% 198 2,197 ide_assists/src_handlers_add_missing_match_arms
20 37 21 10.2% 205 2,013 ide_assists/src_handlers_destructure_tuple_binding

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.