@scalar/cli 2.8.0 → 2.11.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/README.md +84 -1076
- package/chunks/action-25QMCP5G.js +122 -0
- package/chunks/{action-354TUG4H.js → action-2VF6LODL.js} +20 -16
- package/chunks/{action-XIUO64C7.js → action-5I4XDPPG.js} +20 -14
- package/chunks/action-6M5PTDF6.js +100 -0
- package/chunks/{action-NVI5DWFP.js → action-73ELLN3T.js} +8 -11
- package/chunks/{action-Y6NXJQ4H.js → action-7H3AWCHX.js} +21 -16
- package/chunks/{action-LLH4QPXM.js → action-BRSLSOE5.js} +19 -18
- package/chunks/{action-EOAVVL52.js → action-CQQCKSNS.js} +17 -22
- package/chunks/action-D5QWDNQ2.js +65 -0
- package/chunks/{action-Y7OUGD56.js → action-DQDHBOLJ.js} +34 -31
- package/chunks/{action-5SK5NE7E.js → action-EYPYQQVM.js} +18 -23
- package/chunks/{action-YRX6SN5F.js → action-FMA5ECUA.js} +12 -10
- package/chunks/{action-7PEQXDWT.js → action-GXDJLF2G.js} +134 -25
- package/chunks/action-HUICEXJZ.js +75 -0
- package/chunks/action-IH6G77C5.js +38 -0
- package/chunks/{action-H3RTILLM.js → action-IIQMZVRJ.js} +1 -1
- package/chunks/action-IQM54ITT.js +164 -0
- package/chunks/{action-UIKH4SZX.js → action-J5TO3UJW.js} +32 -26
- package/chunks/{action-H6OUJWWM.js → action-KC3ZCNDR.js} +17 -22
- package/chunks/{action-6BYGBXRC.js → action-L7TMS3Q3.js} +44 -37
- package/chunks/{action-GWXLHL2Z.js → action-LAAHRDSR.js} +5 -4
- package/chunks/{action-FCAYFPVR.js → action-LR75GHBA.js} +14 -11
- package/chunks/action-MJMLQFLT.js +1552 -0
- package/chunks/action-NHU4CUKT.js +130 -0
- package/chunks/action-NKTFNFU7.js +64 -0
- package/chunks/{action-F7A2K74G.js → action-NMW5WPD2.js} +12 -16
- package/chunks/{action-VOFDW3U2.js → action-OTPXODUE.js} +8 -7
- package/chunks/{action-43YBNBDR.js → action-RPCDNGCI.js} +54 -39
- package/chunks/{action-QQZLPI42.js → action-RQCXSJPZ.js} +55 -27
- package/chunks/action-SOYSVG67.js +147 -0
- package/chunks/action-Y7EBKCUU.js +16 -0
- package/chunks/{action-WFDNRA7D.js → action-YN4TE7TG.js} +24 -23
- package/chunks/{action-AQRPFQKI.js → action-ZGNVWTHZ.js} +14 -12
- package/chunks/action-ZKKRPLDK.js +64 -0
- package/chunks/{action-HT2DJ34Z.js → action-ZUZL7R3H.js} +20 -15
- package/chunks/{actions-OGIVBQC7.js → actions-S6K76HCW.js} +46 -19
- package/chunks/{agent-ASPV3R5U.js → agent-IRNEV4K5.js} +46 -9
- package/chunks/{asyncapi-QNFKXHEI.js → asyncapi-WQPIQMEZ.js} +15 -10
- package/chunks/{build.action-NM6CAE5F.js → build.action-CLBVKFWD.js} +28 -24
- package/chunks/chunk-25XERWCE.js +1058 -0
- package/chunks/chunk-3RIUDHLG.js +467 -0
- package/chunks/{chunk-MLSZVVTT.js → chunk-3TFOA64C.js} +19 -8
- package/chunks/{chunk-HGOD6THU.js → chunk-4JKXZ5CF.js} +12 -25
- package/chunks/{chunk-C2KAWRIX.js → chunk-5ENKYZA4.js} +1 -1
- package/chunks/{chunk-W24BETFG.js → chunk-5L7V7RCH.js} +10 -10
- package/chunks/chunk-6PSYZO3U.js +24 -0
- package/chunks/{chunk-IMG35UXX.js → chunk-ALYM4ZB2.js} +1 -1
- package/chunks/chunk-AVZFSWPD.js +37 -0
- package/chunks/{chunk-5UHLAJQD.js → chunk-BQYVSPAI.js} +36 -10
- package/chunks/{chunk-XXSQUBXS.js → chunk-CSSTCHHF.js} +6212 -4642
- package/chunks/chunk-DFOZG7ZV.js +15 -0
- package/chunks/{chunk-22HYZ7LE.js → chunk-DQD2753S.js} +3 -3
- package/chunks/{action-F2ZJNURT.js → chunk-EBNFCIKS.js} +7 -10
- package/chunks/{chunk-EXY3ZTV4.js → chunk-F3OPMYME.js} +143 -301
- package/chunks/{chunk-FDC2IESH.js → chunk-FG5AOTDN.js} +8519 -14702
- package/chunks/chunk-GKCVATQJ.js +92 -0
- package/chunks/{chunk-PH3WFNXJ.js → chunk-GMHIK5K2.js} +1 -1
- package/chunks/{chunk-GTV2BVXV.js → chunk-GYR5E6RB.js} +2 -2
- package/chunks/{chunk-OJ2EWIJH.js → chunk-HZN6IIPZ.js} +11 -6
- package/chunks/{chunk-IKT5F47M.js → chunk-I57ID5K7.js} +24 -11
- package/chunks/{chunk-BPGFSSUH.js → chunk-KOD2HX5I.js} +1 -1
- package/chunks/{chunk-L3UXDCBI.js → chunk-LOLVJNI5.js} +4 -4
- package/chunks/{chunk-KCCFN4F7.js → chunk-MN2AFJXM.js} +36 -29
- package/chunks/{chunk-UXJ753NV.js → chunk-N5CJ5MTY.js} +5 -13
- package/chunks/chunk-NAC63XJF.js +10 -0
- package/chunks/{chunk-2OCWX42S.js → chunk-NWJ37GI2.js} +166 -22
- package/chunks/{chunk-3ZJYGGAA.js → chunk-ORCUZITN.js} +1 -1
- package/chunks/chunk-QMLRYD76.js +24 -0
- package/chunks/{chunk-KKRGBXCE.js → chunk-SEURG74P.js} +303 -209
- package/chunks/{chunk-R5LK6VPY.js → chunk-SOV4POMS.js} +370 -264
- package/chunks/chunk-T34TL6KL.js +222 -0
- package/chunks/{chunk-5DEU2DVL.js → chunk-U6VE6JOS.js} +3 -15
- package/chunks/{chunk-YILQODZF.js → chunk-UFSFY7Z4.js} +23 -20
- package/chunks/{chunk-6YPQGVF4.js → chunk-ULRJZXMS.js} +1 -1
- package/chunks/chunk-US54KYOJ.js +131 -0
- package/chunks/chunk-V6LUKXBV.js +37 -0
- package/chunks/{chunk-5JLVQVKO.js → chunk-VRZSDUZK.js} +190 -152
- package/chunks/chunk-VUXPDHTQ.js +22 -0
- package/chunks/chunk-XP5UM7SF.js +21 -0
- package/chunks/chunk-Y6XGC4K5.js +311 -0
- package/chunks/{create.action-FUQ2BVJA.js → create.action-ITEOQ644.js} +34 -30
- package/chunks/{delete.action-47E66R3I.js → delete.action-77MFPLUN.js} +30 -26
- package/chunks/{delete.action-BTDFH7WY.js → delete.action-C6VX4S5Q.js} +30 -26
- package/chunks/{get.action-XC7KC2JO.js → get.action-3BP4FHZC.js} +20 -14
- package/chunks/get.action-LNBOWUVE.js +95 -0
- package/chunks/list.action-6CRFQPJT.js +156 -0
- package/chunks/list.action-KR5YIDR4.js +126 -0
- package/chunks/{publish.action-OS27XOX4.js → publish.action-YBORRPBM.js} +49 -42
- package/chunks/query-WKATAJJ6.js +129 -0
- package/chunks/scripts-6CI6U32J.js +102 -0
- package/chunks/{update.action-AEIBLCWD.js → update.action-O7TSXDGV.js} +34 -27
- package/chunks/{update.action-ZMS4CQ3T.js → update.action-QZI7M2MV.js} +34 -27
- package/index.js +579 -382
- package/package.json +15 -14
- package/skills/scalar-cli/SKILL.md +52 -46
- package/template.md +71 -136
- package/chunks/action-CA4QYPI6.js +0 -125
- package/chunks/action-JAHFRYWZ.js +0 -423
- package/chunks/action-KTYOCA2V.js +0 -229
- package/chunks/action-LEUD5P2U.js +0 -92
- package/chunks/action-LXGXKXZZ.js +0 -72
- package/chunks/action-W3C53GPH.js +0 -54
- package/chunks/action-YLF2G4G5.js +0 -37
- package/chunks/chunk-6XWCMJDB.js +0 -404
- package/chunks/chunk-K74E42RV.js +0 -7311
- package/chunks/chunk-QVQ4PNVL.js +0 -610
- package/chunks/chunk-XEDGMZJD.js +0 -366
- package/chunks/list.action-LXKEUYKO.js +0 -116
- package/chunks/list.action-OFGLMRE7.js +0 -95
- package/docs.html +0 -6245
|
@@ -0,0 +1,1552 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
isAsyncApiContent
|
|
4
|
+
} from "./chunk-QMLRYD76.js";
|
|
5
|
+
import {
|
|
6
|
+
err,
|
|
7
|
+
ok
|
|
8
|
+
} from "./chunk-5ENKYZA4.js";
|
|
9
|
+
import {
|
|
10
|
+
package_default
|
|
11
|
+
} from "./chunk-US54KYOJ.js";
|
|
12
|
+
import "./chunk-MN2AFJXM.js";
|
|
13
|
+
import "./chunk-25XERWCE.js";
|
|
14
|
+
import "./chunk-AVZFSWPD.js";
|
|
15
|
+
import "./chunk-I57ID5K7.js";
|
|
16
|
+
import "./chunk-3MZYUBJ6.js";
|
|
17
|
+
|
|
18
|
+
// src/domains/document/lint/action.ts
|
|
19
|
+
import { writeFile as writeFile3 } from "node:fs/promises";
|
|
20
|
+
import { resolve as resolve5 } from "node:path";
|
|
21
|
+
|
|
22
|
+
// ../../packages/api-document-lint/dist/constants.js
|
|
23
|
+
var DEFAULT_RULESET = `extends: spectral:oas
|
|
24
|
+
rules: {}`;
|
|
25
|
+
var ASYNCAPI_RULESET = `extends: spectral:asyncapi
|
|
26
|
+
rules: {}`;
|
|
27
|
+
|
|
28
|
+
// ../../packages/api-document-lint/dist/default-ruleset.js
|
|
29
|
+
function isAsyncApiContent2(content) {
|
|
30
|
+
const head = content.slice(0, 500);
|
|
31
|
+
if (head.includes('"asyncapi"')) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return head.split("\n").some((line) => /^asyncapi\s*:/.test(line.trimStart()));
|
|
35
|
+
}
|
|
36
|
+
function defaultRulesetFor(content) {
|
|
37
|
+
return isAsyncApiContent2(content) ? ASYNCAPI_RULESET : DEFAULT_RULESET;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ../../packages/api-document-lint/dist/run-spectral.js
|
|
41
|
+
import spectralCore from "@stoplight/spectral-core";
|
|
42
|
+
import spectralParsers from "@stoplight/spectral-parsers";
|
|
43
|
+
import { bundleAndLoadRuleset } from "@stoplight/spectral-ruleset-bundler/with-loader";
|
|
44
|
+
import "@stoplight/spectral-rulesets";
|
|
45
|
+
var { Spectral, Document } = spectralCore;
|
|
46
|
+
var { Yaml } = spectralParsers;
|
|
47
|
+
async function runSpectral(input) {
|
|
48
|
+
const rulesetSource = input.ruleset && input.ruleset.trim().length > 0 ? input.ruleset : defaultRulesetFor(input.document);
|
|
49
|
+
const ruleset = await loadRuleset(rulesetSource);
|
|
50
|
+
if (!ruleset.ok) {
|
|
51
|
+
return ruleset;
|
|
52
|
+
}
|
|
53
|
+
const spectral = new Spectral();
|
|
54
|
+
spectral.setRuleset(ruleset.data);
|
|
55
|
+
const diagnostics = await spectral.run(input.source ? new Document(input.document, Yaml, input.source) : input.document).catch((error) => error instanceof Error ? error : new Error(String(error)));
|
|
56
|
+
if (diagnostics instanceof Error) {
|
|
57
|
+
return err(`Spectral failed to lint the document \u2014 ${diagnostics.message}`);
|
|
58
|
+
}
|
|
59
|
+
return ok(diagnostics);
|
|
60
|
+
}
|
|
61
|
+
async function loadRuleset(source) {
|
|
62
|
+
const ruleset = await bundleAndLoadRuleset("/.spectral.yaml", {
|
|
63
|
+
fs: {
|
|
64
|
+
promises: {
|
|
65
|
+
// @ts-expect-error The loader only ever reads our single virtual file.
|
|
66
|
+
async readFile() {
|
|
67
|
+
return source;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
format: "esm"
|
|
72
|
+
}).catch((error) => error instanceof Error ? error : new Error(String(error)));
|
|
73
|
+
if (ruleset instanceof Error) {
|
|
74
|
+
return err(`Failed to load ruleset \u2014 ${ruleset.message}`);
|
|
75
|
+
}
|
|
76
|
+
return ok(ruleset);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ../../packages/api-document-lint/dist/run-vacuum.js
|
|
80
|
+
import { execFile } from "node:child_process";
|
|
81
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
82
|
+
import { tmpdir } from "node:os";
|
|
83
|
+
import { dirname as dirname2, join as join2, resolve } from "node:path";
|
|
84
|
+
import { fileURLToPath } from "node:url";
|
|
85
|
+
import { promisify } from "node:util";
|
|
86
|
+
|
|
87
|
+
// ../../packages/api-document-lint/dist/normalize-diagnostics.js
|
|
88
|
+
var EMPTY_RANGE = {
|
|
89
|
+
start: { line: 0, character: 0 },
|
|
90
|
+
end: { line: 0, character: 0 }
|
|
91
|
+
};
|
|
92
|
+
function normalizeDiagnostics(raw) {
|
|
93
|
+
if (!Array.isArray(raw)) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
return raw.filter(isObject).map((item) => {
|
|
97
|
+
const source = item.source;
|
|
98
|
+
return {
|
|
99
|
+
code: isCode(item.code) ? item.code : "",
|
|
100
|
+
message: typeof item.message === "string" ? item.message : "",
|
|
101
|
+
severity: normalizeSeverity(item.severity),
|
|
102
|
+
path: Array.isArray(item.path) ? item.path.filter(isSegment) : [],
|
|
103
|
+
range: normalizeRange(item.range),
|
|
104
|
+
...typeof source === "string" ? { source } : {},
|
|
105
|
+
...Array.isArray(item.locations) ? {
|
|
106
|
+
locations: item.locations.filter(isLocation).map((location) => ({
|
|
107
|
+
source: location.source,
|
|
108
|
+
path: location.path,
|
|
109
|
+
range: normalizeRange(location.range)
|
|
110
|
+
}))
|
|
111
|
+
} : {},
|
|
112
|
+
...typeof item.documentationUrl === "string" ? { documentationUrl: item.documentationUrl } : {}
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function isObject(value) {
|
|
117
|
+
return typeof value === "object" && value !== null;
|
|
118
|
+
}
|
|
119
|
+
function isCode(value) {
|
|
120
|
+
return typeof value === "string" || typeof value === "number";
|
|
121
|
+
}
|
|
122
|
+
function isSegment(value) {
|
|
123
|
+
return typeof value === "string" || typeof value === "number";
|
|
124
|
+
}
|
|
125
|
+
function normalizeRange(range) {
|
|
126
|
+
if (!isObject(range)) {
|
|
127
|
+
return EMPTY_RANGE;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
start: normalizePosition(range.start),
|
|
131
|
+
end: normalizePosition(range.end)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function normalizePosition(position) {
|
|
135
|
+
if (!isObject(position)) {
|
|
136
|
+
return { line: 0, character: 0 };
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
line: toCoordinate(position.line),
|
|
140
|
+
character: toCoordinate(position.character)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function toCoordinate(value) {
|
|
144
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : 0;
|
|
145
|
+
}
|
|
146
|
+
function normalizeSeverity(severity) {
|
|
147
|
+
return severity === 1 || severity === 2 || severity === 3 ? severity : 0;
|
|
148
|
+
}
|
|
149
|
+
function isLocation(value) {
|
|
150
|
+
return isObject(value) && typeof value.source === "string" && Array.isArray(value.path) && value.path.every(isSegment) && isObject(value.range);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ../../packages/api-document-lint/dist/resolve-binary.js
|
|
154
|
+
import { statSync } from "node:fs";
|
|
155
|
+
import { createRequire } from "node:module";
|
|
156
|
+
import { dirname, join } from "node:path";
|
|
157
|
+
var binaryName = process.platform === "win32" ? "vacuum.exe" : "vacuum";
|
|
158
|
+
function resolveVacuumBinary(override) {
|
|
159
|
+
const explicit = override ?? process.env.VACUUM_BINARY;
|
|
160
|
+
if (explicit) {
|
|
161
|
+
return isFile(explicit) ? ok(explicit) : err(`vacuum binary not found at ${explicit}`);
|
|
162
|
+
}
|
|
163
|
+
const packaged = resolvePackagedBinary();
|
|
164
|
+
if (packaged) {
|
|
165
|
+
return ok(packaged);
|
|
166
|
+
}
|
|
167
|
+
return ok("vacuum");
|
|
168
|
+
}
|
|
169
|
+
function resolvePackagedBinary() {
|
|
170
|
+
try {
|
|
171
|
+
const require2 = createRequire(import.meta.url);
|
|
172
|
+
const packageJsonPath = require2.resolve("@quobix/vacuum/package.json");
|
|
173
|
+
const candidate = join(dirname(packageJsonPath), "bin", binaryName);
|
|
174
|
+
return isFile(candidate) ? candidate : null;
|
|
175
|
+
} catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function isFile(path) {
|
|
180
|
+
try {
|
|
181
|
+
return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
|
|
182
|
+
} catch {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ../../packages/api-document-lint/dist/validate-inline-document.js
|
|
188
|
+
import { parse } from "yaml";
|
|
189
|
+
function validateInlineDocument(document) {
|
|
190
|
+
const parsed = (() => {
|
|
191
|
+
try {
|
|
192
|
+
return ok(parse(document));
|
|
193
|
+
} catch {
|
|
194
|
+
return err("Document must be valid YAML or JSON before linting.");
|
|
195
|
+
}
|
|
196
|
+
})();
|
|
197
|
+
if (!parsed.ok)
|
|
198
|
+
return parsed;
|
|
199
|
+
const references2 = /* @__PURE__ */ new Set([
|
|
200
|
+
"$ref",
|
|
201
|
+
"$dynamicRef",
|
|
202
|
+
"$recursiveRef",
|
|
203
|
+
"operationRef"
|
|
204
|
+
]);
|
|
205
|
+
const seen = /* @__PURE__ */ new Set();
|
|
206
|
+
const pending = [parsed.data];
|
|
207
|
+
while (pending.length) {
|
|
208
|
+
const value = pending.pop();
|
|
209
|
+
if (!value || typeof value !== "object" || seen.has(value))
|
|
210
|
+
continue;
|
|
211
|
+
seen.add(value);
|
|
212
|
+
for (const [key, child] of Object.entries(value)) {
|
|
213
|
+
if (references2.has(key) && typeof child === "string" && child !== "" && !child.startsWith("#")) {
|
|
214
|
+
return err("External references are not supported by hosted linting. Bundle the document first.");
|
|
215
|
+
}
|
|
216
|
+
if (child && typeof child === "object")
|
|
217
|
+
pending.push(child);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return ok(void 0);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ../../packages/api-document-lint/dist/run-vacuum.js
|
|
224
|
+
var execFileAsync = promisify(execFile);
|
|
225
|
+
var MAX_BUFFER = 64 * 1024 * 1024;
|
|
226
|
+
var TIMEOUT_MS = 6e4;
|
|
227
|
+
async function runVacuum(input, options = {}) {
|
|
228
|
+
if (input.document.trim().length === 0) {
|
|
229
|
+
return ok([]);
|
|
230
|
+
}
|
|
231
|
+
if (options.allowExternalReferences === false) {
|
|
232
|
+
const validation = validateInlineDocument(input.document);
|
|
233
|
+
if (!validation.ok)
|
|
234
|
+
return validation;
|
|
235
|
+
}
|
|
236
|
+
const binary = resolveVacuumBinary(options.binaryPath);
|
|
237
|
+
if (!binary.ok) {
|
|
238
|
+
return binary;
|
|
239
|
+
}
|
|
240
|
+
const directory = await mkdtemp(join2(tmpdir(), "scalar-lint-")).catch(() => null);
|
|
241
|
+
if (directory === null) {
|
|
242
|
+
return err("vacuum lint failed \u2014 could not create a temporary directory");
|
|
243
|
+
}
|
|
244
|
+
const documentPath = join2(directory, "document.yaml");
|
|
245
|
+
const reportPath = join2(directory, "report.json");
|
|
246
|
+
try {
|
|
247
|
+
const wroteDocument = await writeFile(documentPath, input.document, "utf8").then(() => true).catch(() => false);
|
|
248
|
+
if (!wroteDocument) {
|
|
249
|
+
return err("vacuum lint failed \u2014 could not write the document to a temporary file");
|
|
250
|
+
}
|
|
251
|
+
const args = [
|
|
252
|
+
"spectral-report",
|
|
253
|
+
"--no-style",
|
|
254
|
+
"--no-update-check",
|
|
255
|
+
"--skip-check",
|
|
256
|
+
// Match Spectral's working-directory base for document strings.
|
|
257
|
+
"--base",
|
|
258
|
+
options.allowExternalReferences === false ? directory : input.source ? /^https?:\/\//.test(input.source) ? new URL(".", input.source).href : dirname2(input.source) : process.cwd()
|
|
259
|
+
];
|
|
260
|
+
if (options.allowExternalReferences === false) {
|
|
261
|
+
const configPath = join2(directory, "vacuum.conf.yaml");
|
|
262
|
+
const configured = await writeFile(configPath, "{}").then(() => true).catch(() => false);
|
|
263
|
+
if (!configured)
|
|
264
|
+
return err("Could not create hosted lint configuration");
|
|
265
|
+
args.push("--remote=false", "--config", configPath);
|
|
266
|
+
}
|
|
267
|
+
if (input.ruleset && input.ruleset.trim().length > 0) {
|
|
268
|
+
const rulesetPath = join2(directory, "ruleset.yaml");
|
|
269
|
+
const wroteRuleset = await writeFile(rulesetPath, input.ruleset, "utf8").then(() => true).catch(() => false);
|
|
270
|
+
if (!wroteRuleset) {
|
|
271
|
+
return err("vacuum lint failed \u2014 could not write the ruleset to a temporary file");
|
|
272
|
+
}
|
|
273
|
+
args.push("--ruleset", rulesetPath);
|
|
274
|
+
}
|
|
275
|
+
args.push(documentPath, reportPath);
|
|
276
|
+
const failure = await execFileAsync(binary.data, args, {
|
|
277
|
+
maxBuffer: MAX_BUFFER,
|
|
278
|
+
timeout: options.timeoutMs ?? TIMEOUT_MS,
|
|
279
|
+
...options.allowExternalReferences === false ? { cwd: directory } : {}
|
|
280
|
+
}).then(() => null).catch((error) => error);
|
|
281
|
+
const report = await readFile(reportPath, "utf8").catch(() => null);
|
|
282
|
+
if (report === null) {
|
|
283
|
+
if (failure === null) {
|
|
284
|
+
return err("vacuum ran but its report could not be read");
|
|
285
|
+
}
|
|
286
|
+
return err(`vacuum failed to lint the document \u2014 ${describeFailure(failure)}`);
|
|
287
|
+
}
|
|
288
|
+
const parsed = parseReport(report);
|
|
289
|
+
if (!parsed.ok) {
|
|
290
|
+
return parsed;
|
|
291
|
+
}
|
|
292
|
+
const diagnostics = normalizeDiagnostics(parsed.data);
|
|
293
|
+
if (!input.source)
|
|
294
|
+
return ok(diagnostics);
|
|
295
|
+
return ok(diagnostics.map((diagnostic) => {
|
|
296
|
+
const source = diagnostic.source;
|
|
297
|
+
const localSource = source?.startsWith("file:") ? fileURLToPath(source) : source;
|
|
298
|
+
return {
|
|
299
|
+
...diagnostic,
|
|
300
|
+
source: !localSource || resolve(localSource) === documentPath ? input.source : /^https?:\/\//.test(localSource) ? localSource : resolve(localSource)
|
|
301
|
+
};
|
|
302
|
+
}));
|
|
303
|
+
} finally {
|
|
304
|
+
await rm(directory, { recursive: true, force: true }).catch(() => void 0);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function describeFailure(failure) {
|
|
308
|
+
if (failure && typeof failure === "object") {
|
|
309
|
+
const stderr = failure.stderr;
|
|
310
|
+
if (typeof stderr === "string" && stderr.trim().length > 0) {
|
|
311
|
+
return stderr.trim();
|
|
312
|
+
}
|
|
313
|
+
if (failure instanceof Error) {
|
|
314
|
+
return failure.message;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return "no report was written";
|
|
318
|
+
}
|
|
319
|
+
function parseReport(report) {
|
|
320
|
+
try {
|
|
321
|
+
const parsed = JSON.parse(report);
|
|
322
|
+
if (!Array.isArray(parsed)) {
|
|
323
|
+
return err("vacuum produced a report in an unexpected shape");
|
|
324
|
+
}
|
|
325
|
+
return ok(parsed);
|
|
326
|
+
} catch {
|
|
327
|
+
return err("vacuum produced an unreadable report");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ../../packages/api-document-lint/dist/select-engine.js
|
|
332
|
+
import { parse as parseYaml } from "yaml";
|
|
333
|
+
function selectEngine(ruleset) {
|
|
334
|
+
if (!ruleset || ruleset.trim().length === 0) {
|
|
335
|
+
return "vacuum";
|
|
336
|
+
}
|
|
337
|
+
const parsed = parseRuleset(ruleset);
|
|
338
|
+
if (parsed === null) {
|
|
339
|
+
return "spectral";
|
|
340
|
+
}
|
|
341
|
+
if (hasCustomFunctions(parsed) || hasRuleCustomizations(parsed) || extendsUninspectableRuleset(parsed) || overridesRequireSpectral(parsed)) {
|
|
342
|
+
return "spectral";
|
|
343
|
+
}
|
|
344
|
+
return "vacuum";
|
|
345
|
+
}
|
|
346
|
+
function overridesRequireSpectral(ruleset) {
|
|
347
|
+
const overrides = ruleset.overrides;
|
|
348
|
+
if (!Array.isArray(overrides)) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
return overrides.some((entry) => isRecord(entry) && (hasCustomFunctions(entry) || hasRuleCustomizations(entry) || extendsUninspectableRuleset(entry)));
|
|
352
|
+
}
|
|
353
|
+
function hasRuleCustomizations(ruleset) {
|
|
354
|
+
return ruleset.rules !== void 0 && (!isRecord(ruleset.rules) || Object.keys(ruleset.rules).length > 0);
|
|
355
|
+
}
|
|
356
|
+
function isRecord(value) {
|
|
357
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
358
|
+
}
|
|
359
|
+
function parseRuleset(ruleset) {
|
|
360
|
+
try {
|
|
361
|
+
const value = parseYaml(ruleset);
|
|
362
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
} catch {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function hasCustomFunctions(ruleset) {
|
|
371
|
+
const functions = ruleset.functions;
|
|
372
|
+
if (Array.isArray(functions) && functions.length > 0) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
return typeof ruleset.functionsDir === "string" && ruleset.functionsDir.length > 0;
|
|
376
|
+
}
|
|
377
|
+
function extendsUninspectableRuleset(ruleset) {
|
|
378
|
+
const extended = ruleset.extends;
|
|
379
|
+
if (extended === void 0) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
const entries = Array.isArray(extended) ? extended : [extended];
|
|
383
|
+
return entries.some((entry) => !isBuiltInRuleset(entry));
|
|
384
|
+
}
|
|
385
|
+
function isBuiltInRuleset(entry) {
|
|
386
|
+
const source = Array.isArray(entry) ? entry[0] : entry;
|
|
387
|
+
return source === "spectral:oas" || source === "spectral:asyncapi";
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ../../packages/api-document-lint/dist/lint.js
|
|
391
|
+
async function lint(input, options = {}) {
|
|
392
|
+
const ruleset = input.ruleset && input.ruleset.trim().length > 0 ? input.ruleset : defaultRulesetFor(input.document);
|
|
393
|
+
const resolved = { ...input, ruleset };
|
|
394
|
+
const engine = selectEngine(ruleset);
|
|
395
|
+
const diagnostics = engine === "vacuum" ? await runVacuum(resolved, options) : await runSpectral(resolved);
|
|
396
|
+
if (!diagnostics.ok) {
|
|
397
|
+
return diagnostics;
|
|
398
|
+
}
|
|
399
|
+
return ok({ diagnostics: diagnostics.data, engine });
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// src/domains/document/lint/baseline.ts
|
|
403
|
+
import { randomUUID } from "node:crypto";
|
|
404
|
+
import { mkdir, readFile as readFile2, rename, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
405
|
+
import { dirname as dirname3, relative, resolve as resolve2, sep } from "node:path";
|
|
406
|
+
import { setTimeout } from "node:timers/promises";
|
|
407
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
408
|
+
import { parse as parse3, stringify } from "yaml";
|
|
409
|
+
|
|
410
|
+
// src/domains/document/lint/pointer.ts
|
|
411
|
+
function toPointer(path) {
|
|
412
|
+
return `#${path.map((segment) => `/${String(segment).replaceAll("~", "~0").replaceAll("/", "~1")}`).join("")}`;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// src/domains/document/lint/rule-mappings.ts
|
|
416
|
+
import { parse as parse2 } from "yaml";
|
|
417
|
+
var redoclyRuleMappings = {
|
|
418
|
+
"info-contact": { scalar: "info-contact", missingField: "contact" },
|
|
419
|
+
"info-license": { scalar: "info-license", missingField: "license" },
|
|
420
|
+
"operation-description": {
|
|
421
|
+
scalar: "operation-description",
|
|
422
|
+
missingField: "description"
|
|
423
|
+
},
|
|
424
|
+
"operation-operationId": {
|
|
425
|
+
scalar: "operation-operationId",
|
|
426
|
+
missingField: "operationId"
|
|
427
|
+
},
|
|
428
|
+
"operation-operationId-url-safe": {
|
|
429
|
+
scalar: "operation-operationId-valid-in-url"
|
|
430
|
+
},
|
|
431
|
+
"no-path-trailing-slash": { scalar: "path-keys-no-trailing-slash" },
|
|
432
|
+
"path-declaration-must-exist": { scalar: "path-declarations-must-exist" },
|
|
433
|
+
"path-not-include-query": { scalar: "path-not-include-query" },
|
|
434
|
+
"tag-description": { scalar: "tag-description", missingField: "description" },
|
|
435
|
+
"operation-singular-tag": { scalar: "operation-singular-tag" }
|
|
436
|
+
};
|
|
437
|
+
function supportsRedoclyMigration(ruleset) {
|
|
438
|
+
try {
|
|
439
|
+
const parsed = parse2(ruleset);
|
|
440
|
+
if (!isRecord2(parsed) || Object.keys(parsed).some((key) => !["extends", "rules"].includes(key)))
|
|
441
|
+
return false;
|
|
442
|
+
const extended = Array.isArray(parsed.extends) ? parsed.extends : [parsed.extends];
|
|
443
|
+
if (extended.length !== 1 || extended[0] !== "spectral:oas") return false;
|
|
444
|
+
if (parsed.rules === void 0) return true;
|
|
445
|
+
if (!isRecord2(parsed.rules)) return false;
|
|
446
|
+
const audited = new Set(
|
|
447
|
+
Object.values(redoclyRuleMappings).map((mapping) => mapping.scalar)
|
|
448
|
+
);
|
|
449
|
+
return Object.entries(parsed.rules).every(([rule, value]) => {
|
|
450
|
+
if (!audited.has(rule)) return false;
|
|
451
|
+
const severity = isRecord2(value) && Object.keys(value).length === 1 ? value.severity : value;
|
|
452
|
+
return [
|
|
453
|
+
"error",
|
|
454
|
+
"warn",
|
|
455
|
+
"info",
|
|
456
|
+
"hint",
|
|
457
|
+
"off",
|
|
458
|
+
0,
|
|
459
|
+
1,
|
|
460
|
+
2,
|
|
461
|
+
3,
|
|
462
|
+
-1,
|
|
463
|
+
true,
|
|
464
|
+
false
|
|
465
|
+
].some((allowed) => allowed === severity);
|
|
466
|
+
});
|
|
467
|
+
} catch {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
function isRecord2(value) {
|
|
472
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/domains/document/lint/baseline.ts
|
|
476
|
+
function sourceIdentity(source, directory) {
|
|
477
|
+
if (/^https?:\/\//.test(source)) return new URL(source).href;
|
|
478
|
+
const path = source.startsWith("file:") ? fileURLToPath2(source) : source;
|
|
479
|
+
return relative(directory, resolve2(path)).split(sep).join("/");
|
|
480
|
+
}
|
|
481
|
+
function findingIdentity(diagnostic, directory) {
|
|
482
|
+
return {
|
|
483
|
+
source: sourceIdentity(diagnostic.source ?? "", directory),
|
|
484
|
+
rule: String(diagnostic.code),
|
|
485
|
+
path: diagnostic.resolvedPath ?? diagnostic.path
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
function findingKey(finding) {
|
|
489
|
+
return JSON.stringify([finding.source, finding.rule, toPointer(finding.path)]);
|
|
490
|
+
}
|
|
491
|
+
function isRecord3(value) {
|
|
492
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
493
|
+
}
|
|
494
|
+
function isFinding(value) {
|
|
495
|
+
return isRecord3(value) && Object.keys(value).length === 3 && typeof value.source === "string" && typeof value.rule === "string" && Array.isArray(value.path) && value.path.every(
|
|
496
|
+
(segment) => typeof segment === "string" || typeof segment === "number" && Number.isInteger(segment) && segment >= 0
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
function isBaseline(value) {
|
|
500
|
+
return isRecord3(value) && Object.keys(value).length === 2 && value.version === 1 && Array.isArray(value.documents) && value.documents.every(
|
|
501
|
+
(document) => isRecord3(document) && Object.keys(document).every(
|
|
502
|
+
(key) => ["source", "findings", "imported"].includes(key)
|
|
503
|
+
) && (document.imported === void 0 || typeof document.imported === "boolean") && typeof document.source === "string" && Array.isArray(document.findings) && document.findings.every(isFinding)
|
|
504
|
+
) && new Set(value.documents.map((document) => document.source)).size === value.documents.length;
|
|
505
|
+
}
|
|
506
|
+
var OWNERS_PREFIX = "# scalar-owners: ";
|
|
507
|
+
function isIgnoreMap(value) {
|
|
508
|
+
return isRecord3(value) && Object.values(value).every(
|
|
509
|
+
(rules) => isRecord3(rules) && Object.values(rules).every(
|
|
510
|
+
(pointers) => Array.isArray(pointers) && pointers.every(
|
|
511
|
+
(pointer) => typeof pointer === "string" && /^#(?:\/(?:[^~]|~[01])*)*$/.test(pointer)
|
|
512
|
+
)
|
|
513
|
+
)
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
function fromIgnoreMap(mapping, owners, directory) {
|
|
517
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
518
|
+
for (const [input, rules] of Object.entries(mapping)) {
|
|
519
|
+
const source = sourceIdentity(
|
|
520
|
+
/^https?:\/\//.test(input) ? input : resolve2(directory, input),
|
|
521
|
+
directory
|
|
522
|
+
);
|
|
523
|
+
const document = normalized.get(source) ?? { source, findings: [] };
|
|
524
|
+
document.findings.push(
|
|
525
|
+
...Object.entries(rules).flatMap(
|
|
526
|
+
([rule, pointers]) => pointers.map((pointer) => ({
|
|
527
|
+
source,
|
|
528
|
+
rule,
|
|
529
|
+
path: pointer === "#" ? [] : pointer.slice(2).split("/").map(
|
|
530
|
+
(segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")
|
|
531
|
+
)
|
|
532
|
+
}))
|
|
533
|
+
)
|
|
534
|
+
);
|
|
535
|
+
normalized.set(source, document);
|
|
536
|
+
}
|
|
537
|
+
const documents = [...normalized.values()];
|
|
538
|
+
if (owners === void 0)
|
|
539
|
+
return {
|
|
540
|
+
version: 1,
|
|
541
|
+
documents: documents.map((document) => ({ ...document, imported: true }))
|
|
542
|
+
};
|
|
543
|
+
const available = new Set(
|
|
544
|
+
documents.flatMap((document) => document.findings.map(findingKey))
|
|
545
|
+
);
|
|
546
|
+
const owned = owners.documents.map((document) => ({
|
|
547
|
+
...document,
|
|
548
|
+
findings: document.findings.filter(
|
|
549
|
+
(finding) => available.has(findingKey(finding))
|
|
550
|
+
)
|
|
551
|
+
}));
|
|
552
|
+
const assigned = new Set(
|
|
553
|
+
owned.flatMap((document) => document.findings.map(findingKey))
|
|
554
|
+
);
|
|
555
|
+
const result = new Map(owned.map((document) => [document.source, document]));
|
|
556
|
+
for (const document of documents) {
|
|
557
|
+
const additions = document.findings.filter(
|
|
558
|
+
(finding) => !assigned.has(findingKey(finding))
|
|
559
|
+
);
|
|
560
|
+
if (additions.length) {
|
|
561
|
+
const existing = result.get(document.source);
|
|
562
|
+
result.set(document.source, {
|
|
563
|
+
...existing,
|
|
564
|
+
source: document.source,
|
|
565
|
+
findings: [...existing?.findings ?? [], ...additions]
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return { version: 1, documents: [...result.values()] };
|
|
570
|
+
}
|
|
571
|
+
async function loadBaseline(path, required) {
|
|
572
|
+
const content = await readFile2(path, "utf8").catch((error) => error);
|
|
573
|
+
if (typeof content !== "string") {
|
|
574
|
+
if (!required && isRecord3(content) && content.code === "ENOENT") {
|
|
575
|
+
return ok({ version: 1, documents: [] });
|
|
576
|
+
}
|
|
577
|
+
return err(`Could not read ignore file: ${path}`);
|
|
578
|
+
}
|
|
579
|
+
try {
|
|
580
|
+
const parsed = parse3(content);
|
|
581
|
+
if (isBaseline(parsed)) return ok(parsed);
|
|
582
|
+
if (!isIgnoreMap(parsed))
|
|
583
|
+
return err(
|
|
584
|
+
`Invalid ignore file: ${path}. Expected source, rule, and JSON pointer mappings.`
|
|
585
|
+
);
|
|
586
|
+
const metadata = content.split("\n").find((line) => line.startsWith(OWNERS_PREFIX));
|
|
587
|
+
const owners = metadata ? JSON.parse(metadata.slice(OWNERS_PREFIX.length)) : void 0;
|
|
588
|
+
if (owners !== void 0 && !isBaseline(owners))
|
|
589
|
+
return err(`Invalid ownership metadata in ignore file: ${path}`);
|
|
590
|
+
return ok(fromIgnoreMap(parsed, owners, dirname3(path)));
|
|
591
|
+
} catch {
|
|
592
|
+
return err(`Invalid YAML or ownership metadata in ignore file: ${path}`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function updateBaseline(baseline, source, diagnostics, path) {
|
|
596
|
+
const directory = dirname3(path);
|
|
597
|
+
const owner = sourceIdentity(source, directory);
|
|
598
|
+
const findings = new Map(
|
|
599
|
+
diagnostics.map((diagnostic) => {
|
|
600
|
+
const finding = findingIdentity(diagnostic, directory);
|
|
601
|
+
return [findingKey(finding), finding];
|
|
602
|
+
})
|
|
603
|
+
);
|
|
604
|
+
return {
|
|
605
|
+
version: 1,
|
|
606
|
+
documents: [
|
|
607
|
+
...baseline.documents.filter((document) => document.source !== owner),
|
|
608
|
+
{
|
|
609
|
+
source: owner,
|
|
610
|
+
findings: [...findings.values()].sort(
|
|
611
|
+
(a, b) => findingKey(a).localeCompare(findingKey(b))
|
|
612
|
+
)
|
|
613
|
+
}
|
|
614
|
+
].sort((a, b) => a.source.localeCompare(b.source))
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
function applyBaseline(baseline, diagnostics, path, redoclyCompatibility = false) {
|
|
618
|
+
const ignored = new Set(
|
|
619
|
+
baseline.documents.flatMap((document) => document.findings.map(findingKey))
|
|
620
|
+
);
|
|
621
|
+
const imported = new Set(
|
|
622
|
+
baseline.documents.filter((document) => document.imported).flatMap((document) => document.findings.map(findingKey))
|
|
623
|
+
);
|
|
624
|
+
return diagnostics.filter((diagnostic) => {
|
|
625
|
+
if ([
|
|
626
|
+
findingIdentity(diagnostic, dirname3(path)),
|
|
627
|
+
{
|
|
628
|
+
...findingIdentity(diagnostic, dirname3(path)),
|
|
629
|
+
path: diagnostic.path
|
|
630
|
+
}
|
|
631
|
+
].some((finding) => ignored.has(findingKey(finding))))
|
|
632
|
+
return false;
|
|
633
|
+
return !redoclyCompatibility || !ignoreCandidates(diagnostic, dirname3(path)).some(
|
|
634
|
+
(finding) => imported.has(findingKey(finding))
|
|
635
|
+
);
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
async function writeBaseline(path, baseline) {
|
|
639
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
640
|
+
try {
|
|
641
|
+
const mapping = /* @__PURE__ */ Object.create(null);
|
|
642
|
+
for (const document of baseline.documents) {
|
|
643
|
+
for (const finding of document.findings) {
|
|
644
|
+
mapping[finding.source] ??= /* @__PURE__ */ Object.create(null);
|
|
645
|
+
const rules = mapping[finding.source];
|
|
646
|
+
rules[finding.rule] ??= [];
|
|
647
|
+
const pointers = rules[finding.rule];
|
|
648
|
+
const pointer = toPointer(finding.path);
|
|
649
|
+
if (!pointers.includes(pointer)) pointers.push(pointer);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
const sorted = /* @__PURE__ */ Object.create(null);
|
|
653
|
+
for (const source of Object.keys(mapping).sort()) {
|
|
654
|
+
const rules = /* @__PURE__ */ Object.create(null);
|
|
655
|
+
for (const rule of Object.keys(mapping[source] ?? {}).sort())
|
|
656
|
+
rules[rule] = [...mapping[source]?.[rule] ?? []].sort();
|
|
657
|
+
sorted[source] = rules;
|
|
658
|
+
}
|
|
659
|
+
const content = `# Ignore findings by source, rule, and JSON pointer.
|
|
660
|
+
${OWNERS_PREFIX}${JSON.stringify({ version: baseline.version, documents: baseline.documents })}
|
|
661
|
+
${stringify(sorted)}`;
|
|
662
|
+
await writeFile2(temporary, content, {
|
|
663
|
+
encoding: "utf8",
|
|
664
|
+
flag: "wx"
|
|
665
|
+
});
|
|
666
|
+
await rename(temporary, path);
|
|
667
|
+
return ok(void 0);
|
|
668
|
+
} catch {
|
|
669
|
+
return err(`Could not write ignore file: ${path}`);
|
|
670
|
+
} finally {
|
|
671
|
+
await rm2(temporary, { force: true }).catch(() => void 0);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
async function regenerateBaseline(path, source, diagnostics) {
|
|
675
|
+
const lock = `${path}.lock`;
|
|
676
|
+
const deadline = Date.now() + 1e4;
|
|
677
|
+
while (true) {
|
|
678
|
+
try {
|
|
679
|
+
await mkdir(lock);
|
|
680
|
+
break;
|
|
681
|
+
} catch (error) {
|
|
682
|
+
if (!isRecord3(error) || error.code !== "EEXIST")
|
|
683
|
+
return err(`Could not lock ignore file: ${path}`);
|
|
684
|
+
if (Date.now() >= deadline)
|
|
685
|
+
return err(
|
|
686
|
+
`Ignore file is locked: ${path}. Remove ${lock} only if no generator is running.`
|
|
687
|
+
);
|
|
688
|
+
await setTimeout(25);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
const result = await (async () => {
|
|
692
|
+
const loaded = await loadBaseline(path, false);
|
|
693
|
+
if (!loaded.ok) return loaded;
|
|
694
|
+
const baseline = updateBaseline(loaded.data, source, diagnostics, path);
|
|
695
|
+
const written = await writeBaseline(path, baseline);
|
|
696
|
+
return written.ok ? ok(baseline) : written;
|
|
697
|
+
})().catch(() => err(`Could not update ignore file: ${path}`));
|
|
698
|
+
const released = await rm2(lock, { recursive: true, force: true }).then(() => true).catch(() => false);
|
|
699
|
+
return released ? result : err(
|
|
700
|
+
`Could not release ignore file lock: ${lock}. Remove it only if no generator is running.`
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
function unsupportedRedoclyRules(baseline) {
|
|
704
|
+
return [
|
|
705
|
+
...new Set(
|
|
706
|
+
baseline.documents.filter((document) => document.imported).flatMap(
|
|
707
|
+
(document) => document.findings.map((finding) => finding.rule)
|
|
708
|
+
)
|
|
709
|
+
)
|
|
710
|
+
].filter((rule) => !Object.hasOwn(redoclyRuleMappings, rule)).sort();
|
|
711
|
+
}
|
|
712
|
+
function ignoreCandidates(diagnostic, directory) {
|
|
713
|
+
const primary = findingIdentity(diagnostic, directory);
|
|
714
|
+
const rules = Object.entries(redoclyRuleMappings).filter(
|
|
715
|
+
([, mapping]) => mapping.scalar === primary.rule
|
|
716
|
+
);
|
|
717
|
+
const candidates = [primary];
|
|
718
|
+
for (const [redocly, mapping] of rules) {
|
|
719
|
+
candidates.push({ ...primary, rule: redocly });
|
|
720
|
+
const field = mapping.missingField;
|
|
721
|
+
if (field && primary.path.at(-1) !== field)
|
|
722
|
+
candidates.push({
|
|
723
|
+
...primary,
|
|
724
|
+
rule: redocly,
|
|
725
|
+
path: [...primary.path, field]
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
return candidates;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// src/domains/document/lint/document-paths.ts
|
|
732
|
+
import {
|
|
733
|
+
isAlias,
|
|
734
|
+
isMap,
|
|
735
|
+
isScalar,
|
|
736
|
+
isSeq,
|
|
737
|
+
LineCounter,
|
|
738
|
+
parseDocument
|
|
739
|
+
} from "yaml";
|
|
740
|
+
|
|
741
|
+
// src/domains/document/lint/reference.ts
|
|
742
|
+
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
743
|
+
function resolveReference(ref, source) {
|
|
744
|
+
try {
|
|
745
|
+
const url = new URL(
|
|
746
|
+
ref,
|
|
747
|
+
/^https?:\/\//.test(source) ? source : pathToFileURL(source)
|
|
748
|
+
);
|
|
749
|
+
const fragment = decodeURIComponent(url.hash.slice(1));
|
|
750
|
+
if (fragment !== "" && !/^\/(?:[^~]|~[01])*$/.test(fragment))
|
|
751
|
+
return err("Reference is not a JSON pointer");
|
|
752
|
+
const path = fragment === "" ? [] : fragment.slice(1).split("/").map(
|
|
753
|
+
(segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")
|
|
754
|
+
);
|
|
755
|
+
url.hash = "";
|
|
756
|
+
if (!["file:", "http:", "https:"].includes(url.protocol))
|
|
757
|
+
return err("Unsupported reference protocol");
|
|
758
|
+
return ok({
|
|
759
|
+
source: url.protocol === "file:" ? fileURLToPath3(url) : url.href,
|
|
760
|
+
path
|
|
761
|
+
});
|
|
762
|
+
} catch {
|
|
763
|
+
return err("Invalid reference URI");
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// src/domains/document/lint/document-paths.ts
|
|
768
|
+
function resolveDiagnosticPaths(diagnostics, sources, engine) {
|
|
769
|
+
if (engine !== "vacuum") return diagnostics;
|
|
770
|
+
const documents = /* @__PURE__ */ new Map();
|
|
771
|
+
const counters = /* @__PURE__ */ new Map();
|
|
772
|
+
const keys = [];
|
|
773
|
+
for (const [source, content] of sources) {
|
|
774
|
+
if (content === void 0) continue;
|
|
775
|
+
const counter = new LineCounter();
|
|
776
|
+
const document = parseDocument(content, { lineCounter: counter });
|
|
777
|
+
if (!document.errors.length) {
|
|
778
|
+
documents.set(source, document);
|
|
779
|
+
counters.set(source, counter);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
const mounts = [];
|
|
783
|
+
const active = /* @__PURE__ */ new Set();
|
|
784
|
+
function visit(value, source, physical, reported) {
|
|
785
|
+
const document = documents.get(source);
|
|
786
|
+
const node = isAlias(value) && document ? value.resolve(document) : value;
|
|
787
|
+
if (!(isMap(node) || isSeq(node)) || active.has(node)) return;
|
|
788
|
+
active.add(node);
|
|
789
|
+
if (isMap(node)) {
|
|
790
|
+
const ref = node.get("$ref");
|
|
791
|
+
if (typeof ref === "string") {
|
|
792
|
+
const target = resolveReference(ref, source);
|
|
793
|
+
if (target.ok) {
|
|
794
|
+
const destination = documents.get(target.data.source);
|
|
795
|
+
const contents = target.data.path.length ? destination?.getIn(target.data.path, true) : destination?.contents;
|
|
796
|
+
if (contents !== void 0) {
|
|
797
|
+
mounts.push({
|
|
798
|
+
source: target.data.source,
|
|
799
|
+
physical: target.data.path,
|
|
800
|
+
reported
|
|
801
|
+
});
|
|
802
|
+
visit(contents, target.data.source, target.data.path, reported);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
for (const pair of node.items) {
|
|
807
|
+
if (isScalar(pair.key) && typeof pair.key.value === "string") {
|
|
808
|
+
const position = pair.key.range ? counters.get(source)?.linePos(pair.key.range[0]) : void 0;
|
|
809
|
+
if (position)
|
|
810
|
+
keys.push({
|
|
811
|
+
source,
|
|
812
|
+
path: [...physical, pair.key.value],
|
|
813
|
+
line: position.line,
|
|
814
|
+
character: position.col
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
if (isScalar(pair.key) && typeof pair.key.value === "string" && pair.key.value !== "$ref")
|
|
818
|
+
visit(
|
|
819
|
+
pair.value,
|
|
820
|
+
source,
|
|
821
|
+
[...physical, pair.key.value],
|
|
822
|
+
[...reported, pair.key.value]
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
} else {
|
|
826
|
+
node.items.forEach((child, index) => {
|
|
827
|
+
visit(child, source, [...physical, index], [...reported, index]);
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
active.delete(node);
|
|
831
|
+
}
|
|
832
|
+
const root = sources.keys().next().value;
|
|
833
|
+
if (root) visit(documents.get(root)?.contents, root, [], []);
|
|
834
|
+
function containsLocation(source, path, diagnostic) {
|
|
835
|
+
if (keys.some(
|
|
836
|
+
(key) => key.source === source && JSON.stringify(key.path) === JSON.stringify(path) && key.line === diagnostic.range.start.line && key.character === diagnostic.range.start.character
|
|
837
|
+
))
|
|
838
|
+
return true;
|
|
839
|
+
const document = documents.get(source);
|
|
840
|
+
const counter = counters.get(source);
|
|
841
|
+
const line = counter?.lineStarts[diagnostic.range.start.line - 1];
|
|
842
|
+
if (!document || line === void 0) return false;
|
|
843
|
+
const offset = line + Math.max(0, diagnostic.range.start.character - 1);
|
|
844
|
+
const node = path.map(
|
|
845
|
+
(_, index) => document.getIn(path.slice(0, path.length - index), true)
|
|
846
|
+
).find((node2) => node2 !== void 0);
|
|
847
|
+
if (typeof node !== "object" || node === null || !("range" in node) || !Array.isArray(node.range))
|
|
848
|
+
return false;
|
|
849
|
+
const [start, end] = node.range;
|
|
850
|
+
return typeof start === "number" && typeof end === "number" && offset >= start && offset <= end;
|
|
851
|
+
}
|
|
852
|
+
mounts.sort((a, b) => b.reported.length - a.reported.length);
|
|
853
|
+
return diagnostics.map((diagnostic) => {
|
|
854
|
+
if (diagnostic.resolvedPath) return diagnostic;
|
|
855
|
+
if ([
|
|
856
|
+
"path-keys-no-trailing-slash",
|
|
857
|
+
"path-declarations-must-exist",
|
|
858
|
+
"path-not-include-query"
|
|
859
|
+
].includes(String(diagnostic.code))) {
|
|
860
|
+
const key = keys.find(
|
|
861
|
+
(key2) => key2.source === diagnostic.source && key2.line === diagnostic.range.start.line && key2.character === diagnostic.range.start.character
|
|
862
|
+
);
|
|
863
|
+
if (key) return { ...diagnostic, resolvedPath: key.path };
|
|
864
|
+
}
|
|
865
|
+
const mount = mounts.find(
|
|
866
|
+
(mount2) => mount2.source === diagnostic.source && diagnostic.path.length >= mount2.reported.length && mount2.reported.every(
|
|
867
|
+
(segment, index) => String(diagnostic.path[index]) === String(segment)
|
|
868
|
+
) && containsLocation(
|
|
869
|
+
mount2.source,
|
|
870
|
+
[...mount2.physical, ...diagnostic.path.slice(mount2.reported.length)],
|
|
871
|
+
diagnostic
|
|
872
|
+
)
|
|
873
|
+
);
|
|
874
|
+
if (!mount) return diagnostic;
|
|
875
|
+
const resolvedPath = [
|
|
876
|
+
...mount.physical,
|
|
877
|
+
...diagnostic.path.slice(mount.reported.length)
|
|
878
|
+
];
|
|
879
|
+
return { ...diagnostic, resolvedPath };
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// src/domains/document/lint/ignore-path.ts
|
|
884
|
+
import { lstat } from "node:fs/promises";
|
|
885
|
+
import { resolve as resolve3 } from "node:path";
|
|
886
|
+
async function selectIgnorePath(explicit, generate) {
|
|
887
|
+
if (explicit) return ok(resolve3(explicit));
|
|
888
|
+
const scalar = resolve3(".scalar.lint-ignore.yaml");
|
|
889
|
+
if (generate) return ok(scalar);
|
|
890
|
+
try {
|
|
891
|
+
await lstat(scalar);
|
|
892
|
+
return ok(scalar);
|
|
893
|
+
} catch (error) {
|
|
894
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"))
|
|
895
|
+
return err("Could not inspect default ignore file");
|
|
896
|
+
}
|
|
897
|
+
const redocly = resolve3(".redocly.lint-ignore.yaml");
|
|
898
|
+
try {
|
|
899
|
+
await lstat(redocly);
|
|
900
|
+
return ok(redocly);
|
|
901
|
+
} catch (error) {
|
|
902
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"))
|
|
903
|
+
return err("Could not inspect default ignore file");
|
|
904
|
+
return ok(scalar);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/domains/document/lint/locations.ts
|
|
909
|
+
import { isAlias as isAlias2, isMap as isMap2, LineCounter as LineCounter2, parseDocument as parseDocument2 } from "yaml";
|
|
910
|
+
var METHODS = /* @__PURE__ */ new Set([
|
|
911
|
+
"get",
|
|
912
|
+
"put",
|
|
913
|
+
"post",
|
|
914
|
+
"delete",
|
|
915
|
+
"options",
|
|
916
|
+
"head",
|
|
917
|
+
"patch",
|
|
918
|
+
"trace",
|
|
919
|
+
"query"
|
|
920
|
+
]);
|
|
921
|
+
function addRelatedLocations(diagnostics, sources, engine) {
|
|
922
|
+
if (!diagnostics.some(
|
|
923
|
+
(diagnostic) => diagnostic.code === "operation-operationId-unique"
|
|
924
|
+
))
|
|
925
|
+
return diagnostics;
|
|
926
|
+
const parsed = /* @__PURE__ */ new Map();
|
|
927
|
+
for (const [source, content] of sources) {
|
|
928
|
+
if (content === void 0) continue;
|
|
929
|
+
const counter = new LineCounter2();
|
|
930
|
+
const document = parseDocument2(content, { lineCounter: counter });
|
|
931
|
+
if (!document.errors.length) parsed.set(source, { document, counter });
|
|
932
|
+
}
|
|
933
|
+
const operations = [];
|
|
934
|
+
const visited = /* @__PURE__ */ new Set();
|
|
935
|
+
const active = /* @__PURE__ */ new Set();
|
|
936
|
+
function resolveYamlMap(value, source) {
|
|
937
|
+
const document = parsed.get(source)?.document;
|
|
938
|
+
const node = isAlias2(value) && document ? value.resolve(document) : value;
|
|
939
|
+
return isMap2(node) ? node : void 0;
|
|
940
|
+
}
|
|
941
|
+
function reference(ref, source) {
|
|
942
|
+
if (typeof ref !== "string") return void 0;
|
|
943
|
+
const target = resolveReference(ref, source);
|
|
944
|
+
if (!target.ok) return void 0;
|
|
945
|
+
const document = parsed.get(target.data.source)?.document;
|
|
946
|
+
return document ? {
|
|
947
|
+
...target.data,
|
|
948
|
+
node: target.data.path.length ? document.getIn(target.data.path, true) : document.contents
|
|
949
|
+
} : void 0;
|
|
950
|
+
}
|
|
951
|
+
function callbacks(value, source, path, reportedPath = path) {
|
|
952
|
+
const node = resolveYamlMap(value, source);
|
|
953
|
+
if (!node || active.has(node)) return;
|
|
954
|
+
const key = `callback:${source}:${toPointer(path)}:${toPointer(reportedPath)}`;
|
|
955
|
+
if (visited.has(key)) return;
|
|
956
|
+
visited.add(key);
|
|
957
|
+
active.add(node);
|
|
958
|
+
const target = reference(node.get("$ref"), source);
|
|
959
|
+
if (target) callbacks(target.node, target.source, target.path, reportedPath);
|
|
960
|
+
for (const pair of node.items) {
|
|
961
|
+
if (typeof pair.key === "object" && pair.key && "value" in pair.key && typeof pair.key.value === "string" && pair.key.value !== "$ref")
|
|
962
|
+
pathItem(
|
|
963
|
+
pair.value,
|
|
964
|
+
source,
|
|
965
|
+
[...path, pair.key.value],
|
|
966
|
+
[...reportedPath, pair.key.value]
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
active.delete(node);
|
|
970
|
+
}
|
|
971
|
+
function pathItem(value, source, path, reportedPath = path) {
|
|
972
|
+
const node = resolveYamlMap(value, source);
|
|
973
|
+
if (!node || active.has(node)) return;
|
|
974
|
+
const key = `path:${source}:${toPointer(path)}:${toPointer(reportedPath)}`;
|
|
975
|
+
if (visited.has(key)) return;
|
|
976
|
+
visited.add(key);
|
|
977
|
+
active.add(node);
|
|
978
|
+
const target = reference(node.get("$ref"), source);
|
|
979
|
+
if (target) pathItem(target.node, target.source, target.path, reportedPath);
|
|
980
|
+
for (const method of METHODS) {
|
|
981
|
+
const operation = resolveYamlMap(node.get(method, true), source);
|
|
982
|
+
if (!operation) continue;
|
|
983
|
+
const id = operation.get("operationId", true);
|
|
984
|
+
const counter = parsed.get(source)?.counter;
|
|
985
|
+
if (id && typeof id === "object" && "value" in id && typeof id.value === "string" && id.range && counter) {
|
|
986
|
+
const position = (offset) => {
|
|
987
|
+
const point = counter.linePos(offset);
|
|
988
|
+
const adjustment = engine === "spectral" ? 1 : 0;
|
|
989
|
+
return {
|
|
990
|
+
line: point.line - adjustment,
|
|
991
|
+
character: point.col - adjustment
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
operations.push({
|
|
995
|
+
id: id.value,
|
|
996
|
+
reportedPath: [...reportedPath, method],
|
|
997
|
+
source,
|
|
998
|
+
path: [...path, method, "operationId"],
|
|
999
|
+
range: { start: position(id.range[0]), end: position(id.range[1]) }
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
const entries = resolveYamlMap(operation.get("callbacks", true), source);
|
|
1003
|
+
for (const pair of entries?.items ?? []) {
|
|
1004
|
+
if (typeof pair.key === "object" && pair.key && "value" in pair.key && typeof pair.key.value === "string")
|
|
1005
|
+
callbacks(
|
|
1006
|
+
pair.value,
|
|
1007
|
+
source,
|
|
1008
|
+
[...path, method, "callbacks", pair.key.value],
|
|
1009
|
+
[...reportedPath, method, "callbacks", pair.key.value]
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
active.delete(node);
|
|
1014
|
+
}
|
|
1015
|
+
const rootSource = sources.keys().next().value;
|
|
1016
|
+
const root = rootSource ? resolveYamlMap(parsed.get(rootSource)?.document.contents, rootSource) : void 0;
|
|
1017
|
+
if (root && rootSource) {
|
|
1018
|
+
for (const collection of ["paths", "webhooks"]) {
|
|
1019
|
+
const entries = resolveYamlMap(root.get(collection, true), rootSource);
|
|
1020
|
+
for (const pair of entries?.items ?? []) {
|
|
1021
|
+
if (typeof pair.key === "object" && pair.key && "value" in pair.key && typeof pair.key.value === "string")
|
|
1022
|
+
pathItem(pair.value, rootSource, [collection, pair.key.value]);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
return diagnostics.map((diagnostic) => {
|
|
1027
|
+
if (diagnostic.code !== "operation-operationId-unique") return diagnostic;
|
|
1028
|
+
const primary = operations.find(
|
|
1029
|
+
(operation) => operation.source === diagnostic.source && (toPointer(operation.path) === toPointer(diagnostic.path) || toPointer(operation.path.slice(0, -1)) === toPointer(diagnostic.path) || toPointer(operation.reportedPath) === toPointer(diagnostic.path) || toPointer([...operation.reportedPath, "operationId"]) === toPointer(diagnostic.path))
|
|
1030
|
+
);
|
|
1031
|
+
if (!primary) return diagnostic;
|
|
1032
|
+
const peers = operations.filter((operation) => operation.id === primary.id);
|
|
1033
|
+
if (peers.length < 2) return diagnostic;
|
|
1034
|
+
const locations = [
|
|
1035
|
+
...new Map(
|
|
1036
|
+
[primary, ...peers].map(
|
|
1037
|
+
({ id: _id, reportedPath: _reportedPath, ...location }) => [
|
|
1038
|
+
JSON.stringify([location.source, toPointer(location.path)]),
|
|
1039
|
+
location
|
|
1040
|
+
]
|
|
1041
|
+
)
|
|
1042
|
+
).values()
|
|
1043
|
+
];
|
|
1044
|
+
return { ...diagnostic, locations };
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// src/domains/document/lint/paths.ts
|
|
1049
|
+
import { realpath, stat } from "node:fs/promises";
|
|
1050
|
+
import { basename, dirname as dirname4, join as join3, resolve as resolve4 } from "node:path";
|
|
1051
|
+
async function checkOutputPaths(inputs, outputs) {
|
|
1052
|
+
const files = await Promise.all(
|
|
1053
|
+
[...inputs, ...outputs].map(async (path) => ({
|
|
1054
|
+
path,
|
|
1055
|
+
resolved: await realpath(path).catch(
|
|
1056
|
+
async () => join3(
|
|
1057
|
+
await realpath(dirname4(path)).catch(() => dirname4(path)),
|
|
1058
|
+
basename(path)
|
|
1059
|
+
)
|
|
1060
|
+
),
|
|
1061
|
+
stats: await stat(path).catch(() => void 0)
|
|
1062
|
+
}))
|
|
1063
|
+
);
|
|
1064
|
+
for (const output of files.slice(inputs.length)) {
|
|
1065
|
+
for (const other of files) {
|
|
1066
|
+
if (other === output) continue;
|
|
1067
|
+
if (resolve4(output.resolved) === resolve4(other.resolved) || output.stats && other.stats && output.stats.dev === other.stats.dev && output.stats.ino === other.stats.ino) {
|
|
1068
|
+
return err(
|
|
1069
|
+
`Output paths must not overwrite an input or each other: ${output.path}`
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
return ok(void 0);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// src/domains/document/lint/report.ts
|
|
1078
|
+
import { relative as relative2 } from "node:path";
|
|
1079
|
+
import { stripVTControlCharacters } from "node:util";
|
|
1080
|
+
import as2 from "ansis";
|
|
1081
|
+
|
|
1082
|
+
// src/domains/document/lint/codeframe.ts
|
|
1083
|
+
import as from "ansis";
|
|
1084
|
+
function codeframe(content, line, column, highlight) {
|
|
1085
|
+
if (content === void 0) return "";
|
|
1086
|
+
const lines = content.split(/\r?\n/);
|
|
1087
|
+
const start = Math.max(0, line - 3);
|
|
1088
|
+
const end = Math.min(lines.length, line + 2);
|
|
1089
|
+
const width = String(end).length;
|
|
1090
|
+
return lines.slice(start, end).flatMap((text, offset) => {
|
|
1091
|
+
const number = start + offset + 1;
|
|
1092
|
+
const gutter = `${String(number).padStart(width)} |`;
|
|
1093
|
+
const row = `${highlight ? as.gray(gutter) : gutter} ${text}`;
|
|
1094
|
+
const caretGutter = `${" ".repeat(width)} |`;
|
|
1095
|
+
return number === line ? [
|
|
1096
|
+
row,
|
|
1097
|
+
`${highlight ? as.gray(caretGutter) : caretGutter} ${" ".repeat(Math.min(Math.max(0, column - 1), text.length))}${highlight ? highlight("^") : "^"}`
|
|
1098
|
+
] : [row];
|
|
1099
|
+
}).join("\n");
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/domains/document/lint/helpers.ts
|
|
1103
|
+
var severityToLabel = (severity) => {
|
|
1104
|
+
return {
|
|
1105
|
+
0: "Error",
|
|
1106
|
+
1: "Warning",
|
|
1107
|
+
2: "Information",
|
|
1108
|
+
3: "Hint"
|
|
1109
|
+
}[severity];
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
// src/domains/document/lint/markdown.ts
|
|
1113
|
+
function escapeText(value) {
|
|
1114
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("|", "|").replaceAll("\r", "").replaceAll("\n", "<br>");
|
|
1115
|
+
}
|
|
1116
|
+
function markdownCell(value) {
|
|
1117
|
+
const delimiters = [...value.matchAll(/`+/g)];
|
|
1118
|
+
const result = delimiters.reduce(
|
|
1119
|
+
(state, opening, index) => {
|
|
1120
|
+
if (opening.index < state.offset) return state;
|
|
1121
|
+
const backslashes = value.slice(0, opening.index).match(/\\+$/)?.[0].length ?? 0;
|
|
1122
|
+
if (backslashes % 2) return state;
|
|
1123
|
+
const closing = delimiters.slice(index + 1).find((delimiter) => delimiter[0].length === opening[0].length);
|
|
1124
|
+
if (!closing) return state;
|
|
1125
|
+
const end = closing.index + closing[0].length;
|
|
1126
|
+
const span = value.slice(opening.index, end).replace(/\r\n?|\n/g, " ").replaceAll("|", "\\|");
|
|
1127
|
+
const content = value.slice(opening.index + opening[0].length, closing.index).replace(/\r\n?|\n/g, " ");
|
|
1128
|
+
const normalized = content.startsWith(" ") && content.endsWith(" ") && /[^ ]/.test(content) ? content.slice(1, -1) : content;
|
|
1129
|
+
const rendered = content.includes("\\|") ? `<code>${escapeText(normalized).replaceAll("\\", "\")}</code>` : span;
|
|
1130
|
+
return {
|
|
1131
|
+
offset: end,
|
|
1132
|
+
parts: [
|
|
1133
|
+
...state.parts,
|
|
1134
|
+
escapeText(value.slice(state.offset, opening.index)),
|
|
1135
|
+
rendered
|
|
1136
|
+
]
|
|
1137
|
+
};
|
|
1138
|
+
},
|
|
1139
|
+
{ offset: 0, parts: [] }
|
|
1140
|
+
);
|
|
1141
|
+
return [...result.parts, escapeText(value.slice(result.offset))].join("");
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// src/domains/document/lint/report.ts
|
|
1145
|
+
function escapeCommand(value, property = false) {
|
|
1146
|
+
const escaped = value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
1147
|
+
return property ? escaped.replaceAll(":", "%3A").replaceAll(",", "%2C") : escaped;
|
|
1148
|
+
}
|
|
1149
|
+
function escapeXml(value) {
|
|
1150
|
+
return value.replace(
|
|
1151
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: XML 1.0 permits only these character ranges.
|
|
1152
|
+
/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/gu,
|
|
1153
|
+
"\uFFFD"
|
|
1154
|
+
).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'").replaceAll("\r", " ").replaceAll("\n", " ").replaceAll(" ", "	");
|
|
1155
|
+
}
|
|
1156
|
+
function displaySource(source, cwd = process.cwd()) {
|
|
1157
|
+
return /^https?:\/\//.test(source) ? source : relative2(cwd, source);
|
|
1158
|
+
}
|
|
1159
|
+
function groupBy(items, key) {
|
|
1160
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1161
|
+
for (const item of items) {
|
|
1162
|
+
const name = key(item);
|
|
1163
|
+
const group = groups.get(name) ?? [];
|
|
1164
|
+
group.push(item);
|
|
1165
|
+
groups.set(name, group);
|
|
1166
|
+
}
|
|
1167
|
+
return groups;
|
|
1168
|
+
}
|
|
1169
|
+
function renderReport(diagnostics, engine, format, ignored = 0, color = true, options = {}) {
|
|
1170
|
+
const totals = {
|
|
1171
|
+
errors: diagnostics.filter((finding) => finding.severity === 0).length,
|
|
1172
|
+
warnings: diagnostics.filter((finding) => finding.severity === 1).length,
|
|
1173
|
+
ignored
|
|
1174
|
+
};
|
|
1175
|
+
const selected = [...diagnostics].sort((a, b) => a.severity - b.severity).slice(0, options.maxProblems ?? 100);
|
|
1176
|
+
const findings = selected.map((diagnostic) => {
|
|
1177
|
+
const position = (point) => ({
|
|
1178
|
+
line: Math.max(1, point.line + (engine === "spectral" ? 1 : 0)),
|
|
1179
|
+
col: Math.max(1, point.character + (engine === "spectral" ? 1 : 0))
|
|
1180
|
+
});
|
|
1181
|
+
return {
|
|
1182
|
+
ruleId: String(diagnostic.code),
|
|
1183
|
+
severity: ["error", "warn", "info", "hint"][diagnostic.severity],
|
|
1184
|
+
message: diagnostic.message,
|
|
1185
|
+
location: (diagnostic.locations?.length ? diagnostic.locations : [
|
|
1186
|
+
{
|
|
1187
|
+
source: diagnostic.source ?? process.cwd(),
|
|
1188
|
+
path: diagnostic.resolvedPath ?? diagnostic.path,
|
|
1189
|
+
range: diagnostic.range
|
|
1190
|
+
}
|
|
1191
|
+
]).map((location) => ({
|
|
1192
|
+
source: { ref: displaySource(location.source) },
|
|
1193
|
+
pointer: toPointer(location.path),
|
|
1194
|
+
start: position(location.range.start),
|
|
1195
|
+
end: position(location.range.end)
|
|
1196
|
+
})),
|
|
1197
|
+
suggest: [],
|
|
1198
|
+
...diagnostic.documentationUrl ? { reference: diagnostic.documentationUrl } : {}
|
|
1199
|
+
};
|
|
1200
|
+
});
|
|
1201
|
+
if (format === "json") {
|
|
1202
|
+
return `${JSON.stringify({ totals, version: options.version ?? "1", problems: findings }, null, 2)}
|
|
1203
|
+
`;
|
|
1204
|
+
}
|
|
1205
|
+
if (format === "github-actions") {
|
|
1206
|
+
return findings.flatMap(
|
|
1207
|
+
(finding, index) => finding.location.map((location, locationIndex) => {
|
|
1208
|
+
const source = selected[index]?.locations?.[locationIndex]?.source ?? selected[index]?.source ?? "";
|
|
1209
|
+
const remote = /^https?:\/\//.test(source);
|
|
1210
|
+
const file = remote ? "" : `file=${escapeCommand(displaySource(source, process.env.GITHUB_WORKSPACE ?? process.cwd()), true)},line=${location.start.line},col=${location.start.col},endLine=${location.end.line},endColumn=${location.end.col},`;
|
|
1211
|
+
const level = finding.severity === "error" ? "error" : finding.severity === "warn" ? "warning" : "notice";
|
|
1212
|
+
const message = `${remote ? `${source}: ` : ""}${finding.message}${finding.reference ? `
|
|
1213
|
+
|
|
1214
|
+
Reference: ${finding.reference}` : ""}`;
|
|
1215
|
+
return `::${level} ${file}title=${escapeCommand(finding.ruleId, true)}::${escapeCommand(message)}
|
|
1216
|
+
`;
|
|
1217
|
+
})
|
|
1218
|
+
).join("");
|
|
1219
|
+
}
|
|
1220
|
+
if (format === "junit") {
|
|
1221
|
+
const groups = groupBy(
|
|
1222
|
+
findings,
|
|
1223
|
+
(finding) => finding.location[0]?.source.ref ?? ""
|
|
1224
|
+
);
|
|
1225
|
+
const suites = [...groups].map(([source, problems]) => {
|
|
1226
|
+
const errors = problems.filter(
|
|
1227
|
+
(problem) => problem.severity === "error"
|
|
1228
|
+
).length;
|
|
1229
|
+
const warnings = problems.filter(
|
|
1230
|
+
(problem) => problem.severity === "warn"
|
|
1231
|
+
).length;
|
|
1232
|
+
const cases = problems.map((problem) => {
|
|
1233
|
+
const location = problem.location[0];
|
|
1234
|
+
if (!location) return "";
|
|
1235
|
+
const details = escapeXml(
|
|
1236
|
+
`${problem.severity}: ${problem.message}
|
|
1237
|
+
${problem.location.map((point) => `${point.source.ref}:${point.start.line}:${point.start.col}
|
|
1238
|
+
Pointer: ${point.pointer}`).join("\n")}`
|
|
1239
|
+
);
|
|
1240
|
+
const element = problem.severity === "error" ? "error" : problem.severity === "warn" ? "failure" : "system-out";
|
|
1241
|
+
const result = element === "system-out" ? `<system-out>${details}</system-out>` : `<${element} message="${escapeXml(problem.message)}" type="${escapeXml(problem.ruleId)}">${details}</${element}>`;
|
|
1242
|
+
return ` <testcase classname="${escapeXml(problem.ruleId)}" name="${escapeXml(problem.ruleId)}" file="${escapeXml(source)}" line="${location.start.line}">${result}</testcase>`;
|
|
1243
|
+
}).join("\n");
|
|
1244
|
+
return ` <testsuite name="${escapeXml(source)}" tests="${problems.length}" errors="${errors}" failures="${warnings}" skipped="0">
|
|
1245
|
+
${cases}
|
|
1246
|
+
</testsuite>`;
|
|
1247
|
+
}).join("\n");
|
|
1248
|
+
const shownErrors = findings.filter(
|
|
1249
|
+
(problem) => problem.severity === "error"
|
|
1250
|
+
).length;
|
|
1251
|
+
const shownWarnings = findings.filter(
|
|
1252
|
+
(problem) => problem.severity === "warn"
|
|
1253
|
+
).length;
|
|
1254
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
1255
|
+
<testsuites tests="${findings.length}" errors="${shownErrors}" failures="${shownWarnings}">
|
|
1256
|
+
<testsuite name="Scalar lint totals" tests="0" errors="0" failures="0"><properties><property name="errors" value="${totals.errors}"/><property name="warnings" value="${totals.warnings}"/><property name="ignored" value="${ignored}"/><property name="hidden" value="${diagnostics.length - findings.length}"/></properties></testsuite>
|
|
1257
|
+
${suites}
|
|
1258
|
+
</testsuites>
|
|
1259
|
+
`;
|
|
1260
|
+
}
|
|
1261
|
+
const status = `${totals.errors ? "Validation failed" : "Validation successful"}
|
|
1262
|
+
Errors: ${totals.errors}
|
|
1263
|
+
Warnings: ${totals.warnings}
|
|
1264
|
+
Ignored: ${ignored}
|
|
1265
|
+
`;
|
|
1266
|
+
if (format === "markdown") {
|
|
1267
|
+
const groups = groupBy(
|
|
1268
|
+
findings,
|
|
1269
|
+
(finding) => finding.location[0]?.source.ref ?? ""
|
|
1270
|
+
);
|
|
1271
|
+
return `${[...groups].map(
|
|
1272
|
+
([source, problems]) => `## Lint: ${markdownCell(source)}
|
|
1273
|
+
|
|
1274
|
+
| Severity | Location | Problem | Message |
|
|
1275
|
+
|---|---|---|---|
|
|
1276
|
+
${problems.map((problem) => {
|
|
1277
|
+
const locations = problem.location.map(
|
|
1278
|
+
(location) => `${location.source.ref === source ? "" : `${markdownCell(location.source.ref)} `}line ${location.start.line}:${location.start.col}`
|
|
1279
|
+
).join("<br>");
|
|
1280
|
+
return `| ${problem.severity} | ${locations} | ${markdownCell(problem.ruleId)} | ${markdownCell(problem.message)} |`;
|
|
1281
|
+
}).join("\n")}
|
|
1282
|
+
`
|
|
1283
|
+
).join("\n")}
|
|
1284
|
+
${status}`;
|
|
1285
|
+
}
|
|
1286
|
+
if (format === "summary") {
|
|
1287
|
+
const groups = groupBy(
|
|
1288
|
+
findings,
|
|
1289
|
+
(finding) => `${finding.severity} ${finding.ruleId}`
|
|
1290
|
+
);
|
|
1291
|
+
return `${[...groups].map(([key, problems]) => `${key}: ${problems.length}
|
|
1292
|
+
`).join("")}
|
|
1293
|
+
${status}`;
|
|
1294
|
+
}
|
|
1295
|
+
if (format === "codeframe") {
|
|
1296
|
+
const coloredStatus = `${totals.errors ? as2.red("Validation failed") : as2.green("Validation successful")}
|
|
1297
|
+
Errors: ${as2.red(String(totals.errors))}
|
|
1298
|
+
Warnings: ${as2.yellow(String(totals.warnings))}
|
|
1299
|
+
Ignored: ${ignored}
|
|
1300
|
+
`;
|
|
1301
|
+
const text2 = `${findings.map(
|
|
1302
|
+
(finding, index) => finding.location.map((location, locationIndex) => {
|
|
1303
|
+
const source = selected[index]?.locations?.[locationIndex]?.source ?? selected[index]?.source ?? "";
|
|
1304
|
+
const highlight = {
|
|
1305
|
+
error: as2.red,
|
|
1306
|
+
warn: as2.yellow,
|
|
1307
|
+
info: as2.cyan,
|
|
1308
|
+
hint: as2.gray
|
|
1309
|
+
}[finding.severity];
|
|
1310
|
+
const frame = codeframe(
|
|
1311
|
+
options.sources?.get(source),
|
|
1312
|
+
location.start.line,
|
|
1313
|
+
location.start.col,
|
|
1314
|
+
color ? highlight : void 0
|
|
1315
|
+
);
|
|
1316
|
+
return `[${index + 1}] ${as2.bold(`${location.source.ref}:${location.start.line}:${location.start.col}`)} ${as2.gray(`at ${location.pointer}`)}
|
|
1317
|
+
|
|
1318
|
+
${highlight(finding.message)}
|
|
1319
|
+
|
|
1320
|
+
${frame ? `${frame}
|
|
1321
|
+
|
|
1322
|
+
` : ""}${highlight(finding.severity)} was generated by the ${as2.bold(finding.ruleId)} rule.
|
|
1323
|
+
${finding.reference ? `${as2.gray(`Reference: ${finding.reference}`)}
|
|
1324
|
+
` : ""}`;
|
|
1325
|
+
}).join("\n")
|
|
1326
|
+
).join("\n")}
|
|
1327
|
+
${coloredStatus}`;
|
|
1328
|
+
return color ? text2 : stripVTControlCharacters(text2);
|
|
1329
|
+
}
|
|
1330
|
+
const lines = [
|
|
1331
|
+
diagnostics.length ? (totals.errors ? as2.red : as2.yellow)("\u2716 Lint issues found:") : as2.green("\u2714 No lint issues found.")
|
|
1332
|
+
];
|
|
1333
|
+
for (const diagnostic of selected) {
|
|
1334
|
+
lines.push(
|
|
1335
|
+
`${as2.yellow("Rule:")} ${as2.bold(String(diagnostic.code))}`,
|
|
1336
|
+
`${as2.yellow("Message:")} ${diagnostic.message}`,
|
|
1337
|
+
`${as2.yellow("Severity:")} ${severityToLabel(diagnostic.severity)}`,
|
|
1338
|
+
`${as2.yellow("Location:")} ${diagnostic.range.start.line}:${diagnostic.range.start.character} - ${diagnostic.range.end.line}:${diagnostic.range.end.character}`,
|
|
1339
|
+
...(diagnostic.locations ?? []).filter(
|
|
1340
|
+
(location) => location.source !== diagnostic.source || JSON.stringify(location.path) !== JSON.stringify(diagnostic.path)
|
|
1341
|
+
).map(
|
|
1342
|
+
(location) => `Related: ${displaySource(location.source)} at ${toPointer(location.path)} (${location.range.start.line}:${location.range.start.character})`
|
|
1343
|
+
),
|
|
1344
|
+
as2.gray("---")
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
if (ignored)
|
|
1348
|
+
lines.push(`${ignored} ${ignored === 1 ? "finding" : "findings"} ignored.`);
|
|
1349
|
+
const text = `${lines.join("\n")}
|
|
1350
|
+
`;
|
|
1351
|
+
return color ? text : stripVTControlCharacters(text);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
// src/domains/document/lint/sources.ts
|
|
1355
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
1356
|
+
import { fileURLToPath as fileURLToPath4, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
1357
|
+
import { parse as parse4 } from "yaml";
|
|
1358
|
+
async function readSource(source) {
|
|
1359
|
+
try {
|
|
1360
|
+
if (/^https?:\/\//.test(source)) {
|
|
1361
|
+
const response = await fetch(source, {
|
|
1362
|
+
signal: AbortSignal.timeout(1e4)
|
|
1363
|
+
});
|
|
1364
|
+
return response.ok ? ok(await response.text()) : err(`Could not read ${source}: HTTP ${response.status}`);
|
|
1365
|
+
}
|
|
1366
|
+
return ok(await readFile3(source, "utf8"));
|
|
1367
|
+
} catch (error) {
|
|
1368
|
+
return err(
|
|
1369
|
+
`Could not read ${source}: ${error instanceof Error ? error.message : String(error)}`
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
function references(content) {
|
|
1374
|
+
const root = parse4(content);
|
|
1375
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
1376
|
+
const refs = /* @__PURE__ */ new Set();
|
|
1377
|
+
const pending = [root];
|
|
1378
|
+
while (pending.length) {
|
|
1379
|
+
const value = pending.pop();
|
|
1380
|
+
if (value === null || typeof value !== "object" || visited.has(value))
|
|
1381
|
+
continue;
|
|
1382
|
+
visited.add(value);
|
|
1383
|
+
for (const [key, child] of Object.entries(value).reverse()) {
|
|
1384
|
+
if (key === "$ref" && typeof child === "string") refs.add(child);
|
|
1385
|
+
else pending.push(child);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return [...refs];
|
|
1389
|
+
}
|
|
1390
|
+
function referenceSource(ref, source) {
|
|
1391
|
+
try {
|
|
1392
|
+
const url = new URL(
|
|
1393
|
+
ref,
|
|
1394
|
+
/^https?:\/\//.test(source) ? source : pathToFileURL2(source)
|
|
1395
|
+
);
|
|
1396
|
+
url.hash = "";
|
|
1397
|
+
return ["file:", "https:", "http:"].includes(url.protocol) ? ok(url.protocol === "file:" ? fileURLToPath4(url) : url.href) : err("Unsupported reference protocol");
|
|
1398
|
+
} catch {
|
|
1399
|
+
return err("Invalid reference URI");
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
async function collectSources(source, content) {
|
|
1403
|
+
const sources = /* @__PURE__ */ new Map([[source, content]]);
|
|
1404
|
+
for (const [current, text] of sources) {
|
|
1405
|
+
if (text === void 0) continue;
|
|
1406
|
+
const refs = (() => {
|
|
1407
|
+
try {
|
|
1408
|
+
return references(text);
|
|
1409
|
+
} catch {
|
|
1410
|
+
return [];
|
|
1411
|
+
}
|
|
1412
|
+
})();
|
|
1413
|
+
for (const ref of refs) {
|
|
1414
|
+
const resolved = referenceSource(ref, current);
|
|
1415
|
+
if (!resolved.ok) continue;
|
|
1416
|
+
const target = resolved.data;
|
|
1417
|
+
if (sources.has(target)) continue;
|
|
1418
|
+
const loaded = await readSource(target);
|
|
1419
|
+
sources.set(target, loaded.ok ? loaded.data : void 0);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
return sources;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
// src/domains/document/lint/action.ts
|
|
1426
|
+
function fail(message) {
|
|
1427
|
+
process.stderr.write(`[ERROR] ${message}
|
|
1428
|
+
`);
|
|
1429
|
+
process.exitCode = 1;
|
|
1430
|
+
}
|
|
1431
|
+
async function lintAction(inputArgument, options) {
|
|
1432
|
+
if (!inputArgument) {
|
|
1433
|
+
fail("Missing input\n\nProvide an API description file path or URL.\n");
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
try {
|
|
1437
|
+
await runLint(inputArgument, options);
|
|
1438
|
+
} catch (error) {
|
|
1439
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
async function runLint(inputArgument, options) {
|
|
1443
|
+
const remote = (path) => /^https?:\/\//.test(path);
|
|
1444
|
+
const source = remote(inputArgument) ? new URL(inputArgument).href : resolve5(inputArgument);
|
|
1445
|
+
const selectedIgnore = await selectIgnorePath(
|
|
1446
|
+
options.ignoreFile,
|
|
1447
|
+
Boolean(options.generateIgnoreFile)
|
|
1448
|
+
);
|
|
1449
|
+
if (!selectedIgnore.ok) return fail(selectedIgnore.error);
|
|
1450
|
+
const ignorePath = selectedIgnore.data;
|
|
1451
|
+
const outputPath = options.output ? resolve5(options.output) : void 0;
|
|
1452
|
+
const inputs = [source, ...options.rule ? [options.rule] : []].filter((path) => !remote(path)).map((path) => resolve5(path));
|
|
1453
|
+
const destinations = [
|
|
1454
|
+
...outputPath ? [outputPath] : [],
|
|
1455
|
+
...options.generateIgnoreFile ? [ignorePath] : []
|
|
1456
|
+
];
|
|
1457
|
+
const paths = await checkOutputPaths(
|
|
1458
|
+
[...inputs, ...!options.generateIgnoreFile ? [ignorePath] : []],
|
|
1459
|
+
destinations
|
|
1460
|
+
);
|
|
1461
|
+
if (!paths.ok) return fail(paths.error);
|
|
1462
|
+
const loaded = await loadBaseline(
|
|
1463
|
+
ignorePath,
|
|
1464
|
+
Boolean(options.ignoreFile && !options.generateIgnoreFile)
|
|
1465
|
+
);
|
|
1466
|
+
if (!loaded.ok) return fail(loaded.error);
|
|
1467
|
+
const specification = await readSource(source);
|
|
1468
|
+
if (!specification.ok) return fail(specification.error);
|
|
1469
|
+
const ruleset = options.rule ? await readSource(options.rule) : {
|
|
1470
|
+
ok: true,
|
|
1471
|
+
data: isAsyncApiContent(specification.data) ? ASYNCAPI_RULESET : DEFAULT_RULESET
|
|
1472
|
+
};
|
|
1473
|
+
if (!ruleset.ok) return fail(ruleset.error);
|
|
1474
|
+
const sources = await collectSources(source, specification.data);
|
|
1475
|
+
const result = await lint({
|
|
1476
|
+
document: specification.data,
|
|
1477
|
+
ruleset: ruleset.data,
|
|
1478
|
+
source
|
|
1479
|
+
});
|
|
1480
|
+
if (!result.ok)
|
|
1481
|
+
return fail(`Could not lint the API description
|
|
1482
|
+
|
|
1483
|
+
${result.error}`);
|
|
1484
|
+
const diagnostics = addRelatedLocations(
|
|
1485
|
+
resolveDiagnosticPaths(
|
|
1486
|
+
result.data.diagnostics,
|
|
1487
|
+
sources,
|
|
1488
|
+
result.data.engine
|
|
1489
|
+
),
|
|
1490
|
+
sources,
|
|
1491
|
+
result.data.engine
|
|
1492
|
+
);
|
|
1493
|
+
const referencedPaths = [
|
|
1494
|
+
...sources.keys(),
|
|
1495
|
+
...diagnostics.flatMap((diagnostic) => [
|
|
1496
|
+
...diagnostic.source ? [diagnostic.source] : [],
|
|
1497
|
+
...(diagnostic.locations ?? []).map((location) => location.source)
|
|
1498
|
+
])
|
|
1499
|
+
].filter((path) => !remote(path));
|
|
1500
|
+
const checked = await checkOutputPaths(
|
|
1501
|
+
[
|
|
1502
|
+
...inputs,
|
|
1503
|
+
...referencedPaths,
|
|
1504
|
+
...!options.generateIgnoreFile ? [ignorePath] : []
|
|
1505
|
+
],
|
|
1506
|
+
destinations
|
|
1507
|
+
);
|
|
1508
|
+
if (!checked.ok) return fail(checked.error);
|
|
1509
|
+
let baseline = loaded.data;
|
|
1510
|
+
if (options.generateIgnoreFile) {
|
|
1511
|
+
const written = await regenerateBaseline(ignorePath, source, diagnostics);
|
|
1512
|
+
if (!written.ok) return fail(written.error);
|
|
1513
|
+
baseline = written.data;
|
|
1514
|
+
process.stderr.write(`Ignore baseline written to ${ignorePath}
|
|
1515
|
+
`);
|
|
1516
|
+
}
|
|
1517
|
+
const compatibility = Boolean(
|
|
1518
|
+
!isAsyncApiContent(specification.data) && supportsRedoclyMigration(ruleset.data)
|
|
1519
|
+
);
|
|
1520
|
+
if (compatibility) {
|
|
1521
|
+
const unsupported = unsupportedRedoclyRules(baseline);
|
|
1522
|
+
if (unsupported.length)
|
|
1523
|
+
process.stderr.write(
|
|
1524
|
+
`Ignore file contains rules outside the supported Redocly migration subset: ${unsupported.join(", ")}. Only exact Scalar rule/pointer matches apply to these entries.
|
|
1525
|
+
`
|
|
1526
|
+
);
|
|
1527
|
+
}
|
|
1528
|
+
const active = applyBaseline(baseline, diagnostics, ignorePath, compatibility);
|
|
1529
|
+
const report = renderReport(
|
|
1530
|
+
active,
|
|
1531
|
+
result.data.engine,
|
|
1532
|
+
options.format ?? "codeframe",
|
|
1533
|
+
diagnostics.length - active.length,
|
|
1534
|
+
!outputPath,
|
|
1535
|
+
{ maxProblems: options.maxProblems, sources, version: package_default.version }
|
|
1536
|
+
);
|
|
1537
|
+
if (active.length > (options.maxProblems ?? 100)) {
|
|
1538
|
+
process.stderr.write(
|
|
1539
|
+
`${active.length - (options.maxProblems ?? 100)} more problems hidden; increase with --max-problems N
|
|
1540
|
+
`
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
if (outputPath) {
|
|
1544
|
+
await writeFile3(outputPath, report, "utf8");
|
|
1545
|
+
} else {
|
|
1546
|
+
process.stdout.write(report);
|
|
1547
|
+
}
|
|
1548
|
+
process.exitCode = active.some((diagnostic) => diagnostic.severity === 0) ? 1 : 0;
|
|
1549
|
+
}
|
|
1550
|
+
export {
|
|
1551
|
+
lintAction
|
|
1552
|
+
};
|