Skip to content

Commit

Permalink
chore: Add imports_granularity=Module to rustfmt config
Browse files Browse the repository at this point in the history
  • Loading branch information
jbencin committed Oct 10, 2023
1 parent 4202b67 commit 00f10e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/actions/bitcoin-int-tests/Dockerfile.rustfmt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN rustup component add rustfmt

COPY . .

RUN cargo fmt --all -- --check
RUN cargo fmt --all -- --check --config group_imports=StdExternalCrate,imports_granularity=Module
17 changes: 11 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ you push your code. Follow these instruction to set it up:
2. Change the content of `.git/hooks/pre-commit` to be the following
```sh
#!/bin/sh
git diff --name-only --staged | grep '\.rs$' | xargs -P 8 -I {} rustfmt {} --edition 2021 --check --config group_imports=StdExternalCrate || (
echo 'rustfmt failed: run "cargo fmt --all -- --config group_imports=StdExternalCrate"';
git diff --name-only --staged | grep '\.rs$' | xargs -P 8 -I {} rustfmt {} --edition 2021 --check --config group_imports=StdExternalCrate,imports_granularity=Module || (
echo 'rustfmt failed: run "cargo fmt --all -- --config group_imports=StdExternalCrate,imports_granularity=Module"';
exit 1
)
```
Expand Down Expand Up @@ -384,19 +384,24 @@ A test should be marked `#[ignore]` if:

## Formatting

This repository uses the default rustfmt formatting style. PRs will be checked against `rustfmt` and will _fail_ if not
properly formatted.
PRs will be checked against `rustfmt` and will _fail_ if not properly formatted.
Unfortunately, some config options that we require cannot currently be set in `.rustfmt` files currently, so arguments must be passed via the command line.
There is a Makefile target to simplify calling `cargo fmt` with the desired config.

You can check the formatting locally via:

```bash
cargo fmt --all -- --check --config group_imports=StdExternalCrate
cargo fmt --all -- --check --config group_imports=StdExternalCrate,imports_granularity=Module
# Or
make fmt-check
```

You can automatically reformat your commit via:

```bash
cargo fmt --all -- --config group_imports=StdExternalCrate
cargo fmt --all -- --config group_imports=StdExternalCrate,imports_granularity=Module
# Or
make fmt
```

## Comments
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Shortcuts for common commands

.PHONY: fmt fmt-check

# Run `cargo fmt` with CLI options not available in rustfmt.toml
fmt:
cargo fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module

# Run `cargo fmt` with CLI options not available in rustfmt.toml (check only)
fmt-check:
cargo fmt -- --check --config group_imports=StdExternalCrate,imports_granularity=Module

0 comments on commit 00f10e7

Please sign in to comment.