@ipation/specbridge 1.0.2 → 1.0.3
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/CHANGELOG.md +97 -0
- package/dist/cli.js +16 -12
- package/dist/cli.js.map +1 -1
- package/dist/index.js +16 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1323,9 +1323,7 @@ var ErrorsAnalyzer = class {
|
|
|
1323
1323
|
);
|
|
1324
1324
|
if (errorClasses.length < 2) return null;
|
|
1325
1325
|
const files = scanner.getFiles();
|
|
1326
|
-
|
|
1327
|
-
let extendsCustomBase = 0;
|
|
1328
|
-
let customBaseName = null;
|
|
1326
|
+
const baseCount = /* @__PURE__ */ new Map();
|
|
1329
1327
|
for (const errorClass of errorClasses) {
|
|
1330
1328
|
const file = files.find((f) => f.path === errorClass.file);
|
|
1331
1329
|
if (!file) continue;
|
|
@@ -1334,22 +1332,27 @@ var ErrorsAnalyzer = class {
|
|
|
1334
1332
|
const extendClause = classDecl.getExtends();
|
|
1335
1333
|
if (extendClause) {
|
|
1336
1334
|
const baseName = extendClause.getText();
|
|
1337
|
-
if (baseName
|
|
1338
|
-
|
|
1339
|
-
} else if (baseName.endsWith("Error")) {
|
|
1340
|
-
extendsCustomBase++;
|
|
1341
|
-
customBaseName = customBaseName || baseName;
|
|
1335
|
+
if (baseName !== "Error" && baseName.endsWith("Error")) {
|
|
1336
|
+
baseCount.set(baseName, (baseCount.get(baseName) || 0) + 1);
|
|
1342
1337
|
}
|
|
1343
1338
|
}
|
|
1344
1339
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1340
|
+
let customBaseName = null;
|
|
1341
|
+
let maxCount = 0;
|
|
1342
|
+
for (const [baseName, count] of baseCount.entries()) {
|
|
1343
|
+
if (count > maxCount) {
|
|
1344
|
+
maxCount = count;
|
|
1345
|
+
customBaseName = baseName;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
if (maxCount >= 3 && customBaseName) {
|
|
1349
|
+
const confidence = calculateConfidence(maxCount, errorClasses.length);
|
|
1347
1350
|
return createPattern(this.id, {
|
|
1348
1351
|
id: "errors-custom-base",
|
|
1349
1352
|
name: "Custom Error Base Class",
|
|
1350
1353
|
description: `Custom errors extend a common base class (${customBaseName})`,
|
|
1351
1354
|
confidence,
|
|
1352
|
-
occurrences:
|
|
1355
|
+
occurrences: maxCount,
|
|
1353
1356
|
examples: errorClasses.slice(0, 3).map((c) => ({
|
|
1354
1357
|
file: c.file,
|
|
1355
1358
|
line: c.line,
|
|
@@ -1431,10 +1434,11 @@ var ErrorsAnalyzer = class {
|
|
|
1431
1434
|
} else if (text.startsWith("new ") && text.includes("Error")) {
|
|
1432
1435
|
throwCustom++;
|
|
1433
1436
|
if (examples.length < 3) {
|
|
1437
|
+
const snippet = text.length > 50 ? text.slice(0, 50) + "..." : text;
|
|
1434
1438
|
examples.push({
|
|
1435
1439
|
file: path,
|
|
1436
1440
|
line: node.getStartLineNumber(),
|
|
1437
|
-
snippet: `throw ${
|
|
1441
|
+
snippet: `throw ${snippet}`
|
|
1438
1442
|
});
|
|
1439
1443
|
}
|
|
1440
1444
|
}
|