@codacy/tools-opengrep-1 0.3.0 → 0.5.0
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 +59 -78
- package/dist/metadata.d.ts +13 -0
- package/dist/metadata.js +69 -0
- package/package.json +13 -3
package/dist/index.js
CHANGED
|
@@ -20187,6 +20187,48 @@ var patterns_default = [
|
|
|
20187
20187
|
}
|
|
20188
20188
|
];
|
|
20189
20189
|
|
|
20190
|
+
// src/metadata.ts
|
|
20191
|
+
var descriptor = {
|
|
20192
|
+
id: "Semgrep",
|
|
20193
|
+
displayName: "Opengrep",
|
|
20194
|
+
preferredVersion: "1.16.4",
|
|
20195
|
+
languages: [
|
|
20196
|
+
"Apex",
|
|
20197
|
+
"Bash",
|
|
20198
|
+
"C",
|
|
20199
|
+
"C++",
|
|
20200
|
+
"C#",
|
|
20201
|
+
"Clojure",
|
|
20202
|
+
"Dart",
|
|
20203
|
+
"Dockerfile",
|
|
20204
|
+
"Elixir",
|
|
20205
|
+
"Go",
|
|
20206
|
+
"HTML",
|
|
20207
|
+
"Java",
|
|
20208
|
+
"JavaScript",
|
|
20209
|
+
"JSON",
|
|
20210
|
+
"Kotlin",
|
|
20211
|
+
"Lua",
|
|
20212
|
+
"PHP",
|
|
20213
|
+
"Python",
|
|
20214
|
+
"Ruby",
|
|
20215
|
+
"Rust",
|
|
20216
|
+
"Scala",
|
|
20217
|
+
"Shell",
|
|
20218
|
+
"Swift",
|
|
20219
|
+
"Terraform",
|
|
20220
|
+
"TypeScript",
|
|
20221
|
+
"Visual Basic",
|
|
20222
|
+
"Vue",
|
|
20223
|
+
"XML",
|
|
20224
|
+
"YAML"
|
|
20225
|
+
],
|
|
20226
|
+
filePatterns: ["*"],
|
|
20227
|
+
supportedOS: ["linux", "darwin"],
|
|
20228
|
+
supportedArch: ["x64", "arm64"],
|
|
20229
|
+
supportedRunners: ["local", "container"]
|
|
20230
|
+
};
|
|
20231
|
+
|
|
20190
20232
|
// src/adapter.ts
|
|
20191
20233
|
var TOOL_ID = "Semgrep";
|
|
20192
20234
|
var PATTERN_META = new Map(
|
|
@@ -20202,37 +20244,6 @@ function ruleMetadata(ruleId) {
|
|
|
20202
20244
|
const patternId = `${TOOL_ID}_${ruleId}`;
|
|
20203
20245
|
return PATTERN_META.get(patternId) ?? { category: "Security", severity: "Info" };
|
|
20204
20246
|
}
|
|
20205
|
-
function getLineContent(lines, lineNumber) {
|
|
20206
|
-
return lines[lineNumber - 1] ?? "";
|
|
20207
|
-
}
|
|
20208
|
-
async function readFileLines(filePath) {
|
|
20209
|
-
try {
|
|
20210
|
-
const content = await import_promises.default.readFile(filePath, "utf-8");
|
|
20211
|
-
return content.split("\n");
|
|
20212
|
-
} catch {
|
|
20213
|
-
return [];
|
|
20214
|
-
}
|
|
20215
|
-
}
|
|
20216
|
-
function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
|
|
20217
|
-
const durationMs = completedAt.getTime() - startedAt.getTime();
|
|
20218
|
-
return {
|
|
20219
|
-
metadata: {
|
|
20220
|
-
startedAt: startedAt.toISOString(),
|
|
20221
|
-
completedAt: completedAt.toISOString(),
|
|
20222
|
-
durationMs
|
|
20223
|
-
},
|
|
20224
|
-
issues,
|
|
20225
|
-
errors,
|
|
20226
|
-
summary: {
|
|
20227
|
-
toolId: TOOL_ID,
|
|
20228
|
-
status: errors.some((e) => e.level === "error") ? "partial" : "success",
|
|
20229
|
-
issueCount: issues.length,
|
|
20230
|
-
errorCount: errors.length,
|
|
20231
|
-
durationMs,
|
|
20232
|
-
filesAnalyzed
|
|
20233
|
-
}
|
|
20234
|
-
};
|
|
20235
|
-
}
|
|
20236
20247
|
var BINARY = "opengrep";
|
|
20237
20248
|
var RULES_PATH = import_path.default.resolve(__dirname, "..", "src", "rules.yaml");
|
|
20238
20249
|
var LOCAL_CONFIG_FILES = [".semgrep.yaml", ".opengrep.yaml", ".semgrep.yml", ".opengrep.yml"];
|
|
@@ -20303,46 +20314,9 @@ async function materializeConfig(ctx, enabledPatterns) {
|
|
|
20303
20314
|
return configPath;
|
|
20304
20315
|
}
|
|
20305
20316
|
var adapter = {
|
|
20306
|
-
|
|
20307
|
-
displayName: "Opengrep",
|
|
20308
|
-
preferredVersion: "1.16.4",
|
|
20317
|
+
...descriptor,
|
|
20309
20318
|
compatibleVersions: ">=1.0.0",
|
|
20310
20319
|
website: "https://www.opengrep.dev/",
|
|
20311
|
-
languages: [
|
|
20312
|
-
"Apex",
|
|
20313
|
-
"Bash",
|
|
20314
|
-
"C",
|
|
20315
|
-
"C++",
|
|
20316
|
-
"C#",
|
|
20317
|
-
"Clojure",
|
|
20318
|
-
"Dart",
|
|
20319
|
-
"Dockerfile",
|
|
20320
|
-
"Elixir",
|
|
20321
|
-
"Go",
|
|
20322
|
-
"HTML",
|
|
20323
|
-
"Java",
|
|
20324
|
-
"JavaScript",
|
|
20325
|
-
"JSON",
|
|
20326
|
-
"Kotlin",
|
|
20327
|
-
"Lua",
|
|
20328
|
-
"PHP",
|
|
20329
|
-
"Python",
|
|
20330
|
-
"Ruby",
|
|
20331
|
-
"Rust",
|
|
20332
|
-
"Scala",
|
|
20333
|
-
"Shell",
|
|
20334
|
-
"Swift",
|
|
20335
|
-
"Terraform",
|
|
20336
|
-
"TypeScript",
|
|
20337
|
-
"Visual Basic",
|
|
20338
|
-
"Vue",
|
|
20339
|
-
"XML",
|
|
20340
|
-
"YAML"
|
|
20341
|
-
],
|
|
20342
|
-
filePatterns: ["*"],
|
|
20343
|
-
supportedOS: ["linux", "darwin"],
|
|
20344
|
-
supportedArch: ["x64", "arm64"],
|
|
20345
|
-
supportedRunners: ["local", "container"],
|
|
20346
20320
|
prerequisites: [],
|
|
20347
20321
|
/**
|
|
20348
20322
|
* Checks whether the `opengrep` binary is present and runnable.
|
|
@@ -20458,7 +20432,7 @@ var adapter = {
|
|
|
20458
20432
|
const issues = [];
|
|
20459
20433
|
const errors = [];
|
|
20460
20434
|
if (ctx.targetFiles.length === 0) {
|
|
20461
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
|
|
20435
|
+
return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
|
|
20462
20436
|
}
|
|
20463
20437
|
const binary = await resolveBinaryPath(ctx);
|
|
20464
20438
|
let configFile = null;
|
|
@@ -20472,7 +20446,7 @@ var adapter = {
|
|
|
20472
20446
|
ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
|
|
20473
20447
|
toolId: TOOL_ID
|
|
20474
20448
|
});
|
|
20475
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20449
|
+
return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20476
20450
|
}
|
|
20477
20451
|
}
|
|
20478
20452
|
if (!configFile) {
|
|
@@ -20483,7 +20457,7 @@ var adapter = {
|
|
|
20483
20457
|
message: "No configuration file available. Either provide a local config (.semgrep.yaml / .opengrep.yaml) or ensure the bundled rules.yaml exists.",
|
|
20484
20458
|
level: "error"
|
|
20485
20459
|
});
|
|
20486
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20460
|
+
return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20487
20461
|
}
|
|
20488
20462
|
const absoluteFiles = [];
|
|
20489
20463
|
for (const f of ctx.targetFiles) {
|
|
@@ -20497,7 +20471,7 @@ var adapter = {
|
|
|
20497
20471
|
}
|
|
20498
20472
|
}
|
|
20499
20473
|
if (absoluteFiles.length === 0) {
|
|
20500
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
|
|
20474
|
+
return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
|
|
20501
20475
|
}
|
|
20502
20476
|
const args = [
|
|
20503
20477
|
"scan",
|
|
@@ -20529,7 +20503,7 @@ var adapter = {
|
|
|
20529
20503
|
level: "error"
|
|
20530
20504
|
});
|
|
20531
20505
|
}
|
|
20532
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20506
|
+
return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20533
20507
|
}
|
|
20534
20508
|
let output;
|
|
20535
20509
|
try {
|
|
@@ -20542,7 +20516,7 @@ var adapter = {
|
|
|
20542
20516
|
message: `Failed to parse opengrep JSON output: ${err instanceof Error ? err.message : String(err)}`,
|
|
20543
20517
|
level: "error"
|
|
20544
20518
|
});
|
|
20545
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20519
|
+
return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
20546
20520
|
}
|
|
20547
20521
|
if (output.errors && output.errors.length > 0) {
|
|
20548
20522
|
for (const ogError of output.errors) {
|
|
@@ -20574,7 +20548,7 @@ var adapter = {
|
|
|
20574
20548
|
}
|
|
20575
20549
|
for (const [filePath, fileFindings] of findingsByFile) {
|
|
20576
20550
|
const absoluteFilePath = import_path.default.isAbsolute(filePath) ? filePath : import_path.default.resolve(ctx.repositoryRoot, filePath);
|
|
20577
|
-
const lines = await readFileLines(absoluteFilePath);
|
|
20551
|
+
const lines = await (0, import_tooling.readFileLines)(absoluteFilePath);
|
|
20578
20552
|
const relPath = import_path.default.relative(ctx.repositoryRoot, absoluteFilePath);
|
|
20579
20553
|
for (const finding of fileFindings) {
|
|
20580
20554
|
const ruleId = stripCheckIdPrefix(finding.check_id, configPrefix);
|
|
@@ -20592,7 +20566,7 @@ var adapter = {
|
|
|
20592
20566
|
endLine: finding.end.line,
|
|
20593
20567
|
endColumn: finding.end.col,
|
|
20594
20568
|
message: truncate(finding.extra.message, 250),
|
|
20595
|
-
lineContent: getLineContent(lines, finding.start.line),
|
|
20569
|
+
lineContent: (0, import_tooling.getLineContent)(lines, finding.start.line),
|
|
20596
20570
|
multilineContent: (0, import_tooling.getMultilineContent)(lines, finding.start.line, finding.end.line),
|
|
20597
20571
|
category: meta.category,
|
|
20598
20572
|
severity: meta.severity
|
|
@@ -20616,7 +20590,14 @@ ${stderr.trim()}`);
|
|
|
20616
20590
|
level: "error"
|
|
20617
20591
|
});
|
|
20618
20592
|
}
|
|
20619
|
-
const result =
|
|
20593
|
+
const result = (0, import_tooling.buildResult)(
|
|
20594
|
+
TOOL_ID,
|
|
20595
|
+
startedAt,
|
|
20596
|
+
/* @__PURE__ */ new Date(),
|
|
20597
|
+
issues,
|
|
20598
|
+
errors,
|
|
20599
|
+
ctx.targetFiles.length
|
|
20600
|
+
);
|
|
20620
20601
|
ctx.logger.info("Analysis complete", {
|
|
20621
20602
|
toolId: TOOL_ID,
|
|
20622
20603
|
issueCount: result.summary.issueCount,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AdapterDescriptor } from '@codacy/tooling';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight adapter descriptor for lazy loading.
|
|
5
|
+
*
|
|
6
|
+
* This module contains only plain-data metadata fields and has zero heavy
|
|
7
|
+
* imports (no patterns.json, no runtime utilities). The CLI imports this
|
|
8
|
+
* at startup for adapter registration without loading the full adapter module.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
declare const descriptor: AdapterDescriptor;
|
|
12
|
+
|
|
13
|
+
export { descriptor };
|
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/metadata.ts
|
|
21
|
+
var metadata_exports = {};
|
|
22
|
+
__export(metadata_exports, {
|
|
23
|
+
descriptor: () => descriptor
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(metadata_exports);
|
|
26
|
+
var descriptor = {
|
|
27
|
+
id: "Semgrep",
|
|
28
|
+
displayName: "Opengrep",
|
|
29
|
+
preferredVersion: "1.16.4",
|
|
30
|
+
languages: [
|
|
31
|
+
"Apex",
|
|
32
|
+
"Bash",
|
|
33
|
+
"C",
|
|
34
|
+
"C++",
|
|
35
|
+
"C#",
|
|
36
|
+
"Clojure",
|
|
37
|
+
"Dart",
|
|
38
|
+
"Dockerfile",
|
|
39
|
+
"Elixir",
|
|
40
|
+
"Go",
|
|
41
|
+
"HTML",
|
|
42
|
+
"Java",
|
|
43
|
+
"JavaScript",
|
|
44
|
+
"JSON",
|
|
45
|
+
"Kotlin",
|
|
46
|
+
"Lua",
|
|
47
|
+
"PHP",
|
|
48
|
+
"Python",
|
|
49
|
+
"Ruby",
|
|
50
|
+
"Rust",
|
|
51
|
+
"Scala",
|
|
52
|
+
"Shell",
|
|
53
|
+
"Swift",
|
|
54
|
+
"Terraform",
|
|
55
|
+
"TypeScript",
|
|
56
|
+
"Visual Basic",
|
|
57
|
+
"Vue",
|
|
58
|
+
"XML",
|
|
59
|
+
"YAML"
|
|
60
|
+
],
|
|
61
|
+
filePatterns: ["*"],
|
|
62
|
+
supportedOS: ["linux", "darwin"],
|
|
63
|
+
supportedArch: ["x64", "arm64"],
|
|
64
|
+
supportedRunners: ["local", "container"]
|
|
65
|
+
};
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
descriptor
|
|
69
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codacy/tools-opengrep-1",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Opengrep adapter — CLI-mode multi-language SAST scanner",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"yaml": "^2.6.0",
|
|
12
|
-
"@codacy/tooling": "0.
|
|
12
|
+
"@codacy/tooling": "0.5.0"
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"author": "Codacy <support@codacy.com> (https://www.codacy.com)",
|
|
@@ -22,8 +22,18 @@
|
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=20.0.0"
|
|
24
24
|
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./metadata": {
|
|
31
|
+
"types": "./dist/metadata.d.ts",
|
|
32
|
+
"default": "./dist/metadata.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
25
35
|
"scripts": {
|
|
26
|
-
"build": "tsup src/index.ts --format cjs --dts --clean",
|
|
36
|
+
"build": "tsup src/index.ts src/metadata.ts --format cjs --dts --clean",
|
|
27
37
|
"test": "vitest run",
|
|
28
38
|
"lint": "eslint src/",
|
|
29
39
|
"clean": "rm -rf dist",
|