Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 2.25 KB

0125-lisp-critic.org

File metadata and controls

76 lines (60 loc) · 2.25 KB

lisp-critic

A few weeks ago, I’ve reviewed the sblint - a tool to check code quality in terms of warnings from the SBCL compiler. Lisp-critic is another kind of beast. It checks the code quality in terms of common patterns and idioms.

For example, it outputs warning when there is only one subform inside the progn or if you are setting global variables in the function definition:

POFTHEDAY> (lisp-critic:critique
            (progn
              (format t "Hello World!")))
----------------------------------
Why do you think you need a PROGN?
----------------------------------

POFTHEDAY> (lisp-critic:critique
            (defun start-server ()
              (setf *server*
                    (listen-on :port 8080))
              (values)))
----------------------------------------------------
GLOBALS!! Don't use global variables, i.e., *SERVER*
----------------------------------------------------

Lisp-critic operates on patterns. There are 109 built-in patterns and you can define more:

POFTHEDAY> (length (lisp-critic:get-pattern-names))
109

POFTHEDAY> (rutils:take 10
             (lisp-critic:get-pattern-names))
(LISP-CRITIC::?-FOR-PREDICATE
 LISP-CRITIC::ADD-ZERO
 LISP-CRITIC::APPEND-LIST-LIST
 LISP-CRITIC::APPEND-LIST-LOOP
 LISP-CRITIC::APPEND-LIST-RECURSION
 LISP-CRITIC::APPEND-LIST2-LIST
 LISP-CRITIC::APPLY-FOR-FUNCALL
 LISP-CRITIC::CAR-CDR
 LISP-CRITIC::CONCATENATE-LIST
 LISP-CRITIC::COND->OR)

Also, you can use lisp-critic:critique-file to analyze all top-level forms in a file.

It would be nice to:

  • add a command-line tool (like sblint) to check all files in the project;
  • to add the ability to ignore some checks for some forms. Probably declaim could be used for this purpose?

Probably adding an integration with SLIME or SLY would also be a good idea.

This way you’ll be able to hit some shortcuts to receive recommendations from Lisp Critic, or it could happen when you are evaluating a top-level form.