@codacy/tools-jackson 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Codacy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @codacy/tools-jackson
2
+
3
+ ## Table of Contents
4
+ - [Overview](#overview)
5
+ - [Patterns](#patterns)
6
+ - [Updating patterns](#updating-patterns)
7
+ - [Development](#development)
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ Pure TypeScript JSON syntax validator using Node's built-in `JSON.parse`. Detects parse errors and duplicate keys in JSON files. No external binary required.
14
+
15
+ | Property | Value |
16
+ |----------|-------|
17
+ | Tool ID | `jackson` |
18
+ | Codacy UUID | `4f94ee55-6b76-4765-8f38-9ebb3920762b` |
19
+ | Strategy | Native |
20
+ | Languages | JSON |
21
+ | Binary | None — pure TypeScript |
22
+
23
+ ## Patterns
24
+
25
+ | Pattern ID | Description |
26
+ |------------|-------------|
27
+ | `jackson_parse-error` | JSON syntax error |
28
+ | `jackson_duplicate-keys` | Duplicate keys in JSON object |
29
+
30
+ ## Updating patterns
31
+
32
+ ```bash
33
+ # Re-fetch pattern metadata from the Codacy API
34
+ pnpm prefetch
35
+
36
+ # Verify the output
37
+ cat src/patterns.json
38
+ ```
39
+
40
+ The `prefetch` script calls `packages/tools/scripts/fetch-patterns.mjs` with the tool UUID to download pattern metadata (IDs, categories, severity levels) from the Codacy API.
41
+
42
+ After fetching, commit the updated `src/patterns.json`.
43
+
44
+ ## Development
45
+
46
+ ```bash
47
+ pnpm build # Build with tsup
48
+ pnpm test # Run tests
49
+ ```
50
+
51
+ Since this is a Native adapter, no external binary is needed. All analysis is done in TypeScript.
@@ -0,0 +1,5 @@
1
+ import * as _codacy_tooling from '@codacy/tooling';
2
+
3
+ declare const _default: Readonly<_codacy_tooling.ToolAdapter>;
4
+
5
+ export { _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_tooling = require("@codacy/tooling");
37
+
38
+ // src/adapter.ts
39
+ var import_promises = __toESM(require("fs/promises"));
40
+ var import_path = __toESM(require("path"));
41
+ var TOOL_ID = "jackson";
42
+ var PATTERN_PARSE_ERROR = `${TOOL_ID}_parse-error`;
43
+ var PATTERN_DUPLICATE_KEYS = `${TOOL_ID}_duplicate-keys`;
44
+ var adapter = {
45
+ id: TOOL_ID,
46
+ displayName: "Jackson Linter",
47
+ preferredVersion: "1.0.0",
48
+ compatibleVersions: ">=1.0.0",
49
+ website: "https://github.com/FasterXML/jackson-core",
50
+ languages: ["JSON"],
51
+ filePatterns: ["**/*.json"],
52
+ supportedOS: ["linux", "darwin", "win32"],
53
+ supportedArch: ["x64", "arm64"],
54
+ supportedRunners: ["local", "container"],
55
+ prerequisites: [],
56
+ /**
57
+ * Always available — this adapter uses only Node's built-in JSON.parse.
58
+ * No external binary or runtime installation is needed.
59
+ */
60
+ async checkAvailability(ctx) {
61
+ ctx.logger.debug("Checking availability", { toolId: TOOL_ID });
62
+ ctx.logger.debug("Availability check result", { toolId: TOOL_ID, available: true, version: "1.0.0" });
63
+ return { available: true, version: "1.0.0", installation: "bundled" };
64
+ },
65
+ /** No-op — there is nothing to install for a Native adapter. */
66
+ async install(ctx) {
67
+ ctx.logger.info("Starting install", { toolId: TOOL_ID });
68
+ ctx.logger.info("Install not needed \u2014 native adapter", { toolId: TOOL_ID });
69
+ return { success: true, installedVersion: "1.0.0" };
70
+ },
71
+ /**
72
+ * Jackson Linter has no native configuration file concept.
73
+ * Always returns `{ found: false }`.
74
+ */
75
+ async checkLocalConfigurationFile(ctx) {
76
+ ctx.logger.debug("Checking for local config", { toolId: TOOL_ID });
77
+ ctx.logger.debug("Local config check", { toolId: TOOL_ID, found: false, path: void 0 });
78
+ return { found: false };
79
+ },
80
+ /**
81
+ * Analyzes each target file by attempting JSON.parse (parse-error) and by
82
+ * scanning for duplicate object keys (duplicate-keys).
83
+ *
84
+ * Config filtering: when `codacyConfig.patterns` is non-empty, only the
85
+ * enabled patterns are checked. If patterns is empty (all rules enabled),
86
+ * both checks run.
87
+ *
88
+ * For each file:
89
+ * - If the file cannot be read, an AnalysisError with kind "FileReadError" is recorded.
90
+ * - If JSON.parse throws a SyntaxError, the error's character position is decoded
91
+ * into a 1-based line/column and an Issue with patternId `jackson_parse-error` is emitted.
92
+ * - If duplicate object keys are found, each duplicate emits an Issue with patternId
93
+ * `jackson_duplicate-keys`.
94
+ * - Valid JSON files with no duplicates produce no issues.
95
+ *
96
+ * This method never throws — all errors are collected and returned.
97
+ */
98
+ async analyze(ctx, codacyConfig) {
99
+ const startMs = Date.now();
100
+ ctx.logger.info("Starting analysis", { toolId: TOOL_ID, fileCount: ctx.targetFiles.length });
101
+ const startedAt = /* @__PURE__ */ new Date();
102
+ const issues = [];
103
+ const errors = [];
104
+ const enabledPatterns = new Set(codacyConfig.patterns.map((p) => p.patternId));
105
+ const checkParseError = enabledPatterns.size === 0 || enabledPatterns.has(PATTERN_PARSE_ERROR);
106
+ const checkDuplicateKeys = enabledPatterns.size === 0 || enabledPatterns.has(PATTERN_DUPLICATE_KEYS);
107
+ for (const relPath of ctx.targetFiles) {
108
+ const absPath = import_path.default.resolve(ctx.repositoryRoot, relPath);
109
+ let content;
110
+ try {
111
+ content = await import_promises.default.readFile(absPath, "utf-8");
112
+ } catch (err) {
113
+ errors.push({
114
+ toolId: TOOL_ID,
115
+ phase: "toolInvoke",
116
+ kind: "FileReadError",
117
+ message: `Cannot read file ${relPath}: ${err instanceof Error ? err.message : String(err)}`,
118
+ level: "warning",
119
+ filePath: relPath
120
+ });
121
+ continue;
122
+ }
123
+ let parseFailed = false;
124
+ if (checkParseError) {
125
+ try {
126
+ JSON.parse(content);
127
+ } catch (err) {
128
+ if (err instanceof SyntaxError) {
129
+ parseFailed = true;
130
+ const { line, column } = extractPosition(err.message, content);
131
+ const lines = content.split("\n");
132
+ const lineContent = lines[line - 1] ?? "";
133
+ issues.push({
134
+ filePath: relPath,
135
+ patternId: PATTERN_PARSE_ERROR,
136
+ toolId: TOOL_ID,
137
+ line,
138
+ column,
139
+ message: err.message,
140
+ lineContent,
141
+ category: "ErrorProne",
142
+ severity: "Error"
143
+ });
144
+ }
145
+ }
146
+ }
147
+ if (checkDuplicateKeys && !parseFailed) {
148
+ const duplicates = findDuplicateKeys(content);
149
+ const lines = content.split("\n");
150
+ for (const dup of duplicates) {
151
+ const lineContent = lines[dup.line - 1] ?? "";
152
+ issues.push({
153
+ filePath: relPath,
154
+ patternId: PATTERN_DUPLICATE_KEYS,
155
+ toolId: TOOL_ID,
156
+ line: dup.line,
157
+ column: dup.column,
158
+ message: `Duplicate key "${dup.key}"`,
159
+ lineContent,
160
+ category: "ErrorProne",
161
+ severity: "Warning"
162
+ });
163
+ }
164
+ }
165
+ }
166
+ const completedAt = /* @__PURE__ */ new Date();
167
+ ctx.logger.info("Analysis complete", { toolId: TOOL_ID, issueCount: issues.length, errorCount: errors.length, durationMs: Date.now() - startMs });
168
+ return {
169
+ metadata: {
170
+ startedAt: startedAt.toISOString(),
171
+ completedAt: completedAt.toISOString(),
172
+ durationMs: completedAt.getTime() - startedAt.getTime()
173
+ },
174
+ issues,
175
+ errors,
176
+ summary: {
177
+ toolId: TOOL_ID,
178
+ status: errors.some((e) => e.level === "error") ? "partial" : "success",
179
+ issueCount: issues.length,
180
+ errorCount: errors.length,
181
+ durationMs: completedAt.getTime() - startedAt.getTime(),
182
+ filesAnalyzed: ctx.targetFiles.length
183
+ }
184
+ };
185
+ }
186
+ };
187
+ function extractPosition(message, source) {
188
+ const posMatch = message.match(/position (\d+)/);
189
+ if (posMatch) {
190
+ const pos = parseInt(posMatch[1], 10);
191
+ return positionToLineColumn(source, pos);
192
+ }
193
+ return { line: 1, column: 1 };
194
+ }
195
+ function positionToLineColumn(src, position) {
196
+ const before = src.slice(0, Math.min(position, src.length));
197
+ const lines = before.split("\n");
198
+ const line = lines.length;
199
+ const column = (lines[lines.length - 1]?.length ?? 0) + 1;
200
+ return { line, column };
201
+ }
202
+ function findDuplicateKeys(source) {
203
+ const duplicates = [];
204
+ const stack = [];
205
+ let i = 0;
206
+ const len = source.length;
207
+ let line = 1;
208
+ let col = 1;
209
+ while (i < len) {
210
+ const ch = source[i];
211
+ if (ch === '"') {
212
+ const strLine = line;
213
+ const strCol = col;
214
+ let strVal = "";
215
+ i++;
216
+ col++;
217
+ while (i < len) {
218
+ const sc = source[i];
219
+ if (sc === "\\") {
220
+ strVal += sc;
221
+ i++;
222
+ col++;
223
+ if (i < len) {
224
+ strVal += source[i];
225
+ i++;
226
+ col++;
227
+ }
228
+ } else if (sc === '"') {
229
+ i++;
230
+ col++;
231
+ break;
232
+ } else {
233
+ if (sc === "\n") {
234
+ line++;
235
+ col = 1;
236
+ } else {
237
+ col++;
238
+ }
239
+ strVal += sc;
240
+ i++;
241
+ }
242
+ }
243
+ let j = i;
244
+ while (j < len && (source[j] === " " || source[j] === " " || source[j] === "\n" || source[j] === "\r")) {
245
+ j++;
246
+ }
247
+ if (source[j] === ":" && stack.length > 0) {
248
+ const currentKeys = stack[stack.length - 1];
249
+ if (currentKeys.has(strVal)) {
250
+ duplicates.push({ key: strVal, line: strLine, column: strCol });
251
+ } else {
252
+ currentKeys.add(strVal);
253
+ }
254
+ }
255
+ continue;
256
+ } else if (ch === "{") {
257
+ stack.push(/* @__PURE__ */ new Set());
258
+ } else if (ch === "}") {
259
+ stack.pop();
260
+ } else if (ch === "\n") {
261
+ line++;
262
+ col = 1;
263
+ i++;
264
+ continue;
265
+ }
266
+ i++;
267
+ col++;
268
+ }
269
+ return duplicates;
270
+ }
271
+
272
+ // src/index.ts
273
+ var index_default = (0, import_tooling.defineToolAdapter)(adapter);
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@codacy/tools-jackson",
3
+ "version": "0.1.0",
4
+ "description": "Jackson Linter adapter — pure TypeScript JSON syntax validator",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "dependencies": {
11
+ "@codacy/tooling": "0.1.0"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Codacy <support@codacy.com> (https://www.codacy.com)",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/codacy/analysis-cli.git",
18
+ "directory": "packages/tools/jackson"
19
+ },
20
+ "homepage": "https://github.com/codacy/analysis-cli",
21
+ "engines": {
22
+ "node": ">=20.0.0"
23
+ },
24
+ "scripts": {
25
+ "build": "tsup src/index.ts --format cjs --dts --clean",
26
+ "test": "vitest run",
27
+ "lint": "eslint src/",
28
+ "clean": "rm -rf dist",
29
+ "prefetch": "node ../scripts/fetch-patterns.mjs 4f94ee55-6b76-4765-8f38-9ebb3920762b src/patterns.json"
30
+ }
31
+ }