Skip to content

Commit 1030964

Browse files
committed
chore: split lint and format tasks
1 parent 2e7caed commit 1030964

File tree

9 files changed

+277
-74
lines changed

9 files changed

+277
-74
lines changed

.agents/codebase-insights.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flake.nix defines a pre-commit check using git-hooks.nix. Run 'nix develop' to install git hooks.

.agents/codex-setup

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ sudo apt-get install -y --no-install-recommends \
1010
libclang-dev \
1111
capnproto libcapnp-dev
1212

13+
rustup component add rustfmt
14+
1315
pushd ..
1416
just build-extension
1517
popd
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add just targets for running auto formatters (e.g just format). Setup a git pre commit that checks that lints pass using the same technique employed by the Blocksense-network blocksense repo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Break format and lint tasks into per-language subcommands

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ reports/
77
test/benchmarks/tmp/
88
.direnv/
99
.idea/
10+
11+
# Generated by git-hooks.nix
12+
.pre-commit-config.yaml
1013
pkg/
1114

1215
# Built ruby gems

Justfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,33 @@ bench pattern="*" write_report="console":
88

99
build-extension:
1010
cargo build --release --manifest-path gems/codetracer-ruby-recorder/ext/native_tracer/Cargo.toml
11+
12+
format-rust:
13+
cargo fmt --manifest-path gems/codetracer-ruby-recorder/ext/native_tracer/Cargo.toml
14+
15+
format-nix:
16+
if command -v nixfmt >/dev/null; then find . -name '*.nix' -print0 | xargs -0 nixfmt; fi
17+
18+
format-ruby:
19+
if command -v bundle >/dev/null && bundle exec rubocop -v >/dev/null 2>&1; then bundle exec rubocop -A; else echo "Ruby formatter not available; skipping"; fi
20+
21+
format:
22+
just format-rust
23+
just format-ruby
24+
just format-nix
25+
26+
lint-rust:
27+
cargo fmt --check --manifest-path gems/codetracer-ruby-recorder/ext/native_tracer/Cargo.toml
28+
29+
lint-nix:
30+
if command -v nixfmt >/dev/null; then find . -name '*.nix' -print0 | xargs -0 nixfmt --check; fi
31+
32+
lint-ruby:
33+
find . -name '*.rb' -print0 | xargs -0 -n 1 ruby -wc
34+
35+
lint:
36+
just lint-rust
37+
just lint-ruby
38+
just lint-nix
39+
40+
alias fmt := format

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ We'd be very happy if the community finds this useful, and if anyone wants to:
129129

130130
For maintainer instructions, see [MAINTAINERS.md](MAINTAINERS.md).
131131

132+
### Development workflow
133+
134+
Use [just](https://github.com/casey/just) for common tasks:
135+
136+
```bash
137+
just build-extension # compile native extension
138+
just test # run the test suite
139+
just format # apply automatic formatting for all languages
140+
just lint # run all linters
141+
142+
# Language-specific tasks
143+
just format-rust # Rust code
144+
just format-ruby # Ruby code (requires rubocop)
145+
just format-nix # Nix files
146+
just lint-rust # Rust formatting check
147+
just lint-ruby # Ruby syntax check
148+
just lint-nix # Nix formatting check
149+
```
150+
132151
### Legal info
133152

134153
LICENSE: MIT

flake.nix

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,34 @@
22
description = "Development environment for codetracer-ruby-recorder";
33

44
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
5+
inputs.pre-commit-hooks.url = "github:cachix/git-hooks.nix";
56

67
outputs = {
78
self,
89
nixpkgs,
10+
pre-commit-hooks,
911
}: let
1012
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
1113
forEachSystem = nixpkgs.lib.genAttrs systems;
1214
in {
15+
checks = forEachSystem (system: {
16+
pre-commit-check = pre-commit-hooks.lib.${system}.run {
17+
src = ./.;
18+
hooks = {
19+
lint = {
20+
enable = true;
21+
name = "Lint";
22+
entry = "just lint";
23+
language = "system";
24+
pass_filenames = false;
25+
};
26+
};
27+
};
28+
});
29+
1330
devShells = forEachSystem (system: let
14-
pkgs = import nixpkgs {inherit system;};
31+
pkgs = import nixpkgs { inherit system; };
32+
preCommit = self.checks.${system}.pre-commit-check;
1533
isLinux = pkgs.stdenv.isLinux;
1634
isDarwin = pkgs.stdenv.isDarwin;
1735
in {
@@ -43,7 +61,7 @@
4361
# Required for Ruby C extension compilation on macOS
4462
darwin.apple_sdk.frameworks.CoreFoundation
4563
darwin.apple_sdk.frameworks.Security
46-
];
64+
] ++ preCommit.enabledPackages;
4765

4866
# Environment variables required to fix build issues with rb-sys/bindgen
4967

@@ -56,6 +74,8 @@
5674
CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang";
5775
CC = "${pkgs.llvmPackages.clang}/bin/clang";
5876
CXX = "${pkgs.llvmPackages.clang}/bin/clang++";
77+
78+
inherit (preCommit) shellHook;
5979
} // pkgs.lib.optionalAttrs isLinux {
6080
# BINDGEN_EXTRA_CLANG_ARGS: Additional clang arguments for bindgen when parsing Ruby headers
6181
# Includes system header paths that are not automatically discovered in NixOS

0 commit comments

Comments
 (0)