@atlisp/lint 0.2.6 → 0.2.8

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.
@@ -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)
package/dist/runner.js CHANGED
@@ -235,7 +235,7 @@ function lintFilesParallel(files, config, rootDir) {
235
235
  (0, locale_1.setLocale)(config.locale || 'zh');
236
236
  return new Promise(resolve => {
237
237
  const allIssues = [];
238
- let completed = 0;
238
+ const completed = new Set();
239
239
  const maxWorkers = Math.min(os.cpus().length, files.length);
240
240
  let nextIndex = 0;
241
241
  function startWorker() {
@@ -248,14 +248,18 @@ function lintFilesParallel(files, config, rootDir) {
248
248
  workerData: { filepath, relPath, config },
249
249
  });
250
250
  worker.on('message', (msg) => {
251
+ if (completed.has(idx))
252
+ return;
253
+ completed.add(idx);
251
254
  allIssues.push(...msg.issues);
252
- completed++;
253
- worker.terminate();
254
255
  startWorker();
255
- if (completed >= files.length)
256
+ if (completed.size >= files.length)
256
257
  resolve(allIssues);
257
258
  });
258
259
  worker.on('error', (err) => {
260
+ if (completed.has(idx))
261
+ return;
262
+ completed.add(idx);
259
263
  allIssues.push({
260
264
  file: relPath,
261
265
  line: 1,
@@ -263,13 +267,14 @@ function lintFilesParallel(files, config, rootDir) {
263
267
  rule: 'worker',
264
268
  message: err.message,
265
269
  });
266
- completed++;
267
- worker.terminate();
268
270
  startWorker();
269
- if (completed >= files.length)
271
+ if (completed.size >= files.length)
270
272
  resolve(allIssues);
271
273
  });
272
274
  worker.on('exit', code => {
275
+ if (completed.has(idx))
276
+ return;
277
+ completed.add(idx);
273
278
  if (code !== 0) {
274
279
  allIssues.push({
275
280
  file: relPath,
@@ -278,11 +283,10 @@ function lintFilesParallel(files, config, rootDir) {
278
283
  rule: 'worker',
279
284
  message: `Worker exited with code ${code}`,
280
285
  });
281
- completed++;
282
- startWorker();
283
- if (completed >= files.length)
284
- resolve(allIssues);
285
286
  }
287
+ startWorker();
288
+ if (completed.size >= files.length)
289
+ resolve(allIssues);
286
290
  });
287
291
  }
288
292
  for (let i = 0; i < maxWorkers; i++) {
@@ -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 ()))
package/dist/worker.js CHANGED
@@ -4,17 +4,26 @@ const worker_threads_1 = require("worker_threads");
4
4
  const fs_1 = require("fs");
5
5
  const locale_1 = require("./locale");
6
6
  const runner_1 = require("./runner");
7
+ function sendMessage(output) {
8
+ if (!worker_threads_1.parentPort)
9
+ return;
10
+ try {
11
+ worker_threads_1.parentPort.postMessage(output);
12
+ }
13
+ catch {
14
+ // Port already closed, nothing we can do
15
+ }
16
+ }
7
17
  if (worker_threads_1.parentPort && worker_threads_1.workerData) {
8
18
  const input = worker_threads_1.workerData;
9
19
  (0, locale_1.setLocale)(input.config.locale || 'zh');
10
20
  try {
11
21
  const content = (0, fs_1.readFileSync)(input.filepath, 'utf-8');
12
22
  const issues = (0, runner_1.runChecks)(content, input.relPath, input.config);
13
- const output = { filepath: input.filepath, issues };
14
- worker_threads_1.parentPort.postMessage(output);
23
+ sendMessage({ filepath: input.filepath, issues });
15
24
  }
16
25
  catch {
17
- const output = {
26
+ sendMessage({
18
27
  filepath: input.filepath,
19
28
  issues: [
20
29
  {
@@ -25,8 +34,7 @@ if (worker_threads_1.parentPort && worker_threads_1.workerData) {
25
34
  message: 'Cannot read file',
26
35
  },
27
36
  ],
28
- };
29
- worker_threads_1.parentPort.postMessage(output);
37
+ });
30
38
  }
31
39
  }
32
40
  //# sourceMappingURL=worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/lint",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "AutoLISP static analysis tool — parens, security, conventions, SBCL syntax validation",
5
5
  "keywords": [
6
6
  "CAD",