@codacy/tools-cppcheck-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
@@ -3405,6 +3405,18 @@ var patterns_default = [
3405
3405
  }
3406
3406
  ];
3407
3407
 
3408
+ // src/metadata.ts
3409
+ var descriptor = {
3410
+ id: "cppcheck",
3411
+ displayName: "Cppcheck",
3412
+ preferredVersion: "2.18.0",
3413
+ languages: ["C", "C++"],
3414
+ filePatterns: ["**/*.c", "**/*.cpp", "**/*.cc", "**/*.cxx", "**/*.h", "**/*.hpp", "**/*.hh"],
3415
+ supportedOS: ["linux", "darwin", "win32"],
3416
+ supportedArch: ["x64", "arm64"],
3417
+ supportedRunners: ["local", "container"]
3418
+ };
3419
+
3408
3420
  // src/adapter.ts
3409
3421
  var TOOL_ID = "cppcheck";
3410
3422
  var PATTERN_META = new Map(
@@ -3431,37 +3443,6 @@ var xmlParser = new import_fast_xml_parser.XMLParser({
3431
3443
  maxTotalExpansions: 1e5
3432
3444
  }
3433
3445
  });
3434
- function getLineContent(lines, lineNumber) {
3435
- return lines[lineNumber - 1] ?? "";
3436
- }
3437
- async function readFileLines(filePath) {
3438
- try {
3439
- const content = await import_promises.default.readFile(filePath, "utf-8");
3440
- return content.split("\n");
3441
- } catch {
3442
- return [];
3443
- }
3444
- }
3445
- function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
3446
- const durationMs = completedAt.getTime() - startedAt.getTime();
3447
- return {
3448
- metadata: {
3449
- startedAt: startedAt.toISOString(),
3450
- completedAt: completedAt.toISOString(),
3451
- durationMs
3452
- },
3453
- issues,
3454
- errors,
3455
- summary: {
3456
- toolId: TOOL_ID,
3457
- status: errors.some((e) => e.level === "error") ? "partial" : "success",
3458
- issueCount: issues.length,
3459
- errorCount: errors.length,
3460
- durationMs,
3461
- filesAnalyzed
3462
- }
3463
- };
3464
- }
3465
3446
  async function getVersionFromBinary(binaryPath) {
3466
3447
  try {
3467
3448
  const { stdout, exitCode } = await (0, import_tooling.spawnTool)(binaryPath, ["--version"], {
@@ -3481,16 +3462,9 @@ async function resolveBinaryPath(ctx) {
3481
3462
  return BINARY;
3482
3463
  }
3483
3464
  var adapter = {
3484
- id: TOOL_ID,
3485
- displayName: "Cppcheck",
3486
- preferredVersion: "2.18.0",
3465
+ ...descriptor,
3487
3466
  compatibleVersions: ">=2.0.0",
3488
3467
  website: "https://cppcheck.sourceforge.io",
3489
- languages: ["C", "C++"],
3490
- filePatterns: ["**/*.c", "**/*.cpp", "**/*.cc", "**/*.cxx", "**/*.h", "**/*.hpp", "**/*.hh"],
3491
- supportedOS: ["linux", "darwin", "win32"],
3492
- supportedArch: ["x64", "arm64"],
3493
- supportedRunners: ["local", "container"],
3494
3468
  prerequisites: [],
3495
3469
  /**
3496
3470
  * Checks whether the `cppcheck` binary is present and runnable.
@@ -3607,7 +3581,7 @@ var adapter = {
3607
3581
  const issues = [];
3608
3582
  const errors = [];
3609
3583
  if (ctx.targetFiles.length === 0) {
3610
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
3584
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
3611
3585
  }
3612
3586
  const binary = await resolveBinaryPath(ctx);
3613
3587
  const absoluteFiles = ctx.targetFiles.map((f) => import_path.default.resolve(ctx.repositoryRoot, f));
@@ -3621,11 +3595,6 @@ var adapter = {
3621
3595
  ];
3622
3596
  if (codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile) {
3623
3597
  args.push(`--suppressions-list=${codacyConfig.localConfigurationFile}`);
3624
- } else if (codacyConfig.patterns.length === 0) {
3625
- ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
3626
- toolId: TOOL_ID
3627
- });
3628
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3629
3598
  }
3630
3599
  args.push(...absoluteFiles);
3631
3600
  try {
@@ -3641,10 +3610,10 @@ var adapter = {
3641
3610
  message: `cppcheck exited with code ${exitCode}${stderr ? `: ${stderr.trim()}` : ""}`,
3642
3611
  level: "error"
3643
3612
  });
3644
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3613
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3645
3614
  }
3646
3615
  if (!stderr.trim()) {
3647
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3616
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3648
3617
  }
3649
3618
  let cppcheckErrors;
3650
3619
  try {
@@ -3658,7 +3627,7 @@ var adapter = {
3658
3627
  message: `Failed to parse cppcheck XML output: ${err instanceof Error ? err.message : String(err)}`,
3659
3628
  level: "error"
3660
3629
  });
3661
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3630
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3662
3631
  }
3663
3632
  const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
3664
3633
  const errorsByFile = /* @__PURE__ */ new Map();
@@ -3675,7 +3644,7 @@ var adapter = {
3675
3644
  errorsByFile.set(filePath, list);
3676
3645
  }
3677
3646
  for (const [absoluteFilePath, fileErrors] of errorsByFile) {
3678
- const lines = await readFileLines(absoluteFilePath);
3647
+ const lines = await (0, import_tooling.readFileLines)(absoluteFilePath);
3679
3648
  const relPath = import_path.default.relative(ctx.repositoryRoot, absoluteFilePath);
3680
3649
  for (const { error, location } of fileErrors) {
3681
3650
  const errorId = error["@_id"];
@@ -3693,7 +3662,7 @@ var adapter = {
3693
3662
  line,
3694
3663
  column,
3695
3664
  message: error["@_msg"],
3696
- lineContent: getLineContent(lines, line),
3665
+ lineContent: (0, import_tooling.getLineContent)(lines, line),
3697
3666
  category: meta.category,
3698
3667
  severity: meta.severity
3699
3668
  });
@@ -3715,7 +3684,7 @@ var adapter = {
3715
3684
  errorCount: errors.length,
3716
3685
  durationMs
3717
3686
  });
3718
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3687
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
3719
3688
  }
3720
3689
  };
3721
3690
 
@@ -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: "cppcheck",
28
+ displayName: "Cppcheck",
29
+ preferredVersion: "2.18.0",
30
+ languages: ["C", "C++"],
31
+ filePatterns: ["**/*.c", "**/*.cpp", "**/*.cc", "**/*.cxx", "**/*.h", "**/*.hpp", "**/*.hh"],
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-cppcheck-2",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Cppcheck adapter — CLI-mode C/C++ static analyzer",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "fast-xml-parser": "^5.5.6",
12
- "@codacy/tooling": "0.4.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",