1

I want to add a static code checker as a pre-commit hook on my Emacs-Lisp code, mainly for catching errors such as Symbol’s function definition is void.

Static code analysis tool for Common Lisp? suggests lisp-critic (original and remake). It uses ASDF (Another System Definition Facility), which I'd need to install on my machine, and wrap the call to lisp-critic in a bash script in .git/hooks/pre-commit as in Git: Prevent commits in master branch.

The documentation for lisp-critic uses inline code:

 (critique
    (defun count-a (lst)
      (setq n 0)
      (dolist (x lst)
        (if (equal x 'a)
          (setq n (+ n 1))))
      n))

and I'm not sure if the package analyzes code defined in a separate file. And I also don't know if lisp-critic is compatible with Emacs-LISP.

Has anyone set up a similar system who can give me some pointers?

miguelmorin
  • 5,025
  • 4
  • 29
  • 64
  • 5
    There's pretty much zero chance lisp-critic will work for elisp: elisp's last common ancestor with CL was in the late 1970s. Wouldn't using some kind of test framework be better? –  Dec 31 '19 at 18:12
  • Yes, probably. I found the Emacs function `elint-file` and attempted to include it in a pre-commit hook, but `emacs --batch -f package-initialize --eval "(elint-file 'functions.el')"` throws `Invalid read syntax: ")"` when running it from Emacs does not; and also to include it in an ERT test with `(ert-deftest lint-free () (should (equal (elint-file ...))` in the file but couldn't find how to refer to the file from the file itself. – miguelmorin Jan 07 '20 at 19:22

0 Answers0