Skip to content

Commit

Permalink
Add typo checking on pre-commit
Browse files Browse the repository at this point in the history
This will use https://github.com/crate-ci/typos to warn on new typos
before committing using bin/pre-commit.
  • Loading branch information
tobias committed Jun 30, 2024
1 parent 02a1023 commit b5fbe9e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
18 changes: 18 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[default]
extend-ignore-re = [
# ns alias
":as [0-9a-z]*\\]"
]

[default.extend-words]
Blance = "Blance"
edn = "edn"
juxt = "juxt"

[type.gpg]
extend-glob = ["*.gpg"]
check-file = false

[type.min-js]
extend-glob = ["*.min.js"]
check-file = false
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ tag-release:
test:
./bin/kaocha

.PHONY: typos
typos:
./bin/typos

.PHONY: uberjar
uberjar:
clojure -T:build uberjar
9 changes: 8 additions & 1 deletion bin/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Make sure I'm not about to introduce more kondo linting errors/warnings
# Make sure I'm not about to introduce more kondo linting errors/warnings or typos

# get just the clj/cljs files from the git changeset
changed_clj="$(git diff --cached --name-only | grep -E 'cljs?$')"
Expand All @@ -18,3 +18,10 @@ if [ -n "${changed_clj}" ] ; then
git add "$f"
done
fi

changed_files="$(git diff --cached --name-only)"
if [ -n "${changed_files}" ]; then
if ! ./bin/typos $changed_files; then
exit 1
fi
fi
54 changes: 54 additions & 0 deletions bin/typos
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Self-extracting typos shim. Sourced releases from GitHub.

set -euo pipefail

TYPOS_VERSION="v1.22.9"
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd)

function ensure_typos() {
# Doesn't take args, simply reads variables set above.
VERSION=$TYPOS_VERSION
PLATFORM="$(uname -s)"
ARCH="$(uname -m)"
PATH_SUFFIX=""

if [ "${PLATFORM}" == "Darwin" ]; then
if [ "${ARCH}" == "x86_64" ]; then
PATH_SUFFIX="x86_64-apple-darwin"
elif [ "${ARCH}" == "arm64" ]; then
PATH_SUFFIX="aarch64-apple-darwin"
fi
elif [ "${PLATFORM}" == "Linux" ]; then
if [ "${ARCH}" == "x86_64" ]; then
PATH_SUFFIX="x86_64-unknown-linux-musl"
fi
fi

if [ -z "$PATH_SUFFIX" ]; then
echo "Platform ${PLATFORM} and ${ARCH} combination is currently not supported" >&2 && exit 1
fi

ARCHIVE="typos-${VERSION}-${PATH_SUFFIX}.tar.gz"
CACHE_DIR="$ROOT/bin/.cache/typos-${VERSION}"
if ! [ -f "${CACHE_DIR}/BOOTSTRAPPED" ]; then
echo "Missing typos binary for version [${VERSION}] -- will download." >&2
PACKAGE_FULL_URL="https://github.com/crate-ci/typos/releases/download/${VERSION}/${ARCHIVE}"
mkdir -p "$ROOT/bin/.cache"
pushd "$ROOT/bin/.cache" >/dev/null 2>&1 || exit 1
echo "Downloading ${PACKAGE_FULL_URL}..." >&2
curl -#L -O "${PACKAGE_FULL_URL}" ||
(echo "Failed to download ${PACKAGE_FULL_URL}." && exit 1)

(rm -rf "$CACHE_DIR" &&
mkdir "$CACHE_DIR" &&
tar --extract --directory="$CACHE_DIR" -f "${ARCHIVE}") >&2 ||
(echo "Failed to extract ${PACKAGE_FULL_URL}." && exit 1)
rm -rf "${ARCHIVE}"
touch "${CACHE_DIR}/BOOTSTRAPPED"
popd >/dev/null 2>&1 || exit 2
fi
}

ensure_typos
exec "${ROOT}/bin/.cache/typos-${VERSION}/typos" "$@"
2 changes: 1 addition & 1 deletion resources/public/stylesheets/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ a.login-button {
color: #ffffff;
padding: 5px 10px;
display: block;
-webkit-appearence: button;
-webkit-appearance: button;
text-align: center;

margin-top: 15px;
Expand Down

0 comments on commit b5fbe9e

Please sign in to comment.