@diff-cov/oxlint 0.0.0-stage → 0.3.1
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 +21 -0
- package/README.md +22 -2
- package/dist/index.cjs +123 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +94 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -3
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,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @diff-cov/oxlint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Oxlint adapter for [diff-cov](https://github.com/aprilandjan/diff-cov).
|
|
4
|
+
|
|
5
|
+
This package is installed with `@diff-cov/cli`; you do not add it separately. The
|
|
6
|
+
project still needs its own `oxlint` binary.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add -D @diff-cov/cli oxlint
|
|
10
|
+
pnpm exec diff-cov oxlint --base stable --fail-on error
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The adapter runs `oxlint <args> . --format sarif`, parses the SARIF regions, and
|
|
14
|
+
returns `Finding[]` with paths relative to the working directory. The CLI makes
|
|
15
|
+
them repository-relative and keeps only findings whose range intersects a changed
|
|
16
|
+
line.
|
|
17
|
+
|
|
18
|
+
`parse` and `collect` are exported for programmatic use. `--input report.sarif`
|
|
19
|
+
reads an existing report without spawning oxlint.
|
|
20
|
+
|
|
21
|
+
See the [lint guide](https://github.com/aprilandjan/diff-cov/blob/main/docs/lint.md).
|
|
22
|
+
|
|
23
|
+
MIT licensed.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
normalizeSarifUri: () => normalizeSarifUri,
|
|
26
|
+
parse: () => parse,
|
|
27
|
+
parseOxlintSarif: () => parseOxlintSarif
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
var import_node_child_process = require("child_process");
|
|
31
|
+
var import_node_fs = require("fs");
|
|
32
|
+
var import_node_path = require("path");
|
|
33
|
+
var import_core = require("@diff-cov/core");
|
|
34
|
+
|
|
35
|
+
// src/sarif.ts
|
|
36
|
+
var import_node_url = require("url");
|
|
37
|
+
function normalizeSarifUri(uri) {
|
|
38
|
+
if (uri.startsWith("file://")) {
|
|
39
|
+
try {
|
|
40
|
+
return (0, import_node_url.fileURLToPath)(uri);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return decodeURIComponent(uri).replace(/\\/g, "/");
|
|
45
|
+
}
|
|
46
|
+
function parseOxlintSarif(input) {
|
|
47
|
+
const runs = input?.runs;
|
|
48
|
+
if (!Array.isArray(runs)) return [];
|
|
49
|
+
const findings = [];
|
|
50
|
+
for (const run of runs) {
|
|
51
|
+
for (const result of run.results ?? []) {
|
|
52
|
+
const rule = result.ruleId;
|
|
53
|
+
if (!rule) continue;
|
|
54
|
+
const severity = result.level === "error" ? "error" : "warning";
|
|
55
|
+
const message = result.message?.text ?? "";
|
|
56
|
+
for (const location of result.locations ?? []) {
|
|
57
|
+
const uri = location.physicalLocation?.artifactLocation?.uri;
|
|
58
|
+
const region = location.physicalLocation?.region;
|
|
59
|
+
if (!uri || typeof region?.startLine !== "number") continue;
|
|
60
|
+
const finding = {
|
|
61
|
+
file: normalizeSarifUri(uri),
|
|
62
|
+
startLine: region.startLine,
|
|
63
|
+
endLine: typeof region.endLine === "number" && region.endLine >= region.startLine ? region.endLine : region.startLine,
|
|
64
|
+
rule,
|
|
65
|
+
severity,
|
|
66
|
+
message
|
|
67
|
+
};
|
|
68
|
+
if (typeof region.startColumn === "number") finding.startColumn = region.startColumn;
|
|
69
|
+
if (typeof region.endColumn === "number") finding.endColumn = region.endColumn;
|
|
70
|
+
findings.push(finding);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return findings;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/index.ts
|
|
78
|
+
var name = "oxlint";
|
|
79
|
+
function parse(content, _options) {
|
|
80
|
+
try {
|
|
81
|
+
return parseOxlintSarif(JSON.parse(content));
|
|
82
|
+
} catch {
|
|
83
|
+
throw new import_core.DiffCovError("oxlint did not return valid SARIF JSON.", "OXLINT_BAD_OUTPUT");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function collect(options) {
|
|
87
|
+
const command = options.command ?? resolveCommand(options.cwd);
|
|
88
|
+
const args = [...command.args, ...options.args ?? [], ".", "--format", "sarif"];
|
|
89
|
+
const result = (0, import_node_child_process.spawnSync)(command.program, args, {
|
|
90
|
+
cwd: options.cwd,
|
|
91
|
+
encoding: "utf8",
|
|
92
|
+
maxBuffer: 64 * 1024 * 1024
|
|
93
|
+
});
|
|
94
|
+
if (result.error) {
|
|
95
|
+
throw new import_core.DiffCovError(`Cannot run oxlint: ${result.error.message}`, "OXLINT_FAILED");
|
|
96
|
+
}
|
|
97
|
+
const stdout = result.stdout?.trim() ?? "";
|
|
98
|
+
if (!stdout) {
|
|
99
|
+
throw new import_core.DiffCovError(
|
|
100
|
+
`oxlint produced no output (exit ${result.status}).
|
|
101
|
+
${result.stderr?.trim() ?? ""}`,
|
|
102
|
+
"OXLINT_FAILED"
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return parse(stdout);
|
|
106
|
+
}
|
|
107
|
+
function resolveCommand(cwd) {
|
|
108
|
+
const bin = process.platform === "win32" ? "oxlint.cmd" : "oxlint";
|
|
109
|
+
const local = (0, import_node_path.join)(cwd, "node_modules", ".bin", bin);
|
|
110
|
+
if ((0, import_node_fs.existsSync)(local)) return { program: local, args: [] };
|
|
111
|
+
const probe = (0, import_node_child_process.spawnSync)("oxlint", ["--version"], { cwd, encoding: "utf8" });
|
|
112
|
+
if (!probe.error && probe.status === 0) return { program: "oxlint", args: [] };
|
|
113
|
+
return { program: "npx", args: ["-y", "oxlint"] };
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
collect,
|
|
118
|
+
name,
|
|
119
|
+
normalizeSarifUri,
|
|
120
|
+
parse,
|
|
121
|
+
parseOxlintSarif
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sarif.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 { parseOxlintSarif } from './sarif.js'\n\nexport const name = 'oxlint'\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 parseOxlintSarif(JSON.parse(content))\n } catch {\n throw new DiffCovError('oxlint did not return valid SARIF JSON.', 'OXLINT_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', 'sarif']\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 oxlint: ${result.error.message}`, 'OXLINT_FAILED')\n }\n\n const stdout = result.stdout?.trim() ?? ''\n if (!stdout) {\n throw new DiffCovError(\n `oxlint produced no output (exit ${result.status}).\\n${result.stderr?.trim() ?? ''}`,\n 'OXLINT_FAILED',\n )\n }\n\n return parse(stdout)\n}\n\nfunction resolveCommand(cwd: string): AdapterCommand {\n const bin = process.platform === 'win32' ? 'oxlint.cmd' : 'oxlint'\n const local = join(cwd, 'node_modules', '.bin', bin)\n if (existsSync(local)) return { program: local, args: [] }\n\n const probe = spawnSync('oxlint', ['--version'], { cwd, encoding: 'utf8' })\n if (!probe.error && probe.status === 0) return { program: 'oxlint', args: [] }\n\n return { program: 'npx', args: ['-y', 'oxlint'] }\n}\n\nexport { normalizeSarifUri, parseOxlintSarif } from './sarif.js'\n","import { fileURLToPath } from 'node:url'\nimport type { Finding, Severity } from '@diff-cov/core'\n\ninterface SarifRegion {\n startLine?: number\n endLine?: number\n startColumn?: number\n endColumn?: number\n}\n\ninterface SarifLocation {\n physicalLocation?: {\n artifactLocation?: { uri?: string }\n region?: SarifRegion\n }\n}\n\ninterface SarifResult {\n ruleId?: string\n level?: string\n message?: { text?: string }\n locations?: SarifLocation[]\n}\n\ninterface SarifLog {\n runs?: Array<{ results?: SarifResult[] }>\n}\n\nexport function normalizeSarifUri(uri: string): string {\n if (uri.startsWith('file://')) {\n try {\n return fileURLToPath(uri)\n } catch {\n // Fall through to the string form when the URI cannot be parsed.\n }\n }\n return decodeURIComponent(uri).replace(/\\\\/g, '/')\n}\n\nexport function parseOxlintSarif(input: unknown): Finding[] {\n const runs = (input as SarifLog | null)?.runs\n if (!Array.isArray(runs)) return []\n\n const findings: Finding[] = []\n for (const run of runs) {\n for (const result of run.results ?? []) {\n const rule = result.ruleId\n if (!rule) continue\n\n const severity: Severity = result.level === 'error' ? 'error' : 'warning'\n const message = result.message?.text ?? ''\n\n for (const location of result.locations ?? []) {\n const uri = location.physicalLocation?.artifactLocation?.uri\n const region = location.physicalLocation?.region\n if (!uri || typeof region?.startLine !== 'number') continue\n\n const finding: Finding = {\n file: normalizeSarifUri(uri),\n startLine: region.startLine,\n endLine:\n typeof region.endLine === 'number' && region.endLine >= region.startLine\n ? region.endLine\n : region.startLine,\n rule,\n severity,\n message,\n }\n if (typeof region.startColumn === 'number') finding.startColumn = region.startColumn\n if (typeof region.endColumn === 'number') finding.endColumn = region.endColumn\n findings.push(finding)\n }\n }\n }\n return findings\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAA0B;AAC1B,qBAA2B;AAC3B,uBAAqB;AACrB,kBAA2C;;;ACH3C,sBAA8B;AA4BvB,SAAS,kBAAkB,KAAqB;AACrD,MAAI,IAAI,WAAW,SAAS,GAAG;AAC7B,QAAI;AACF,iBAAO,+BAAc,GAAG;AAAA,IAC1B,QAAQ;AAAA,IAER;AAAA,EACF;AACA,SAAO,mBAAmB,GAAG,EAAE,QAAQ,OAAO,GAAG;AACnD;AAEO,SAAS,iBAAiB,OAA2B;AAC1D,QAAM,OAAQ,OAA2B;AACzC,MAAI,CAAC,MAAM,QAAQ,IAAI,EAAG,QAAO,CAAC;AAElC,QAAM,WAAsB,CAAC;AAC7B,aAAW,OAAO,MAAM;AACtB,eAAW,UAAU,IAAI,WAAW,CAAC,GAAG;AACtC,YAAM,OAAO,OAAO;AACpB,UAAI,CAAC,KAAM;AAEX,YAAM,WAAqB,OAAO,UAAU,UAAU,UAAU;AAChE,YAAM,UAAU,OAAO,SAAS,QAAQ;AAExC,iBAAW,YAAY,OAAO,aAAa,CAAC,GAAG;AAC7C,cAAM,MAAM,SAAS,kBAAkB,kBAAkB;AACzD,cAAM,SAAS,SAAS,kBAAkB;AAC1C,YAAI,CAAC,OAAO,OAAO,QAAQ,cA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AAe,KAA6B;AACnD,QAAM,MAAM,QAAQ,aAAa,UAAU,eAAe;AAC1D,QAAM,YAAQ,uBAAK,KAAK,gBAAgB,QAAQ,GAAG;AACnD,UAAI,2BAAW,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":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Finding } from '@diff-cov/core';
|
|
2
|
+
|
|
3
|
+
declare function normalizeSarifUri(uri: string): string;
|
|
4
|
+
declare function parseOxlintSarif(input: unknown): Finding[];
|
|
5
|
+
|
|
6
|
+
declare const name = "oxlint";
|
|
7
|
+
interface AdapterCommand {
|
|
8
|
+
program: string;
|
|
9
|
+
args: string[];
|
|
10
|
+
}
|
|
11
|
+
interface CollectOptions {
|
|
12
|
+
cwd: string;
|
|
13
|
+
args?: string[];
|
|
14
|
+
command?: AdapterCommand;
|
|
15
|
+
}
|
|
16
|
+
declare function parse(content: string, _options?: {
|
|
17
|
+
cwd: string;
|
|
18
|
+
}): Finding[];
|
|
19
|
+
declare function collect(options: CollectOptions): Promise<Finding[]>;
|
|
20
|
+
|
|
21
|
+
export { collect, name, normalizeSarifUri, parse, parseOxlintSarif };
|
|
22
|
+
export type { AdapterCommand, CollectOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Finding } from '@diff-cov/core';
|
|
2
|
+
|
|
3
|
+
declare function normalizeSarifUri(uri: string): string;
|
|
4
|
+
declare function parseOxlintSarif(input: unknown): Finding[];
|
|
5
|
+
|
|
6
|
+
declare const name = "oxlint";
|
|
7
|
+
interface AdapterCommand {
|
|
8
|
+
program: string;
|
|
9
|
+
args: string[];
|
|
10
|
+
}
|
|
11
|
+
interface CollectOptions {
|
|
12
|
+
cwd: string;
|
|
13
|
+
args?: string[];
|
|
14
|
+
command?: AdapterCommand;
|
|
15
|
+
}
|
|
16
|
+
declare function parse(content: string, _options?: {
|
|
17
|
+
cwd: string;
|
|
18
|
+
}): Finding[];
|
|
19
|
+
declare function collect(options: CollectOptions): Promise<Finding[]>;
|
|
20
|
+
|
|
21
|
+
export { collect, name, normalizeSarifUri, parse, parseOxlintSarif };
|
|
22
|
+
export type { AdapterCommand, CollectOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { spawnSync } from "child_process";
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
import { DiffCovError } from "@diff-cov/core";
|
|
6
|
+
|
|
7
|
+
// src/sarif.ts
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
function normalizeSarifUri(uri) {
|
|
10
|
+
if (uri.startsWith("file://")) {
|
|
11
|
+
try {
|
|
12
|
+
return fileURLToPath(uri);
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return decodeURIComponent(uri).replace(/\\/g, "/");
|
|
17
|
+
}
|
|
18
|
+
function parseOxlintSarif(input) {
|
|
19
|
+
const runs = input?.runs;
|
|
20
|
+
if (!Array.isArray(runs)) return [];
|
|
21
|
+
const findings = [];
|
|
22
|
+
for (const run of runs) {
|
|
23
|
+
for (const result of run.results ?? []) {
|
|
24
|
+
const rule = result.ruleId;
|
|
25
|
+
if (!rule) continue;
|
|
26
|
+
const severity = result.level === "error" ? "error" : "warning";
|
|
27
|
+
const message = result.message?.text ?? "";
|
|
28
|
+
for (const location of result.locations ?? []) {
|
|
29
|
+
const uri = location.physicalLocation?.artifactLocation?.uri;
|
|
30
|
+
const region = location.physicalLocation?.region;
|
|
31
|
+
if (!uri || typeof region?.startLine !== "number") continue;
|
|
32
|
+
const finding = {
|
|
33
|
+
file: normalizeSarifUri(uri),
|
|
34
|
+
startLine: region.startLine,
|
|
35
|
+
endLine: typeof region.endLine === "number" && region.endLine >= region.startLine ? region.endLine : region.startLine,
|
|
36
|
+
rule,
|
|
37
|
+
severity,
|
|
38
|
+
message
|
|
39
|
+
};
|
|
40
|
+
if (typeof region.startColumn === "number") finding.startColumn = region.startColumn;
|
|
41
|
+
if (typeof region.endColumn === "number") finding.endColumn = region.endColumn;
|
|
42
|
+
findings.push(finding);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return findings;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/index.ts
|
|
50
|
+
var name = "oxlint";
|
|
51
|
+
function parse(content, _options) {
|
|
52
|
+
try {
|
|
53
|
+
return parseOxlintSarif(JSON.parse(content));
|
|
54
|
+
} catch {
|
|
55
|
+
throw new DiffCovError("oxlint did not return valid SARIF JSON.", "OXLINT_BAD_OUTPUT");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function collect(options) {
|
|
59
|
+
const command = options.command ?? resolveCommand(options.cwd);
|
|
60
|
+
const args = [...command.args, ...options.args ?? [], ".", "--format", "sarif"];
|
|
61
|
+
const result = spawnSync(command.program, args, {
|
|
62
|
+
cwd: options.cwd,
|
|
63
|
+
encoding: "utf8",
|
|
64
|
+
maxBuffer: 64 * 1024 * 1024
|
|
65
|
+
});
|
|
66
|
+
if (result.error) {
|
|
67
|
+
throw new DiffCovError(`Cannot run oxlint: ${result.error.message}`, "OXLINT_FAILED");
|
|
68
|
+
}
|
|
69
|
+
const stdout = result.stdout?.trim() ?? "";
|
|
70
|
+
if (!stdout) {
|
|
71
|
+
throw new DiffCovError(
|
|
72
|
+
`oxlint produced no output (exit ${result.status}).
|
|
73
|
+
${result.stderr?.trim() ?? ""}`,
|
|
74
|
+
"OXLINT_FAILED"
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return parse(stdout);
|
|
78
|
+
}
|
|
79
|
+
function resolveCommand(cwd) {
|
|
80
|
+
const bin = process.platform === "win32" ? "oxlint.cmd" : "oxlint";
|
|
81
|
+
const local = join(cwd, "node_modules", ".bin", bin);
|
|
82
|
+
if (existsSync(local)) return { program: local, args: [] };
|
|
83
|
+
const probe = spawnSync("oxlint", ["--version"], { cwd, encoding: "utf8" });
|
|
84
|
+
if (!probe.error && probe.status === 0) return { program: "oxlint", args: [] };
|
|
85
|
+
return { program: "npx", args: ["-y", "oxlint"] };
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
collect,
|
|
89
|
+
name,
|
|
90
|
+
normalizeSarifUri,
|
|
91
|
+
parse,
|
|
92
|
+
parseOxlintSarif
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sarif.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 { parseOxlintSarif } from './sarif.js'\n\nexport const name = 'oxlint'\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 parseOxlintSarif(JSON.parse(content))\n } catch {\n throw new DiffCovError('oxlint did not return valid SARIF JSON.', 'OXLINT_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', 'sarif']\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 oxlint: ${result.error.message}`, 'OXLINT_FAILED')\n }\n\n const stdout = result.stdout?.trim() ?? ''\n if (!stdout) {\n throw new DiffCovError(\n `oxlint produced no output (exit ${result.status}).\\n${result.stderr?.trim() ?? ''}`,\n 'OXLINT_FAILED',\n )\n }\n\n return parse(stdout)\n}\n\nfunction resolveCommand(cwd: string): AdapterCommand {\n const bin = process.platform === 'win32' ? 'oxlint.cmd' : 'oxlint'\n const local = join(cwd, 'node_modules', '.bin', bin)\n if (existsSync(local)) return { program: local, args: [] }\n\n const probe = spawnSync('oxlint', ['--version'], { cwd, encoding: 'utf8' })\n if (!probe.error && probe.status === 0) return { program: 'oxlint', args: [] }\n\n return { program: 'npx', args: ['-y', 'oxlint'] }\n}\n\nexport { normalizeSarifUri, parseOxlintSarif } from './sarif.js'\n","import { fileURLToPath } from 'node:url'\nimport type { Finding, Severity } from '@diff-cov/core'\n\ninterface SarifRegion {\n startLine?: number\n endLine?: number\n startColumn?: number\n endColumn?: number\n}\n\ninterface SarifLocation {\n physicalLocation?: {\n artifactLocation?: { uri?: string }\n region?: SarifRegion\n }\n}\n\ninterface SarifResult {\n ruleId?: string\n level?: string\n message?: { text?: string }\n locations?: SarifLocation[]\n}\n\ninterface SarifLog {\n runs?: Array<{ results?: SarifResult[] }>\n}\n\nexport function normalizeSarifUri(uri: string): string {\n if (uri.startsWith('file://')) {\n try {\n return fileURLToPath(uri)\n } catch {\n // Fall through to the string form when the URI cannot be parsed.\n }\n }\n return decodeURIComponent(uri).replace(/\\\\/g, '/')\n}\n\nexport function parseOxlintSarif(input: unknown): Finding[] {\n const runs = (input as SarifLog | null)?.runs\n if (!Array.isArray(runs)) return []\n\n const findings: Finding[] = []\n for (const run of runs) {\n for (const result of run.results ?? []) {\n const rule = result.ruleId\n if (!rule) continue\n\n const severity: Severity = result.level === 'error' ? 'error' : 'warning'\n const message = result.message?.text ?? ''\n\n for (const location of result.locations ?? []) {\n const uri = location.physicalLocation?.artifactLocation?.uri\n const region = location.physicalLocation?.region\n if (!uri || typeof region?.startLine !== 'number') continue\n\n const finding: Finding = {\n file: normalizeSarifUri(uri),\n startLine: region.startLine,\n endLine:\n typeof region.endLine === 'number' && region.endLine >= region.startLine\n ? region.endLine\n : region.startLine,\n rule,\n severity,\n message,\n }\n if (typeof region.startColumn === 'number') finding.startColumn = region.startColumn\n if (typeof region.endColumn === 'number') finding.endColumn = region.endColumn\n findings.push(finding)\n }\n }\n }\n return findings\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,oBAAkC;;;ACH3C,SAAS,qBAAqB;AA4BvB,SAAS,kBAAkB,KAAqB;AACrD,MAAI,IAAI,WAAW,SAAS,GAAG;AAC7B,QAAI;AACF,aAAO,cAAc,GAAG;AAAA,IAC1B,QAAQ;AAAA,IAER;AAAA,EACF;AACA,SAAO,mBAAmB,GAAG,EAAE,QAAQ,OAAO,GAAG;AACnD;AAEO,SAAS,iBAAiB,OAA2B;AAC1D,QAAM,OAAQ,OAA2B;AACzC,MAAI,CAAC,MAAM,QAAQ,IAAI,EAAG,QAAO,CAAC;AAElC,QAAM,WAAsB,CAAC;AAC7B,aAAW,OAAO,MAAM;AACtB,eAAW,UAAU,IAAI,WAAW,CAAC,GAAG;AACtC,YAAM,OAAO,OAAO;AACpB,UAAI,CAAC,KAAM;AAEX,YAAM,WAAqB,OAAO,UAAU,UAAU,UAAU;AAChE,YAAM,UAAU,OAAO,SAAS,QAAQ;AAExC,iBAAW,YAAY,OAAO,aAAa,CAAC,GAAG;AAC7C,cAAM,MAAM,SAAS,kBAAkB,kBAAkB;AACzD,cAAM,SAAS,SAAS,kBAAkB;AAC1C,YAAI,CAAC,OAAO,OAAO,QAAQ,cAAc,SAAU;AAEnD,cAAM,UAAmB;AAAA,UACvB,MAAM,kBAAkB,GAAG;AAAA,UAC3B,WAAW,OAAO;AAAA,UAClB,SACE,OAAO,OAAO,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,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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diff-cov/oxlint",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Oxlint 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/oxlint"
|
|
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
|
+
"oxlint"
|
|
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.1"
|
|
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
|
}
|