#rustfmt #toml-config #config

app rustfmt-unstable

A wrapper around cargo fmt or rustfmt for parsing a config file and passing it as cli args instead

5 releases (1 stable)

1.0.0 Apr 10, 2024
0.2.2 Feb 6, 2024
0.2.1 Jan 13, 2024
0.2.0 Jan 13, 2024
0.1.0 Jan 13, 2024

#912 in Command line utilities

41 downloads per month

MIT/Apache

10KB
146 lines

rustfmt-unstable

Rustfmt currently allows unstable options to be passed on the commandline only when used on stable. This behaviour is known to the rustfmt team and is not intended to change until version v2.0 in which a a new feature flag will be introduced that enables these features in the config. It is often desireable to use a rustfmt.toml config anyways, even with unstable features, to enable easier sharing of configuration across machines and developers. To aid in this purpose, this crate provides a way to parse the config and pass it as arguments instead.

Usage

cargo install rustfmt-unstable
rustfmt-unstable

The rustfmt-unstable binary accepts a config file and then parses everything after the -- as the actual command to be executed with the provided config. It will then pass --config feature1=foo,feature2=bar,... at the end of the provided command, if no --config is found in it already. If there is, rustfmt-unstable will instead ammend the feature list with the features in the config and replace it in-place. The command defaults to cargo fmt --check --all --.

The --apply flag is present if you simply wish to run cargo fmt --all --

Additional config options can be either provided through the --config option on rustfmt-unstable or through the --config option on the binary you wish to execute (after the first --).

The configuration file read can be specified by using the --config-file option. By default (with the auto-resolve feature enabled, which it is unless it is disabled) rustfmt-unstable tries to locate a rustfmt.toml file at the workspace root.

Usage examples

I wish to see a diff showing all the files not formatted correctly

rustfmt-unstable

I wish to format all my unformatted files

rustfmt-unstable --apply

I wish to provide another config file and format all my files accordingly

rustfmt-unstable --config-file my-config.toml --apply

I just wish to wrap my existing cargo fmt -- --config opt_a=foo,opt_b=bar command to use the config file correctly

rustfmt-unstable -- cargo fmt -- --config opt_a=foo,opt_b=bar

I wish to check that all my files were correctly formatted in ci

It's probably a good idea to check for overly long lines as well. I'd reccomend

rustfmt-unstable -- cargo fmt --check --all -- --config error_on_line_overflow=true

or if you don't wish to do that just

rustfmt-unstable

Dependencies

~6–12MB
~151K SLoC