@codacy/tools-hadolint-2 0.4.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
@@ -836,6 +836,18 @@ var patterns_default = [
836
836
  }
837
837
  ];
838
838
 
839
+ // src/metadata.ts
840
+ var descriptor = {
841
+ id: "Hadolint",
842
+ displayName: "Hadolint",
843
+ preferredVersion: "2.14.0",
844
+ languages: ["Dockerfile"],
845
+ filePatterns: ["**/Dockerfile", "**/*.dockerfile", "**/Dockerfile.*"],
846
+ supportedOS: ["linux", "darwin", "win32"],
847
+ supportedArch: ["x64", "arm64"],
848
+ supportedRunners: ["local", "container"]
849
+ };
850
+
839
851
  // src/adapter.ts
840
852
  var TOOL_ID = "Hadolint";
841
853
  var PATTERN_META = new Map(
@@ -851,37 +863,6 @@ function ruleMetadata(code) {
851
863
  const patternId = `${TOOL_ID}_${code}`;
852
864
  return PATTERN_META.get(patternId) ?? { category: "BestPractice", severity: "Info" };
853
865
  }
854
- function getLineContent(lines, lineNumber) {
855
- return lines[lineNumber - 1] ?? "";
856
- }
857
- async function readFileLines(filePath) {
858
- try {
859
- const content = await import_promises.default.readFile(filePath, "utf-8");
860
- return content.split("\n");
861
- } catch {
862
- return [];
863
- }
864
- }
865
- function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
866
- const durationMs = completedAt.getTime() - startedAt.getTime();
867
- return {
868
- metadata: {
869
- startedAt: startedAt.toISOString(),
870
- completedAt: completedAt.toISOString(),
871
- durationMs
872
- },
873
- issues,
874
- errors,
875
- summary: {
876
- toolId: TOOL_ID,
877
- status: errors.some((e) => e.level === "error") ? "partial" : "success",
878
- issueCount: issues.length,
879
- errorCount: errors.length,
880
- durationMs,
881
- filesAnalyzed
882
- }
883
- };
884
- }
885
866
  var BINARY = "hadolint";
886
867
  var PLATFORM_MAP = {
887
868
  "darwin-arm64": "macos-arm64",
@@ -908,16 +889,9 @@ async function resolveBinaryPath(ctx) {
908
889
  return BINARY;
909
890
  }
910
891
  var adapter = {
911
- id: TOOL_ID,
912
- displayName: "Hadolint",
913
- preferredVersion: "2.14.0",
892
+ ...descriptor,
914
893
  compatibleVersions: ">=2.0.0",
915
894
  website: "https://github.com/hadolint/hadolint",
916
- languages: ["Dockerfile"],
917
- filePatterns: ["**/Dockerfile", "**/*.dockerfile", "**/Dockerfile.*"],
918
- supportedOS: ["linux", "darwin", "win32"],
919
- supportedArch: ["x64", "arm64"],
920
- supportedRunners: ["local", "container"],
921
895
  prerequisites: [],
922
896
  /**
923
897
  * Checks whether the `hadolint` binary is present and runnable.
@@ -1070,18 +1044,13 @@ var adapter = {
1070
1044
  const issues = [];
1071
1045
  const errors = [];
1072
1046
  if (ctx.targetFiles.length === 0) {
1073
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
1047
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
1074
1048
  }
1075
1049
  const binary = await resolveBinaryPath(ctx);
1076
1050
  const absoluteFiles = ctx.targetFiles.map((f) => import_path.default.resolve(ctx.repositoryRoot, f));
1077
1051
  const args = ["--format", "json"];
1078
1052
  if (codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile) {
1079
1053
  args.push("--config", codacyConfig.localConfigurationFile);
1080
- } else if (codacyConfig.patterns.length === 0) {
1081
- ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
1082
- toolId: TOOL_ID
1083
- });
1084
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1085
1054
  }
1086
1055
  args.push(...absoluteFiles);
1087
1056
  try {
@@ -1097,10 +1066,10 @@ var adapter = {
1097
1066
  message: `hadolint exited with code ${exitCode}${stderr ? `: ${stderr.trim()}` : ""}`,
1098
1067
  level: "error"
1099
1068
  });
1100
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1069
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1101
1070
  }
1102
1071
  if (!stdout.trim()) {
1103
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1072
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1104
1073
  }
1105
1074
  let findings;
1106
1075
  try {
@@ -1113,7 +1082,7 @@ var adapter = {
1113
1082
  message: `Failed to parse hadolint JSON output: ${err instanceof Error ? err.message : String(err)}`,
1114
1083
  level: "error"
1115
1084
  });
1116
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1085
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1117
1086
  }
1118
1087
  const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
1119
1088
  const findingsByFile = /* @__PURE__ */ new Map();
@@ -1124,7 +1093,7 @@ var adapter = {
1124
1093
  }
1125
1094
  for (const [filePath, fileFindings] of findingsByFile) {
1126
1095
  const absoluteFilePath = import_path.default.isAbsolute(filePath) ? filePath : import_path.default.resolve(ctx.repositoryRoot, filePath);
1127
- const lines = await readFileLines(absoluteFilePath);
1096
+ const lines = await (0, import_tooling.readFileLines)(absoluteFilePath);
1128
1097
  const relPath = import_path.default.isAbsolute(filePath) ? import_path.default.relative(ctx.repositoryRoot, filePath) : filePath;
1129
1098
  for (const finding of fileFindings) {
1130
1099
  const patternId = `${TOOL_ID}_${finding.code}`;
@@ -1141,7 +1110,7 @@ var adapter = {
1141
1110
  endLine: finding.endLine,
1142
1111
  endColumn: finding.endColumn,
1143
1112
  message: finding.message,
1144
- lineContent: getLineContent(lines, finding.line),
1113
+ lineContent: (0, import_tooling.getLineContent)(lines, finding.line),
1145
1114
  multilineContent: (0, import_tooling.getMultilineContent)(lines, finding.line, finding.endLine),
1146
1115
  category: meta.category,
1147
1116
  severity: meta.severity
@@ -1173,7 +1142,7 @@ var adapter = {
1173
1142
  errorCount: errors.length,
1174
1143
  durationMs
1175
1144
  });
1176
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1145
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1177
1146
  }
1178
1147
  };
1179
1148
 
@@ -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: "Hadolint",
28
+ displayName: "Hadolint",
29
+ preferredVersion: "2.14.0",
30
+ languages: ["Dockerfile"],
31
+ filePatterns: ["**/Dockerfile", "**/*.dockerfile", "**/Dockerfile.*"],
32
+ supportedOS: ["linux", "darwin", "win32"],
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-hadolint-2",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Hadolint adapter — CLI-mode Dockerfile 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.4.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",