Skip to content

Commit 893ae1f

Browse files
committed
Use pre-commit from Nix shell for CI style check
1 parent 4f8b44d commit 893ae1f

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

.github/workflows/ci.yml

+6-26
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,18 @@ env:
77
RUST_BACKTRACE: full
88

99
jobs:
10-
format:
11-
name: Format
10+
style:
11+
name: Code style check
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v3
16-
- name: Install Rust
17-
uses: actions-rs/toolchain@v1
18-
with:
19-
profile: minimal
20-
toolchain: nightly
21-
components: rustfmt
22-
- name: Check format
23-
run: cargo fmt --all -- --check
24-
25-
clippy:
26-
name: Clippy
27-
runs-on: ubuntu-latest
28-
steps:
29-
- name: Checkout
30-
uses: actions/checkout@v3
31-
# For builtins.
3216
- name: Install Nix
3317
uses: cachix/install-nix-action@v17
34-
- name: Install Rust
35-
uses: actions-rs/toolchain@v1
36-
with:
37-
profile: minimal
38-
toolchain: stable
39-
components: clippy
40-
- name: Check clippy
41-
run: cargo clippy --all -- -D warnings
18+
- name: Prepare devShell
19+
run: nix develop --command true
20+
- name: Run pre-commit
21+
run: nix develop --command pre-commit
4222

4323
test:
4424
name: Test

flake.nix

+12-4
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,22 @@
3838
pkgs = nixpkgs.legacyPackages.${system};
3939
rustPkgs = rust-overlay.packages.${system};
4040

41+
clippyFlags = lib.concatStringsSep " " [
42+
"-D" "warnings"
43+
"-D" "clippy::dbg_macro"
44+
];
45+
4146
pre-commit = pkgs.writeShellScriptBin "pre-commit" ''
4247
set -e
4348
die() { echo "$*" >&2; exit 1; }
4449
45-
cd "$(git rev-parse --show-toplevel)"
46-
rg --fixed-strings 'dbg!' --glob '*.rs' \
47-
&& die 'Found dbg!()'
48-
cargo fmt --quiet --check >/dev/null \
50+
if git_dir="$(git rev-parse --show-toplevel)"; then
51+
cd "$git_dir"
52+
fi
53+
cargo fmt --all --check \
4954
|| die 'Format failed'
55+
cargo clippy --all --all-targets -- ${clippyFlags} \
56+
|| die 'Clippy failed'
5057
'';
5158

5259
nil = pkgs.callPackage mkNil { };
@@ -79,6 +86,7 @@
7986

8087
RUST_BACKTRACE = "short";
8188
NIXPKGS = nixpkgs;
89+
CLIPPY_FLAGS = clippyFlags;
8290

8391
# bash
8492
shellHook = ''

0 commit comments

Comments
 (0)