@atlisp/lint 0.1.12 → 0.1.14
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.
- package/dist/checks/unused-variable.js +7 -2
- package/dist/index.js +11 -5
- package/package.json +1 -1
|
@@ -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 (
|
|
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,
|
|
172
|
+
.replace(/\*\*\//g, GLOB_PLACEHOLDER)
|
|
168
173
|
.replace(/\*\*/g, '.*')
|
|
169
174
|
.replace(/\*/g, '[^/]*')
|
|
170
175
|
.replace(/\?/g, '.')
|
|
171
|
-
.replace(
|
|
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(
|
|
206
|
+
.replace(/\*\*\//g, GLOB_PLACEHOLDER)
|
|
207
|
+
.replace(/\*\*/g, '.*')
|
|
202
208
|
.replace(/\*/g, '[^/]*')
|
|
203
|
-
.replace(
|
|
209
|
+
.replace(GLOB_RE, '(.*/)?');
|
|
204
210
|
return new RegExp(`^${str}$`);
|
|
205
211
|
});
|
|
206
212
|
return Array.from(files)
|