@atlisp/lint 0.2.16 → 0.2.18

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 (80) hide show
  1. package/README.md +1 -1
  2. package/atlisp-lint.default.json +1 -1
  3. package/dist/checks/arg-count.d.ts +2 -1
  4. package/dist/checks/arg-count.js +37 -19
  5. package/dist/checks/builtin-arg-count.d.ts +2 -1
  6. package/dist/checks/builtin-arg-count.js +3 -2
  7. package/dist/checks/cond-duplicate.js +5 -6
  8. package/dist/checks/constant-condition.js +9 -9
  9. package/dist/checks/dangerous-calls.js +1 -1
  10. package/dist/checks/dangling-defun.d.ts +0 -7
  11. package/dist/checks/dangling-defun.js +0 -63
  12. package/dist/checks/double-not.js +1 -1
  13. package/dist/checks/empty-branch.js +1 -1
  14. package/dist/checks/empty-catch.d.ts +2 -1
  15. package/dist/checks/empty-catch.js +8 -7
  16. package/dist/checks/function-complexity.js +5 -18
  17. package/dist/checks/global-naming.js +1 -1
  18. package/dist/checks/identical-branches.js +3 -3
  19. package/dist/checks/if-without-else.js +1 -1
  20. package/dist/checks/misplaced-else.js +2 -2
  21. package/dist/checks/missing-export.js +3 -3
  22. package/dist/checks/missing-princ.js +1 -1
  23. package/dist/checks/multiple-setq.js +1 -1
  24. package/dist/checks/no-return.d.ts +2 -1
  25. package/dist/checks/no-return.js +4 -3
  26. package/dist/checks/nth-usage.js +1 -1
  27. package/dist/checks/parameter-naming.js +2 -2
  28. package/dist/checks/quote-vs-function.js +1 -1
  29. package/dist/checks/recursive-call.js +1 -1
  30. package/dist/checks/redundant-let.js +1 -1
  31. package/dist/checks/redundant-nil-else.js +1 -1
  32. package/dist/checks/redundant-progn.js +1 -1
  33. package/dist/checks/redundant-setq.js +1 -1
  34. package/dist/checks/self-compare.js +1 -1
  35. package/dist/checks/setq-single-arg.js +3 -2
  36. package/dist/checks/single-arg-and-or.js +1 -1
  37. package/dist/checks/undeclared-setq.d.ts +2 -1
  38. package/dist/checks/undeclared-setq.js +6 -5
  39. package/dist/checks/unused-let.js +3 -3
  40. package/dist/checks/unused-local-fun.js +2 -2
  41. package/dist/checks/unused-package-dep.d.ts +0 -1
  42. package/dist/checks/unused-package-dep.js +6 -93
  43. package/dist/checks/unused-param.js +2 -2
  44. package/dist/checks/unused-variable.js +2 -2
  45. package/dist/checks/variable-shadow.js +3 -3
  46. package/dist/checks/while-constant.js +1 -1
  47. package/dist/cli/collector.js +26 -19
  48. package/dist/config.d.ts +1 -1
  49. package/dist/config.js +18 -9
  50. package/dist/fixes/index.d.ts +4 -0
  51. package/dist/fixes/index.js +843 -140
  52. package/dist/formatter.d.ts +0 -1
  53. package/dist/formatter.js +141 -31
  54. package/dist/index.js +59 -51
  55. package/dist/project.d.ts +1 -1
  56. package/dist/project.js +98 -112
  57. package/dist/runner.d.ts +1 -1
  58. package/dist/runner.js +17 -8
  59. package/dist/utils.js +21 -30
  60. package/dist/validate.js +3 -3
  61. package/dist/visitor-runner.d.ts +0 -28
  62. package/dist/visitor-runner.js +3 -809
  63. package/dist/visitors/equal-nil.d.ts +2 -2
  64. package/dist/visitors/equal-nil.js +5 -4
  65. package/dist/visitors/index.d.ts +1 -1
  66. package/dist/visitors/progn-in-cond.d.ts +2 -2
  67. package/dist/visitors/progn-in-cond.js +5 -4
  68. package/dist/visitors/redundant-and-or.d.ts +2 -2
  69. package/dist/visitors/redundant-and-or.js +3 -3
  70. package/dist/visitors/redundant-car-cdr.d.ts +2 -2
  71. package/dist/visitors/redundant-car-cdr.js +3 -3
  72. package/dist/visitors/register.d.ts +6 -0
  73. package/dist/visitors/register.js +625 -0
  74. package/dist/visitors/shared.d.ts +40 -0
  75. package/dist/visitors/shared.js +129 -0
  76. package/dist/visitors/types.d.ts +2 -7
  77. package/dist/visitors/types.js +0 -69
  78. package/dist/watch.js +33 -12
  79. package/dist/worker.js +1 -1
  80. package/package.json +2 -2
@@ -0,0 +1,625 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerVisitorRules = registerVisitorRules;
4
+ const parser_1 = require("@atlisp/parser");
5
+ const locale_1 = require("../locale");
6
+ const shared_1 = require("./shared");
7
+ function registerVisitorRules(visitor, state, checks, addIssue, config, file) {
8
+ if (checks['redundant_progn'] !== 'off') {
9
+ visitor.on('progn', node => {
10
+ if (!(0, parser_1.astIsList)(node))
11
+ return;
12
+ if (node.children.length === 2) {
13
+ addIssue('redundant_progn', node.pos.line, (0, locale_1.t)('redundant_progn', 'progn'));
14
+ }
15
+ });
16
+ }
17
+ if (checks['redundant_setq'] !== 'off') {
18
+ visitor.on('setq', node => {
19
+ if (!(0, parser_1.astIsList)(node))
20
+ return;
21
+ for (let i = 1; i < node.children.length - 1; i += 2) {
22
+ const varNode = node.children[i];
23
+ const valNode = node.children[i + 1];
24
+ if ((0, parser_1.astIsSymbol)(varNode) && (0, parser_1.astIsSymbol)(valNode) && varNode.name === valNode.name) {
25
+ addIssue('redundant_setq', varNode.pos.line, (0, locale_1.t)('redundant_setq', varNode.name || ''));
26
+ }
27
+ }
28
+ });
29
+ }
30
+ if (checks['redundant_nil_else'] !== 'off') {
31
+ visitor.on('if', node => {
32
+ if (!(0, parser_1.astIsList)(node))
33
+ return;
34
+ if (node.children.length === 4) {
35
+ const last = node.children[3];
36
+ if ((0, parser_1.astIsSymbol)(last, 'nil')) {
37
+ addIssue('redundant_nil_else', node.pos.line, (0, locale_1.t)('redundant_nil_else'));
38
+ }
39
+ }
40
+ });
41
+ }
42
+ if (checks['single_arg_and_or'] !== 'off') {
43
+ const checkSingleArg = (node) => {
44
+ if (!(0, parser_1.astIsList)(node))
45
+ return;
46
+ if (node.children.length === 2) {
47
+ const name = (0, parser_1.astIsSymbol)(node.children[0]) ? node.children[0].name : '';
48
+ addIssue('single_arg_and_or', node.pos.line, (0, locale_1.t)('single_arg_and_or', name || 'and/or'));
49
+ }
50
+ };
51
+ visitor.on('and', checkSingleArg);
52
+ visitor.on('or', checkSingleArg);
53
+ }
54
+ if (checks['redundant_let'] !== 'off') {
55
+ visitor.on('let', node => {
56
+ if (!(0, parser_1.astIsList)(node))
57
+ return;
58
+ if (node.children.length >= 2) {
59
+ const bindings = node.children[1];
60
+ if ((0, parser_1.astIsList)(bindings) && bindings.children.length === 0) {
61
+ addIssue('redundant_let', node.pos.line, (0, locale_1.t)('redundant_let'));
62
+ }
63
+ }
64
+ });
65
+ }
66
+ if (checks['self_compare'] !== 'off') {
67
+ const compareFns = new Set(['=', '/=', '<', '>', '<=', '>=', 'eq', 'equal']);
68
+ visitor.on('*', node => {
69
+ if ((0, parser_1.astIsList)(node) && node.children.length === 3) {
70
+ const op = node.children[0];
71
+ if ((0, parser_1.astIsSymbol)(op) && op.name && compareFns.has(op.name)) {
72
+ const a = node.children[1];
73
+ const b = node.children[2];
74
+ if ((0, parser_1.astIsSymbol)(a) && (0, parser_1.astIsSymbol)(b) && a.name === b.name) {
75
+ addIssue('self_compare', node.pos.line, (0, locale_1.t)('self_compare', `(${op.name} ${a.name} ${b.name})`));
76
+ }
77
+ }
78
+ }
79
+ });
80
+ }
81
+ if (checks['double_not'] !== 'off') {
82
+ visitor.on('not', node => {
83
+ if (!(0, parser_1.astIsList)(node))
84
+ return;
85
+ if (node.children.length >= 2 && (0, parser_1.astIsList)(node.children[1], 'not')) {
86
+ addIssue('double_not', node.pos.line, (0, locale_1.t)('double_not'));
87
+ }
88
+ });
89
+ }
90
+ if (checks['setq_single_arg'] !== 'off') {
91
+ visitor.on('setq', node => {
92
+ if (!(0, parser_1.astIsList)(node))
93
+ return;
94
+ if (node.children.length === 2) {
95
+ const varName = (0, parser_1.astIsSymbol)(node.children[1]) ? node.children[1].name : '';
96
+ addIssue('setq_single_arg', node.pos.line, (0, locale_1.t)('setq_single_arg', varName || ''));
97
+ }
98
+ });
99
+ }
100
+ if (checks['empty_branch'] !== 'off') {
101
+ visitor.on('if', node => {
102
+ if (!(0, parser_1.astIsList)(node))
103
+ return;
104
+ if (node.children.length < 3) {
105
+ addIssue('empty_branch', node.pos.line, (0, locale_1.t)('empty_branch', 'if'));
106
+ }
107
+ });
108
+ }
109
+ if (checks['misplaced_else'] !== 'off') {
110
+ visitor.on('if', node => {
111
+ if (!(0, parser_1.astIsList)(node))
112
+ return;
113
+ if (node.children.length === 4) {
114
+ const cond = node.children[1];
115
+ if ((0, parser_1.astIsList)(cond, 'not') && cond.children.length >= 2) {
116
+ const innerName = (0, parser_1.astIsSymbol)(cond.children[1]) ? cond.children[1].name || '' : '';
117
+ addIssue('misplaced_else', node.pos.line, (0, locale_1.t)('misplaced_else', innerName));
118
+ }
119
+ }
120
+ });
121
+ }
122
+ if (checks['while_constant'] !== 'off') {
123
+ visitor.on('while', node => {
124
+ if (!(0, parser_1.astIsList)(node))
125
+ return;
126
+ if (node.children.length >= 2) {
127
+ const cond = node.children[1];
128
+ if ((0, shared_1.isLiteral)(cond)) {
129
+ const name = (0, parser_1.astIsSymbol)(cond) ? cond.name || '' : String(cond.value ?? '');
130
+ addIssue('while_constant', node.pos.line, (0, locale_1.t)('while_constant', name));
131
+ }
132
+ }
133
+ });
134
+ }
135
+ if (checks['constant_condition'] !== 'off') {
136
+ const checkConstant = (node, formName) => {
137
+ if (!(0, parser_1.astIsList)(node))
138
+ return;
139
+ if (node.children.length >= 2) {
140
+ const cond = node.children[1];
141
+ if ((0, shared_1.isLiteral)(cond)) {
142
+ const name = (0, parser_1.astIsSymbol)(cond) ? cond.name || '' : String(cond.value ?? '');
143
+ addIssue('constant_condition', node.pos.line, (0, locale_1.t)('constant_condition', name, formName));
144
+ }
145
+ }
146
+ };
147
+ visitor.on('if', node => checkConstant(node, 'if'));
148
+ visitor.on('while', node => checkConstant(node, 'while'));
149
+ visitor.on('cond', node => {
150
+ if (!(0, parser_1.astIsList)(node))
151
+ return;
152
+ if (node.children.length >= 2) {
153
+ const clause = node.children[1];
154
+ if ((0, parser_1.astIsList)(clause) && clause.children.length >= 2) {
155
+ const test = clause.children[1];
156
+ if ((0, shared_1.isLiteral)(test)) {
157
+ const name = (0, parser_1.astIsSymbol)(test) ? test.name || '' : String(test.value ?? '');
158
+ addIssue('constant_condition', node.pos.line, (0, locale_1.t)('constant_condition', name, 'cond'));
159
+ }
160
+ }
161
+ }
162
+ });
163
+ }
164
+ if (checks['quote_vs_function'] !== 'off') {
165
+ visitor.on('quote', node => {
166
+ if (!(0, parser_1.astIsList)(node))
167
+ return;
168
+ if (node.children.length >= 2 && (0, parser_1.astIsList)(node.children[1], 'lambda')) {
169
+ const parent = node.parent;
170
+ if (parent && (0, parser_1.astIsList)(parent) && parent.children.length > 0) {
171
+ const pName = (0, parser_1.astIsSymbol)(parent.children[0]) ? parent.children[0].name || '' : '';
172
+ if (shared_1.higherOrderFuncs.has(pName)) {
173
+ addIssue('quote_vs_function', node.pos.line, (0, locale_1.t)('quote_vs_function', pName));
174
+ }
175
+ }
176
+ }
177
+ });
178
+ }
179
+ if (checks['redundant_quotes'] !== 'off') {
180
+ visitor.on('quote', node => {
181
+ if (!(0, parser_1.astIsList)(node))
182
+ return;
183
+ if (node.children.length >= 2 && (0, parser_1.astIsList)(node.children[1], 'quote')) {
184
+ addIssue('redundant_quotes', node.pos.line, (0, locale_1.t)('redundant_quotes'));
185
+ }
186
+ });
187
+ }
188
+ if (checks['parameter_naming'] !== 'off') {
189
+ visitor.on('defun', node => {
190
+ if (!(0, parser_1.astIsList)(node))
191
+ return;
192
+ if (node.children.length < 3)
193
+ return;
194
+ const paramList = node.children[2];
195
+ const fnName = (0, parser_1.astIsSymbol)(node.children[1]) ? node.children[1].name || '' : '';
196
+ for (const child of (0, parser_1.astChildren)(paramList)) {
197
+ if (!(0, parser_1.astIsSymbol)(child) || !child.name)
198
+ continue;
199
+ if (/^[A-Z]/.test(child.name) && child.name !== 'T' && child.name !== 'nil') {
200
+ addIssue('parameter_naming', child.pos.line, (0, locale_1.t)('parameter_naming', child.name, fnName));
201
+ }
202
+ }
203
+ });
204
+ }
205
+ if (checks['assoc_without_cdr'] !== 'off') {
206
+ visitor.on('assoc', node => {
207
+ if (!(0, parser_1.astIsList)(node))
208
+ return;
209
+ const parent = node.parent;
210
+ if (!parent) {
211
+ addIssue('assoc_without_cdr', node.pos.line, (0, locale_1.t)('assoc_without_cdr'));
212
+ return;
213
+ }
214
+ if ((0, parser_1.astIsList)(parent) && parent.children.length > 0 && (0, parser_1.astIsSymbol)(parent.children[0])) {
215
+ if (parent.children[0].name === 'cdr' || parent.children[0].name === 'cadr') {
216
+ return;
217
+ }
218
+ }
219
+ addIssue('assoc_without_cdr', node.pos.line, (0, locale_1.t)('assoc_without_cdr'));
220
+ });
221
+ }
222
+ if (checks['identical_branches'] !== 'off') {
223
+ visitor.on('if', node => {
224
+ if (!(0, parser_1.astIsList)(node))
225
+ return;
226
+ if (node.children.length === 4) {
227
+ const thenBranch = node.children[2];
228
+ const elseBranch = node.children[3];
229
+ if ((0, shared_1.astEqual)(thenBranch, elseBranch)) {
230
+ addIssue('identical_branches', node.pos.line, (0, locale_1.t)('identical_branches'));
231
+ }
232
+ }
233
+ });
234
+ }
235
+ if (checks['open_without_close'] !== 'off') {
236
+ visitor.on('open', () => {
237
+ state.openCount++;
238
+ });
239
+ visitor.on('close', () => {
240
+ state.closeCount++;
241
+ });
242
+ }
243
+ if (checks['cond_duplicate'] !== 'off') {
244
+ visitor.on('cond', node => {
245
+ if (!(0, parser_1.astIsList)(node))
246
+ return;
247
+ const seen = new Set();
248
+ for (let i = 1; i < node.children.length; i++) {
249
+ const clause = node.children[i];
250
+ if (!(0, parser_1.astIsList)(clause) || clause.children.length < 1)
251
+ continue;
252
+ const condTest = clause.children[0];
253
+ const key = (0, shared_1.getCondKey)(condTest);
254
+ if (seen.has(key)) {
255
+ addIssue('cond_duplicate', clause.pos.line, (0, locale_1.t)('cond_duplicate'));
256
+ }
257
+ seen.add(key);
258
+ }
259
+ });
260
+ }
261
+ if (checks['quit_exit'] !== 'off') {
262
+ const dangerNames = new Set();
263
+ const dc = config.dangerous_calls;
264
+ if (dc.quit !== 'off')
265
+ dangerNames.add('quit');
266
+ if (dc.exit !== 'off')
267
+ dangerNames.add('exit');
268
+ if (dc.startapp !== 'off')
269
+ dangerNames.add('startapp');
270
+ if (dc.vl_registry_write !== 'off')
271
+ dangerNames.add('vl-registry-write');
272
+ if (dc.eval !== 'off')
273
+ dangerNames.add('eval');
274
+ if (dangerNames.size > 0) {
275
+ visitor.on('*', node => {
276
+ if ((0, parser_1.astIsList)(node) && node.children.length > 0 && (0, parser_1.astIsSymbol)(node.children[0]) && node.children[0].name && dangerNames.has(node.children[0].name)) {
277
+ if (!(0, shared_1.isInQuote)(node)) {
278
+ state.dangerousCalls.push({ name: node.children[0].name, node });
279
+ }
280
+ }
281
+ });
282
+ }
283
+ }
284
+ if (checks['multiple_setq'] !== 'off') {
285
+ visitor.on('*', node => {
286
+ if ((0, parser_1.astIsList)(node)) {
287
+ let prevSetq = false;
288
+ for (const child of node.children) {
289
+ if ((0, parser_1.astIsList)(child, 'setq')) {
290
+ if (prevSetq) {
291
+ addIssue('multiple_setq', child.pos.line, (0, locale_1.t)('multiple_setq'));
292
+ prevSetq = false;
293
+ }
294
+ else {
295
+ prevSetq = true;
296
+ }
297
+ }
298
+ else {
299
+ prevSetq = false;
300
+ }
301
+ }
302
+ }
303
+ });
304
+ }
305
+ if (checks['recursive_call'] !== 'off') {
306
+ visitor.on('defun', node => {
307
+ if (!(0, parser_1.astIsList)(node))
308
+ return;
309
+ if (node.children.length < 4)
310
+ return;
311
+ const fnName = (0, parser_1.astIsSymbol)(node.children[1]) ? node.children[1].name : '';
312
+ if (!fnName)
313
+ return;
314
+ const body = node.children.slice(3);
315
+ if ((0, shared_1.hasSelfCall)(body, fnName) && !(0, shared_1.hasConditionalForm)(body)) {
316
+ addIssue('recursive_call', node.pos.line, (0, locale_1.t)('recursive_call', fnName));
317
+ }
318
+ });
319
+ }
320
+ if (checks['variable_shadow'] !== 'off') {
321
+ visitor.on('let', node => {
322
+ if (!(0, parser_1.astIsList)(node))
323
+ return;
324
+ if (node.children.length < 2)
325
+ return;
326
+ const bindings = node.children[1];
327
+ if (!(0, parser_1.astIsList)(bindings))
328
+ return;
329
+ const letVars = new Set();
330
+ for (const b of bindings.children) {
331
+ if ((0, parser_1.astIsList)(b) && b.children.length > 0 && (0, parser_1.astIsSymbol)(b.children[0]) && b.children[0].name) {
332
+ letVars.add(b.children[0].name);
333
+ }
334
+ }
335
+ const walkBodyForSetq = (forms) => {
336
+ for (const form of forms) {
337
+ if ((0, parser_1.astIsList)(form) && form.children.length > 0 && (0, parser_1.astIsSymbol)(form.children[0])) {
338
+ if (form.children[0].name === 'setq' && form.children.length > 1) {
339
+ for (let i = 1; i < form.children.length; i += 2) {
340
+ const child = form.children[i];
341
+ if (!(0, parser_1.astIsSymbol)(child) || !child.name)
342
+ continue;
343
+ if (letVars.has(child.name)) {
344
+ addIssue('variable_shadow', child.pos.line, (0, locale_1.t)('variable_shadow', child.name));
345
+ }
346
+ }
347
+ }
348
+ else if (form.children[0].name !== 'let') {
349
+ walkBodyForSetq(form.children.slice(1));
350
+ }
351
+ }
352
+ }
353
+ };
354
+ walkBodyForSetq(node.children.slice(2));
355
+ });
356
+ }
357
+ if (checks['unused_let_binding'] !== 'off') {
358
+ visitor.on('let', node => {
359
+ if (!(0, parser_1.astIsList)(node))
360
+ return;
361
+ if (node.children.length < 2)
362
+ return;
363
+ const bindings = node.children[1];
364
+ if (!(0, parser_1.astIsList)(bindings))
365
+ return;
366
+ const letVars = [];
367
+ for (const b of bindings.children) {
368
+ if ((0, parser_1.astIsList)(b) && b.children.length > 0 && (0, parser_1.astIsSymbol)(b.children[0]) && b.children[0].name) {
369
+ letVars.push({ name: b.children[0].name, line: b.children[0].pos.line });
370
+ }
371
+ }
372
+ if (letVars.length === 0)
373
+ return;
374
+ const bodyRefs = new Set();
375
+ for (const form of node.children.slice(2)) {
376
+ (0, shared_1.collectSymbolRefs)(form, bodyRefs);
377
+ }
378
+ for (const v of letVars) {
379
+ if (!bodyRefs.has(v.name)) {
380
+ addIssue('unused_let_binding', v.line, (0, locale_1.t)('unused_let_binding', v.name));
381
+ }
382
+ }
383
+ });
384
+ }
385
+ if (checks['unused_parameter'] !== 'off' || checks['unused_local_fun'] !== 'off') {
386
+ visitor.on('defun', node => {
387
+ if (!(0, parser_1.astIsList)(node))
388
+ return;
389
+ if (node.children.length < 4)
390
+ return;
391
+ const fnName = (0, parser_1.astIsSymbol)(node.children[1]) ? node.children[1].name : '';
392
+ if (!fnName || fnName.startsWith('C:') || fnName.startsWith('c:'))
393
+ return;
394
+ const body = node.children.slice(3);
395
+ if (checks['unused_parameter'] !== 'off') {
396
+ const params = (0, shared_1.defunParams)(node);
397
+ if (params.length > 0) {
398
+ const bodyRefs = new Set();
399
+ for (const form of body) {
400
+ (0, shared_1.collectSymbolRefs)(form, bodyRefs);
401
+ }
402
+ for (const p of params) {
403
+ if (!bodyRefs.has(p) && p !== fnName) {
404
+ addIssue('unused_parameter', node.pos.line, (0, locale_1.t)('unused_parameter', p, fnName));
405
+ }
406
+ }
407
+ }
408
+ }
409
+ if (checks['unused_local_fun'] !== 'off') {
410
+ const locals = (0, shared_1.defunLocals)(node);
411
+ if (locals.length > 0) {
412
+ const bodyRefs = new Set();
413
+ for (const form of body) {
414
+ (0, shared_1.collectSymbolRefs)(form, bodyRefs);
415
+ }
416
+ for (const l of locals) {
417
+ if (!bodyRefs.has(l)) {
418
+ addIssue('unused_local_fun', node.pos.line, (0, locale_1.t)('unused_local_fun', l));
419
+ }
420
+ }
421
+ }
422
+ }
423
+ });
424
+ }
425
+ if (checks['unused_variable'] !== 'off') {
426
+ visitor.on('setq', node => {
427
+ if (!(0, parser_1.astIsList)(node))
428
+ return;
429
+ for (let i = 1; i < node.children.length; i += 2) {
430
+ const varNode = node.children[i];
431
+ if ((0, parser_1.astIsSymbol)(varNode) &&
432
+ varNode.name &&
433
+ !varNode.name.startsWith('*') &&
434
+ !varNode.name.includes(':*') &&
435
+ varNode.name !== 'T' &&
436
+ varNode.name !== 'nil' &&
437
+ !varNode.name.startsWith('/')) {
438
+ state.setqDefs.set(varNode.name, { line: varNode.pos.line, file });
439
+ }
440
+ }
441
+ });
442
+ }
443
+ if (checks['unused_variable'] !== 'off') {
444
+ visitor.on('*', node => {
445
+ if ((0, parser_1.astIsSymbol)(node) && node.name) {
446
+ state.symbolRefs.set(node.name, (state.symbolRefs.get(node.name) || 0) + 1);
447
+ }
448
+ });
449
+ }
450
+ if (checks['function_complexity'] !== 'off') {
451
+ visitor.on('defun', node => {
452
+ if (!(0, parser_1.astIsList)(node))
453
+ return;
454
+ if (node.children.length >= 3) {
455
+ const fnName = ((0, parser_1.astIsSymbol)(node.children[1]) ? node.children[1].name : '<anonymous>') || '<anonymous>';
456
+ state.defunScopes.push({
457
+ name: fnName,
458
+ params: [],
459
+ body: node.children.slice(3),
460
+ line: node.pos.line,
461
+ file,
462
+ });
463
+ }
464
+ });
465
+ }
466
+ if (checks['if_without_else'] !== 'off') {
467
+ visitor.on('if', node => {
468
+ if (!(0, parser_1.astIsList)(node))
469
+ return;
470
+ if (node.children.length === 3) {
471
+ const parent = node.parent;
472
+ if (parent && (0, parser_1.astIsList)(parent) && parent.children.length > 0 && (0, parser_1.astIsSymbol)(parent.children[0])) {
473
+ const parentName = parent.children[0].name;
474
+ if (parentName === 'cond' || parentName === 'if')
475
+ return;
476
+ }
477
+ addIssue('if_without_else', node.pos.line, (0, locale_1.t)('if_without_else'));
478
+ }
479
+ });
480
+ }
481
+ if (checks['strcat_or_arg'] !== 'off') {
482
+ visitor.on('*', node => {
483
+ if ((0, parser_1.astIsList)(node, 'strcat') && node.children.length > 1) {
484
+ if ((0, shared_1.isInQuote)(node))
485
+ return;
486
+ for (let i = 1; i < node.children.length; i++) {
487
+ const arg = node.children[i];
488
+ if ((0, parser_1.astIsList)(arg, 'or')) {
489
+ addIssue('strcat_or_arg', arg.pos.line, (0, locale_1.t)('strcat_or_arg'));
490
+ }
491
+ }
492
+ }
493
+ });
494
+ }
495
+ if (checks['redundant_list'] !== 'off') {
496
+ visitor.on('list', node => {
497
+ if (!(0, parser_1.astIsList)(node))
498
+ return;
499
+ if (node.children.length === 1) {
500
+ addIssue('redundant_list', node.pos.line, (0, locale_1.t)('redundant_list'));
501
+ }
502
+ });
503
+ }
504
+ if (checks['command_s'] !== 'off') {
505
+ visitor.on('command', node => {
506
+ if (!(0, parser_1.astIsList)(node))
507
+ return;
508
+ if (node.children.length >= 2) {
509
+ const subCmd = node.children[1];
510
+ if ((0, parser_1.astIsString)(subCmd) && subCmd.value === 'shell')
511
+ return;
512
+ addIssue('command_s', node.pos.line, (0, locale_1.t)('command_s'));
513
+ }
514
+ });
515
+ }
516
+ if (checks['zerop_usage'] !== 'off') {
517
+ const checkZero = (node) => {
518
+ if (!(0, parser_1.astIsList)(node))
519
+ return;
520
+ if (node.children.length === 3) {
521
+ const a = node.children[1];
522
+ const b = node.children[2];
523
+ const extract = (n) => (0, parser_1.astIsSymbol)(n) ? n.name || '' : (0, parser_1.astIsNumber)(n) ? String(n.value ?? '') : '';
524
+ if ((0, parser_1.astIsNumber)(a) && a.value === 0 && (0, parser_1.astIsSymbol)(b)) {
525
+ addIssue('zerop_usage', node.pos.line, (0, locale_1.t)('zerop_usage', extract(b)));
526
+ }
527
+ else if ((0, parser_1.astIsNumber)(b) && b.value === 0 && (0, parser_1.astIsSymbol)(a)) {
528
+ addIssue('zerop_usage', node.pos.line, (0, locale_1.t)('zerop_usage', extract(a)));
529
+ }
530
+ }
531
+ };
532
+ visitor.on('=', checkZero);
533
+ visitor.on('equal', checkZero);
534
+ }
535
+ if (checks['progn_in_body'] !== 'off') {
536
+ const checkPrognInBody = (node, formName, bodyStartIdx) => {
537
+ if (!(0, parser_1.astIsList)(node))
538
+ return;
539
+ if (node.children.length > bodyStartIdx) {
540
+ const firstBody = node.children[bodyStartIdx];
541
+ if ((0, parser_1.astIsList)(firstBody, 'progn')) {
542
+ addIssue('progn_in_body', firstBody.pos.line, (0, locale_1.t)('progn_in_body', formName));
543
+ }
544
+ }
545
+ };
546
+ visitor.on('while', node => checkPrognInBody(node, 'while', 2));
547
+ visitor.on('repeat', node => checkPrognInBody(node, 'repeat', 2));
548
+ visitor.on('foreach', node => checkPrognInBody(node, 'foreach', 3));
549
+ }
550
+ if (checks['if_progn_both'] !== 'off') {
551
+ visitor.on('if', node => {
552
+ if (!(0, parser_1.astIsList)(node))
553
+ return;
554
+ if (node.children.length === 4) {
555
+ const thenBranch = node.children[2];
556
+ const elseBranch = node.children[3];
557
+ if ((0, parser_1.astIsList)(thenBranch, 'progn') && (0, parser_1.astIsList)(elseBranch, 'progn')) {
558
+ addIssue('if_progn_both', node.pos.line, (0, locale_1.t)('if_progn_both'));
559
+ }
560
+ }
561
+ });
562
+ }
563
+ if (checks['redundant_cond'] !== 'off') {
564
+ visitor.on('cond', node => {
565
+ if (!(0, parser_1.astIsList)(node))
566
+ return;
567
+ if (node.children.length === 2) {
568
+ const clause = node.children[1];
569
+ if ((0, parser_1.astIsList)(clause) && clause.children.length === 2) {
570
+ const test = clause.children[0];
571
+ if ((0, parser_1.astIsSymbol)(test, 't'))
572
+ return;
573
+ addIssue('redundant_cond', node.pos.line, (0, locale_1.t)('redundant_cond'));
574
+ }
575
+ }
576
+ });
577
+ }
578
+ if (checks['empty_branch_cond'] !== 'off') {
579
+ visitor.on('cond', node => {
580
+ if (!(0, parser_1.astIsList)(node))
581
+ return;
582
+ for (let i = 1; i < node.children.length; i++) {
583
+ const clause = node.children[i];
584
+ if ((0, parser_1.astIsList)(clause) && clause.children.length < 2) {
585
+ addIssue('empty_branch_cond', clause.pos.line, (0, locale_1.t)('empty_branch_cond'));
586
+ }
587
+ }
588
+ });
589
+ }
590
+ if (checks['selection_set_leak'] !== 'off') {
591
+ visitor.on('ssget', () => {
592
+ state.ssgetCount++;
593
+ });
594
+ visitor.on('ssset', () => {
595
+ state.sssetCount++;
596
+ });
597
+ }
598
+ if (checks['promise_handler'] !== 'off') {
599
+ visitor.on('*', node => {
600
+ if ((0, parser_1.astIsList)(node) &&
601
+ node.children.length > 0 &&
602
+ (0, parser_1.astIsSymbol)(node.children[0]) &&
603
+ node.children[0].name &&
604
+ (node.children[0].name.startsWith('vlax-invoke') || node.children[0].name.startsWith('vlax-invoke-method'))) {
605
+ if ((0, shared_1.isInQuote)(node))
606
+ return;
607
+ const parent = node.parent;
608
+ if (parent && (0, parser_1.astIsList)(parent) && parent.children.length > 0 && (0, parser_1.astIsSymbol)(parent.children[0], 'vl-catch-all-apply')) {
609
+ return;
610
+ }
611
+ let hasCallback = false;
612
+ for (const child of node.children.slice(1)) {
613
+ if ((0, parser_1.astIsList)(child) && child.children.length > 0 && (0, parser_1.astIsSymbol)(child.children[0]) && (child.children[0].name === 'lambda' || child.children[0].name === 'function')) {
614
+ hasCallback = true;
615
+ break;
616
+ }
617
+ }
618
+ if (!hasCallback) {
619
+ addIssue('promise_handler', node.pos.line, (0, locale_1.t)('promise_handler'));
620
+ }
621
+ }
622
+ });
623
+ }
624
+ }
625
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1,40 @@
1
+ import { AstNode } from '@atlisp/parser';
2
+ export interface CollectState {
3
+ openCount: number;
4
+ closeCount: number;
5
+ setqDefs: Map<string, {
6
+ line: number;
7
+ file: string;
8
+ }>;
9
+ symbolRefs: Map<string, number>;
10
+ condKeys: Map<number, Set<string>>;
11
+ defunScopes: Array<{
12
+ name: string;
13
+ params: string[];
14
+ body: AstNode[];
15
+ line: number;
16
+ file: string;
17
+ }>;
18
+ letScopes: Array<{
19
+ bindings: string[];
20
+ body: AstNode[];
21
+ line: number;
22
+ }>;
23
+ dangerousCalls: Array<{
24
+ name: string;
25
+ node: AstNode;
26
+ }>;
27
+ ssgetCount: number;
28
+ sssetCount: number;
29
+ }
30
+ export declare function isInQuote(node: AstNode, checkFunction?: boolean): boolean;
31
+ export declare function isLiteral(node: AstNode): boolean;
32
+ export declare function astEqual(a: AstNode, b: AstNode): boolean;
33
+ export declare function getCondKey(node: AstNode): string;
34
+ export declare function hasConditionalForm(body: AstNode[]): boolean;
35
+ export declare function hasSelfCall(body: AstNode[], fnName: string): boolean;
36
+ export declare function defunParams(defunNode: AstNode): string[];
37
+ export declare function defunLocals(defunNode: AstNode): string[];
38
+ export declare function collectSymbolRefs(node: AstNode, result: Set<string>): void;
39
+ export declare const higherOrderFuncs: Set<string>;
40
+ //# sourceMappingURL=shared.d.ts.map