@atlisp/lint 0.1.20 → 0.1.22

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.
@@ -61,19 +61,30 @@ function getSetqVarName(node) {
61
61
  return null;
62
62
  }
63
63
  function hasErrorCheckInSiblings(node, varName) {
64
- const parent = node.parent;
64
+ let parent = node.parent;
65
65
  if (!parent || !parent.children)
66
66
  return false;
67
67
  const idx = parent.children.indexOf(node);
68
68
  for (let i = idx + 1; i < parent.children.length; i++) {
69
- const sibling = parent.children[i];
70
- if ((0, parser_1.astIsList)(sibling, 'vl-catch-all-error-p')) {
71
- if (sibling.children && sibling.children.length >= 2 &&
72
- (0, parser_1.astIsSymbol)(sibling.children[1], varName)) {
73
- return true;
69
+ if (containsErrorCheck(parent.children[i], varName))
70
+ return true;
71
+ }
72
+ if ((0, parser_1.astIsList)(parent, 'setq')) {
73
+ const grandparent = parent.parent;
74
+ if (grandparent && grandparent.children) {
75
+ const parentIdx = grandparent.children.indexOf(parent);
76
+ for (let i = parentIdx + 1; i < grandparent.children.length; i++) {
77
+ if (containsErrorCheck(grandparent.children[i], varName))
78
+ return true;
74
79
  }
75
80
  }
76
81
  }
77
82
  return false;
78
83
  }
84
+ function containsErrorCheck(node, varName) {
85
+ const matches = (0, parser_1.astFindAll)(node, n => (0, parser_1.astIsList)(n, 'vl-catch-all-error-p') &&
86
+ n.children && n.children.length >= 2 &&
87
+ (0, parser_1.astIsSymbol)(n.children[1], varName));
88
+ return matches.length > 0;
89
+ }
79
90
  //# sourceMappingURL=empty-catch.js.map
@@ -2,27 +2,48 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkUnusedCatchResult = checkUnusedCatchResult;
4
4
  const locale_1 = require("../locale");
5
+ const parser_1 = require("@atlisp/parser");
5
6
  function checkUnusedCatchResult(content, file) {
6
7
  const issues = [];
7
- const lines = content.split('\n');
8
- const catchRe = /\(vl-catch-all-apply\s+'[^)]+\)/g;
9
- for (let i = 0; i < lines.length; i++) {
10
- const line = lines[i];
11
- let match;
12
- while ((match = catchRe.exec(line)) !== null) {
13
- const col = match.index;
14
- const after = line.slice(col + match[0].length).trim();
15
- if (!after.startsWith(')')) {
16
- issues.push({
17
- file,
18
- line: i + 1,
19
- severity: 'warn',
20
- rule: 'unused_catch_result',
21
- message: (0, locale_1.t)('unused_catch_result'),
22
- });
23
- }
24
- }
8
+ const ast = (0, parser_1.parseAst)(content);
9
+ const catchNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'vl-catch-all-apply'));
10
+ for (const node of catchNodes) {
11
+ if (isInQuote(node))
12
+ continue;
13
+ if (isWrappedByCatchError(node))
14
+ continue;
15
+ if (isSetqStored(node))
16
+ continue;
17
+ issues.push({
18
+ file,
19
+ line: node.pos.line,
20
+ severity: 'warn',
21
+ rule: 'unused_catch_result',
22
+ message: (0, locale_1.t)('unused_catch_result'),
23
+ });
25
24
  }
26
25
  return issues;
27
26
  }
27
+ function isInQuote(node) {
28
+ let p = node.parent;
29
+ while (p) {
30
+ if ((0, parser_1.astIsList)(p, 'quote'))
31
+ return true;
32
+ p = p.parent;
33
+ }
34
+ return false;
35
+ }
36
+ function isWrappedByCatchError(node) {
37
+ const parent = node.parent;
38
+ return !!(parent && (0, parser_1.astIsList)(parent, 'vl-catch-all-error-p'));
39
+ }
40
+ function isSetqStored(node) {
41
+ const parent = node.parent;
42
+ if (!parent || !(0, parser_1.astIsList)(parent, 'setq'))
43
+ return false;
44
+ if (!parent.children || parent.children.length < 3)
45
+ return false;
46
+ const idx = parent.children.indexOf(node);
47
+ return idx >= 2 && idx % 2 === 0;
48
+ }
28
49
  //# sourceMappingURL=unused-catch-result.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/lint",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "AutoLISP static analysis tool — parens, security, conventions, SBCL syntax validation",
5
5
  "keywords": [
6
6
  "CAD",
@@ -37,7 +37,7 @@
37
37
  "prepack": "npm run build"
38
38
  },
39
39
  "dependencies": {
40
- "@atlisp/parser": "^0.1.0"
40
+ "@atlisp/parser": "^0.1.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/jest": "^29",