@atlisp/lint 0.1.5 → 0.1.6

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 (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -58
  3. package/atlisp-lint.default.json +31 -1
  4. package/dist/atlisp-lint.default.json +90 -0
  5. package/dist/cache.d.ts +2 -2
  6. package/dist/cache.js +6 -6
  7. package/dist/checks/append-single.d.ts +3 -0
  8. package/dist/checks/append-single.js +17 -0
  9. package/dist/checks/arg-count.d.ts +3 -0
  10. package/dist/checks/arg-count.js +123 -0
  11. package/dist/checks/assoc-without-cdr.d.ts +5 -0
  12. package/dist/checks/assoc-without-cdr.js +32 -0
  13. package/dist/checks/comment-style.d.ts +3 -0
  14. package/dist/checks/comment-style.js +24 -0
  15. package/dist/checks/cond-duplicate.d.ts +5 -0
  16. package/dist/checks/cond-duplicate.js +52 -0
  17. package/dist/checks/cond-simplify.d.ts +3 -0
  18. package/dist/checks/cond-simplify.js +45 -0
  19. package/dist/checks/constant-condition.js +4 -4
  20. package/dist/checks/dangerous-calls.js +2 -2
  21. package/dist/checks/dangling-defun.d.ts +3 -0
  22. package/dist/checks/dangling-defun.js +10 -28
  23. package/dist/checks/double-not.js +1 -1
  24. package/dist/checks/duplicate-defun.d.ts +6 -0
  25. package/dist/checks/duplicate-defun.js +50 -0
  26. package/dist/checks/dynamic-doc.d.ts +3 -0
  27. package/dist/checks/dynamic-doc.js +21 -0
  28. package/dist/checks/empty-branch.js +1 -1
  29. package/dist/checks/empty-catch.d.ts +3 -0
  30. package/dist/checks/empty-catch.js +34 -0
  31. package/dist/checks/eq-usage.d.ts +3 -0
  32. package/dist/checks/eq-usage.js +25 -0
  33. package/dist/checks/error-handling.d.ts +3 -0
  34. package/dist/checks/error-handling.js +56 -0
  35. package/dist/checks/extra-parens.d.ts +3 -0
  36. package/dist/checks/extra-parens.js +45 -0
  37. package/dist/checks/function-complexity.js +1 -1
  38. package/dist/checks/function-order.d.ts +3 -0
  39. package/dist/checks/function-order.js +33 -0
  40. package/dist/checks/global-naming.d.ts +3 -0
  41. package/dist/checks/global-naming.js +62 -0
  42. package/dist/checks/identical-branches.d.ts +5 -0
  43. package/dist/checks/identical-branches.js +54 -0
  44. package/dist/checks/index.d.ts +3 -0
  45. package/dist/checks/index.js +117 -0
  46. package/dist/checks/lambda-syntax.d.ts +3 -0
  47. package/dist/checks/lambda-syntax.js +25 -0
  48. package/dist/checks/long-function-call.d.ts +3 -0
  49. package/dist/checks/long-function-call.js +54 -0
  50. package/dist/checks/loop-optimization.d.ts +3 -0
  51. package/dist/checks/loop-optimization.js +17 -0
  52. package/dist/checks/magic-number.d.ts +3 -0
  53. package/dist/checks/magic-number.js +21 -0
  54. package/dist/checks/misplaced-else.js +1 -1
  55. package/dist/checks/missing-export.js +2 -2
  56. package/dist/checks/mixed-indent.d.ts +3 -0
  57. package/dist/checks/mixed-indent.js +19 -0
  58. package/dist/checks/module-reg.js +1 -1
  59. package/dist/checks/multiple-setq.js +1 -1
  60. package/dist/checks/no-return.d.ts +3 -0
  61. package/dist/checks/no-return.js +51 -0
  62. package/dist/checks/nth-usage.d.ts +3 -0
  63. package/dist/checks/nth-usage.js +17 -0
  64. package/dist/checks/quote-style.d.ts +3 -0
  65. package/dist/checks/quote-style.js +25 -0
  66. package/dist/checks/quote-vs-function.js +1 -1
  67. package/dist/checks/recursive-call.js +1 -1
  68. package/dist/checks/redundant-if.d.ts +3 -0
  69. package/dist/checks/redundant-if.js +17 -0
  70. package/dist/checks/redundant-let.js +1 -1
  71. package/dist/checks/redundant-nil-else.js +1 -1
  72. package/dist/checks/redundant-progn.js +1 -1
  73. package/dist/checks/redundant-quotes.js +1 -1
  74. package/dist/checks/redundant-setq.js +1 -1
  75. package/dist/checks/self-compare.js +1 -1
  76. package/dist/checks/setq-multiple.d.ts +3 -0
  77. package/dist/checks/setq-multiple.js +17 -0
  78. package/dist/checks/setq-single-arg.d.ts +5 -0
  79. package/dist/checks/setq-single-arg.js +30 -0
  80. package/dist/checks/shadow-builtin.d.ts +3 -0
  81. package/dist/checks/shadow-builtin.js +77 -0
  82. package/dist/checks/single-arg-and-or.js +1 -1
  83. package/dist/checks/strcat-usage.d.ts +3 -0
  84. package/dist/checks/strcat-usage.js +25 -0
  85. package/dist/checks/type-check.d.ts +3 -0
  86. package/dist/checks/type-check.js +26 -0
  87. package/dist/checks/unused-let.js +1 -1
  88. package/dist/checks/unused-package-dep.js +3 -3
  89. package/dist/checks/variable-shadow.js +1 -1
  90. package/dist/checks/while-constant.d.ts +5 -0
  91. package/dist/checks/while-constant.js +40 -0
  92. package/dist/config.d.ts +1 -0
  93. package/dist/config.js +70 -2
  94. package/dist/disable.js +1 -1
  95. package/dist/formatters.d.ts +1 -0
  96. package/dist/formatters.js +18 -2
  97. package/dist/index.js +53 -13
  98. package/dist/lib/lint-sbcl.lisp +161 -0
  99. package/dist/locale.js +24 -0
  100. package/dist/presets.d.ts +4 -0
  101. package/dist/presets.js +158 -0
  102. package/dist/project.js +37 -6
  103. package/dist/rules.d.ts +9 -0
  104. package/dist/rules.js +238 -0
  105. package/dist/runner.d.ts +2 -0
  106. package/dist/runner.js +198 -11
  107. package/dist/sbcl.js +1 -1
  108. package/dist/stub-packages.json +41 -0
  109. package/dist/types.d.ts +6 -0
  110. package/dist/validate.d.ts +8 -0
  111. package/dist/validate.js +125 -0
  112. package/dist/watch.d.ts +9 -0
  113. package/dist/watch.js +113 -0
  114. package/package.json +1 -1
@@ -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
@@ -52,6 +52,15 @@ const messages = {
52
52
  quote_vs_function: 'Quoted lambda passed to {0} — use (function (lambda ...)) instead for compiled code',
53
53
  commented_code: 'Commented-out code detected — remove or uncomment if needed',
54
54
  double_not: 'Double (not (not ...)) — simplifies to single not',
55
+ error_handling: "Functions using command but missing *error*: '{0}'",
56
+ global_naming: "Global variable '{0}' should use *...* naming convention",
57
+ extra_parens: 'Suspicious excessive closing parenthesis: {0} extra )',
58
+ setq_single_arg: "Variable '{0}' is setq'd with no value — likely a typo",
59
+ assoc_without_cdr: 'assoc result is not used — wrap with cdr to extract the value',
60
+ identical_branches: 'if has identical then and else branches — possible copy-paste error',
61
+ while_constant: "while with constant condition '{0}' — loop may never execute or never terminate",
62
+ cond_duplicate: 'cond has duplicate conditions — second clause is unreachable',
63
+ duplicate_defun: "Function '{0}' is defined multiple times",
55
64
  dangling_defun: "Function '{0}' is defined but never called",
56
65
  missing_export: "Function '{0}' is not registered in @::*modules*",
57
66
  unused_package_dep: "Imported package '{0}' is never referenced",
@@ -74,6 +83,9 @@ const messages = {
74
83
  'index.cached': 'Cached, skipping',
75
84
  'index.all_cached': 'All files are cached, nothing to lint',
76
85
  'index.cache_cleared': 'Cache cleared',
86
+ 'index.watching': 'Watching',
87
+ 'index.watch_hint': 'Press Ctrl+C to stop',
88
+ 'index.watch_status': '{0} files checked: {1} error(s), {2} warning(s)',
77
89
  },
78
90
  zh: {
79
91
  'parens.mismatch': "括号不匹配:{0} 个 '(' vs {1} 个 ')'({2})",
@@ -123,6 +135,15 @@ const messages = {
123
135
  quote_vs_function: '在 {0} 中使用引用 lambda —— 建议改用 (function (lambda ...)) 以支持编译优化',
124
136
  commented_code: '检测到被注释掉的代码 —— 请删除或取消注释',
125
137
  double_not: '双重 (not (not ...)) —— 可以简化为单个 not',
138
+ error_handling: "使用 command 但缺少 *error* 的函数: '{0}'",
139
+ global_naming: "全局变量 '{0}' 应使用 *...* 命名约定",
140
+ extra_parens: '可疑的过多闭合括号:多余 {0} 个 )',
141
+ setq_single_arg: "变量 '{0}' 被 setq 但未赋值——可能是笔误",
142
+ assoc_without_cdr: 'assoc 的结果未被使用——应使用 cdr 获取值',
143
+ identical_branches: 'if 的 then 和 else 分支完全相同——可能是复制粘贴错误',
144
+ while_constant: "while 使用了常量条件 '{0}'——循环可能永不执行或永不终止",
145
+ cond_duplicate: 'cond 中存在重复条件——第二个子句不可达',
146
+ duplicate_defun: "函数 '{0}' 被多次定义",
126
147
  dangling_defun: "函数 '{0}' 定义了但从未被调用",
127
148
  missing_export: "函数 '{0}' 未注册到 @::*modules*",
128
149
  unused_package_dep: "导入的包 '{0}' 从未被引用",
@@ -145,6 +166,9 @@ const messages = {
145
166
  'index.cached': '已缓存,跳过',
146
167
  'index.all_cached': '所有文件均已缓存,无需检查',
147
168
  'index.cache_cleared': '缓存已清除',
169
+ 'index.watching': '监听中',
170
+ 'index.watch_hint': '按 Ctrl+C 停止',
171
+ 'index.watch_status': '已检查 {0} 个文件: {1} 个错误, {2} 个警告',
148
172
  },
149
173
  };
150
174
  let currentLocale = 'zh';
@@ -0,0 +1,4 @@
1
+ import { LintConfig } from './types';
2
+ export type PresetName = 'recommended' | 'strict' | 'relaxed';
3
+ export declare const PRESETS: Record<PresetName, Partial<LintConfig>>;
4
+ //# sourceMappingURL=presets.d.ts.map
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRESETS = void 0;
4
+ exports.PRESETS = {
5
+ recommended: {
6
+ checks: {
7
+ parens: 'error',
8
+ encoding: 'error',
9
+ cl_syntax: 'warn',
10
+ quit_exit: 'error',
11
+ command_shell: 'error',
12
+ startapp: 'warn',
13
+ vl_registry_write: 'warn',
14
+ token_in_url: 'warn',
15
+ open_without_close: 'warn',
16
+ line_length: 'warn',
17
+ function_complexity: 'warn',
18
+ parameter_naming: 'warn',
19
+ unused_variable: 'warn',
20
+ missing_doc: 'warn',
21
+ trailing_whitespace: 'warn',
22
+ unused_parameter: 'warn',
23
+ constant_condition: 'warn',
24
+ redundant_progn: 'warn',
25
+ empty_branch: 'warn',
26
+ unused_let_binding: 'warn',
27
+ recursive_call: 'warn',
28
+ variable_shadow: 'warn',
29
+ redundant_cond: 'warn',
30
+ unused_local_fun: 'warn',
31
+ multiple_setq: 'warn',
32
+ redundant_quotes: 'warn',
33
+ trailing_paren: 'warn',
34
+ empty_comment: 'warn',
35
+ redundant_setq: 'warn',
36
+ redundant_nil_else: 'warn',
37
+ single_arg_and_or: 'warn',
38
+ redundant_let: 'warn',
39
+ self_compare: 'warn',
40
+ misplaced_else: 'warn',
41
+ quote_vs_function: 'warn',
42
+ commented_code: 'warn',
43
+ double_not: 'warn',
44
+ setq_single_arg: 'warn',
45
+ assoc_without_cdr: 'warn',
46
+ identical_branches: 'warn',
47
+ while_constant: 'warn',
48
+ cond_duplicate: 'warn',
49
+ error_handling: 'warn',
50
+ global_naming: 'warn',
51
+ extra_parens: 'warn',
52
+ arg_count: 'warn',
53
+ strcat_usage: 'warn',
54
+ cond_simplify: 'warn',
55
+ quote_style: 'warn',
56
+ eq_usage: 'warn',
57
+ lambda_syntax: 'warn',
58
+ comment_style: 'warn',
59
+ empty_catch: 'warn',
60
+ nth_usage: 'warn',
61
+ append_single: 'warn',
62
+ setq_multiple: 'warn',
63
+ mixed_indent: 'warn',
64
+ long_function_call: 'warn',
65
+ no_return: 'warn',
66
+ shadow_builtin: 'warn',
67
+ dynamic_doc: 'warn',
68
+ redundant_if: 'warn',
69
+ },
70
+ },
71
+ strict: {
72
+ checks: {
73
+ parens: 'error',
74
+ encoding: 'error',
75
+ cl_syntax: 'error',
76
+ quit_exit: 'error',
77
+ command_shell: 'error',
78
+ startapp: 'error',
79
+ vl_registry_write: 'error',
80
+ vlax_without_loading: 'error',
81
+ token_in_url: 'error',
82
+ open_without_close: 'error',
83
+ bare_function_names: 'error',
84
+ line_length: 'error',
85
+ function_complexity: 'error',
86
+ parameter_naming: 'error',
87
+ unused_variable: 'error',
88
+ missing_doc: 'error',
89
+ trailing_whitespace: 'error',
90
+ unused_parameter: 'error',
91
+ constant_condition: 'error',
92
+ redundant_progn: 'error',
93
+ empty_branch: 'error',
94
+ unused_let_binding: 'error',
95
+ recursive_call: 'error',
96
+ variable_shadow: 'error',
97
+ redundant_cond: 'error',
98
+ unused_local_fun: 'error',
99
+ multiple_setq: 'warn',
100
+ redundant_quotes: 'error',
101
+ trailing_paren: 'error',
102
+ empty_comment: 'error',
103
+ redundant_setq: 'error',
104
+ redundant_nil_else: 'error',
105
+ single_arg_and_or: 'error',
106
+ redundant_let: 'error',
107
+ self_compare: 'error',
108
+ misplaced_else: 'error',
109
+ quote_vs_function: 'error',
110
+ commented_code: 'error',
111
+ double_not: 'error',
112
+ setq_single_arg: 'error',
113
+ assoc_without_cdr: 'error',
114
+ identical_branches: 'error',
115
+ while_constant: 'error',
116
+ cond_duplicate: 'error',
117
+ duplicate_defun: 'error',
118
+ dangling_defun: 'error',
119
+ missing_export: 'error',
120
+ unused_package_dep: 'error',
121
+ error_handling: 'error',
122
+ global_naming: 'error',
123
+ extra_parens: 'error',
124
+ arg_count: 'error',
125
+ strcat_usage: 'error',
126
+ cond_simplify: 'error',
127
+ quote_style: 'error',
128
+ eq_usage: 'error',
129
+ lambda_syntax: 'error',
130
+ comment_style: 'error',
131
+ empty_catch: 'error',
132
+ nth_usage: 'error',
133
+ append_single: 'error',
134
+ setq_multiple: 'error',
135
+ function_order: 'warn',
136
+ magic_number: 'warn',
137
+ mixed_indent: 'error',
138
+ long_function_call: 'error',
139
+ no_return: 'error',
140
+ shadow_builtin: 'error',
141
+ dynamic_doc: 'error',
142
+ loop_optimization: 'warn',
143
+ type_check: 'warn',
144
+ redundant_if: 'error',
145
+ module_registration: 'error',
146
+ namespace_header: 'error',
147
+ },
148
+ },
149
+ relaxed: {
150
+ checks: {
151
+ parens: 'error',
152
+ encoding: 'error',
153
+ quit_exit: 'error',
154
+ command_shell: 'error',
155
+ },
156
+ },
157
+ };
158
+ //# sourceMappingURL=presets.js.map
package/dist/project.js CHANGED
@@ -40,12 +40,13 @@ const parser_1 = require("@atlisp/parser");
40
40
  const dangling_defun_1 = require("./checks/dangling-defun");
41
41
  const missing_export_1 = require("./checks/missing-export");
42
42
  const unused_package_dep_1 = require("./checks/unused-package-dep");
43
+ const duplicate_defun_1 = require("./checks/duplicate-defun");
43
44
  const locale_1 = require("./locale");
44
45
  function collectDefuns(file) {
45
46
  const content = fs.readFileSync(file, 'utf-8');
46
47
  const ast = (0, parser_1.parseAst)(content);
47
48
  const results = [];
48
- const defunNodes = (0, parser_1.astFindAll)(ast, (n) => (0, parser_1.astIsList)(n, 'defun') || (0, parser_1.astIsList)(n, 'defun-q'));
49
+ const defunNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'defun') || (0, parser_1.astIsList)(n, 'defun-q'));
49
50
  for (const node of defunNodes) {
50
51
  if (node.children && node.children.length >= 2 && (0, parser_1.astIsSymbol)(node.children[1])) {
51
52
  results.push({ name: node.children[1].name, line: node.pos.line });
@@ -53,10 +54,27 @@ function collectDefuns(file) {
53
54
  }
54
55
  return results;
55
56
  }
57
+ function collectReferences(file, _filepath) {
58
+ const content = fs.readFileSync(file, 'utf-8');
59
+ const ast = (0, parser_1.parseAst)(content);
60
+ const results = [];
61
+ const allCalls = (0, parser_1.astFindAll)(ast, n => {
62
+ if (n.type !== 'list' || !n.children || n.children.length === 0)
63
+ return false;
64
+ return (0, parser_1.astIsSymbol)(n.children[0]);
65
+ });
66
+ for (const call of allCalls) {
67
+ const name = call.children[0].name;
68
+ if (name !== 'defun' && name !== 'defun-q' && !name.startsWith('c:') && !name.includes(':')) {
69
+ results.push({ name, line: call.pos.line });
70
+ }
71
+ }
72
+ return results;
73
+ }
56
74
  function lintProject(files, config, rootDir) {
57
75
  (0, locale_1.setLocale)(config.locale || 'zh');
58
76
  const allIssues = [];
59
- const defuns = { defuns: new Map() };
77
+ const symbols = { defuns: new Map(), references: new Map() };
60
78
  const fileContents = new Map();
61
79
  for (const filepath of files) {
62
80
  try {
@@ -70,9 +88,15 @@ function lintProject(files, config, rootDir) {
70
88
  for (const [filepath] of fileContents) {
71
89
  const defunList = collectDefuns(filepath);
72
90
  for (const d of defunList) {
73
- const list = defuns.defuns.get(d.name) || [];
91
+ const list = symbols.defuns.get(d.name) || [];
74
92
  list.push({ file: filepath, line: d.line });
75
- defuns.defuns.set(d.name, list);
93
+ symbols.defuns.set(d.name, list);
94
+ }
95
+ const refList = collectReferences(filepath, filepath);
96
+ for (const r of refList) {
97
+ const list = symbols.references.get(r.name) || [];
98
+ list.push({ file: filepath, line: r.line });
99
+ symbols.references.set(r.name, list);
76
100
  }
77
101
  }
78
102
  for (const [filepath] of fileContents) {
@@ -80,7 +104,7 @@ function lintProject(files, config, rootDir) {
80
104
  const override = findProjectOverride(filepath);
81
105
  const checks = override?.checks || config.checks;
82
106
  if (checks['dangling_defun'] !== 'off') {
83
- const danglingIssues = (0, dangling_defun_1.checkDanglingDefun)(filepath, defuns.defuns);
107
+ const danglingIssues = (0, dangling_defun_1.checkDanglingDefun)(filepath, symbols.defuns, symbols.references);
84
108
  for (const iss of danglingIssues) {
85
109
  iss.file = relPath;
86
110
  allIssues.push(iss);
@@ -89,7 +113,7 @@ function lintProject(files, config, rootDir) {
89
113
  if (checks['missing_export'] !== 'off') {
90
114
  const pkgDir = findPackageDir(filepath);
91
115
  if (pkgDir) {
92
- const missingIssues = (0, missing_export_1.checkMissingExport)(filepath, pkgDir, defuns.defuns);
116
+ const missingIssues = (0, missing_export_1.checkMissingExport)(filepath, pkgDir, symbols.defuns);
93
117
  for (const iss of missingIssues) {
94
118
  iss.file = relPath;
95
119
  allIssues.push(iss);
@@ -103,6 +127,13 @@ function lintProject(files, config, rootDir) {
103
127
  allIssues.push(iss);
104
128
  }
105
129
  }
130
+ if (checks['duplicate_defun'] !== 'off') {
131
+ const dupIssues = (0, duplicate_defun_1.checkDuplicateDefun)(filepath, symbols.defuns);
132
+ for (const iss of dupIssues) {
133
+ iss.file = relPath;
134
+ allIssues.push(iss);
135
+ }
136
+ }
106
137
  }
107
138
  return allIssues;
108
139
  }
@@ -0,0 +1,9 @@
1
+ export interface RuleDoc {
2
+ name: string;
3
+ defaultSeverity: string;
4
+ description: string;
5
+ category: string;
6
+ }
7
+ export declare const RULES: RuleDoc[];
8
+ export declare function generateRulesMarkdown(): string;
9
+ //# sourceMappingURL=rules.d.ts.map