chloro 0.6.8

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: +94,024 / -13,420

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

Top 20 Most Impacted Files

Rank Size Rank Diff Rank Impact + - File
1 7 1 40.9% 1,559 3,814 rust_analyzer/src_config
2 2 11 3.8% 245 6,440 hir/src_lib
3 1 33 1.5% 165 11,159 ide/src_hover_tests
4 3 16 3.6% 216 6,084 ide_assists/src_handlers_extract_function
5 15 5 12.4% 373 3,020 rust_analyzer/src_lsp_to_proto
6 6 19 5.1% 201 3,916 ide/src_goto_definition
7 60 2 53.4% 798 1,495 hir_expand/src_builtin_derive_macro
8 29 6 15.0% 346 2,313 hir_ty/src_next_solver_interner
9 89 3 37.3% 428 1,147 ide/src_navigation_target
10 67 4 30.5% 419 1,376 hir_def/src_lib
11 41 7 17.8% 335 1,882 ide_assists/src_handlers_auto_import
12 8 38 4.0% 152 3,788 ide/src_rename
13 14 31 5.6% 171 3,066 ide/src_references
14 33 17 9.3% 204 2,197 ide_assists/src_handlers_add_missing_match_arms
15 13 57 4.0% 123 3,100 ide_assists/src_handlers_generate_function
16 95 8 24.4% 273 1,121 rust_analyzer/tests_slow-tests_ratoml
17 44 20 10.5% 193 1,838 ide_assists/src_handlers_generate_delegate_trait
18 19 50 5.0% 132 2,635 ide_assists/src_handlers_extract_variable
19 37 28 8.6% 174 2,034 ide_assists/src_handlers_destructure_tuple_binding
20 11 97 2.8% 90 3,270 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.