From: Frank Duncan Date: Sun, 12 Jul 2015 15:15:55 +0000 (-0500) Subject: Check for spaces/newlines after opening a form X-Git-Tag: 0.1~7 X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=commitdiff_plain;h=52971da82a4de888ce44eedbc942ee480bc0306f;p=wolf Check for spaces/newlines after opening a form --- diff --git a/resources/good.lisp b/resources/good.lisp index bca3e85..adb5e37 100644 --- a/resources/good.lisp +++ b/resources/good.lisp @@ -5,7 +5,10 @@ (defun hello-world (a b c) (progn - (with-open-file (str "increasinglylongfilenamesfailme.dat" :direction :input :if-does-not-exist :create) - (when - (read-line str) - (format t "This file had some things in int, yay!~%"))))) + (let + ((x y) + (z 9)) + (with-open-file (str "increasinglylongfilenamesfailme.dat" :direction :input :if-does-not-exist :create) + (when + (read-line str) + (format t "This file had some things in int, yay!~%"))))) diff --git a/resources/newlineafteropenparens.lisp b/resources/newlineafteropenparens.lisp new file mode 100644 index 0000000..749ffba --- /dev/null +++ b/resources/newlineafteropenparens.lisp @@ -0,0 +1,15 @@ +(in-package #:nothing) + +(defun small-guy (a b) (+ a b)) +(defun small-guy-2 (a b) (+ a b)) + +(defun hello-world (a b c) + (progn + (let + ((x y) + (z 9)) + (with-open-file (str "increasinglylongfilenamesfailme.dat" :direction :input :if-does-not-exist :create) + ( + when + (read-line str) + (format t "This file had some things in int, yay!~%"))))) diff --git a/resources/spaceafteropenparens.lisp b/resources/spaceafteropenparens.lisp new file mode 100644 index 0000000..4cab605 --- /dev/null +++ b/resources/spaceafteropenparens.lisp @@ -0,0 +1,14 @@ +(in-package #:nothing) + +(defun small-guy (a b) (+ a b)) +(defun small-guy-2 (a b) (+ a b)) + +(defun hello-world (a b c) + (progn + (let + ((x y) + (z 9)) + (with-open-file (str "increasinglylongfilenamesfailme.dat" :direction :input :if-does-not-exist :create) + ( when + (read-line str) + (format t "This file had some things in int, yay!~%"))))) diff --git a/src/main/checker.lisp b/src/main/checker.lisp index 3db05e2..02a3d2d 100644 --- a/src/main/checker.lisp +++ b/src/main/checker.lisp @@ -1,7 +1,8 @@ (in-package #:style-checker) ; Rules -; - Elements in each form must be indented the same amount +; - Elements on new line in each form must be indented the same amount +; * No space/newline after open parens ; * No form longer than 50 lines ; * Top level multiline forms must be separated by exactly one space ; * No line longer than 120 characters @@ -40,6 +41,7 @@ :beginning-of-line-with-separator ; empty space in there :beginning-of-symbols :beginning-of-symbols-with-separator + :first-symbol-of-form ; After an open parens :all ; matches everything ))) @@ -112,40 +114,29 @@ ; These are in reverse order (progn (setf *evaluators* nil) - (defevaluator :all "\\t" - (constantly "Must not use tabs")) - (defevaluator :begin "\\(in-package[^\\)]*\\)" - (lambda () (set-state :normal))) - (defevaluator :beginning-of-line-with-separator :eof - (constantly "Must not end with empty line")) - (defevaluator :beginning-of-line-with-separator "\\n" - (constantly "Must not have two empty lines in a row")) - (defevaluator :begin ".*" - (constantly "Must begin with in-package form")) - (defevaluator :normal "\\( *in-package " - (constantly "Only one in-package per file")) + (defevaluator :all "\\t" (constantly "Must not use tabs")) + (defevaluator :begin "\\(in-package[^\\)]*\\)" (lambda () (set-state :normal))) + (defevaluator :beginning-of-line-with-separator :eof (constantly "Must not end with empty line")) + (defevaluator :beginning-of-line-with-separator "\\n" (constantly "Must not have two empty lines in a row")) + (defevaluator :begin ".*" (constantly "Must begin with in-package form")) + (defevaluator :normal "\\( *in-package " (constantly "Only one in-package per file")) (defevaluator :normal "\\n" (lambda () (set-state :beginning-of-line) (incf *line-no*) (setf *col-no* -1) nil)) - (defevaluator :normal " +\\n" - (constantly "No whitespace at end of line")) - (defevaluator :beginning-of-line " *" - (lambda () (set-state :beginning-of-symbols))) - (defevaluator :beginning-of-line-with-separator " *" - (lambda () (set-state :beginning-of-symbols-with-separator))) + (defevaluator :normal " +\\n" (constantly "No whitespace at end of line")) + (defevaluator :beginning-of-line " *" (lambda () (set-state :beginning-of-symbols))) + (defevaluator :beginning-of-line-with-separator " *" (lambda () (set-state :beginning-of-symbols-with-separator))) (defevaluator :beginning-of-symbols "\\n" (lambda () (if (< 0 *col-no*) "No whitespace only lines" (set-state :beginning-of-line-with-separator)))) - (defevaluator :beginning-of-symbols "\\)" - (constantly "No hanging close parens")) - (defevaluator :beginning-of-symbols-with-separator "\\)" - (constantly "No hanging close parens")) + (defevaluator :beginning-of-symbols "\\)" (constantly "No hanging close parens")) + (defevaluator :beginning-of-symbols-with-separator "\\)" (constantly "No hanging close parens")) (defevaluator :beginning-of-symbols "" (lambda () (if @@ -160,7 +151,7 @@ (push (list *line-no* *col-no*) *form-stack*) - nil)) + (set-state :first-symbol-of-form))) (defevaluator :normal "\\)" (lambda () (let @@ -169,6 +160,8 @@ ((not form) "Unmatched ending paren") ((< 50 (- *line-no* (car form))) "Forms can't be over 50 lines long") (t (setf *form-ended-on-same-line* (= *line-no* (car form))) nil))))) - (defevaluator :normal "::" - (constantly "No internal symbols from other packages")) + (defevaluator :normal "::" (constantly "No internal symbols from other packages")) + (defevaluator :first-symbol-of-form "\\n" (constantly "No new line after opening form")) + (defevaluator :first-symbol-of-form " " (constantly "No space after opening parens")) + (defevaluator :first-symbol-of-form "" (lambda () (set-state :normal))) (defevaluator :normal "." (constantly nil)))