@codacy/tools-scalastyle-1 0.3.0 → 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 +25 -71
- package/dist/metadata.d.ts +13 -0
- package/dist/metadata.js +39 -0
- package/package.json +13 -3
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";
|
|
@@ -935,22 +947,11 @@ var FILE_LEVEL_CHECKERS = /* @__PURE__ */ new Set([
|
|
|
935
947
|
"RegexChecker",
|
|
936
948
|
"WhitespaceEndOfLineChecker"
|
|
937
949
|
]);
|
|
938
|
-
var VALID_CATEGORIES = /* @__PURE__ */ new Set([
|
|
939
|
-
"Security",
|
|
940
|
-
"ErrorProne",
|
|
941
|
-
"CodeStyle",
|
|
942
|
-
"Compatibility",
|
|
943
|
-
"Performance",
|
|
944
|
-
"UnusedCode",
|
|
945
|
-
"Complexity",
|
|
946
|
-
"BestPractice",
|
|
947
|
-
"Documentation"
|
|
948
|
-
]);
|
|
949
950
|
var PATTERN_META = new Map(
|
|
950
951
|
patterns_default.map((p) => [
|
|
951
952
|
p.id,
|
|
952
953
|
{
|
|
953
|
-
category:
|
|
954
|
+
category: import_tooling.ISSUE_CATEGORIES.has(p.category) ? p.category : "BestPractice",
|
|
954
955
|
severity: p.severityLevel ?? "Info"
|
|
955
956
|
}
|
|
956
957
|
])
|
|
@@ -967,37 +968,6 @@ var xmlParser = new import_fast_xml_parser.XMLParser({
|
|
|
967
968
|
maxTotalExpansions: 1e5
|
|
968
969
|
}
|
|
969
970
|
});
|
|
970
|
-
function getLineContent(lines, lineNumber) {
|
|
971
|
-
return lines[lineNumber - 1] ?? "";
|
|
972
|
-
}
|
|
973
|
-
async function readFileLines(filePath) {
|
|
974
|
-
try {
|
|
975
|
-
const content = await import_promises.default.readFile(filePath, "utf-8");
|
|
976
|
-
return content.split("\n");
|
|
977
|
-
} catch {
|
|
978
|
-
return [];
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
function buildResult(startedAt, completedAt, issues, errors, filesAnalyzed) {
|
|
982
|
-
const durationMs = completedAt.getTime() - startedAt.getTime();
|
|
983
|
-
return {
|
|
984
|
-
metadata: {
|
|
985
|
-
startedAt: startedAt.toISOString(),
|
|
986
|
-
completedAt: completedAt.toISOString(),
|
|
987
|
-
durationMs
|
|
988
|
-
},
|
|
989
|
-
issues,
|
|
990
|
-
errors,
|
|
991
|
-
summary: {
|
|
992
|
-
toolId: TOOL_ID,
|
|
993
|
-
status: errors.some((e) => e.level === "error") ? "partial" : "success",
|
|
994
|
-
issueCount: issues.length,
|
|
995
|
-
errorCount: errors.length,
|
|
996
|
-
durationMs,
|
|
997
|
-
filesAnalyzed
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
971
|
function derivePatternId(source) {
|
|
1002
972
|
const lastDot = source.lastIndexOf(".");
|
|
1003
973
|
const checkerName = lastDot >= 0 ? source.substring(lastDot + 1) : source;
|
|
@@ -1050,7 +1020,7 @@ function generateScalastyleConfig(patterns) {
|
|
|
1050
1020
|
}
|
|
1051
1021
|
if (mergedParams.length > 0) {
|
|
1052
1022
|
const paramLines = mergedParams.map(
|
|
1053
|
-
(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>`
|
|
1054
1024
|
).join("\n");
|
|
1055
1025
|
checks.push(
|
|
1056
1026
|
` <check level="warning" class="${fqcn}" enabled="true">
|
|
@@ -1071,9 +1041,6 @@ ${paramLines}
|
|
|
1071
1041
|
];
|
|
1072
1042
|
return lines.join("\n") + "\n";
|
|
1073
1043
|
}
|
|
1074
|
-
function escapeXml(str) {
|
|
1075
|
-
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1076
|
-
}
|
|
1077
1044
|
var REQUIRES_USER_PARAMS = /* @__PURE__ */ new Set([
|
|
1078
1045
|
"HeaderMatchesChecker",
|
|
1079
1046
|
// needs `header` parameter
|
|
@@ -1084,16 +1051,9 @@ var REQUIRES_USER_PARAMS = /* @__PURE__ */ new Set([
|
|
|
1084
1051
|
]);
|
|
1085
1052
|
var CONFIG_FILE_CANDIDATES = ["scalastyle_config.xml", "scalastyle-config.xml"];
|
|
1086
1053
|
var adapter = {
|
|
1087
|
-
|
|
1088
|
-
displayName: "Scalastyle",
|
|
1089
|
-
preferredVersion: SCALASTYLE_VERSION,
|
|
1054
|
+
...descriptor,
|
|
1090
1055
|
compatibleVersions: ">=1.0.0",
|
|
1091
1056
|
website: "http://www.scalastyle.org/",
|
|
1092
|
-
languages: ["Scala"],
|
|
1093
|
-
filePatterns: ["**/*.scala"],
|
|
1094
|
-
supportedOS: ["linux", "darwin", "win32"],
|
|
1095
|
-
supportedArch: ["x64", "arm64"],
|
|
1096
|
-
supportedRunners: ["local", "container"],
|
|
1097
1057
|
prerequisites: [
|
|
1098
1058
|
{
|
|
1099
1059
|
name: "Java",
|
|
@@ -1241,15 +1201,9 @@ var adapter = {
|
|
|
1241
1201
|
const issues = [];
|
|
1242
1202
|
const errors = [];
|
|
1243
1203
|
if (ctx.targetFiles.length === 0) {
|
|
1244
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
|
|
1204
|
+
return (0, import_tooling.buildResult)(TOOL_ID, startedAt, /* @__PURE__ */ new Date(), issues, errors, 0);
|
|
1245
1205
|
}
|
|
1246
1206
|
const useLocal = codacyConfig.useLocalConfigurationFile && codacyConfig.localConfigurationFile;
|
|
1247
|
-
if (!useLocal && codacyConfig.patterns.length === 0) {
|
|
1248
|
-
ctx.logger.info("Skipping analysis: no local config and no patterns enabled", {
|
|
1249
|
-
toolId: TOOL_ID
|
|
1250
|
-
});
|
|
1251
|
-
return buildResult(startedAt, /* @__PURE__ */ new Date(), issues, errors, ctx.targetFiles.length);
|
|
1252
|
-
}
|
|
1253
1207
|
const javaBin = await resolveJavaBinary(ctx);
|
|
1254
1208
|
const jarPath = await resolveJarPath(ctx);
|
|
1255
1209
|
if (!jarPath) {
|
|
@@ -1260,7 +1214,7 @@ var adapter = {
|
|
|
1260
1214
|
message: `Scalastyle JAR not found at ${import_path.default.join(ctx.toolInstallDir, JAR_NAME)}. Run install first.`,
|
|
1261
1215
|
level: "error"
|
|
1262
1216
|
});
|
|
1263
|
-
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);
|
|
1264
1218
|
}
|
|
1265
1219
|
const tmpDir = await import_promises.default.mkdtemp(import_path.default.join(import_os.default.tmpdir(), "scalastyle-"));
|
|
1266
1220
|
const reportFile = import_path.default.join(tmpDir, "scalastyle-output.xml");
|
|
@@ -1280,7 +1234,7 @@ var adapter = {
|
|
|
1280
1234
|
});
|
|
1281
1235
|
} else {
|
|
1282
1236
|
await cleanupTmpDir(tmpDir);
|
|
1283
|
-
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);
|
|
1284
1238
|
}
|
|
1285
1239
|
const args = [
|
|
1286
1240
|
"-cp",
|
|
@@ -1309,7 +1263,7 @@ var adapter = {
|
|
|
1309
1263
|
await cleanupTmpDir(tmpDir);
|
|
1310
1264
|
if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
|
|
1311
1265
|
});
|
|
1312
|
-
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);
|
|
1313
1267
|
}
|
|
1314
1268
|
let xmlContent;
|
|
1315
1269
|
try {
|
|
@@ -1327,13 +1281,13 @@ var adapter = {
|
|
|
1327
1281
|
await cleanupTmpDir(tmpDir);
|
|
1328
1282
|
if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
|
|
1329
1283
|
});
|
|
1330
|
-
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);
|
|
1331
1285
|
}
|
|
1332
1286
|
if (!xmlContent.trim()) {
|
|
1333
1287
|
await cleanupTmpDir(tmpDir);
|
|
1334
1288
|
if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
|
|
1335
1289
|
});
|
|
1336
|
-
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);
|
|
1337
1291
|
}
|
|
1338
1292
|
let files;
|
|
1339
1293
|
try {
|
|
@@ -1351,7 +1305,7 @@ var adapter = {
|
|
|
1351
1305
|
await cleanupTmpDir(tmpDir);
|
|
1352
1306
|
if (generatedConfigPath) await import_promises.default.unlink(generatedConfigPath).catch(() => {
|
|
1353
1307
|
});
|
|
1354
|
-
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);
|
|
1355
1309
|
}
|
|
1356
1310
|
const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
|
|
1357
1311
|
for (const file of files) {
|
|
@@ -1363,7 +1317,7 @@ var adapter = {
|
|
|
1363
1317
|
const relPath = import_path.default.isAbsolute(filePath) ? import_path.default.relative(ctx.repositoryRoot, filePath) : filePath;
|
|
1364
1318
|
if (!targetFileSet.has(import_path.default.normalize(relPath))) continue;
|
|
1365
1319
|
const absolutePath = import_path.default.resolve(ctx.repositoryRoot, relPath);
|
|
1366
|
-
const lines = await readFileLines(absolutePath);
|
|
1320
|
+
const lines = await (0, import_tooling.readFileLines)(absolutePath);
|
|
1367
1321
|
for (const error of fileErrors) {
|
|
1368
1322
|
const source = error["@_source"] ?? "";
|
|
1369
1323
|
if (!source) continue;
|
|
@@ -1381,7 +1335,7 @@ var adapter = {
|
|
|
1381
1335
|
line,
|
|
1382
1336
|
column,
|
|
1383
1337
|
message: error["@_message"],
|
|
1384
|
-
lineContent: getLineContent(lines, line),
|
|
1338
|
+
lineContent: (0, import_tooling.getLineContent)(lines, line),
|
|
1385
1339
|
category: meta.category,
|
|
1386
1340
|
severity: meta.severity
|
|
1387
1341
|
});
|
|
@@ -1426,7 +1380,7 @@ var adapter = {
|
|
|
1426
1380
|
errorCount: errors.length,
|
|
1427
1381
|
durationMs
|
|
1428
1382
|
});
|
|
1429
|
-
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);
|
|
1430
1384
|
}
|
|
1431
1385
|
};
|
|
1432
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 };
|
package/dist/metadata.js
ADDED
|
@@ -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.
|
|
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.
|
|
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",
|