@atlisp/lint 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atlisp-lint.default.json +90 -0
- package/dist/lib/lint-sbcl.lisp +161 -0
- package/dist/stub-packages.json +41 -0
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"locale": "zh",
|
|
3
|
+
"source": {
|
|
4
|
+
"globs": ["**/*.lsp"],
|
|
5
|
+
"exclude": ["**/node_modules/**", "**/vendor/**", "**/.git/**"]
|
|
6
|
+
},
|
|
7
|
+
"checks": {
|
|
8
|
+
"parens": "error",
|
|
9
|
+
"encoding": "warn",
|
|
10
|
+
"cl_syntax": "warn",
|
|
11
|
+
"quit_exit": "error",
|
|
12
|
+
"command_shell": "error",
|
|
13
|
+
"startapp": "warn",
|
|
14
|
+
"vl_registry_write": "warn",
|
|
15
|
+
"vlax_without_loading": "off",
|
|
16
|
+
"token_in_url": "warn",
|
|
17
|
+
"open_without_close": "warn",
|
|
18
|
+
"bare_function_names": "off",
|
|
19
|
+
"line_length": "warn",
|
|
20
|
+
"function_complexity": "warn",
|
|
21
|
+
"parameter_naming": "warn",
|
|
22
|
+
"unused_variable": "warn",
|
|
23
|
+
"missing_doc": "warn",
|
|
24
|
+
"error_handling": "warn",
|
|
25
|
+
"global_naming": "warn",
|
|
26
|
+
"extra_parens": "warn",
|
|
27
|
+
"arg_count": "warn",
|
|
28
|
+
"strcat_usage": "warn",
|
|
29
|
+
"cond_simplify": "warn",
|
|
30
|
+
"redundant_progn": "warn",
|
|
31
|
+
"quote_style": "warn",
|
|
32
|
+
"eq_usage": "warn",
|
|
33
|
+
"lambda_syntax": "warn",
|
|
34
|
+
"comment_style": "warn",
|
|
35
|
+
"empty_catch": "warn",
|
|
36
|
+
"nth_usage": "warn",
|
|
37
|
+
"append_single": "warn",
|
|
38
|
+
"setq_multiple": "warn",
|
|
39
|
+
"function_order": "off",
|
|
40
|
+
"magic_number": "off",
|
|
41
|
+
"mixed_indent": "warn",
|
|
42
|
+
"long_function_call": "warn",
|
|
43
|
+
"no_return": "warn",
|
|
44
|
+
"shadow_builtin": "warn",
|
|
45
|
+
"dynamic_doc": "warn",
|
|
46
|
+
"loop_optimization": "off",
|
|
47
|
+
"type_check": "off",
|
|
48
|
+
"redundant_if": "warn",
|
|
49
|
+
"trailing_whitespace": "warn",
|
|
50
|
+
"module_registration": "off",
|
|
51
|
+
"namespace_header": "off"
|
|
52
|
+
},
|
|
53
|
+
"line_length": {
|
|
54
|
+
"max": 100,
|
|
55
|
+
"tab_width": 2
|
|
56
|
+
},
|
|
57
|
+
"function_complexity": {
|
|
58
|
+
"max_lines": 60,
|
|
59
|
+
"max_nesting": 6
|
|
60
|
+
},
|
|
61
|
+
"cl_syntax": {
|
|
62
|
+
"keywords": ["&key"]
|
|
63
|
+
},
|
|
64
|
+
"dangerous_calls": {
|
|
65
|
+
"quit": "error",
|
|
66
|
+
"exit": "error",
|
|
67
|
+
"command_shell": "error",
|
|
68
|
+
"startapp": "warn",
|
|
69
|
+
"vl_registry_write": "warn"
|
|
70
|
+
},
|
|
71
|
+
"module_registration": {
|
|
72
|
+
"severity": "off",
|
|
73
|
+
"patterns": [],
|
|
74
|
+
"dirs": ["modules"]
|
|
75
|
+
},
|
|
76
|
+
"namespace_header": {
|
|
77
|
+
"severity": "off",
|
|
78
|
+
"package": "",
|
|
79
|
+
"deps": [],
|
|
80
|
+
"search_lines": 15
|
|
81
|
+
},
|
|
82
|
+
"bare_function_names": {
|
|
83
|
+
"allowlist": ["T", "nil"],
|
|
84
|
+
"namespace_pattern": "^[a-z]+:"
|
|
85
|
+
},
|
|
86
|
+
"sbcl": {
|
|
87
|
+
"walk_exclude": [".vscode", "vendor", ".git"],
|
|
88
|
+
"defmacro_allow_files": ["compat-cl"]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
;; @lisp SBCL Lint — syntax validation via SBCL
|
|
2
|
+
;; Usage: sbcl --script lint-sbcl.lisp <src-dir> <stub-packages.json> <walk-exclude-json> <defmacro-allow-files-json> <locale>
|
|
3
|
+
|
|
4
|
+
(require :uiop)
|
|
5
|
+
|
|
6
|
+
(defparameter *errors* 0)
|
|
7
|
+
(defparameter *warnings* 0)
|
|
8
|
+
(defparameter *checked* 0)
|
|
9
|
+
(defparameter *locale* "zh")
|
|
10
|
+
|
|
11
|
+
;; ── i18n ──────────────────────────────────────────────────────────────
|
|
12
|
+
(defun i18n (key)
|
|
13
|
+
(cdr (assoc key
|
|
14
|
+
(if (string= *locale* "zh")
|
|
15
|
+
'((:not-found . "not found symbol")
|
|
16
|
+
(:syntax-error . "syntax error")
|
|
17
|
+
(:vec-syntax . "#( vector syntax")
|
|
18
|
+
(:char-syntax . "# backslash char literal")
|
|
19
|
+
(:eval-syntax . "#. read-time eval")
|
|
20
|
+
(:defmacro . "defmacro")
|
|
21
|
+
(:trailing-ws . "trailing whitespace")
|
|
22
|
+
(:ok . "OK")
|
|
23
|
+
(:fail . "FAIL")
|
|
24
|
+
(:header . " @lisp SBCL Lint")
|
|
25
|
+
(:source . " Source")
|
|
26
|
+
(:found . " Found ~d .lsp files")
|
|
27
|
+
(:scanned . " Scanned")
|
|
28
|
+
(:errors . " Errors")
|
|
29
|
+
(:warnings . " Warnings"))
|
|
30
|
+
'((:not-found . "not found symbol")
|
|
31
|
+
(:syntax-error . "syntax error")
|
|
32
|
+
(:vec-syntax . "#( vector syntax")
|
|
33
|
+
(:char-syntax . "# backslash char literal")
|
|
34
|
+
(:eval-syntax . "#. read-time eval")
|
|
35
|
+
(:defmacro . "defmacro")
|
|
36
|
+
(:trailing-ws . "trailing whitespace")
|
|
37
|
+
(:ok . "OK")
|
|
38
|
+
(:fail . "FAIL")
|
|
39
|
+
(:header . " @lisp SBCL Lint")
|
|
40
|
+
(:source . " Source")
|
|
41
|
+
(:found . " Found ~d .lsp files")
|
|
42
|
+
(:scanned . " Scanned")
|
|
43
|
+
(:errors . " Errors")
|
|
44
|
+
(:warnings . " Warnings"))))))
|
|
45
|
+
|
|
46
|
+
;; ── Stub packages from external file ──────────────────────────────────
|
|
47
|
+
(defun load-stub-packages (file-path)
|
|
48
|
+
(flet ((ensure-pkg (name &optional use-list)
|
|
49
|
+
(unless (find-package name)
|
|
50
|
+
(make-package name :use (or use-list '())))))
|
|
51
|
+
(with-open-file (s file-path :direction :input)
|
|
52
|
+
(let ((packages (read s)))
|
|
53
|
+
(dolist (pkg packages)
|
|
54
|
+
(ensure-pkg (first pkg) (second pkg)))))))
|
|
55
|
+
|
|
56
|
+
;; ── File walking ──────────────────────────────────────────────────────
|
|
57
|
+
(defun source-files (dir)
|
|
58
|
+
(sort
|
|
59
|
+
(remove-if-not
|
|
60
|
+
(lambda (p)
|
|
61
|
+
(let ((n (pathname-type p)))
|
|
62
|
+
(and n (string-equal n "lsp"))))
|
|
63
|
+
(uiop:directory-files dir))
|
|
64
|
+
'string< :key #'namestring))
|
|
65
|
+
|
|
66
|
+
(defun walk-tree (dir exclude-dirs)
|
|
67
|
+
(let ((result (source-files dir)))
|
|
68
|
+
(dolist (sub (uiop:subdirectories dir))
|
|
69
|
+
(let ((name (car (last (pathname-directory sub)))))
|
|
70
|
+
(unless (find name exclude-dirs :test 'string=)
|
|
71
|
+
(setf result (append result (walk-tree sub exclude-dirs))))))
|
|
72
|
+
result))
|
|
73
|
+
|
|
74
|
+
;; ── Per-file check ────────────────────────────────────────────────────
|
|
75
|
+
(defun check-file (path src-dir defmacro-allow-files)
|
|
76
|
+
(incf *checked*)
|
|
77
|
+
(let* ((rel (enough-namestring path src-dir))
|
|
78
|
+
(fullname (format nil "~a.~a" (pathname-name path) (pathname-type path))))
|
|
79
|
+
(format t " ~a ... " rel)
|
|
80
|
+
(force-output)
|
|
81
|
+
;; Syntax check via READ
|
|
82
|
+
(handler-case
|
|
83
|
+
(with-open-file (s path :direction :input)
|
|
84
|
+
(loop for form = (read s nil :eof)
|
|
85
|
+
until (eq form :eof)))
|
|
86
|
+
(error (e)
|
|
87
|
+
(let ((msg (princ-to-string e)))
|
|
88
|
+
(cond
|
|
89
|
+
((search "not found" msg)
|
|
90
|
+
(format t "~% [NOTE] ~a: ~a~%" rel (i18n :not-found))
|
|
91
|
+
(incf *warnings*))
|
|
92
|
+
(t
|
|
93
|
+
(format t "~a~% [ERROR] ~a: ~a~%" (i18n :fail) rel (i18n :syntax-error))
|
|
94
|
+
(incf *errors*)
|
|
95
|
+
(return-from check-file))))))
|
|
96
|
+
;; Trailing whitespace
|
|
97
|
+
(with-open-file (s path :direction :input)
|
|
98
|
+
(loop for line = (read-line s nil nil)
|
|
99
|
+
for lineno from 1
|
|
100
|
+
while line
|
|
101
|
+
when (and (> (length line) 0)
|
|
102
|
+
(find (char line (1- (length line))) '(#\Space #\Tab)))
|
|
103
|
+
do (progn
|
|
104
|
+
(format t "~% [WARN] ~a line ~d: ~a~%" rel lineno (i18n :trailing-ws))
|
|
105
|
+
(incf *warnings*))))
|
|
106
|
+
;; CL-ism checks: raw content scan
|
|
107
|
+
(with-open-file (s path :direction :input)
|
|
108
|
+
(let ((content (make-string (file-length s))))
|
|
109
|
+
(file-position s 0)
|
|
110
|
+
(read-sequence content s)
|
|
111
|
+
(when (search "#(" content)
|
|
112
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :vec-syntax))
|
|
113
|
+
(incf *warnings*))
|
|
114
|
+
(when (search "#\\" content)
|
|
115
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :char-syntax))
|
|
116
|
+
(incf *warnings*))
|
|
117
|
+
(when (search "#." content)
|
|
118
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :eval-syntax))
|
|
119
|
+
(incf *warnings*))
|
|
120
|
+
(when (and (search "defmacro" content)
|
|
121
|
+
(not (some (lambda (s) (search s fullname)) defmacro-allow-files)))
|
|
122
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :defmacro))
|
|
123
|
+
(incf *warnings*))))
|
|
124
|
+
(format t "~a~%" (i18n :ok))))
|
|
125
|
+
|
|
126
|
+
;; ── Main ──────────────────────────────────────────────────────────────
|
|
127
|
+
(defun main ()
|
|
128
|
+
(let* ((args (uiop:command-line-arguments))
|
|
129
|
+
(src-dir (first args))
|
|
130
|
+
(stub-file (second args))
|
|
131
|
+
(walk-exclude (if (third args)
|
|
132
|
+
(read-from-string (third args))
|
|
133
|
+
'(".vscode" "test" "experiment" "tools" ".git")))
|
|
134
|
+
(defmacro-allow (if (fourth args)
|
|
135
|
+
(read-from-string (fourth args))
|
|
136
|
+
'("compat-cl")))
|
|
137
|
+
(locale (fifth args)))
|
|
138
|
+
(when locale (setf *locale* locale))
|
|
139
|
+
(load-stub-packages stub-file)
|
|
140
|
+
|
|
141
|
+
(format t "~%==================================================~%")
|
|
142
|
+
(format t "~a~%" (i18n :header))
|
|
143
|
+
(format t "~a: ~a~%" (i18n :source) (namestring (pathname src-dir)))
|
|
144
|
+
(format t "==================================================~%~%")
|
|
145
|
+
(setf *errors* 0 *warnings* 0 *checked* 0)
|
|
146
|
+
|
|
147
|
+
(let ((files (walk-tree src-dir walk-exclude)))
|
|
148
|
+
(format t "~a~%~%" (format nil (i18n :found) (length files)))
|
|
149
|
+
(dolist (f files)
|
|
150
|
+
(check-file f src-dir defmacro-allow)))
|
|
151
|
+
|
|
152
|
+
(format t "~%==================================================~%")
|
|
153
|
+
(format t "~a: ~d~%" (i18n :scanned) *checked*)
|
|
154
|
+
(format t "~a: ~d~%" (i18n :errors) *errors*)
|
|
155
|
+
(format t "~a: ~d~%" (i18n :warnings) *warnings*)
|
|
156
|
+
(format t "==================================================~%~%")
|
|
157
|
+
(if (> *errors* 0)
|
|
158
|
+
(uiop:quit 1)
|
|
159
|
+
(uiop:quit 0))))
|
|
160
|
+
|
|
161
|
+
(main)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
((AUTOLISP ())
|
|
2
|
+
(@ (COMMON-LISP AUTOLISP))
|
|
3
|
+
(C ())
|
|
4
|
+
(JSON ())
|
|
5
|
+
(SIDEBAR ())
|
|
6
|
+
(FUN ())
|
|
7
|
+
(DCL ())
|
|
8
|
+
(BASE ())
|
|
9
|
+
(STRING ())
|
|
10
|
+
(BLOCK ())
|
|
11
|
+
(ENTITY ())
|
|
12
|
+
(LAYER ())
|
|
13
|
+
(LAYOUT ())
|
|
14
|
+
(CURVE ())
|
|
15
|
+
(LIST ())
|
|
16
|
+
(M ())
|
|
17
|
+
(P ())
|
|
18
|
+
(UI ())
|
|
19
|
+
(SYS ())
|
|
20
|
+
(EXCEL ())
|
|
21
|
+
(WORD ())
|
|
22
|
+
(RE ())
|
|
23
|
+
(VECTRA ())
|
|
24
|
+
(DOS ())
|
|
25
|
+
(AT-PM ())
|
|
26
|
+
(QRENCODE ())
|
|
27
|
+
(NETWORK ())
|
|
28
|
+
(PKGMAN ())
|
|
29
|
+
(DATETIME ())
|
|
30
|
+
(DICT ())
|
|
31
|
+
(@NLP ())
|
|
32
|
+
(AT-SIDEBAR ())
|
|
33
|
+
(S ())
|
|
34
|
+
(VL ())
|
|
35
|
+
(VLR ())
|
|
36
|
+
(VLAX ())
|
|
37
|
+
(THEME ())
|
|
38
|
+
(AJAX ())
|
|
39
|
+
(ATLISP ())
|
|
40
|
+
(LOG ())
|
|
41
|
+
(ATLISP-CORE ()))
|