@code-sentinel-cli/code-sentinel-cli 4.0.8 → 4.0.9
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/bin.js +1334 -568
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +26 -0
- package/dist/index.js +1334 -568
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { asTsMorphSourceFile } from '@code-sentinel/parsers';
|
|
2
|
+
import { SyntaxKind, Node } from 'ts-morph';
|
|
2
3
|
|
|
3
4
|
// builtin-rules/static/general/no-unused-export.rule.ts
|
|
4
5
|
var TYPE_ONLY_KINDS = /* @__PURE__ */ new Set([
|
|
@@ -63,6 +64,30 @@ var declarationLines = (parsed) => {
|
|
|
63
64
|
}
|
|
64
65
|
return lines;
|
|
65
66
|
};
|
|
67
|
+
var isReferencedInternally = (parsed, symbolName) => {
|
|
68
|
+
if (!symbolName || symbolName === "default") return false;
|
|
69
|
+
try {
|
|
70
|
+
const sf = asTsMorphSourceFile(parsed);
|
|
71
|
+
for (const id of sf.getDescendantsOfKind(SyntaxKind.Identifier)) {
|
|
72
|
+
if (id.getText() !== symbolName) continue;
|
|
73
|
+
const parent = id.getParent();
|
|
74
|
+
if (!parent) continue;
|
|
75
|
+
if (Node.isVariableDeclaration(parent) && parent.getNameNode() === id) continue;
|
|
76
|
+
if ((Node.isFunctionDeclaration(parent) || Node.isClassDeclaration(parent) || Node.isInterfaceDeclaration(parent) || Node.isEnumDeclaration(parent) || Node.isTypeAliasDeclaration(parent)) && parent.getNameNode() === id) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (Node.isPropertyAssignment(parent) && parent.getNameNode() === id && !parent.wasPropertyAssignmentComputed()) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (Node.isShorthandPropertyAssignment(parent) && parent.getNameNode() === id) continue;
|
|
83
|
+
if (Node.isImportSpecifier(parent) && parent.getNameNode() === id) continue;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
66
91
|
var REGEX_SPECIAL = new Set(".+^$()|[]\\".split(""));
|
|
67
92
|
var globToRegex = (pattern) => {
|
|
68
93
|
let out = "^";
|
|
@@ -171,6 +196,7 @@ var rule = {
|
|
|
171
196
|
if (symbol.name === "default" && !options.includeDefaultExports) continue;
|
|
172
197
|
if (!options.includeTypeOnlyExports && TYPE_ONLY_KINDS.has(symbol.kind)) continue;
|
|
173
198
|
if (consumed.has(symbol.name)) continue;
|
|
199
|
+
if (isReferencedInternally(ctx.parsed, symbol.name)) continue;
|
|
174
200
|
findings.push({
|
|
175
201
|
message: `Exported ${symbol.kind} '${symbol.name}' is not imported by any file in the project.`,
|
|
176
202
|
file: ctx.file.path,
|