summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorojacobson <ojacobson@noreply.codeberg.org>2025-06-10 00:43:57 +0200
committerojacobson <ojacobson@noreply.codeberg.org>2025-06-10 00:43:57 +0200
commit71919b461f25bed1bb4708b0494d603de373ae11 (patch)
treec6fa8e3f4dc6200dbda83fe5257b5631f59bed22
parent2273b6dce6cb650c0a72b71491421f198518bfb7 (diff)
parentbf1ef354817dba47cc955e9654dc204f0dc07d27 (diff)
Rework project formatting tools.
* Changes JS formatting policy to expect trailing commas in most of the places they're allowed. * Moves format checking out of `npm` and into tool scripts. * _Documents_ formatting tools, as well as a shot at a policy for format-only changes designed to alleviate low-value review. This was originally part of [another proposal][pr-6]. I've broken it out to make the intent clearer, and to make the proposal easier to get a handle on in isolation from other, related changes. Thanks to @wlonk for their input on this! [pr-6]: https://codeberg.org/ojacobson/pilcrow/pulls/6 Merges prop/project-formatting into main.
-rw-r--r--.prettierignore13
-rw-r--r--.prettierrc1
-rw-r--r--docs/formatting.md30
-rwxr-xr-xgit-hooks/pre-commit5
-rw-r--r--package.json3
-rwxr-xr-xtools/check-format11
-rwxr-xr-xtools/reformat10
7 files changed, 65 insertions, 8 deletions
diff --git a/.prettierignore b/.prettierignore
index ab78a95..1ebcb2e 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -1,4 +1,11 @@
-# Package Managers
+# Project files
package-lock.json
-pnpm-lock.yaml
-yarn.lock
+/.sqlx/
+/docs/api/mermaid/
+/target/
+/coverage/
+
+# IDE-specific files
+#
+# (There's no local ignores, so it's not practical to separate these out of the project config)
+/.nova/
diff --git a/.prettierrc b/.prettierrc
index 3d01ccd..190fedf 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -1,7 +1,6 @@
{
"useTabs": false,
"singleQuote": true,
- "trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
diff --git a/docs/formatting.md b/docs/formatting.md
new file mode 100644
index 0000000..5339be0
--- /dev/null
+++ b/docs/formatting.md
@@ -0,0 +1,30 @@
+# Formatting
+
+We use automated tools, rather than human effort, to maintain a consistent code formatting convention, where possible. This is handled by two tools:
+
+- Javascript, Markdown, and JSON files are formatted using [prettier].
+- Rust is formatted using [rustfmt].
+
+[prettier]: https://prettier.io
+
+[rustfmt]: https://doc.rust-lang.org/cargo/commands/cargo-fmt.html
+
+## Tools
+
+- To check that code formatting rules are being followed, run
+ `tools/check-format`. This should be run any time you're making changes, and is part of the optional
+ `git-hooks/pre-commit` hook script.
+
+- To reformat the whole project, run `tools/reformat`.
+
+You can also run the individual formatting tools directly. The tool scripts listed above contain the specific commands needed.
+
+## Formatting and code review
+
+Checking in changes produced solely using
+`tools/reformat` or its constituent commands doesn't require review if it's the only thing you're doing. We assume that these tools make sound changes, and that the code style configured for the project is acceptable by default.
+
+However, formatting changes carry an outsized risk of merge conflicts, so they almost always require
+_coordination_. This risk is more severe for larger formatting changes. If you make a formatting fix, it's incumbent on you to follow up on it and to assist other developers with conflicts.
+
+In general, we try to avoid these by fixing formatting issues before they pile up, but if you plan to commit a formatting fix, please check for outstanding work that may conflict with it. You may even want to delay or rescope formatting fixes to accommodate others' in-progress changes.
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