chloro 0.6.6

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:

Summary: +97,036 / -13,578

Top 5 Removed Lines Top 5 Added Lines
- } × 112- }, × 93- ); × 87- /// × 72- }, × 64 +} × 75+/// × 75+ }, × 72+ } × 65+ } × 53

Top 20 Most Impacted Files

Rank Size Rank Diff Rank Impact + - File
1 7 1 41.0% 1,560 3,801 rust_analyzer/src_config
2 2 10 3.9% 248 6,433 hir/src_lib
3 1 21 1.8% 202 11,160 ide/src_hover_tests
4 3 16 3.7% 227 6,083 ide_assists/src_handlers_extract_function
5 15 4 12.5% 378 3,019 rust_analyzer/src_lsp_to_proto
6 60 2 53.4% 793 1,486 hir_expand/src_builtin_derive_macro
7 6 20 5.2% 202 3,915 ide/src_goto_definition
8 29 5 16.5% 377 2,290 hir_ty/src_next_solver_interner
9 88 3 38.0% 436 1,147 ide/src_navigation_target
10 8 38 4.0% 152 3,788 ide/src_rename
11 73 6 26.8% 344 1,283 hir_def/src_lib
12 46 12 13.5% 239 1,768 ide_assists/src_handlers_auto_import
13 33 18 9.4% 207 2,194 ide_assists/src_handlers_add_missing_match_arms
14 14 43 4.6% 140 3,029 ide/src_references
15 13 50 4.2% 131 3,088 ide_assists/src_handlers_generate_function
16 139 7 35.2% 305 867 rust_analyzer/tests_slow-tests_ratoml
17 124 8 29.1% 268 921 hir_def/src_signatures
18 21 48 5.3% 136 2,571 ide_assists/src_handlers_extract_variable
19 11 93 2.8% 93 3,267 ide_completion/src_render
20 43 25 10.4% 191 1,832 ide_assists/src_handlers_generate_delegate_trait

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.