summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-05-26 23:19:24 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-05-30 19:49:31 -0400
commit1b75b5b7dfc1f3e0afa5125836d899e6f8552368 (patch)
tree022a94dc785855d8e804856f3ab892c7072607af
parentd30584270c657dd69231986cbf612c9d60465899 (diff)
Consolidate code style checks into tool scripts.
The new `tools/check-format` script checks _all_ project formatting - JS (through `prettier`), and Rust (through `rustfmt`). It also checks `prettier` against the whole project, not just against what's in the `ui` subdir, which means it now catches formatting issues in various JS config files (like `.prettierrc` itself). This commit does not include style _fixes_, which means that it does not pass its own `tools/check-format` script. This is intentional, and is intended to make the Git history a bit easier to reason about; a future commit will include format fixes.
-rwxr-xr-xgit-hooks/pre-commit5
-rw-r--r--package.json3
-rwxr-xr-xtools/check-format11
-rwxr-xr-xtools/reformat10
4 files changed, 25 insertions, 4 deletions
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index 587e349..3d0ae17 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -1,8 +1,9 @@
#!/bin/bash -e
# Don't put anything here that routinely takes longer than a second or so to
-# run. It gets old fast. That's why this uses `cargo check` and not `cargo
-# test`, for example.
+# run. It gets old fast. That's why this doesn't run tests, for example.
+
+tools/check-format
# Make sure package-lock.json is up to date with package.json
npm ci --dry-run
diff --git a/package.json b/package.json
index 4501576..3a75fcb 100644
--- a/package.json
+++ b/package.json
@@ -7,8 +7,7 @@
"node": ">=22.0.0 <23.0.0"
},
"scripts": {
- "lint": "prettier --check ui && eslint ui",
- "format": "prettier --write ui"
+ "lint": "eslint ui"
},
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.8",
diff --git a/tools/check-format b/tools/check-format
new file mode 100755
index 0000000..3b68537
--- /dev/null
+++ b/tools/check-format
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+## tools/check-format
+##
+## Verifies that the project's code conforms to the project's preferred style. Exits non-zero
+## if there are style differences.
+
+cd "$(dirname "$0")/.."
+
+npx prettier --check .
+cargo fmt --all --check
diff --git a/tools/reformat b/tools/reformat
new file mode 100755
index 0000000..4dfe7c3
--- /dev/null
+++ b/tools/reformat
@@ -0,0 +1,10 @@
+#!/bin/bash -e
+
+## tools/reformat
+##
+## Automatically reformats code in this project to match the project style.
+
+cd "$(dirname "$0")/.."
+
+npx prettier --write .
+cargo fmt --all