codesentry 0.1.4 → 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.
Files changed (2) hide show
  1. package/dist/index.js +24 -14
  2. 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, sep } from "path";
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 isInsideIgnoredDir = (relativePath) => {
279
- return relativePath.split(sep).some((segment) => IGNORED_DIRS.has(segment));
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
- const entries = await readdir(targetDir, { recursive: true, withFileTypes: true });
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
  }
@@ -573,9 +583,9 @@ var isSourceNode2 = (value) => {
573
583
  var walkChildren = (node, depth, results) => {
574
584
  for (const value of Object.values(node)) {
575
585
  if (Array.isArray(value)) {
576
- value.filter(isSourceNode2).forEach((child) => walk(child, depth, results));
586
+ value.filter(isSourceNode2).forEach((child) => walk2(child, depth, results));
577
587
  } else if (isSourceNode2(value)) {
578
- walk(value, depth, results);
588
+ walk2(value, depth, results);
579
589
  }
580
590
  }
581
591
  };
@@ -586,7 +596,7 @@ var checkDepth = (newDepth, line, results) => {
586
596
  };
587
597
  var walkIfChild = (value, depth, results) => {
588
598
  if (isSourceNode2(value)) {
589
- walk(value, depth, results);
599
+ walk2(value, depth, results);
590
600
  }
591
601
  };
592
602
  var walkIfAlternate = (alternate, depth, results) => {
@@ -597,7 +607,7 @@ var walkIfAlternate = (alternate, depth, results) => {
597
607
  walkIfChain(alternate, depth, results);
598
608
  return;
599
609
  }
600
- walk(alternate, depth + 1, results);
610
+ walk2(alternate, depth + 1, results);
601
611
  };
602
612
  var walkIfChain = (node, depth, results) => {
603
613
  const chainDepth = depth + 1;
@@ -617,13 +627,13 @@ var walkNestingBlock = (node, depth, results) => {
617
627
  var selectWalker = (node) => {
618
628
  return FUNCTION_TYPES.has(node.type) ? walkFunction : node.type === "IfStatement" ? walkIfChain : NESTING_TYPES.has(node.type) ? walkNestingBlock : walkChildren;
619
629
  };
620
- var walk = (node, depth, results) => {
630
+ var walk2 = (node, depth, results) => {
621
631
  selectWalker(node)(node, depth, results);
622
632
  };
623
633
  var findDeepNesting = (filePath, content) => {
624
634
  const results = [];
625
635
  const sourceFile = parseSourceFile(filePath, content);
626
- walk(sourceFile, 0, results);
636
+ walk2(sourceFile, 0, results);
627
637
  return results;
628
638
  };
629
639
  var deepNestingRule = {
@@ -892,9 +902,9 @@ var appendOverLimitContext = (context, state) => {
892
902
  };
893
903
  var walkChild = (value, parent, context, state) => {
894
904
  if (Array.isArray(value)) {
895
- value.filter(isSourceNode3).forEach((child) => walk2(child, parent, context, state));
905
+ value.filter(isSourceNode3).forEach((child) => walk3(child, parent, context, state));
896
906
  } else if (isSourceNode3(value)) {
897
- walk2(value, parent, context, state);
907
+ walk3(value, parent, context, state);
898
908
  }
899
909
  };
900
910
  var walkChildren2 = (node, context, state) => {
@@ -912,7 +922,7 @@ var incrementStatementCount = (node, context, state) => {
912
922
  context.count += 1;
913
923
  }
914
924
  };
915
- var walk2 = (node, parent, context, state) => {
925
+ var walk3 = (node, parent, context, state) => {
916
926
  if (FUNCTION_TYPES2.has(node.type)) {
917
927
  walkFunction2(node, parent, state);
918
928
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codesentry",
3
- "version": "0.1.4",
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.4",
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.4",
63
- "codesentry-semgrep-win32-x64": "0.1.4"
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",