@codacy/tools-bandit-1 0.15.0 → 0.16.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.
Files changed (2) hide show
  1. package/dist/index.js +15 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -786,6 +786,15 @@ function mapConfidence(confidence) {
786
786
  }
787
787
  }
788
788
  var CONFIG_FILE_CANDIDATES = [".bandit", "bandit.yml", "pyproject.toml"];
789
+ var PYPROJECT_BANDIT_SECTION = /^\[tool\.bandit(\.[\w-]+)*\]/m;
790
+ async function pyprojectHasBanditSection(pyprojectPath) {
791
+ try {
792
+ const content = await import_promises.default.readFile(pyprojectPath, "utf-8");
793
+ return PYPROJECT_BANDIT_SECTION.test(content);
794
+ } catch {
795
+ return false;
796
+ }
797
+ }
789
798
  async function resolveBinaryPath(ctx) {
790
799
  const venvDir = (0, import_tooling.getVenvDir)(ctx.globalDir, ADAPTER_ID);
791
800
  const venvBin = (0, import_tooling.resolveVenvBinary)((0, import_tooling.getVenvPaths)(venvDir), "bandit");
@@ -942,7 +951,9 @@ var adapter = {
942
951
  * Checks for bandit configuration files in the repository root.
943
952
  *
944
953
  * Looks for `.bandit`, `bandit.yml`, or `pyproject.toml` (in that order).
945
- * Returns the first found file.
954
+ * `pyproject.toml` only counts if it actually has a `[tool.bandit]` table —
955
+ * unlike the other two candidates, its mere existence says nothing about
956
+ * whether Bandit is configured (see {@link pyprojectHasBanditSection}).
946
957
  */
947
958
  async checkLocalConfigurationFile(ctx) {
948
959
  ctx.logger.debug("Checking for local config", { toolId: TOOL_ID });
@@ -950,6 +961,9 @@ var adapter = {
950
961
  const candidatePath = import_path.default.join(ctx.repositoryRoot, candidate);
951
962
  try {
952
963
  await import_promises.default.access(candidatePath);
964
+ if (candidate === "pyproject.toml" && !await pyprojectHasBanditSection(candidatePath)) {
965
+ continue;
966
+ }
953
967
  ctx.logger.debug("Found local config", { toolId: TOOL_ID, path: candidatePath });
954
968
  return { found: true, path: candidatePath };
955
969
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/tools-bandit-1",
3
- "version": "0.15.0",
3
+ "version": "0.16.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.15.0"
11
+ "@codacy/tooling": "0.16.0"
12
12
  },
13
13
  "license": "MIT",
14
14
  "author": "Codacy <support@codacy.com> (https://www.codacy.com)",