codesentry 0.1.3 → 0.1.5
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/index.js +27 -15
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -272,16 +272,26 @@ import { availableParallelism } from "os";
|
|
|
272
272
|
|
|
273
273
|
// src/scanner/file-finder.ts
|
|
274
274
|
import { readdir } from "fs/promises";
|
|
275
|
-
import { join
|
|
275
|
+
import { join } from "path";
|
|
276
276
|
var SCANNABLE_EXTENSIONS = [".js", ".ts", ".jsx", ".tsx"];
|
|
277
277
|
var IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".next"]);
|
|
278
|
-
var
|
|
279
|
-
|
|
278
|
+
var isScannable = (fileName) => SCANNABLE_EXTENSIONS.some((ext) => fileName.endsWith(ext));
|
|
279
|
+
var walk = async (currentDir) => {
|
|
280
|
+
const entries = await readdir(currentDir, { withFileTypes: true });
|
|
281
|
+
const files = [];
|
|
282
|
+
for (const entry of entries) {
|
|
283
|
+
if (entry.isDirectory()) {
|
|
284
|
+
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
285
|
+
files.push(...await walk(join(currentDir, entry.name)));
|
|
286
|
+
} else if (entry.isFile() && isScannable(entry.name)) {
|
|
287
|
+
files.push(join(currentDir, entry.name));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return files;
|
|
280
291
|
};
|
|
281
292
|
var findFiles = async (targetDir) => {
|
|
282
293
|
try {
|
|
283
|
-
|
|
284
|
-
return entries.filter((entry) => entry.isFile()).map((entry) => join(entry.parentPath, entry.name)).filter((filePath) => !isInsideIgnoredDir(filePath)).filter((filePath) => SCANNABLE_EXTENSIONS.some((ext) => filePath.endsWith(ext)));
|
|
294
|
+
return await walk(targetDir);
|
|
285
295
|
} catch (error) {
|
|
286
296
|
throw new Error(`N\xE3o foi poss\xEDvel listar os arquivos em "${targetDir}".`, { cause: error });
|
|
287
297
|
}
|
|
@@ -446,7 +456,9 @@ var runBundledSemgrep = async (targetDir, runtime = resolveBundledSemgrepRuntime
|
|
|
446
456
|
"dist",
|
|
447
457
|
"--exclude",
|
|
448
458
|
".next",
|
|
449
|
-
targetDir
|
|
459
|
+
// Não repetir targetDir aqui: o processo já roda com cwd = targetDir
|
|
460
|
+
// (abaixo), então o alvo relativo a esse cwd é o diretório atual.
|
|
461
|
+
"."
|
|
450
462
|
];
|
|
451
463
|
let stdout;
|
|
452
464
|
const env = {
|
|
@@ -571,9 +583,9 @@ var isSourceNode2 = (value) => {
|
|
|
571
583
|
var walkChildren = (node, depth, results) => {
|
|
572
584
|
for (const value of Object.values(node)) {
|
|
573
585
|
if (Array.isArray(value)) {
|
|
574
|
-
value.filter(isSourceNode2).forEach((child) =>
|
|
586
|
+
value.filter(isSourceNode2).forEach((child) => walk2(child, depth, results));
|
|
575
587
|
} else if (isSourceNode2(value)) {
|
|
576
|
-
|
|
588
|
+
walk2(value, depth, results);
|
|
577
589
|
}
|
|
578
590
|
}
|
|
579
591
|
};
|
|
@@ -584,7 +596,7 @@ var checkDepth = (newDepth, line, results) => {
|
|
|
584
596
|
};
|
|
585
597
|
var walkIfChild = (value, depth, results) => {
|
|
586
598
|
if (isSourceNode2(value)) {
|
|
587
|
-
|
|
599
|
+
walk2(value, depth, results);
|
|
588
600
|
}
|
|
589
601
|
};
|
|
590
602
|
var walkIfAlternate = (alternate, depth, results) => {
|
|
@@ -595,7 +607,7 @@ var walkIfAlternate = (alternate, depth, results) => {
|
|
|
595
607
|
walkIfChain(alternate, depth, results);
|
|
596
608
|
return;
|
|
597
609
|
}
|
|
598
|
-
|
|
610
|
+
walk2(alternate, depth + 1, results);
|
|
599
611
|
};
|
|
600
612
|
var walkIfChain = (node, depth, results) => {
|
|
601
613
|
const chainDepth = depth + 1;
|
|
@@ -615,13 +627,13 @@ var walkNestingBlock = (node, depth, results) => {
|
|
|
615
627
|
var selectWalker = (node) => {
|
|
616
628
|
return FUNCTION_TYPES.has(node.type) ? walkFunction : node.type === "IfStatement" ? walkIfChain : NESTING_TYPES.has(node.type) ? walkNestingBlock : walkChildren;
|
|
617
629
|
};
|
|
618
|
-
var
|
|
630
|
+
var walk2 = (node, depth, results) => {
|
|
619
631
|
selectWalker(node)(node, depth, results);
|
|
620
632
|
};
|
|
621
633
|
var findDeepNesting = (filePath, content) => {
|
|
622
634
|
const results = [];
|
|
623
635
|
const sourceFile = parseSourceFile(filePath, content);
|
|
624
|
-
|
|
636
|
+
walk2(sourceFile, 0, results);
|
|
625
637
|
return results;
|
|
626
638
|
};
|
|
627
639
|
var deepNestingRule = {
|
|
@@ -890,9 +902,9 @@ var appendOverLimitContext = (context, state) => {
|
|
|
890
902
|
};
|
|
891
903
|
var walkChild = (value, parent, context, state) => {
|
|
892
904
|
if (Array.isArray(value)) {
|
|
893
|
-
value.filter(isSourceNode3).forEach((child) =>
|
|
905
|
+
value.filter(isSourceNode3).forEach((child) => walk3(child, parent, context, state));
|
|
894
906
|
} else if (isSourceNode3(value)) {
|
|
895
|
-
|
|
907
|
+
walk3(value, parent, context, state);
|
|
896
908
|
}
|
|
897
909
|
};
|
|
898
910
|
var walkChildren2 = (node, context, state) => {
|
|
@@ -910,7 +922,7 @@ var incrementStatementCount = (node, context, state) => {
|
|
|
910
922
|
context.count += 1;
|
|
911
923
|
}
|
|
912
924
|
};
|
|
913
|
-
var
|
|
925
|
+
var walk3 = (node, parent, context, state) => {
|
|
914
926
|
if (FUNCTION_TYPES2.has(node.type)) {
|
|
915
927
|
walkFunction2(node, parent, state);
|
|
916
928
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codesentry",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"workspaces": [
|
|
5
5
|
"packages/semgrep-rules"
|
|
6
6
|
],
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@clack/prompts": "^1.7.0",
|
|
49
49
|
"chalk": "^6.0.0",
|
|
50
50
|
"cli-table3": "^0.6.5",
|
|
51
|
-
"codesentry-semgrep-rules": "0.1.
|
|
51
|
+
"codesentry-semgrep-rules": "0.1.5",
|
|
52
52
|
"commander": "^15.0.0",
|
|
53
53
|
"eslint": "^10.10.0",
|
|
54
54
|
"eslint-plugin-no-unsanitized": "^4.1.5",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"p-limit": "^7.3.2"
|
|
60
60
|
},
|
|
61
61
|
"optionalDependencies": {
|
|
62
|
-
"codesentry-semgrep-linux-x64": "0.1.
|
|
63
|
-
"codesentry-semgrep-win32-x64": "0.1.
|
|
62
|
+
"codesentry-semgrep-linux-x64": "0.1.5",
|
|
63
|
+
"codesentry-semgrep-win32-x64": "0.1.5"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/node": "^26.4.1",
|