aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadon Rosborough <radon.neon@gmail.com>2022-01-03 20:07:29 -0800
committerRadon Rosborough <radon.neon@gmail.com>2022-01-03 20:07:29 -0800
commita606d59c2dbe3b7fc70950c989ca02e6a0a15095 (patch)
tree498c1103a7894c24bd6450213b8942035d0256f8
parente1dbc1b1c04eca33749d7e931c5bb17ea6f9379e (diff)
Port longlines checker from CTRLF
-rw-r--r--Makefile13
-rwxr-xr-xscripts/check-line-length.bash26
2 files changed, 28 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 259ad75..f80d759 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,6 @@ EMACS ?= emacs
# The order is important for compilation.
for_compile := *.el
for_checkdoc := *.el
-for_longlines := $(wildcard *.el *.md *.yml) Makefile
.PHONY: help
help: ## Show this message
@@ -42,16 +41,8 @@ checkdoc: ## Check for missing or poorly formatted docstrings
done
.PHONY: longlines
-longlines: ## Check for lines longer than 79 characters
- @for file in $(for_longlines); do \
- echo "[longlines] $$file" ;\
- cat "$$file" \
- | sed '/[l]onglines-start/,/longlines-stop/d' \
- | grep -E '.{80}' \
- | grep -E -v 'https?://' \
- | sed "s/^/$$file:long line: /" \
- | grep . && exit 1 || true ;\
- done
+longlines: ## Check for long lines
+ @scripts/check-line-length.bash
.PHONY: clean
clean: ## Remove build artifacts
diff --git a/scripts/check-line-length.bash b/scripts/check-line-length.bash
new file mode 100755
index 0000000..c6a040d
--- /dev/null
+++ b/scripts/check-line-length.bash
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+set -e
+set -o pipefail
+
+find=(
+ find .
+ -name .git -prune -o
+ -name "*.elc" -o
+ -type f -print
+)
+
+readarray -t files < <("${find[@]}" | sed 's#./##' | sort)
+
+code="$(cat <<"EOF"
+
+(length($0) >= 80 && $0 !~ /https?:\/\//) \
+{ printf "%s:%d: %s\n", FILENAME, NR, $0 }
+
+EOF
+)"
+
+for file in "${files[@]}"; do
+ echo "[longlines] $file" >&2
+ awk "$code" "$file"
+done | (! grep .)