@codacy/tools-bandit-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 CHANGED
@@ -668,6 +668,18 @@ var patterns_default = [
668
668
  }
669
669
  ];
670
670
 
671
+ // src/metadata.ts
672
+ var descriptor = {
673
+ id: "Bandit",
674
+ displayName: "Bandit",
675
+ preferredVersion: "1.8.3",
676
+ languages: ["Python"],
677
+ filePatterns: ["**/*.py"],
678
+ supportedOS: ["linux", "darwin"],
679
+ supportedArch: ["x64", "arm64"],
680
+ supportedRunners: ["local", "container"]
681
+ };
682
+
671
683
  // src/adapter.ts
672
684
  var TOOL_ID = "Bandit";
673
685
  var ADAPTER_ID = "bandit-1";
@@ -695,37 +707,6 @@ function mapConfidence(confidence) {
695
707
  return 1;
696
708
  }
697
709
  }
698
- function getLineContent(lines, lineNumber) {
699
- return lines[lineNumber - 1] ?? "";
700
- }
701
- async function readFileLines(filePath) {
702
- try {
703
- const content = await import_promises.default.readFile(filePath, "utf-8");
704
- return content.split("\n");
705
- } catch {
706
- return [];
707
- }
708
- }
709
- function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
710
- const durationMs = completedAt.getTime() - startedAt.getTime();
711
- return {
712
- metadata: {
713
- startedAt: startedAt.toISOString(),
714
- completedAt: completedAt.toISOString(),
715
- durationMs
716
- },
717
- issues,
718
- errors,
719
- summary: {
720
- toolId: TOOL_ID,
721
- status: errors.some((e) => e.level === "error") ? "partial" : "success",
722
- issueCount: issues.length,
723
- errorCount: errors.length,
724
- durationMs,
725
- filesAnalyzed
726
- }
727
- };
728
- }
729
710
  var CONFIG_FILE_CANDIDATES = [".bandit", "bandit.yml", "pyproject.toml"];
730
711
  async function resolveBinaryPath(ctx) {
731
712
  const venvDir = (0, import_tooling.getVenvDir)(ctx.globalDir, ADAPTER_ID);
@@ -745,16 +726,9 @@ function buildMessage(result) {
745
726
  return base;
746
727
  }
747
728
  var adapter = {
748
- id: TOOL_ID,
749
- displayName: "Bandit",
750
- preferredVersion: "1.8.3",
729
+ ...descriptor,
751
730
  compatibleVersions: ">=1.7.0",
752
731
  website: "https://bandit.readthedocs.io/",
753
- languages: ["Python"],
754
- filePatterns: ["**/*.py"],
755
- supportedOS: ["linux", "darwin"],
756
- supportedArch: ["x64", "arm64"],
757
- supportedRunners: ["local", "container"],
758
732
  prerequisites: [
759
733
  {
760
734
  name: "Python",
@@ -935,7 +909,7 @@ var adapter = {
935
909
  const issues = [];
936
910
  const errors = [];
937
911
  if (ctx.targetFiles.length === 0) {
938
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
912
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
939
913
  }
940
914
  const binary = await resolveBinaryPath(ctx);
941
915
  const absoluteFiles = ctx.targetFiles.map((f) => import_path.default.resolve(ctx.repositoryRoot, f));
@@ -948,11 +922,6 @@ var adapter = {
948
922
  } else {
949
923
  args.push("-c", configPath);
950
924
  }
951
- } else if (codacyConfig.patterns.length === 0) {
952
- ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
953
- toolId: TOOL_ID
954
- });
955
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
956
925
  }
957
926
  args.push(...absoluteFiles);
958
927
  try {
@@ -968,10 +937,10 @@ var adapter = {
968
937
  message: `bandit exited with code ${exitCode}${stderr ? `: ${stderr.trim()}` : ""}`,
969
938
  level: "error"
970
939
  });
971
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
940
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
972
941
  }
973
942
  if (!stdout.trim()) {
974
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
943
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
975
944
  }
976
945
  let banditOutput;
977
946
  try {
@@ -984,7 +953,7 @@ var adapter = {
984
953
  message: `Failed to parse bandit JSON output: ${err instanceof Error ? err.message : String(err)}`,
985
954
  level: "error"
986
955
  });
987
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
956
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
988
957
  }
989
958
  if (banditOutput.errors && banditOutput.errors.length > 0) {
990
959
  for (const banditError of banditOutput.errors) {
@@ -1006,7 +975,7 @@ var adapter = {
1006
975
  }
1007
976
  for (const [filePath, fileResults] of resultsByFile) {
1008
977
  const absolutePath = import_path.default.isAbsolute(filePath) ? filePath : import_path.default.resolve(ctx.repositoryRoot, filePath);
1009
- const lines = await readFileLines(absolutePath);
978
+ const lines = await (0, import_tooling.readFileLines)(absolutePath);
1010
979
  const relPath = import_path.default.relative(ctx.repositoryRoot, absolutePath);
1011
980
  for (const result2 of fileResults) {
1012
981
  const patternId = (0, import_tooling.buildPatternId)(TOOL_ID, result2.test_id);
@@ -1026,7 +995,7 @@ var adapter = {
1026
995
  endColumn: result2.end_col_offset ? result2.end_col_offset + 1 : void 0,
1027
996
  // 0-based → 1-based
1028
997
  message: buildMessage(result2),
1029
- lineContent: getLineContent(lines, result2.line_number),
998
+ lineContent: (0, import_tooling.getLineContent)(lines, result2.line_number),
1030
999
  multilineContent: (0, import_tooling.getMultilineContent)(lines, result2.line_number, endLine),
1031
1000
  category: meta.category,
1032
1001
  severity: meta.severity,
@@ -1054,7 +1023,14 @@ var adapter = {
1054
1023
  level: "error"
1055
1024
  });
1056
1025
  }
1057
- const result = buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1026
+ const result = (0, import_tooling.buildResult)(
1027
+ TOOL_ID,
1028
+ startedAt,
1029
+ /* @__PURE__ */ new Date(),
1030
+ issues,
1031
+ errors,
1032
+ ctx.targetFiles.length
1033
+ );
1058
1034
  ctx.logger.info("Analysis complete", {
1059
1035
  toolId: TOOL_ID,
1060
1036
  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 };
@@ -0,0 +1,39 @@
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: "Bandit",
28
+ displayName: "Bandit",
29
+ preferredVersion: "1.8.3",
30
+ languages: ["Python"],
31
+ filePatterns: ["**/*.py"],
32
+ supportedOS: ["linux", "darwin"],
33
+ supportedArch: ["x64", "arm64"],
34
+ supportedRunners: ["local", "container"]
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ descriptor
39
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/tools-bandit-1",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Bandit adapter — CLI-mode Python security linter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
- "@codacy/tooling": "0.3.0"
11
+ "@codacy/tooling": "0.5.0"
12
12
  },
13
13
  "license": "MIT",
14
14
  "author": "Codacy <support@codacy.com> (https://www.codacy.com)",
@@ -21,8 +21,18 @@
21
21
  "engines": {
22
22
  "node": ">=20.0.0"
23
23
  },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./metadata": {
30
+ "types": "./dist/metadata.d.ts",
31
+ "default": "./dist/metadata.js"
32
+ }
33
+ },
24
34
  "scripts": {
25
- "build": "tsup src/index.ts --format cjs --dts --clean",
35
+ "build": "tsup src/index.ts src/metadata.ts --format cjs --dts --clean",
26
36
  "test": "vitest run",
27
37
  "lint": "eslint src/",
28
38
  "clean": "rm -rf dist",