@atlisp/lint 0.1.12 → 0.1.15

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.
@@ -2,60 +2,48 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkGlobalNaming = checkGlobalNaming;
4
4
  const locale_1 = require("../locale");
5
- const utils_1 = require("../utils");
6
- function checkGlobalNaming(content, file) {
7
- const issues = [];
8
- const lines = content.split('\n');
9
- let depth = 0;
10
- let inDefun = false;
11
- let defunLocals = new Set();
12
- for (let i = 0; i < lines.length; i++) {
13
- const stripped = (0, utils_1.stripLine)(lines[i]);
14
- // Track depth
15
- for (const ch of stripped) {
16
- if (ch === '(')
17
- depth++;
18
- else if (ch === ')')
19
- depth--;
20
- }
21
- // Detect defun start and extract local variables
22
- if (!inDefun) {
23
- const defunMatch = stripped.match(/\(defun\s+\S+\s+\(([^)]*\/\s+[^)]*)\)/);
24
- if (defunMatch) {
25
- inDefun = true;
26
- const all = defunMatch[1];
27
- const slashIdx = all.indexOf('/');
28
- defunLocals = new Set(all
29
- .slice(slashIdx + 1)
30
- .split(/\s+/)
31
- .filter(Boolean));
32
- }
33
- }
34
- if (depth <= 0) {
35
- inDefun = false;
36
- defunLocals = new Set();
37
- }
38
- // setq at depth 0 or 1 (top-level or directly inside progn) is global
39
- if (depth <= 1) {
40
- const m = stripped.match(/\(setq\s+(\S+)/);
41
- if (m) {
42
- const v = m[1];
43
- if (v !== 'T' &&
44
- v !== 'nil' &&
45
- !v.startsWith('*') &&
46
- !v.endsWith('*') &&
47
- !v.includes('/') &&
48
- !defunLocals.has(v)) {
49
- issues.push({
50
- file,
51
- line: i + 1,
52
- severity: 'warn',
53
- rule: 'global_naming',
54
- message: (0, locale_1.t)('global_naming', v),
55
- });
5
+ const parser_1 = require("@atlisp/parser");
6
+ function isInsideLocalScope(node) {
7
+ let cur = node.parent;
8
+ while (cur) {
9
+ if (cur.type === 'list' && cur.children && cur.children.length > 0) {
10
+ const head = cur.children[0];
11
+ if (head.type === 'symbol' && head.name) {
12
+ if (['defun', 'lambda', 'let', 'let*'].includes(head.name)) {
13
+ return true;
56
14
  }
57
15
  }
58
16
  }
17
+ cur = cur.parent;
18
+ }
19
+ return false;
20
+ }
21
+ function checkGlobalNaming(content, file) {
22
+ const issues = [];
23
+ const ast = (0, parser_1.parseAst)(content);
24
+ const setqForms = (0, parser_1.astFindListWithHead)(ast, 'setq');
25
+ for (const form of setqForms) {
26
+ if (!form.children || form.children.length < 2)
27
+ continue;
28
+ // Skip setq inside defun/lambda/let — those are local
29
+ if (isInsideLocalScope(form))
30
+ continue;
31
+ for (let i = 1; i < form.children.length; i += 2) {
32
+ const v = form.children[i];
33
+ if (v.type !== 'symbol' || !v.name)
34
+ continue;
35
+ if (v.name === 'T' || v.name === 'nil')
36
+ continue;
37
+ if (v.name.startsWith('*') && v.name.endsWith('*'))
38
+ continue;
39
+ issues.push({
40
+ file,
41
+ line: v.pos.line,
42
+ severity: 'warn',
43
+ rule: 'global_naming',
44
+ message: (0, locale_1.t)('global_naming', v.name),
45
+ });
46
+ }
59
47
  }
60
48
  return issues;
61
49
  }
@@ -24,8 +24,8 @@ function checkUnusedVariableAst(ast, file) {
24
24
  continue;
25
25
  if (v.name.startsWith('/'))
26
26
  continue;
27
- // Skip earmuffed globals (*var*) — typically cross-file
28
- if (v.name.startsWith('*') && v.name.endsWith('*') && v.name.length > 2)
27
+ // Skip earmuffed globals (*var*) and namespaced earmuffed (ns:*var*) — typically cross-file
28
+ if (isEarmuffed(v.name))
29
29
  continue;
30
30
  if (!setqVars.has(v.name)) {
31
31
  setqVars.set(v.name, v.pos.line);
@@ -69,6 +69,11 @@ function checkUnusedVariableAst(ast, file) {
69
69
  }
70
70
  return issues;
71
71
  }
72
+ /** Check if a variable name is earmuffed (*var*), optionally with a namespace prefix (ns:*var*) */
73
+ function isEarmuffed(name) {
74
+ const localName = name.includes(':') ? name.slice(name.lastIndexOf(':') + 1) : name;
75
+ return localName.startsWith('*') && localName.endsWith('*') && localName.length > 2;
76
+ }
72
77
  function isInsideLetBinding(node, varName) {
73
78
  let cur = node.parent;
74
79
  while (cur) {
package/dist/index.js CHANGED
@@ -151,24 +151,29 @@ function* walkFiles(dir, rootDir, regex) {
151
151
  catch {
152
152
  continue;
153
153
  }
154
+ const rel = path.relative(rootDir, fullPath).replace(/\\/g, '/');
155
+ if (rel.startsWith('..'))
156
+ continue;
154
157
  if (stat.isDirectory()) {
155
158
  yield* walkFiles(fullPath, rootDir, regex);
156
159
  }
157
160
  else if (stat.isFile()) {
158
- const rel = path.relative(rootDir, fullPath).replace(/\\/g, '/');
159
161
  if (regex.test(rel))
160
162
  yield fullPath;
161
163
  }
162
164
  }
163
165
  }
166
+ // Placeholder regex (dynamically constructed to avoid no-control-regex)
167
+ const GLOB_PLACEHOLDER = '\x00GLOB\x00';
168
+ const GLOB_RE = new RegExp(GLOB_PLACEHOLDER, 'g');
164
169
  function globFiles(pattern, rootDir) {
165
170
  const regexStr = pattern
166
171
  .replace(/\./g, '\\.')
167
- .replace(/\*\*\//g, '\x00GLOB\x00')
172
+ .replace(/\*\*\//g, GLOB_PLACEHOLDER)
168
173
  .replace(/\*\*/g, '.*')
169
174
  .replace(/\*/g, '[^/]*')
170
175
  .replace(/\?/g, '.')
171
- .replace(/\x00GLOB\x00/g, '(.*/)?');
176
+ .replace(GLOB_RE, '(.*/)?');
172
177
  const regex = new RegExp(`^${regexStr}$`);
173
178
  return Array.from(walkFiles(rootDir, rootDir, regex));
174
179
  }
@@ -198,9 +203,10 @@ function collectFiles(rootDir, opts, config) {
198
203
  const excludePatterns = config.source.exclude.map(e => {
199
204
  const str = e
200
205
  .replace(/\./g, '\\.')
201
- .replace(/\*\*/g, '\x00STAR\x00')
206
+ .replace(/\*\*\//g, GLOB_PLACEHOLDER)
207
+ .replace(/\*\*/g, '.*')
202
208
  .replace(/\*/g, '[^/]*')
203
- .replace(/\x00STAR\x00/g, '.*');
209
+ .replace(GLOB_RE, '(.*/)?');
204
210
  return new RegExp(`^${str}$`);
205
211
  });
206
212
  return Array.from(files)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/lint",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "description": "AutoLISP static analysis tool — parens, security, conventions, SBCL syntax validation",
5
5
  "keywords": [
6
6
  "CAD",