chloro 0.7.0

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: +91,179 / -11,823

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

Top 20 Most Impacted Files

Rank Size Rank Diff Rank Impact + - File
1 2 11 3.4% 218 6,479 hir/src_lib
2 1 28 1.5% 165 11,159 ide/src_hover_tests
3 3 12 3.6% 216 6,084 ide_assists/src_handlers_extract_function
4 15 3 12.4% 373 3,020 rust_analyzer/src_lsp_to_proto
5 61 1 52.0% 784 1,509 hir_expand/src_builtin_derive_macro
6 7 14 5.1% 201 3,916 ide/src_goto_definition
7 28 6 13.0% 305 2,354 hir_ty/src_next_solver_interner
8 90 2 37.3% 428 1,147 ide/src_navigation_target
9 41 5 17.8% 335 1,882 ide_assists/src_handlers_auto_import
10 5 45 3.2% 132 4,173 rust_analyzer/src_config
11 59 4 23.6% 357 1,512 hir_def/src_lib
12 8 33 4.0% 152 3,788 ide/src_rename
13 14 26 5.6% 171 3,066 ide/src_references
14 33 13 9.3% 204 2,197 ide_assists/src_handlers_add_missing_match_arms
15 95 7 24.4% 273 1,121 rust_analyzer/tests_slow-tests_ratoml
16 13 52 4.0% 123 3,100 ide_assists/src_handlers_generate_function
17 44 16 10.5% 193 1,838 ide_assists/src_handlers_generate_delegate_trait
18 37 23 8.6% 174 2,034 ide_assists/src_handlers_destructure_tuple_binding
19 19 46 5.0% 132 2,635 ide_assists/src_handlers_extract_variable
20 52 17 11.6% 189 1,625 ide/src_typing

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.