@atlisp/lint 0.1.23 → 0.1.25

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.
Files changed (50) hide show
  1. package/atlisp-lint.default.json +2 -1
  2. package/dist/atlisp-lint.default.json +90 -0
  3. package/dist/checks/arg-count.js +1 -1
  4. package/dist/checks/assoc-without-cdr.js +1 -1
  5. package/dist/checks/builtin-arg-count.d.ts +3 -0
  6. package/dist/checks/builtin-arg-count.js +282 -0
  7. package/dist/checks/cond-duplicate.js +1 -1
  8. package/dist/checks/constant-condition.js +3 -3
  9. package/dist/checks/dangerous-calls.js +1 -1
  10. package/dist/checks/dangling-defun.js +1 -1
  11. package/dist/checks/double-not.js +1 -1
  12. package/dist/checks/empty-branch.js +1 -1
  13. package/dist/checks/empty-catch.js +1 -1
  14. package/dist/checks/function-complexity.js +1 -1
  15. package/dist/checks/global-naming.js +1 -1
  16. package/dist/checks/identical-branches.js +1 -1
  17. package/dist/checks/misplaced-else.js +1 -1
  18. package/dist/checks/multiple-setq.js +1 -1
  19. package/dist/checks/no-return.js +1 -1
  20. package/dist/checks/open-close.js +1 -1
  21. package/dist/checks/parameter-naming.js +1 -1
  22. package/dist/checks/quote-vs-function.js +1 -1
  23. package/dist/checks/recursive-call.js +1 -1
  24. package/dist/checks/redundant-let.js +1 -1
  25. package/dist/checks/redundant-nil-else.js +1 -1
  26. package/dist/checks/redundant-progn.js +1 -1
  27. package/dist/checks/redundant-quotes.js +1 -1
  28. package/dist/checks/redundant-setq.js +1 -1
  29. package/dist/checks/self-compare.js +1 -1
  30. package/dist/checks/setq-single-arg.js +1 -1
  31. package/dist/checks/single-arg-and-or.js +1 -1
  32. package/dist/checks/undeclared-setq.js +1 -1
  33. package/dist/checks/unused-catch-result.js +1 -1
  34. package/dist/checks/unused-let.js +1 -1
  35. package/dist/checks/unused-local-fun.js +1 -1
  36. package/dist/checks/unused-package-dep.js +1 -1
  37. package/dist/checks/unused-param.js +1 -1
  38. package/dist/checks/unused-variable.js +1 -1
  39. package/dist/checks/variable-shadow.js +1 -1
  40. package/dist/checks/while-constant.js +1 -1
  41. package/dist/formatters.d.ts +0 -1
  42. package/dist/formatters.js +0 -16
  43. package/dist/lib/lint-sbcl.lisp +161 -0
  44. package/dist/locale.js +2 -0
  45. package/dist/project.js +5 -5
  46. package/dist/rules.js +2 -1
  47. package/dist/runner.d.ts +0 -1
  48. package/dist/runner.js +150 -100
  49. package/dist/stub-packages.json +41 -0
  50. package/package.json +2 -2
@@ -5,7 +5,7 @@ exports.checkSingleArgAndOrAst = checkSingleArgAndOrAst;
5
5
  const locale_1 = require("../locale");
6
6
  const parser_1 = require("@atlisp/parser");
7
7
  function checkSingleArgAndOr(content, file) {
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  return checkSingleArgAndOrAst(ast, file);
10
10
  }
11
11
  function checkSingleArgAndOrAst(ast, file) {
@@ -42,7 +42,7 @@ function findEnclosingDefun(node) {
42
42
  }
43
43
  function checkUndeclaredSetq(content, file) {
44
44
  const issues = [];
45
- const ast = (0, parser_1.parseAst)(content);
45
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
46
46
  const setqForms = (0, parser_1.astFindListWithHead)(ast, 'setq');
47
47
  for (const setq of setqForms) {
48
48
  if (!setq.children || setq.children.length < 2)
@@ -5,7 +5,7 @@ const locale_1 = require("../locale");
5
5
  const parser_1 = require("@atlisp/parser");
6
6
  function checkUnusedCatchResult(content, file) {
7
7
  const issues = [];
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  const catchNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'vl-catch-all-apply'));
10
10
  for (const node of catchNodes) {
11
11
  if (isInQuote(node))
@@ -5,7 +5,7 @@ exports.checkUnusedLetBindingAst = checkUnusedLetBindingAst;
5
5
  const locale_1 = require("../locale");
6
6
  const parser_1 = require("@atlisp/parser");
7
7
  function checkUnusedLetBinding(content, file) {
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  return checkUnusedLetBindingAst(ast, file);
10
10
  }
11
11
  function checkUnusedLetBindingAst(ast, file) {
@@ -5,7 +5,7 @@ exports.checkUnusedLocalFunAst = checkUnusedLocalFunAst;
5
5
  const locale_1 = require("../locale");
6
6
  const parser_1 = require("@atlisp/parser");
7
7
  function checkUnusedLocalFun(content, file) {
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  return checkUnusedLocalFunAst(ast, file);
10
10
  }
11
11
  function checkUnusedLocalFunAst(ast, file) {
@@ -40,7 +40,7 @@ const fs = __importStar(require("fs"));
40
40
  function checkUnusedPackageDep(file) {
41
41
  const issues = [];
42
42
  const content = fs.readFileSync(file, 'utf-8');
43
- const ast = (0, parser_1.parseAst)(content);
43
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
44
44
  const inPackageNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'in-package'));
45
45
  if (inPackageNodes.length === 0)
46
46
  return issues;
@@ -5,7 +5,7 @@ exports.checkUnusedParameterAst = checkUnusedParameterAst;
5
5
  const locale_1 = require("../locale");
6
6
  const parser_1 = require("@atlisp/parser");
7
7
  function checkUnusedParameter(content, file) {
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  return checkUnusedParameterAst(ast, file);
10
10
  }
11
11
  function checkUnusedParameterAst(ast, file) {
@@ -5,7 +5,7 @@ exports.checkUnusedVariableAst = checkUnusedVariableAst;
5
5
  const locale_1 = require("../locale");
6
6
  const parser_1 = require("@atlisp/parser");
7
7
  function checkUnusedVariable(content, file) {
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  return checkUnusedVariableAst(ast, file);
10
10
  }
11
11
  function checkUnusedVariableAst(ast, file) {
@@ -5,7 +5,7 @@ exports.checkVariableShadowAst = checkVariableShadowAst;
5
5
  const locale_1 = require("../locale");
6
6
  const parser_1 = require("@atlisp/parser");
7
7
  function checkVariableShadow(content, file) {
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  return checkVariableShadowAst(ast, file);
10
10
  }
11
11
  function checkVariableShadowAst(ast, file) {
@@ -5,7 +5,7 @@ exports.checkWhileConstantAst = checkWhileConstantAst;
5
5
  const locale_1 = require("../locale");
6
6
  const parser_1 = require("@atlisp/parser");
7
7
  function checkWhileConstant(content, file) {
8
- const ast = (0, parser_1.parseAst)(content);
8
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
9
9
  return checkWhileConstantAst(ast, file);
10
10
  }
11
11
  function checkWhileConstantAst(ast, file) {
@@ -1,5 +1,4 @@
1
1
  import { Issue } from './types';
2
2
  export declare function formatDefault(issues: Issue[], fileContents?: Map<string, string>): string;
3
- export declare function formatHtml(issues: Issue[], errorCount: number, warningCount: number): string;
4
3
  export declare function formatJson(issues: Issue[], errorCount?: number, warningCount?: number): string;
5
4
  //# sourceMappingURL=formatters.d.ts.map
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatDefault = formatDefault;
4
- exports.formatHtml = formatHtml;
5
4
  exports.formatJson = formatJson;
6
5
  const locale_1 = require("./locale");
7
6
  const colors = {
@@ -69,21 +68,6 @@ function formatDefault(issues, fileContents) {
69
68
  }
70
69
  return lines.join('\n');
71
70
  }
72
- function formatHtml(issues, errorCount, warningCount) {
73
- let html = `<!DOCTYPE html>
74
- <html lang="en">
75
- <head><meta charset="UTF-8"><title>@atlisp/lint Report</title></head>
76
- <body>
77
- <h1>@atlisp/lint Report</h1>
78
- <p>${errorCount} error(s), ${warningCount} warning(s)</p>
79
- <ul>
80
- `;
81
- for (const iss of issues) {
82
- html += ` <li>${iss.severity}: ${iss.file}:${iss.line} — ${iss.message}</li>\n`;
83
- }
84
- html += '</ul>\n</body>\n</html>';
85
- return html;
86
- }
87
71
  function formatJson(issues, errorCount, warningCount) {
88
72
  return JSON.stringify({
89
73
  issues,
@@ -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/locale.js CHANGED
@@ -19,6 +19,8 @@ const messages = {
19
19
  token_in_url: 'Possible token exposure in string: token= in URL',
20
20
  open_without_close: 'File has {0} open() calls but {1} close() calls (possible resource leak)',
21
21
  arg_count: "Function '{0}' called with {1} arguments but defined with {2}",
22
+ 'builtin_arg_count.too_few': "Built-in function '{0}' called with {1} arguments, expected at least {2}",
23
+ 'builtin_arg_count.too_many': "Built-in function '{0}' called with {1} arguments, expected at most {2}",
22
24
  bare_function_names: "Unnamespaced function '{0}' (missing @:: or C: prefix)",
23
25
  module_registration: 'Module file missing @::*modules* registration (expected in last lines)',
24
26
  'namespace_header.missing': 'Missing (in-package {0}) header',
package/dist/project.js CHANGED
@@ -44,7 +44,7 @@ const duplicate_defun_1 = require("./checks/duplicate-defun");
44
44
  const locale_1 = require("./locale");
45
45
  function collectDefuns(file) {
46
46
  const content = fs.readFileSync(file, 'utf-8');
47
- const ast = (0, parser_1.parseAst)(content);
47
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
48
48
  const results = [];
49
49
  const defunNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'defun') || (0, parser_1.astIsList)(n, 'defun-q'));
50
50
  for (const node of defunNodes) {
@@ -56,7 +56,7 @@ function collectDefuns(file) {
56
56
  }
57
57
  function collectReferences(file) {
58
58
  const content = fs.readFileSync(file, 'utf-8');
59
- const ast = (0, parser_1.parseAst)(content);
59
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
60
60
  const results = [];
61
61
  const allCalls = (0, parser_1.astFindAll)(ast, n => {
62
62
  if (n.type !== 'list' || !n.children || n.children.length === 0)
@@ -73,7 +73,7 @@ function collectReferences(file) {
73
73
  }
74
74
  function countFunctionArgs(file) {
75
75
  const content = fs.readFileSync(file, 'utf-8');
76
- const ast = (0, parser_1.parseAst)(content);
76
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
77
77
  const result = new Map();
78
78
  const defunNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'defun') || (0, parser_1.astIsList)(n, 'defun-q'));
79
79
  for (const node of defunNodes) {
@@ -102,7 +102,7 @@ function countFunctionArgs(file) {
102
102
  }
103
103
  function countCallArgs(file) {
104
104
  const content = fs.readFileSync(file, 'utf-8');
105
- const ast = (0, parser_1.parseAst)(content);
105
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
106
106
  const result = new Map();
107
107
  const allCalls = (0, parser_1.astFindAll)(ast, n => {
108
108
  if (n.type !== 'list' || !n.children || n.children.length === 0)
@@ -122,7 +122,7 @@ function countCallArgs(file) {
122
122
  }
123
123
  function findModuleDeps(filepath) {
124
124
  const content = fs.readFileSync(filepath, 'utf-8');
125
- const ast = (0, parser_1.parseAst)(content);
125
+ const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
126
126
  const imports = [];
127
127
  const exports = [];
128
128
  const inPackageNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'in-package'));
package/dist/rules.js CHANGED
@@ -11,7 +11,7 @@ exports.RULES = [
11
11
  },
12
12
  {
13
13
  name: 'arg_count',
14
- defaultSeverity: 'warn',
14
+ defaultSeverity: 'error',
15
15
  description: '检查函数调用参数数量是否与定义匹配',
16
16
  category: '最佳实践',
17
17
  },
@@ -236,6 +236,7 @@ exports.RULES = [
236
236
  { name: 'promise_handler', defaultSeverity: 'warn', description: '检测 vlax-invoke 缺少回调处理器', category: '最佳实践' },
237
237
  { name: 'module_cycle', defaultSeverity: 'warn', description: '检测模块循环依赖', category: '架构' },
238
238
  { name: 'arg_count_project', defaultSeverity: 'warn', description: '跨文件检查函数参数数量', category: '正确性' },
239
+ { name: 'builtin_arg_count', defaultSeverity: 'error', description: '检查 AutoLISP 内置函数调用参数个数是否匹配', category: '正确性' },
239
240
  ];
240
241
  function generateRulesMarkdown() {
241
242
  const lines = [
package/dist/runner.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Issue, LintConfig } from './types';
2
2
  export declare function runChecks(content: string, file: string, config: LintConfig): Issue[];
3
- export declare function runChecksWithVisitorWrapper(content: string, file: string, config: LintConfig): Issue[];
4
3
  export declare function lintFiles(files: string[], config: LintConfig, rootDir: string): Issue[];
5
4
  export declare function lintFilesParallel(files: string[], config: LintConfig, rootDir: string): Promise<Issue[]>;
6
5
  export declare const FIXABLE_RULES: Set<string>;