@diff-cov/eslint 0.0.0-stage → 0.3.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 DiffCov contributors
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 CHANGED
@@ -1,3 +1,20 @@
1
- # Temporary Holding Version
1
+ # @diff-cov/eslint
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ESLint adapter for [`diff-cov`](https://github.com/aprilandjan/diff-cov).
4
+
5
+ ```bash
6
+ pnpm add -D @diff-cov/cli @diff-cov/eslint
7
+ pnpm exec diff-cov eslint --base stable --fail-on error
8
+ ```
9
+
10
+ The adapter runs `eslint <args> . --format json`, parses the messages, and
11
+ returns `Finding[]` with paths relative to the working directory. The CLI turns
12
+ those into repository-relative paths and keeps only findings whose range
13
+ intersects a changed line.
14
+
15
+ `parse` and `collect` are exported for programmatic use. `--input report.json`
16
+ reads an existing report without spawning ESLint. Plugins such as
17
+ `eslint-plugin-boundaries` are covered automatically because their diagnostics
18
+ travel through ESLint's JSON output.
19
+
20
+ MIT licensed.
package/dist/index.cjs ADDED
@@ -0,0 +1,130 @@
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 name2 in all)
8
+ __defProp(target, name2, { get: all[name2], 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/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ collect: () => collect,
24
+ name: () => name,
25
+ parse: () => parse,
26
+ parseEslintJson: () => parseEslintJson
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_node_child_process = require("child_process");
30
+ var import_node_fs2 = require("fs");
31
+ var import_node_path2 = require("path");
32
+ var import_core = require("@diff-cov/core");
33
+
34
+ // src/json.ts
35
+ var import_node_fs = require("fs");
36
+ var import_node_path = require("path");
37
+ function parseEslintJson(input, options) {
38
+ if (!Array.isArray(input)) return [];
39
+ const cwd = normalizePath(options.cwd);
40
+ const findings = [];
41
+ for (const result of input) {
42
+ if (!result.filePath) continue;
43
+ const file = (0, import_node_path.relative)(cwd, normalizePath(result.filePath)).split(import_node_path.sep).join("/");
44
+ for (const message of result.messages ?? []) {
45
+ const line = message.line;
46
+ if (typeof line !== "number" || line <= 0) continue;
47
+ const rule = message.ruleId ?? (message.fatal ? "parse-error" : null);
48
+ if (!rule) continue;
49
+ const severity = message.severity === 2 ? "error" : "warning";
50
+ const endLine = typeof message.endLine === "number" && message.endLine >= line ? message.endLine : line;
51
+ const finding = {
52
+ file,
53
+ startLine: line,
54
+ endLine,
55
+ rule,
56
+ severity,
57
+ message: message.message ?? ""
58
+ };
59
+ if (typeof message.column === "number") finding.startColumn = message.column;
60
+ if (typeof message.endColumn === "number") finding.endColumn = message.endColumn;
61
+ findings.push(finding);
62
+ }
63
+ }
64
+ return findings;
65
+ }
66
+ function normalizePath(path) {
67
+ try {
68
+ return (0, import_node_fs.realpathSync)(path);
69
+ } catch {
70
+ let current = path;
71
+ const suffix = [];
72
+ while (true) {
73
+ const parent = (0, import_node_path.dirname)(current);
74
+ if (parent === current) return path;
75
+ suffix.unshift((0, import_node_path.basename)(current));
76
+ current = parent;
77
+ try {
78
+ return (0, import_node_path.join)((0, import_node_fs.realpathSync)(current), ...suffix);
79
+ } catch {
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ // src/index.ts
86
+ var name = "eslint";
87
+ function parse(content, options) {
88
+ try {
89
+ return parseEslintJson(JSON.parse(content), options);
90
+ } catch {
91
+ throw new import_core.DiffCovError("ESLint did not return valid JSON.", "ESLINT_BAD_OUTPUT");
92
+ }
93
+ }
94
+ async function collect(options) {
95
+ const command = options.command ?? resolveCommand(options.cwd);
96
+ const args = [...command.args, ...options.args ?? [], ".", "--format", "json"];
97
+ const result = (0, import_node_child_process.spawnSync)(command.program, args, {
98
+ cwd: options.cwd,
99
+ encoding: "utf8",
100
+ maxBuffer: 64 * 1024 * 1024
101
+ });
102
+ if (result.error) {
103
+ throw new import_core.DiffCovError(`Cannot run ESLint: ${result.error.message}`, "ESLINT_FAILED");
104
+ }
105
+ const stdout = result.stdout?.trim() ?? "";
106
+ if (!stdout) {
107
+ throw new import_core.DiffCovError(
108
+ `ESLint produced no output (exit ${result.status}).
109
+ ${result.stderr?.trim() ?? ""}`,
110
+ "ESLINT_FAILED"
111
+ );
112
+ }
113
+ return parse(stdout, { cwd: options.cwd });
114
+ }
115
+ function resolveCommand(cwd) {
116
+ const bin = process.platform === "win32" ? "eslint.cmd" : "eslint";
117
+ const local = (0, import_node_path2.join)(cwd, "node_modules", ".bin", bin);
118
+ if ((0, import_node_fs2.existsSync)(local)) return { program: local, args: [] };
119
+ const probe = (0, import_node_child_process.spawnSync)("eslint", ["--version"], { cwd, encoding: "utf8" });
120
+ if (!probe.error && probe.status === 0) return { program: "eslint", args: [] };
121
+ return { program: "npx", args: ["-y", "eslint"] };
122
+ }
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ collect,
126
+ name,
127
+ parse,
128
+ parseEslintJson
129
+ });
130
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/json.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { DiffCovError, type Finding } from '@diff-cov/core'\nimport { parseEslintJson } from './json.js'\n\nexport const name = 'eslint'\n\nexport interface AdapterCommand {\n program: string\n args: string[]\n}\n\nexport interface CollectOptions {\n cwd: string\n args?: string[]\n command?: AdapterCommand\n}\n\nexport function parse(content: string, options: { cwd: string }): Finding[] {\n try {\n return parseEslintJson(JSON.parse(content), options)\n } catch {\n throw new DiffCovError('ESLint did not return valid JSON.', 'ESLINT_BAD_OUTPUT')\n }\n}\n\nexport async function collect(options: CollectOptions): Promise<Finding[]> {\n const command = options.command ?? resolveCommand(options.cwd)\n const args = [...command.args, ...(options.args ?? []), '.', '--format', 'json']\n const result = spawnSync(command.program, args, {\n cwd: options.cwd,\n encoding: 'utf8',\n maxBuffer: 64 * 1024 * 1024,\n })\n\n if (result.error) {\n throw new DiffCovError(`Cannot run ESLint: ${result.error.message}`, 'ESLINT_FAILED')\n }\n\n const stdout = result.stdout?.trim() ?? ''\n if (!stdout) {\n throw new DiffCovError(\n `ESLint produced no output (exit ${result.status}).\\n${result.stderr?.trim() ?? ''}`,\n 'ESLINT_FAILED',\n )\n }\n\n return parse(stdout, { cwd: options.cwd })\n}\n\nfunction resolveCommand(cwd: string): AdapterCommand {\n const bin = process.platform === 'win32' ? 'eslint.cmd' : 'eslint'\n const local = join(cwd, 'node_modules', '.bin', bin)\n if (existsSync(local)) return { program: local, args: [] }\n\n const probe = spawnSync('eslint', ['--version'], { cwd, encoding: 'utf8' })\n if (!probe.error && probe.status === 0) return { program: 'eslint', args: [] }\n\n return { program: 'npx', args: ['-y', 'eslint'] }\n}\n\nexport { parseEslintJson } from './json.js'\n","import { realpathSync } from 'node:fs'\nimport { basename, dirname, join, relative, sep } from 'node:path'\nimport type { Finding, Severity } from '@diff-cov/core'\n\ninterface EslintMessage {\n ruleId?: string | null\n severity?: number\n message?: string\n line?: number\n endLine?: number\n column?: number\n endColumn?: number\n fatal?: boolean\n}\n\ninterface EslintResult {\n filePath?: string\n messages?: EslintMessage[]\n}\n\nexport function parseEslintJson(input: unknown, options: { cwd: string }): Finding[] {\n if (!Array.isArray(input)) return []\n\n const cwd = normalizePath(options.cwd)\n const findings: Finding[] = []\n for (const result of input as EslintResult[]) {\n if (!result.filePath) continue\n const file = relative(cwd, normalizePath(result.filePath)).split(sep).join('/')\n\n for (const message of result.messages ?? []) {\n const line = message.line\n if (typeof line !== 'number' || line <= 0) continue\n\n const rule = message.ruleId ?? (message.fatal ? 'parse-error' : null)\n if (!rule) continue\n\n const severity: Severity = message.severity === 2 ? 'error' : 'warning'\n const endLine =\n typeof message.endLine === 'number' && message.endLine >= line ? message.endLine : line\n const finding: Finding = {\n file,\n startLine: line,\n endLine,\n rule,\n severity,\n message: message.message ?? '',\n }\n if (typeof message.column === 'number') finding.startColumn = message.column\n if (typeof message.endColumn === 'number') finding.endColumn = message.endColumn\n findings.push(finding)\n }\n }\n return findings\n}\n\nfunction normalizePath(path: string): string {\n try {\n return realpathSync(path)\n } catch {\n // Resolve the deepest existing ancestor so a missing file still yields a\n // canonical path (macOS exposes /var as a symlink to /private/var).\n let current = path\n const suffix: string[] = []\n while (true) {\n const parent = dirname(current)\n if (parent === current) return path\n suffix.unshift(basename(current))\n current = parent\n try {\n return join(realpathSync(current), ...suffix)\n } catch {\n // keep walking up\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAA0B;AAC1B,IAAAA,kBAA2B;AAC3B,IAAAC,oBAAqB;AACrB,kBAA2C;;;ACH3C,qBAA6B;AAC7B,uBAAuD;AAmBhD,SAAS,gBAAgB,OAAgB,SAAqC;AACnF,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AAEnC,QAAM,MAAM,cAAc,QAAQ,GAAG;AACrC,QAAM,WAAsB,CAAC;AAC7B,aAAW,UAAU,OAAyB;AAC5C,QAAI,CAAC,OAAO,SAAU;AACtB,UAAM,WAAO,2BAAS,KAAK,cAAc,OAAO,QAAQ,CAAC,EAAE,MAAM,oBAAG,EAAE,KAAK,GAAG;AAE9E,eAAW,WAAW,OAAO,YAAY,CAAC,GAAG;AAC3C,YAAM,OAAO,QAAQ;AACrB,UAAI,OAAO,SAAS,YAAY,QAAQ,EAAG;AAE3C,YAAM,OAAO,QAAQ,WAAW,QAAQ,QAAQ,gBAAgB;AAChE,UAAI,CAAC,KAAM;AAEX,YAAM,WAAqB,QAAQ,aAAa,IAAI,UAAU;AAC9D,YAAM,UACJ,OAAO,QAAQ,YAAY,YAAY,QAAQ,WAAW,OAAO,QAAQ,UAAU;AACrF,YAAM,UAAmB;AAAA,QACvB;AAAA,QACA,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,QAAQ,WAAW;AAAA,MAC9B;AACA,UAAI,OAAO,QAAQ,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AmC,OAAO,MAAM;AAAA,EAAO,OAAO,QAAQ,KAAK,KAAK,EAAE;AAAA,MAClF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,MAAM,QAAQ,EAAE,KAAK,QAAQ,IAAI,CAAC;AAC3C;AAEA,SAAS,eAAe,KAA6B;AACnD,QAAM,MAAM,QAAQ,aAAa,UAAU,eAAe;AAC1D,QAAM,YAAQ,wBAAK,KAAK,gBAAgB,QAAQ,GAAG;AACnD,UAAI,4BAAW,KAAK,EAAG,QAAO,EAAE,SAAS,OAAO,MAAM,CAAC,EAAE;AAEzD,QAAM,YAAQ,qCAAU,UAAU,CAAC,WAAW,GAAG,EAAE,KAAK,UAAU,OAAO,CAAC;AAC1E,MAAI,CAAC,MAAM,SAAS,MAAM,WAAW,EAAG,QAAO,EAAE,SAAS,UAAU,MAAM,CAAC,EAAE;AAE7E,SAAO,EAAE,SAAS,OAAO,MAAM,CAAC,MAAM,QAAQ,EAAE;AAClD;","names":["import_node_fs","import_node_path"]}
@@ -0,0 +1,23 @@
1
+ import { Finding } from '@diff-cov/core';
2
+
3
+ declare function parseEslintJson(input: unknown, options: {
4
+ cwd: string;
5
+ }): Finding[];
6
+
7
+ declare const name = "eslint";
8
+ interface AdapterCommand {
9
+ program: string;
10
+ args: string[];
11
+ }
12
+ interface CollectOptions {
13
+ cwd: string;
14
+ args?: string[];
15
+ command?: AdapterCommand;
16
+ }
17
+ declare function parse(content: string, options: {
18
+ cwd: string;
19
+ }): Finding[];
20
+ declare function collect(options: CollectOptions): Promise<Finding[]>;
21
+
22
+ export { collect, name, parse, parseEslintJson };
23
+ export type { AdapterCommand, CollectOptions };
@@ -0,0 +1,23 @@
1
+ import { Finding } from '@diff-cov/core';
2
+
3
+ declare function parseEslintJson(input: unknown, options: {
4
+ cwd: string;
5
+ }): Finding[];
6
+
7
+ declare const name = "eslint";
8
+ interface AdapterCommand {
9
+ program: string;
10
+ args: string[];
11
+ }
12
+ interface CollectOptions {
13
+ cwd: string;
14
+ args?: string[];
15
+ command?: AdapterCommand;
16
+ }
17
+ declare function parse(content: string, options: {
18
+ cwd: string;
19
+ }): Finding[];
20
+ declare function collect(options: CollectOptions): Promise<Finding[]>;
21
+
22
+ export { collect, name, parse, parseEslintJson };
23
+ export type { AdapterCommand, CollectOptions };
package/dist/index.js ADDED
@@ -0,0 +1,102 @@
1
+ // src/index.ts
2
+ import { spawnSync } from "child_process";
3
+ import { existsSync } from "fs";
4
+ import { join as join2 } from "path";
5
+ import { DiffCovError } from "@diff-cov/core";
6
+
7
+ // src/json.ts
8
+ import { realpathSync } from "fs";
9
+ import { basename, dirname, join, relative, sep } from "path";
10
+ function parseEslintJson(input, options) {
11
+ if (!Array.isArray(input)) return [];
12
+ const cwd = normalizePath(options.cwd);
13
+ const findings = [];
14
+ for (const result of input) {
15
+ if (!result.filePath) continue;
16
+ const file = relative(cwd, normalizePath(result.filePath)).split(sep).join("/");
17
+ for (const message of result.messages ?? []) {
18
+ const line = message.line;
19
+ if (typeof line !== "number" || line <= 0) continue;
20
+ const rule = message.ruleId ?? (message.fatal ? "parse-error" : null);
21
+ if (!rule) continue;
22
+ const severity = message.severity === 2 ? "error" : "warning";
23
+ const endLine = typeof message.endLine === "number" && message.endLine >= line ? message.endLine : line;
24
+ const finding = {
25
+ file,
26
+ startLine: line,
27
+ endLine,
28
+ rule,
29
+ severity,
30
+ message: message.message ?? ""
31
+ };
32
+ if (typeof message.column === "number") finding.startColumn = message.column;
33
+ if (typeof message.endColumn === "number") finding.endColumn = message.endColumn;
34
+ findings.push(finding);
35
+ }
36
+ }
37
+ return findings;
38
+ }
39
+ function normalizePath(path) {
40
+ try {
41
+ return realpathSync(path);
42
+ } catch {
43
+ let current = path;
44
+ const suffix = [];
45
+ while (true) {
46
+ const parent = dirname(current);
47
+ if (parent === current) return path;
48
+ suffix.unshift(basename(current));
49
+ current = parent;
50
+ try {
51
+ return join(realpathSync(current), ...suffix);
52
+ } catch {
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ // src/index.ts
59
+ var name = "eslint";
60
+ function parse(content, options) {
61
+ try {
62
+ return parseEslintJson(JSON.parse(content), options);
63
+ } catch {
64
+ throw new DiffCovError("ESLint did not return valid JSON.", "ESLINT_BAD_OUTPUT");
65
+ }
66
+ }
67
+ async function collect(options) {
68
+ const command = options.command ?? resolveCommand(options.cwd);
69
+ const args = [...command.args, ...options.args ?? [], ".", "--format", "json"];
70
+ const result = spawnSync(command.program, args, {
71
+ cwd: options.cwd,
72
+ encoding: "utf8",
73
+ maxBuffer: 64 * 1024 * 1024
74
+ });
75
+ if (result.error) {
76
+ throw new DiffCovError(`Cannot run ESLint: ${result.error.message}`, "ESLINT_FAILED");
77
+ }
78
+ const stdout = result.stdout?.trim() ?? "";
79
+ if (!stdout) {
80
+ throw new DiffCovError(
81
+ `ESLint produced no output (exit ${result.status}).
82
+ ${result.stderr?.trim() ?? ""}`,
83
+ "ESLINT_FAILED"
84
+ );
85
+ }
86
+ return parse(stdout, { cwd: options.cwd });
87
+ }
88
+ function resolveCommand(cwd) {
89
+ const bin = process.platform === "win32" ? "eslint.cmd" : "eslint";
90
+ const local = join2(cwd, "node_modules", ".bin", bin);
91
+ if (existsSync(local)) return { program: local, args: [] };
92
+ const probe = spawnSync("eslint", ["--version"], { cwd, encoding: "utf8" });
93
+ if (!probe.error && probe.status === 0) return { program: "eslint", args: [] };
94
+ return { program: "npx", args: ["-y", "eslint"] };
95
+ }
96
+ export {
97
+ collect,
98
+ name,
99
+ parse,
100
+ parseEslintJson
101
+ };
102
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/json.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { DiffCovError, type Finding } from '@diff-cov/core'\nimport { parseEslintJson } from './json.js'\n\nexport const name = 'eslint'\n\nexport interface AdapterCommand {\n program: string\n args: string[]\n}\n\nexport interface CollectOptions {\n cwd: string\n args?: string[]\n command?: AdapterCommand\n}\n\nexport function parse(content: string, options: { cwd: string }): Finding[] {\n try {\n return parseEslintJson(JSON.parse(content), options)\n } catch {\n throw new DiffCovError('ESLint did not return valid JSON.', 'ESLINT_BAD_OUTPUT')\n }\n}\n\nexport async function collect(options: CollectOptions): Promise<Finding[]> {\n const command = options.command ?? resolveCommand(options.cwd)\n const args = [...command.args, ...(options.args ?? []), '.', '--format', 'json']\n const result = spawnSync(command.program, args, {\n cwd: options.cwd,\n encoding: 'utf8',\n maxBuffer: 64 * 1024 * 1024,\n })\n\n if (result.error) {\n throw new DiffCovError(`Cannot run ESLint: ${result.error.message}`, 'ESLINT_FAILED')\n }\n\n const stdout = result.stdout?.trim() ?? ''\n if (!stdout) {\n throw new DiffCovError(\n `ESLint produced no output (exit ${result.status}).\\n${result.stderr?.trim() ?? ''}`,\n 'ESLINT_FAILED',\n )\n }\n\n return parse(stdout, { cwd: options.cwd })\n}\n\nfunction resolveCommand(cwd: string): AdapterCommand {\n const bin = process.platform === 'win32' ? 'eslint.cmd' : 'eslint'\n const local = join(cwd, 'node_modules', '.bin', bin)\n if (existsSync(local)) return { program: local, args: [] }\n\n const probe = spawnSync('eslint', ['--version'], { cwd, encoding: 'utf8' })\n if (!probe.error && probe.status === 0) return { program: 'eslint', args: [] }\n\n return { program: 'npx', args: ['-y', 'eslint'] }\n}\n\nexport { parseEslintJson } from './json.js'\n","import { realpathSync } from 'node:fs'\nimport { basename, dirname, join, relative, sep } from 'node:path'\nimport type { Finding, Severity } from '@diff-cov/core'\n\ninterface EslintMessage {\n ruleId?: string | null\n severity?: number\n message?: string\n line?: number\n endLine?: number\n column?: number\n endColumn?: number\n fatal?: boolean\n}\n\ninterface EslintResult {\n filePath?: string\n messages?: EslintMessage[]\n}\n\nexport function parseEslintJson(input: unknown, options: { cwd: string }): Finding[] {\n if (!Array.isArray(input)) return []\n\n const cwd = normalizePath(options.cwd)\n const findings: Finding[] = []\n for (const result of input as EslintResult[]) {\n if (!result.filePath) continue\n const file = relative(cwd, normalizePath(result.filePath)).split(sep).join('/')\n\n for (const message of result.messages ?? []) {\n const line = message.line\n if (typeof line !== 'number' || line <= 0) continue\n\n const rule = message.ruleId ?? (message.fatal ? 'parse-error' : null)\n if (!rule) continue\n\n const severity: Severity = message.severity === 2 ? 'error' : 'warning'\n const endLine =\n typeof message.endLine === 'number' && message.endLine >= line ? message.endLine : line\n const finding: Finding = {\n file,\n startLine: line,\n endLine,\n rule,\n severity,\n message: message.message ?? '',\n }\n if (typeof message.column === 'number') finding.startColumn = message.column\n if (typeof message.endColumn === 'number') finding.endColumn = message.endColumn\n findings.push(finding)\n }\n }\n return findings\n}\n\nfunction normalizePath(path: string): string {\n try {\n return realpathSync(path)\n } catch {\n // Resolve the deepest existing ancestor so a missing file still yields a\n // canonical path (macOS exposes /var as a symlink to /private/var).\n let current = path\n const suffix: string[] = []\n while (true) {\n const parent = dirname(current)\n if (parent === current) return path\n suffix.unshift(basename(current))\n current = parent\n try {\n return join(realpathSync(current), ...suffix)\n } catch {\n // keep walking up\n }\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,QAAAA,aAAY;AACrB,SAAS,oBAAkC;;;ACH3C,SAAS,oBAAoB;AAC7B,SAAS,UAAU,SAAS,MAAM,UAAU,WAAW;AAmBhD,SAAS,gBAAgB,OAAgB,SAAqC;AACnF,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AAEnC,QAAM,MAAM,cAAc,QAAQ,GAAG;AACrC,QAAM,WAAsB,CAAC;AAC7B,aAAW,UAAU,OAAyB;AAC5C,QAAI,CAAC,OAAO,SAAU;AACtB,UAAM,OAAO,SAAS,KAAK,cAAc,OAAO,QAAQ,CAAC,EAAE,MAAM,GAAG,EAAE,KAAK,GAAG;AAE9E,eAAW,WAAW,OAAO,YAAY,CAAC,GAAG;AAC3C,YAAM,OAAO,QAAQ;AACrB,UAAI,OAAO,S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CAAC,GAAI,KAAK,YAAY,MAAM;AAC/E,QAAM,SAAS,UAAU,QAAQ,SAAS,MAAM;AAAA,IAC9C,KAAK,QAAQ;AAAA,IACb,UAAU;AAAA,IACV,WAAW,KAAK,OAAO;AAAA,EACzB,CAAC;AAED,MAAI,OAAO,OAAO;AAChB,UAAM,IAAI,aAAa,sBAAsB,OAAO,MAAM,OAAO,IAAI,eAAe;AAAA,EACtF;AAEA,QAAM,SAAS,OAAO,QAAQ,KAAK,KAAK;AACxC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR,mCAAmC,OAAO,MAAM;AAAA,EAAO,OAAO,QAAQ,KAAK,KAAK,EAAE;AAAA,MAClF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,MAAM,QAAQ,EAAE,KAAK,QAAQ,IAAI,CAAC;AAC3C;AAEA,SAAS,eAAe,KAA6B;AACnD,QAAM,MAAM,QAAQ,aAAa,UAAU,eAAe;AAC1D,QAAM,QAAQC,MAAK,KAAK,gBAAgB,QAAQ,GAAG;AACnD,MAAI,WAAW,KAAK,EAAG,QAAO,EAAE,SAAS,OAAO,MAAM,CAAC,EAAE;AAEzD,QAAM,QAAQ,UAAU,UAAU,CAAC,WAAW,GAAG,EAAE,KAAK,UAAU,OAAO,CAAC;AAC1E,MAAI,CAAC,MAAM,SAAS,MAAM,WAAW,EAAG,QAAO,EAAE,SAAS,UAAU,MAAM,CAAC,EAAE;AAE7E,SAAO,EAAE,SAAS,OAAO,MAAM,CAAC,MAAM,QAAQ,EAAE;AAClD;","names":["join","join"]}
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@diff-cov/eslint",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.0",
4
+ "description": "ESLint adapter for diff-scoped lint checks.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/aprilandjan/diff-cov.git",
10
+ "directory": "packages/eslint"
11
+ },
12
+ "homepage": "https://github.com/aprilandjan/diff-cov#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/aprilandjan/diff-cov/issues"
15
+ },
16
+ "keywords": [
17
+ "lint",
18
+ "diff",
19
+ "eslint"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "engines": {
39
+ "node": ">=20"
40
+ },
41
+ "dependencies": {
42
+ "@diff-cov/core": "0.3.0"
43
+ },
44
+ "devDependencies": {
45
+ "tsup": "^9.0.0",
46
+ "typescript": "^5.9.3",
47
+ "vitest": "4.1.9"
48
+ },
49
+ "scripts": {
50
+ "build": "tsup",
51
+ "test": "vitest run",
52
+ "typecheck": "tsc --noEmit"
53
+ }
6
54
  }