From a8220722fd5379ca503ac67d0c4e29d0e0a08160 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sat, 30 Dec 2023 14:57:18 -0700 Subject: [PATCH] Add linter for Elisp indentation --- Makefile | 25 ++++++++++++++++++++++++- scripts/radian-indent.el | 10 ++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 scripts/radian-indent.el diff --git a/Makefile b/Makefile index a059064..3bfbde7 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ +SHELL := bash + VERSION ?= CMD ?= longlines_files := $(shell find . -name .git -prune -o -print) +for_checkindent := $(shell find . -name .git -prune -o -name '*.el' -print) .PHONY: help help: ## Show this message @@ -32,12 +35,32 @@ checkdoc: ## Check docstring style in radian.el longlines: ## Check for long lines @scripts/check-line-length.bash +.PHONY: checkindent +checkindent: ## Ensure that indentation is correct + @tmpdir="$$(mktemp -d)"; for file in $(for_checkindent); do \ + emacs -Q --batch \ + -l scripts/radian-indent.el \ + --eval "(setq inhibit-message t)" \ + --eval "(progn \ + (setq straight-safe-mode t) \ + (load (expand-file-name \"init.el\" \ + user-emacs-directory) nil t))" \ + --eval "(find-file \"$$file\")" \ + --eval "(indent-region (point-min) (point-max))" \ + --eval "(write-file \"$$tmpdir/indented.el\")"; \ + (diff <(cat "$$file" | nl -v1 -ba | \ + sed "s/\t/: /" | sed "s|^ *|$$file:|") \ + <(cat "$$tmpdir/indented.el" | nl -v1 -ba | \ + sed "s/\t/: /" | sed "s|^ *|$$file:|") ) \ + | grep -F ">" | grep -o "[a-z].*" | grep . && exit 1 || true; \ + done + .PHONY: validate validate: ## Validate el-patches @scripts/validate-patches.bash .PHONY: lint -lint: build compile validate checkdoc longlines ## Run all linters +lint: build compile validate checkdoc longlines checkindent ## Run all linters .PHONY: clean clean: ## Remove build artifacts diff --git a/scripts/radian-indent.el b/scripts/radian-indent.el new file mode 100644 index 0000000..ec69881 --- /dev/null +++ b/scripts/radian-indent.el @@ -0,0 +1,10 @@ +;; This file has code that is evaluated in CI before the indentation +;; of Radian is checked. This is helpful because it allows us to +;; ensure that various things are indented correctly if they require +;; some setup for Emacs to know how to do the right thing. + +;; The indentation of `define-key' has for some reason changed in +;; Emacs 29 when it was deprecated in favor of `keymap-set'. Maybe +;; that is a bug and they will change it, but for now, force the +;; indentation to the backwards-compatible version. +(put #'define-key 'lisp-indent-function 'defun)