From a606d59c2dbe3b7fc70950c989ca02e6a0a15095 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Mon, 3 Jan 2022 20:07:29 -0800 Subject: Port longlines checker from CTRLF --- Makefile | 13 ++----------- scripts/check-line-length.bash | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100755 scripts/check-line-length.bash 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 .) -- cgit v1.0