@codacy/tools-opengrep-1 0.6.0 → 0.6.1

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 CHANGED
@@ -28515,6 +28515,48 @@ function truncate(str, maxLen) {
28515
28515
  if (str.length <= maxLen) return str;
28516
28516
  return str.slice(0, maxLen - 3) + "...";
28517
28517
  }
28518
+ var ARGV_BYTE_BUDGET = 200 * 1024;
28519
+ function minimalCoverDirs(files) {
28520
+ const dirs = /* @__PURE__ */ new Set();
28521
+ for (const f of files) {
28522
+ const d = import_path.default.dirname(f);
28523
+ dirs.add(d === "" ? "." : d);
28524
+ }
28525
+ const sorted = [...dirs].sort((a, b) => {
28526
+ if (a === ".") return -1;
28527
+ if (b === ".") return 1;
28528
+ return a.split(import_path.default.sep).length - b.split(import_path.default.sep).length;
28529
+ });
28530
+ const kept = [];
28531
+ for (const d of sorted) {
28532
+ const covered = kept.some((k) => {
28533
+ if (k === d) return true;
28534
+ if (k === ".") return true;
28535
+ return d.startsWith(k + import_path.default.sep);
28536
+ });
28537
+ if (!covered) kept.push(d);
28538
+ }
28539
+ return kept;
28540
+ }
28541
+ function argvBytes(paths) {
28542
+ let total = 0;
28543
+ for (const p of paths) total += Buffer.byteLength(p) + 1;
28544
+ return total;
28545
+ }
28546
+ function chooseScanTargets(validatedAbsoluteFiles, repositoryRoot) {
28547
+ if (argvBytes(validatedAbsoluteFiles) <= ARGV_BYTE_BUDGET) {
28548
+ return { targets: validatedAbsoluteFiles, strategy: "files" };
28549
+ }
28550
+ const relFiles = validatedAbsoluteFiles.map((f) => import_path.default.relative(repositoryRoot, f));
28551
+ const dirs = minimalCoverDirs(relFiles);
28552
+ if (dirs.length > 0 && !(dirs.length === 1 && dirs[0] === ".")) {
28553
+ const absoluteDirs = dirs.map((d) => import_path.default.resolve(repositoryRoot, d));
28554
+ if (argvBytes(absoluteDirs) <= ARGV_BYTE_BUDGET) {
28555
+ return { targets: absoluteDirs, strategy: "dirs" };
28556
+ }
28557
+ }
28558
+ return { targets: [repositoryRoot], strategy: "root" };
28559
+ }
28518
28560
  async function materializeConfig(ctx, enabledPatterns) {
28519
28561
  let rulesContent;
28520
28562
  try {
@@ -28691,20 +28733,36 @@ var adapter = {
28691
28733
  });
28692
28734
  return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
28693
28735
  }
28694
- const absoluteFiles = [];
28736
+ const targetPathSet = /* @__PURE__ */ new Set();
28737
+ const validatedAbsoluteFiles = [];
28695
28738
  for (const f of ctx.targetFiles) {
28696
28739
  const abs = import_path.default.resolve(ctx.repositoryRoot, f);
28697
28740
  try {
28698
28741
  const real = await import_promises.default.realpath(abs);
28699
28742
  const stat = await import_promises.default.stat(real);
28700
- if (stat.isFile()) absoluteFiles.push(real);
28743
+ if (stat.isFile()) {
28744
+ targetPathSet.add(real);
28745
+ targetPathSet.add(abs);
28746
+ targetPathSet.add(import_path.default.relative(ctx.repositoryRoot, abs));
28747
+ validatedAbsoluteFiles.push(real);
28748
+ }
28701
28749
  } catch {
28702
28750
  ctx.logger.debug("Skipping unresolvable file", { file: f });
28703
28751
  }
28704
28752
  }
28705
- if (absoluteFiles.length === 0) {
28753
+ if (targetPathSet.size === 0) {
28706
28754
  return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
28707
28755
  }
28756
+ const { targets: scanTargets, strategy: scanStrategy } = chooseScanTargets(
28757
+ validatedAbsoluteFiles,
28758
+ ctx.repositoryRoot
28759
+ );
28760
+ ctx.logger.debug("Opengrep scan targets chosen", {
28761
+ toolId: TOOL_ID,
28762
+ strategy: scanStrategy,
28763
+ targetCount: scanTargets.length,
28764
+ fileCount: ctx.targetFiles.length
28765
+ });
28708
28766
  const args = [
28709
28767
  "scan",
28710
28768
  "--json",
@@ -28718,7 +28776,8 @@ var adapter = {
28718
28776
  "0",
28719
28777
  "--max-memory",
28720
28778
  "5000",
28721
- ...absoluteFiles
28779
+ "--disable-version-check",
28780
+ ...scanTargets
28722
28781
  ];
28723
28782
  try {
28724
28783
  const { stdout, stderr, exitCode } = await (0, import_tooling.spawnTool)(binary, args, {
@@ -28774,6 +28833,11 @@ var adapter = {
28774
28833
  const findingsByFile = /* @__PURE__ */ new Map();
28775
28834
  for (const finding of output.results) {
28776
28835
  if (finding.extra.is_ignored) continue;
28836
+ const absFinding = import_path.default.isAbsolute(finding.path) ? finding.path : import_path.default.resolve(ctx.repositoryRoot, finding.path);
28837
+ const relFinding = import_path.default.relative(ctx.repositoryRoot, absFinding);
28838
+ if (!targetPathSet.has(finding.path) && !targetPathSet.has(absFinding) && !targetPathSet.has(relFinding)) {
28839
+ continue;
28840
+ }
28777
28841
  const list = findingsByFile.get(finding.path) ?? [];
28778
28842
  list.push(finding);
28779
28843
  findingsByFile.set(finding.path, list);
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@codacy/tools-opengrep-1",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Opengrep adapter — CLI-mode multi-language SAST scanner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "src/rules.yaml"
9
10
  ],
10
11
  "dependencies": {
11
12
  "yaml": "^2.6.0",
12
- "@codacy/tooling": "0.6.0"
13
+ "@codacy/tooling": "0.6.1"
13
14
  },
14
15
  "license": "MIT",
15
16
  "author": "Codacy <support@codacy.com> (https://www.codacy.com)",