Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
chore: install flakebox
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jan 17, 2024
1 parent 845cca5 commit 28f51af
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
1 change: 1 addition & 0 deletions .config/flakebox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp/
12 changes: 12 additions & 0 deletions .config/flakebox/bin/flakebox-in-each-cargo-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Run a given command in every directory that contains cargo workspace
# Right now it just scans for `Cargo.lock`

set -euo pipefail

find . -name Cargo.lock | while read -r path ; do
(
cd "$(dirname "$path")"
"$@"
)
done
2 changes: 1 addition & 1 deletion .config/flakebox/id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6ed8d7bac0d49950f28394f623607c29d00896bcf1505d366717626babadd81f8f111f93afd1b991b7087d5ce0684b4bcc10124aad93b3876ba1aba600a09cb4
4554d31c5e79420d5b097aad56a49a1c61bb89f32d6b93fb5ff4d0677bc9b587e3426e881d01f5551ff816cfcec2941d0529130f491f6098abb64e6c28592c94
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ group_imports = "StdExternalCrate"
wrap_comments = true
format_code_in_doc_comments = true
imports_granularity = "Module"
edition = "2021"
52 changes: 42 additions & 10 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,81 @@ default:


# run `cargo build` on everything
build:
cargo build --workspace --all-targets
build *ARGS="--workspace --all-targets":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo build {{ARGS}}

# run `cargo check` on everything
check:
cargo check --workspace --all-targets
check *ARGS="--workspace --all-targets":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo check {{ARGS}}

# run all checks recommended before opening a PR
final-check: lint clippy
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo test --doc
just test

# run code formatters
format:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo fmt --all
nixpkgs-fmt $(echo **.nix)

# run lints (git pre-commit hook)
lint:
#!/usr/bin/env bash
set -euo pipefail
env NO_STASH=true $(git rev-parse --git-common-dir)/hooks/pre-commit

# run tests
test: build
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo test

# run and restart on changes
watch:
env RUST_LOG=${RUST_LOG:-debug} cargo watch -x run
watch *ARGS="-x run":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
env RUST_LOG=${RUST_LOG:-debug} cargo watch {{ARGS}}

# run `cargo clippy` on everything
clippy:
cargo clippy --locked --offline --workspace --all-targets -- --deny warnings --allow deprecated
clippy *ARGS="--locked --offline --workspace --all-targets":
cargo clippy {{ARGS}} -- --deny warnings --allow deprecated

# run `cargo clippy --fix` on everything
clippy-fix:
cargo clippy --locked --offline --workspace --all-targets --fix
clippy-fix *ARGS="--locked --offline --workspace --all-targets":
cargo clippy {{ARGS}} --fix


# run `semgrep`
Expand Down
15 changes: 10 additions & 5 deletions misc/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export -f check_nothing
function check_cargo_fmt() {
set -euo pipefail

cargo fmt --all --check
flakebox-in-each-cargo-workspace cargo fmt --all --check

}
export -f check_cargo_fmt
Expand All @@ -43,7 +43,7 @@ function check_cargo_lock() {
set -euo pipefail

# https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5
cargo update --workspace --locked
flakebox-in-each-cargo-workspace cargo update --workspace --locked

}
export -f check_cargo_lock
Expand All @@ -52,7 +52,7 @@ function check_leftover_dbg() {
set -euo pipefail

errors=""
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do
if grep 'dbg!(' "$path" > /dev/null; then
>&2 echo "$path contains dbg! macro"
errors="true"
Expand Down Expand Up @@ -132,8 +132,13 @@ export -f check_trailing_newline
function check_trailing_whitespace() {
set -euo pipefail

if ! git diff --check HEAD ; then
echo "Trailing whitespace detected. Please remove them before committing."
rev="HEAD"
if ! git rev-parse -q 1>/dev/null HEAD 2>/dev/null ; then
>&2 echo "Warning: no commits yet, checking against --root"
rev="--root"
fi
if ! git diff --check $rev ; then
>&2 echo "Trailing whitespace detected. Please remove them before committing."
return 1
fi

Expand Down

0 comments on commit 28f51af

Please sign in to comment.