@codacy/tools-scalastyle-1 0.3.1 → 0.3.2

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
@@ -919,6 +919,18 @@ var patterns_default = [
919
919
  }
920
920
  ];
921
921
 
922
+ // src/metadata.ts
923
+ var descriptor = {
924
+ id: "ScalaStyle",
925
+ displayName: "Scalastyle",
926
+ preferredVersion: "1.5.1",
927
+ languages: ["Scala"],
928
+ filePatterns: ["**/*.scala"],
929
+ supportedOS: ["linux", "darwin", "win32"],
930
+ supportedArch: ["x64", "arm64"],
931
+ supportedRunners: ["local", "container"]
932
+ };
933
+
922
934
  // src/adapter.ts
923
935
  var TOOL_ID = "ScalaStyle";
924
936
  var SCALASTYLE_VERSION = "1.5.1";
@@ -956,37 +968,6 @@ var xmlParser = new import_fast_xml_parser.XMLParser({
956
968
  maxTotalExpansions: 1e5
957
969
  }
958
970
  });
959
- function getLineContent(lines, lineNumber) {
960
- return lines[lineNumber - 1] ?? "";
961
- }
962
- async function readFileLines(filePath) {
963
- try {
964
- const content = await import_promises.default.readFile(filePath, "utf-8");
965
- return content.split("\n");
966
- } catch {
967
- return [];
968
- }
969
- }
970
- function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
971
- const durationMs = completedAt.getTime() - startedAt.getTime();
972
- return {
973
- metadata: {
974
- startedAt: startedAt.toISOString(),
975
- completedAt: completedAt.toISOString(),
976
- durationMs
977
- },
978
- issues,
979
- errors,
980
- summary: {
981
- toolId: TOOL_ID,
982
- status: errors.some((e) => e.level === "error") ? "partial" : "success",
983
- issueCount: issues.length,
984
- errorCount: errors.length,
985
- durationMs,
986
- filesAnalyzed
987
- }
988
- };
989
- }
990
971
  function derivePatternId(source) {
991
972
  const lastDot = source.lastIndexOf(".");
992
973
  const checkerName = lastDot >= 0 ? source.substring(lastDot + 1) : source;
@@ -1039,7 +1020,7 @@ function generateScalastyleConfig(patterns) {
1039
1020
  }
1040
1021
  if (mergedParams.length > 0) {
1041
1022
  const paramLines = mergedParams.map(
1042
- (p) => ` <parameter name="${escapeXml(p.name)}">${escapeXml(p.value)}</parameter>`
1023
+ (p) => ` <parameter name="${(0, import_tooling.escapeXml)(p.name)}">${(0, import_tooling.escapeXml)(p.value)}</parameter>`
1043
1024
  ).join("\n");
1044
1025
  checks.push(
1045
1026
  ` <check level="warning" class="${fqcn}" enabled="true">
@@ -1060,9 +1041,6 @@ ${paramLines}
1060
1041
  ];
1061
1042
  return lines.join("\n") + "\n";
1062
1043
  }
1063
- function escapeXml(str) {
1064
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
1065
- }
1066
1044
  var REQUIRES_USER_PARAMS = /* @__PURE__ */ new Set([
1067
1045
  "HeaderMatchesChecker",
1068
1046
  // needs `header` parameter
@@ -1073,16 +1051,9 @@ var REQUIRES_USER_PARAMS = /* @__PURE__ */ new Set([
1073
1051
  ]);
1074
1052
  var CONFIG_FILE_CANDIDATES = ["scalastyle_config.xml", "scalastyle-config.xml"];
1075
1053
  var adapter = {
1076
- id: TOOL_ID,
1077
- displayName: "Scalastyle",
1078
- preferredVersion: SCALASTYLE_VERSION,
1054
+ ...descriptor,
1079
1055
  compatibleVersions: ">=1.0.0",
1080
1056
  website: "http://www.scalastyle.org/",
1081
- languages: ["Scala"],
1082
- filePatterns: ["**/*.scala"],
1083
- supportedOS: ["linux", "darwin", "win32"],
1084
- supportedArch: ["x64", "arm64"],
1085
- supportedRunners: ["local", "container"],
1086
1057
  prerequisites: [
1087
1058
  {
1088
1059
  name: "Java",
@@ -1230,15 +1201,9 @@ var adapter = {
1230
1201
  const issues = [];
1231
1202
  const errors = [];
1232
1203
  if (ctx.targetFiles.length === 0) {
1233
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
1204
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
1234
1205
  }
1235
1206
  const useLocal = codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile;
1236
- if (!useLocal && codacyConfig.patterns.length === 0) {
1237
- ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
1238
- toolId: TOOL_ID
1239
- });
1240
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1241
- }
1242
1207
  const javaBin = await resolveJavaBinary(ctx);
1243
1208
  const jarPath = await resolveJarPath(ctx);
1244
1209
  if (!jarPath) {
@@ -1249,7 +1214,7 @@ var adapter = {
1249
1214
  message: `Scalastyle JAR not found at ${import_path.default.join(ctx.toolInstallDir, JAR_NAME)}. Run install first.`,
1250
1215
  level: "error"
1251
1216
  });
1252
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1217
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1253
1218
  }
1254
1219
  const tmpDir = await import_promises.default.mkdtemp(import_path.default.join(import_os.default.tmpdir(), "scalastyle-"));
1255
1220
  const reportFile = import_path.default.join(tmpDir, "scalastyle-output.xml");
@@ -1269,7 +1234,7 @@ var adapter = {
1269
1234
  });
1270
1235
  } else {
1271
1236
  await cleanupTmpDir(tmpDir);
1272
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1237
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1273
1238
  }
1274
1239
  const args = [
1275
1240
  "-cp",
@@ -1298,7 +1263,7 @@ var adapter = {
1298
1263
  await cleanupTmpDir(tmpDir);
1299
1264
  if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
1300
1265
  });
1301
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1266
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1302
1267
  }
1303
1268
  let xmlContent;
1304
1269
  try {
@@ -1316,13 +1281,13 @@ var adapter = {
1316
1281
  await cleanupTmpDir(tmpDir);
1317
1282
  if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
1318
1283
  });
1319
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1284
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1320
1285
  }
1321
1286
  if (!xmlContent.trim()) {
1322
1287
  await cleanupTmpDir(tmpDir);
1323
1288
  if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
1324
1289
  });
1325
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1290
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1326
1291
  }
1327
1292
  let files;
1328
1293
  try {
@@ -1340,7 +1305,7 @@ var adapter = {
1340
1305
  await cleanupTmpDir(tmpDir);
1341
1306
  if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
1342
1307
  });
1343
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1308
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1344
1309
  }
1345
1310
  const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
1346
1311
  for (const file of files) {
@@ -1352,7 +1317,7 @@ var adapter = {
1352
1317
  const relPath = import_path.default.isAbsolute(filePath) ? import_path.default.relative(ctx.repositoryRoot, filePath) : filePath;
1353
1318
  if (!targetFileSet.has(import_path.default.normalize(relPath))) continue;
1354
1319
  const absolutePath = import_path.default.resolve(ctx.repositoryRoot, relPath);
1355
- const lines = await readFileLines(absolutePath);
1320
+ const lines = await (0, import_tooling.readFileLines)(absolutePath);
1356
1321
  for (const error of fileErrors) {
1357
1322
  const source = error["@_source"] ?? "";
1358
1323
  if (!source) continue;
@@ -1370,7 +1335,7 @@ var adapter = {
1370
1335
  line,
1371
1336
  column,
1372
1337
  message: error["@_message"],
1373
- lineContent: getLineContent(lines, line),
1338
+ lineContent: (0, import_tooling.getLineContent)(lines, line),
1374
1339
  category: meta.category,
1375
1340
  severity: meta.severity
1376
1341
  });
@@ -1415,7 +1380,7 @@ var adapter = {
1415
1380
  errorCount: errors.length,
1416
1381
  durationMs
1417
1382
  });
1418
- return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1383
+ return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
1419
1384
  }
1420
1385
  };
1421
1386
  async function cleanupTmpDir(tmpDir) {
@@ -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: "ScalaStyle",
28
+ displayName: "Scalastyle",
29
+ preferredVersion: "1.5.1",
30
+ languages: ["Scala"],
31
+ filePatterns: ["**/*.scala"],
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-scalastyle-1",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Scalastyle adapter — CLI-mode Scala style checker",
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": "^4.5.0",
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",