/cargo-derivefmt

Primary LanguageRustApache License 2.0Apache-2.0

cargo-derivefmt

A tool for ordering derives in Rust code.

Motivation

cargo-derivefmt ensures that your derives are written in alphabetical order.

// Before: pure chaos.
#[derive(Debug, PartialEq, Ord, Clone, Copy)]
struct S;

// After: blissful order.
#[derive(Clone, Copy, Debug, Ord, PartialEq)]
struct S;

That's it! That's all this does.

Installation

This package is currently implemented using rust-analyzer internals, so cannot be published on crates.io.

cargo install --locked --git https://github.com/dcchut/cargo-derivefmt --bin cargo-derivefmt

Usage

Formatting the current crate

cargo derivefmt 

Formatting a different crate

cargo derivefmt --manifest-path /path/to/Cargo.toml

Formatting a single file

cargo derivefmt --file path/to/src.rs

Formatting multiple files

cargo derivefmt --file path/to/src.rs --file /path/to/another.rs

Formatting folders

Passing a folder formats all .rs files contained within it and its subfolders:

cargo derivefmt --file /path/to/folder/

Roadmap

  • Better identification of files to format (particularly in the context of a cargo project).
  • Better handling of comments.