summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorojacobson <ojacobson@noreply.codeberg.org>2025-06-11 18:27:15 +0200
committerojacobson <ojacobson@noreply.codeberg.org>2025-06-11 18:27:15 +0200
commita6ae7ee0170e2235ffc9c4eacddae2fb6878ad07 (patch)
treeb183dc5557b9e6c6d46385581f74d30001d06065
parent71919b461f25bed1bb4708b0494d603de373ae11 (diff)
parentc0f3495ea54d12b2bad9b937ea9334594d0aa248 (diff)
Consolidate project linting into tool scripts.
The new `tools/check-lint` script checks lints across _all_ lintable files - JS (through `eslint`), and Rust (through `clippy` and `cargo check`). It also checks `eslint` against the whole project, not just against what's in the `ui` subdir, which means it now catches lintable issues in various JS config files. 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/lint-checks into main.
-rw-r--r--docs/linting.md23
-rw-r--r--eslint.config.js9
-rwxr-xr-xgit-hooks/pre-commit4
-rw-r--r--package.json3
-rwxr-xr-xtools/check-lint11
-rwxr-xr-xtools/delint11
6 files changed, 54 insertions, 7 deletions
diff --git a/docs/linting.md b/docs/linting.md
new file mode 100644
index 0000000..6620a74
--- /dev/null
+++ b/docs/linting.md
@@ -0,0 +1,23 @@
+# Linting
+
+We use automated tools, rather than human effort, to spot possible bugs or dubious structural choices, where possible. This is handled by three tools:
+
+- Javascript is linted using [eslint].
+- Rust is linted using [cargo check] and [clippy].
+
+[eslint]: https://eslint.org/
+
+[cargo check]: https://doc.rust-lang.org/cargo/commands/cargo-check.html
+
+[clippy]: https://doc.rust-lang.org/cargo/commands/cargo-clippy.html
+
+## Tools
+
+- To check for detectable lints, run
+ `tools/check-lint`. This should be run whenever making changes, and is part of the optional
+ `git-hooks/pre-commit` hook script.
+
+- To fix lints that have automatic fixes, run
+ `tools/delint`.
+
+You can also run the individual lint tools directly. The tool scripts listed above contain the specific commands needed.
diff --git a/eslint.config.js b/eslint.config.js
index 7d23626..57b0875 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -1,3 +1,10 @@
import prettier from 'eslint-config-prettier';
import svelte from 'eslint-plugin-svelte';
-export default [prettier, ...svelte.configs['flat/prettier']];
+
+export default [
+ prettier,
+ ...svelte.configs['flat/prettier'],
+ {
+ ignores: ['target/', 'coverage/'],
+ },
+];
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index 3d0ae17..ea34684 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -4,14 +4,12 @@
# run. It gets old fast. That's why this doesn't run tests, for example.
tools/check-format
+tools/check-lint
# Make sure package-lock.json is up to date with package.json
npm ci --dry-run
# Make sure Cargo.lock is up to date with Cargo.toml.
cargo update --locked --workspace
-# Make sure there are no screamers in the code (both languages).
-npm run lint
-cargo check
# Make sure the prepared statement data in .sqlx is up to date. Requires
# `cargo-sqlx` (`cargo install cargo-sqlx`).
export DATABASE_URL=sqlite://pilcrow.db.pre-commit?mode=rwc
diff --git a/package.json b/package.json
index 3a75fcb..6a1446e 100644
--- a/package.json
+++ b/package.json
@@ -6,9 +6,6 @@
"npm": ">=10.0.0 <11.0.0",
"node": ">=22.0.0 <23.0.0"
},
- "scripts": {
- "lint": "eslint ui"
- },
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.8",
"@sveltejs/kit": "^2.17.2",
diff --git a/tools/check-lint b/tools/check-lint
new file mode 100755
index 0000000..ab7fdd3
--- /dev/null
+++ b/tools/check-lint
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+## tools/check-lint
+##
+## Detects lintable mistakes and stylistic problems.
+
+cd "$(dirname "$0")/.."
+
+npx eslint
+cargo check
+cargo clippy
diff --git a/tools/delint b/tools/delint
new file mode 100755
index 0000000..132841b
--- /dev/null
+++ b/tools/delint
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+## tools/delint
+##
+## Automatically fixes lintable mistakes and stylistic problems, where possible.
+
+cd "$(dirname "$0")/.."
+
+npx eslint --fix
+cargo fix
+cargo clippy --fix