check / check (push) Failing after 2s
gofumpt was pinned only by its version tag. It is now a tool of a separate module in tools/, so `go tool` builds it from source checked against the hashes in tools/go.sum, and mfer's own module gains no dependencies. script/prettier no longer falls back to a prettier on PATH, and fails when node_modules holds a different version than package.json pins. The bootstrap comment now says what --frozen-lockfile really does, package.json drops its made-up version, and the golang image comment names its exact version. Model: opus-5-5
62 lines
2.2 KiB
Bash
Executable File
62 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# script/prettier: run prettier over this repo's canonical file set.
|
|
#
|
|
# Takes exactly one mode argument, --write or --check, and applies the
|
|
# same patterns in both modes. script/fmt and script/fmt-check both go
|
|
# through here, so the set of files that get formatted and the set that
|
|
# get verified cannot drift apart.
|
|
#
|
|
# Failures are never swallowed: a missing prettier is an error, not a
|
|
# silent skip. A formatter that quietly does nothing is worse than one
|
|
# that fails loudly.
|
|
set -eu
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
|
|
usage() {
|
|
echo "usage: script/prettier --write|--check" >&2
|
|
exit 2
|
|
}
|
|
|
|
# Only the prettier yarn installed from yarn.lock, never one on PATH: a
|
|
# different version formats differently.
|
|
PRETTIER="$ROOT/node_modules/.bin/prettier"
|
|
|
|
main() {
|
|
[ "$#" -eq 1 ] || usage
|
|
case "$1" in
|
|
--write | --check) mode="$1" ;;
|
|
*) usage ;;
|
|
esac
|
|
|
|
cd "$ROOT"
|
|
|
|
# node_modules keeps the old prettier after package.json moves to a new
|
|
# one, until script/bootstrap runs again, so compare the two. A prettier
|
|
# that runs also means node is on PATH, which reading package.json needs.
|
|
if ! installed="$("$PRETTIER" --version 2>/dev/null)"; then
|
|
echo "prettier: not installed; run script/bootstrap" >&2
|
|
exit 1
|
|
fi
|
|
pinned="$(node -p 'require("./package.json").devDependencies.prettier')"
|
|
if [ "$installed" != "$pinned" ]; then
|
|
echo "prettier: package.json pins $pinned but $installed is" \
|
|
"installed; run script/bootstrap" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Markdown and JSON, repo-wide rather than root-only, so files in
|
|
# subdirectories (docs/, once it exists) are covered too. Exclusions
|
|
# live in .prettierignore; REPO_POLICIES.md is excluded there because
|
|
# it is a verbatim copy of an upstream document.
|
|
#
|
|
# --no-error-on-unmatched-pattern is deliberately NOT used: both
|
|
# patterns always match at least one tracked file (README.md,
|
|
# package.json), so an empty match means the glob broke, and prettier
|
|
# erroring out is exactly what we want rather than a vacuous pass.
|
|
"$PRETTIER" "$mode" "**/*.md"
|
|
"$PRETTIER" "$mode" "**/*.json"
|
|
}
|
|
|
|
main "$@"
|