@ryuugg/stanza 0.3.3 → 0.4.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/README.md +15 -13
- package/package.json +19 -11
- package/src/launcher +102 -8
- package/src/cli.ts +0 -684
- package/src/compile/darwin-arm64.ts +0 -3
- package/src/compile/darwin-x64.ts +0 -3
- package/src/compile/linux-arm64-musl.ts +0 -3
- package/src/compile/linux-arm64.ts +0 -3
- package/src/compile/linux-x64-musl.ts +0 -3
- package/src/compile/linux-x64.ts +0 -3
- package/src/compiled.ts +0 -9
- package/src/depth.ts +0 -372
- package/src/directories.ts +0 -77
- package/src/engine/attach.ts +0 -62
- package/src/engine/directives.ts +0 -157
- package/src/engine/doc.ts +0 -93
- package/src/engine/edits.ts +0 -79
- package/src/engine/explain.ts +0 -337
- package/src/engine/gaps.ts +0 -361
- package/src/engine/hunks.ts +0 -319
- package/src/engine/index.ts +0 -273
- package/src/engine/model.ts +0 -103
- package/src/engine/rules.ts +0 -104
- package/src/engine/types.ts +0 -38
- package/src/files.ts +0 -1186
- package/src/format.ts +0 -159
- package/src/gitignore.ts +0 -280
- package/src/hook.ts +0 -380
- package/src/languages/index.ts +0 -34
- package/src/languages/javascript/ast.ts +0 -261
- package/src/languages/javascript/braces.ts +0 -374
- package/src/languages/javascript/config/biome.ts +0 -112
- package/src/languages/javascript/config/eslint.ts +0 -128
- package/src/languages/javascript/config/evaluate.ts +0 -278
- package/src/languages/javascript/config/find.ts +0 -105
- package/src/languages/javascript/config/glob.ts +0 -149
- package/src/languages/javascript/config/index.ts +0 -48
- package/src/languages/javascript/config/layers.ts +0 -468
- package/src/languages/javascript/config/module.ts +0 -327
- package/src/languages/javascript/config/oxlint.ts +0 -170
- package/src/languages/javascript/config/width.ts +0 -723
- package/src/languages/javascript/deserializers.ts +0 -17
- package/src/languages/javascript/embedded.ts +0 -7
- package/src/languages/javascript/entry.ts +0 -42
- package/src/languages/javascript/facts.ts +0 -294
- package/src/languages/javascript/index.ts +0 -20
- package/src/languages/javascript/lists.ts +0 -64
- package/src/languages/javascript/oracle.ts +0 -191
- package/src/languages/javascript/oxc-raw.d.ts +0 -31
- package/src/languages/javascript/parse.ts +0 -131
- package/src/languages/javascript/raw.ts +0 -95
- package/src/languages/javascript/scan.ts +0 -68
- package/src/languages/language.ts +0 -109
- package/src/native-file.d.ts +0 -4
- package/src/pool.ts +0 -473
- package/src/start.ts +0 -49
- package/src/step.ts +0 -113
- package/src/usage.ts +0 -35
- package/src/worker.ts +0 -5
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, relative, sep } from "node:path";
|
|
3
|
-
import type { Node } from "oxc-parser";
|
|
4
|
-
import { walk } from "../ast.ts";
|
|
5
|
-
import {
|
|
6
|
-
UNKNOWN,
|
|
7
|
-
NO_SETTING,
|
|
8
|
-
type Value,
|
|
9
|
-
evaluate,
|
|
10
|
-
exported,
|
|
11
|
-
known,
|
|
12
|
-
object,
|
|
13
|
-
origin,
|
|
14
|
-
property,
|
|
15
|
-
} from "./evaluate.ts";
|
|
16
|
-
import { configDirectories, resolveModule, type Loader } from "./find.ts";
|
|
17
|
-
import { globReach } from "./glob.ts";
|
|
18
|
-
import { moduleAt, type ConfigModule } from "./module.ts";
|
|
19
|
-
|
|
20
|
-
export type Setting = "on" | "off" | "unknown";
|
|
21
|
-
export type Reach = "all" | "none" | "some";
|
|
22
|
-
export type Coverage = Reach | ((dir: string, extension?: string) => Reach);
|
|
23
|
-
type Family = "flat" | "legacy" | "biome" | "oxlint";
|
|
24
|
-
|
|
25
|
-
export interface Layer {
|
|
26
|
-
readonly reach: Coverage;
|
|
27
|
-
readonly setting: Setting;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface Decision {
|
|
31
|
-
family: Family;
|
|
32
|
-
setting: Setting;
|
|
33
|
-
files: string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface Reader {
|
|
37
|
-
family: Family;
|
|
38
|
-
files: readonly string[];
|
|
39
|
-
candidate?(file: string): boolean;
|
|
40
|
-
backstop: readonly string[];
|
|
41
|
-
backstopImports: boolean;
|
|
42
|
-
layers(value: Value, context: Context): Layer[];
|
|
43
|
-
decide(dir: string, extension: string | undefined): Decision | null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface Tree {
|
|
47
|
-
scope(value: Value, context: Context): Coverage;
|
|
48
|
-
own(value: Value, context: Context): Layer[];
|
|
49
|
-
extend(entry: string, parent: Value, context: Context): Layer[];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type Mode = "anchored" | "legacy" | "biome1";
|
|
53
|
-
|
|
54
|
-
export interface Found {
|
|
55
|
-
setting: Setting | null;
|
|
56
|
-
root: Value;
|
|
57
|
-
file: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface Context {
|
|
61
|
-
reader: Reader;
|
|
62
|
-
file: string;
|
|
63
|
-
shared: boolean;
|
|
64
|
-
chain: string[];
|
|
65
|
-
consumed: Set<Node>;
|
|
66
|
-
ancestors: Value[];
|
|
67
|
-
modules: Set<ConfigModule>;
|
|
68
|
-
work: {
|
|
69
|
-
count: number;
|
|
70
|
-
exceeded: boolean;
|
|
71
|
-
cycles: number;
|
|
72
|
-
memo: Map<Value, Map<string, Layer[]>>;
|
|
73
|
-
charged: Set<string>;
|
|
74
|
-
reaching: Set<string>[];
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const UNKNOWN_LAYER: Layer = { reach: "all", setting: "unknown" };
|
|
79
|
-
const EXPANSION_BUDGET = 100000;
|
|
80
|
-
|
|
81
|
-
const layerCache = new Map<string, { layers: Layer[]; root: Value; reached: Set<string> }>();
|
|
82
|
-
const exclusiveCost = new Map<string, number>();
|
|
83
|
-
|
|
84
|
-
export function lastLayers(layers: Layer[]): Layer[] {
|
|
85
|
-
const seen = new Set<Layer>();
|
|
86
|
-
const result: Layer[] = [];
|
|
87
|
-
for (let index = layers.length - 1; index >= 0; index--) {
|
|
88
|
-
const layer = layers[index]!;
|
|
89
|
-
if (seen.has(layer)) continue;
|
|
90
|
-
|
|
91
|
-
seen.add(layer);
|
|
92
|
-
result.push(layer);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return result.reverse();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function expanded(
|
|
99
|
-
value: Value,
|
|
100
|
-
context: Context,
|
|
101
|
-
phase: string,
|
|
102
|
-
produce: () => Layer[],
|
|
103
|
-
): Layer[] {
|
|
104
|
-
const work = context.work;
|
|
105
|
-
if (work.exceeded) return [UNKNOWN_LAYER];
|
|
106
|
-
|
|
107
|
-
const key = JSON.stringify([context.file, context.shared, context.chain, phase]);
|
|
108
|
-
const cached = work.memo.get(value)?.get(key);
|
|
109
|
-
if (cached) return cached;
|
|
110
|
-
|
|
111
|
-
const cycles = work.cycles;
|
|
112
|
-
const result = produce();
|
|
113
|
-
|
|
114
|
-
work.count += result.length + 1;
|
|
115
|
-
if (work.count > EXPANSION_BUDGET) work.exceeded = true;
|
|
116
|
-
if (work.exceeded) return [UNKNOWN_LAYER];
|
|
117
|
-
|
|
118
|
-
if (work.cycles === cycles) {
|
|
119
|
-
let entries = work.memo.get(value);
|
|
120
|
-
if (!entries) {
|
|
121
|
-
entries = new Map();
|
|
122
|
-
work.memo.set(value, entries);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
entries.set(key, result);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function levelOf(value: Value): Setting {
|
|
132
|
-
const seen = new Set<Value>();
|
|
133
|
-
while (!seen.has(value)) {
|
|
134
|
-
if (value === "off" || value === 0) return "off";
|
|
135
|
-
if (typeof value === "string" || typeof value === "number") return "on";
|
|
136
|
-
|
|
137
|
-
seen.add(value);
|
|
138
|
-
|
|
139
|
-
if (Array.isArray(value)) value = value[0];
|
|
140
|
-
else if (object(value)) value = property(value, "level");
|
|
141
|
-
else return "unknown";
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return "unknown";
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function intersect(left: Reach, right: Reach): Reach {
|
|
148
|
-
if (left === "none" || right === "none") return "none";
|
|
149
|
-
return left === "all" ? right : right === "all" ? left : "some";
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function reachAt(coverage: Coverage, dir: string, extension?: string): Reach {
|
|
153
|
-
return typeof coverage === "function" ? coverage(dir, extension) : coverage;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function intersectCoverage(left: Coverage, right: Coverage): Coverage {
|
|
157
|
-
if (left === "all") return right;
|
|
158
|
-
if (right === "all") return left;
|
|
159
|
-
if (left === "none" || right === "none") return "none";
|
|
160
|
-
return (dir, extension) =>
|
|
161
|
-
intersect(reachAt(left, dir, extension), reachAt(right, dir, extension));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function fold(layers: Layer[], dir: string, extension?: string): Setting | null {
|
|
165
|
-
let setting: Setting | null = null;
|
|
166
|
-
for (const layer of layers) {
|
|
167
|
-
const reach = reachAt(layer.reach, dir, extension);
|
|
168
|
-
if (reach === "all" || (reach === "some" && layer.setting !== "off")) setting = layer.setting;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return setting;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function read(value: Value, key: string, context: Context): Value {
|
|
175
|
-
const node = origin(value, key);
|
|
176
|
-
if (node) context.consumed.add(node);
|
|
177
|
-
return property(value, key);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function patterns(value: Value, context: Context, mode: Mode): Coverage {
|
|
181
|
-
if (value === undefined) return "all";
|
|
182
|
-
if (!Array.isArray(value) || !value.every((item): item is string => typeof item === "string"))
|
|
183
|
-
return "some";
|
|
184
|
-
|
|
185
|
-
if (context.shared) return "some";
|
|
186
|
-
if (value.length === 0) return "none";
|
|
187
|
-
if (mode === "biome1") return "some";
|
|
188
|
-
|
|
189
|
-
const anchor = dirname(context.file);
|
|
190
|
-
return (dir, extension) =>
|
|
191
|
-
globReach(value, relative(anchor, dir).split(sep).join("/"), mode === "legacy", extension);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export function excluding(
|
|
195
|
-
reach: Coverage,
|
|
196
|
-
exclusion: Value,
|
|
197
|
-
context: Context,
|
|
198
|
-
mode: Mode,
|
|
199
|
-
): Coverage {
|
|
200
|
-
if (exclusion === undefined) return reach;
|
|
201
|
-
|
|
202
|
-
const excluded = patterns(exclusion, context, mode);
|
|
203
|
-
return (dir, extension) => {
|
|
204
|
-
const included = reachAt(reach, dir, extension);
|
|
205
|
-
return included === "all" && reachAt(excluded, dir, extension) !== "none" ? "some" : included;
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function inherit(entry: Value, parent: Value, context: Context, hooks: Tree): Layer[] {
|
|
210
|
-
if (typeof entry !== "string") return context.reader.layers(entry, { ...context, shared: true });
|
|
211
|
-
|
|
212
|
-
const preset = known(entry);
|
|
213
|
-
if (preset !== undefined) return context.reader.layers(preset, { ...context, shared: true });
|
|
214
|
-
|
|
215
|
-
return hooks.extend(entry, parent, context);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function resolved(specifier: string, context: Context, loader: Loader): Layer[] {
|
|
219
|
-
const file = resolveModule(specifier, context.file, loader);
|
|
220
|
-
return file ? fileLayers(file, { ...context, shared: true }).layers : [UNKNOWN_LAYER];
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function tree(value: Value, context: Context, hooks: Tree): Layer[] {
|
|
224
|
-
if (value === NO_SETTING) return [];
|
|
225
|
-
if (context.work.exceeded) return [UNKNOWN_LAYER];
|
|
226
|
-
if (context.ancestors.includes(value)) {
|
|
227
|
-
context.work.cycles++;
|
|
228
|
-
return [UNKNOWN_LAYER];
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return expanded(value, context, "tree", () => {
|
|
232
|
-
const next: Context = { ...context, ancestors: [...context.ancestors, value] };
|
|
233
|
-
if (Array.isArray(value)) return lastLayers(value.flatMap((item) => tree(item, next, hooks)));
|
|
234
|
-
if (!object(value)) return [UNKNOWN_LAYER];
|
|
235
|
-
|
|
236
|
-
const reach = hooks.scope(value, next);
|
|
237
|
-
const inherited = property(value, "extends");
|
|
238
|
-
const entries: Value[] =
|
|
239
|
-
inherited === undefined ? [] : Array.isArray(inherited) ? inherited : [inherited];
|
|
240
|
-
|
|
241
|
-
const result = entries.flatMap((entry) => inherit(entry, value, next, hooks));
|
|
242
|
-
result.push(...hooks.own(value, next));
|
|
243
|
-
|
|
244
|
-
const scoped = lastLayers(result).map((layer) => ({
|
|
245
|
-
...layer,
|
|
246
|
-
reach: intersectCoverage(layer.reach, reach),
|
|
247
|
-
}));
|
|
248
|
-
|
|
249
|
-
const overrides = property(value, "overrides");
|
|
250
|
-
if (overrides !== undefined) {
|
|
251
|
-
const items: Value[] = Array.isArray(overrides) ? overrides : [UNKNOWN];
|
|
252
|
-
scoped.push(
|
|
253
|
-
...lastLayers(items.flatMap((item) => tree(item, next, hooks))).map((layer) => ({
|
|
254
|
-
...layer,
|
|
255
|
-
reach: intersectCoverage(reach, layer.reach),
|
|
256
|
-
})),
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return scoped;
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function yamlSetting(text: string): Setting | null {
|
|
265
|
-
const lines = text.split(/\r?\n/).map((line) => line.replace(/\s#.*$/, "").trimEnd());
|
|
266
|
-
const index = lines.findIndex((line) => /^\s*["']?curly["']?\s*:/.test(line));
|
|
267
|
-
|
|
268
|
-
if (lines.some((line, at) => at !== index && /\bcurly\b/.test(line))) return "unknown";
|
|
269
|
-
|
|
270
|
-
let setting: Setting | null = null;
|
|
271
|
-
if (index !== -1) {
|
|
272
|
-
let value = lines[index]!.replace(/^[^:]*:\s*/, "");
|
|
273
|
-
if (value === "")
|
|
274
|
-
value =
|
|
275
|
-
lines
|
|
276
|
-
.slice(index + 1)
|
|
277
|
-
.find((line) => line.trim() !== "")
|
|
278
|
-
?.trim() ?? "";
|
|
279
|
-
|
|
280
|
-
const first = value
|
|
281
|
-
.replace(/[[\]]/g, "")
|
|
282
|
-
.replace(/^[-\s]+/, "")
|
|
283
|
-
.split(",")[0]!
|
|
284
|
-
.trim()
|
|
285
|
-
.replace(/^["']|["']$/g, "");
|
|
286
|
-
|
|
287
|
-
setting = first === "off" || first === "0" ? "off" : "on";
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return setting !== "on" && lines.some((line) => /^(extends|overrides)\s*:/.test(line))
|
|
291
|
-
? "unknown"
|
|
292
|
-
: setting;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function backstop(module: ConfigModule, context: Context, result: Layer[]): void {
|
|
296
|
-
if (!module.program) return;
|
|
297
|
-
|
|
298
|
-
walk(module.program, (node) => {
|
|
299
|
-
if (node.type !== "Property" || context.consumed.has(node)) return;
|
|
300
|
-
|
|
301
|
-
const key =
|
|
302
|
-
node.key.type === "Identifier"
|
|
303
|
-
? node.key.name
|
|
304
|
-
: node.key.type === "Literal"
|
|
305
|
-
? node.key.value
|
|
306
|
-
: null;
|
|
307
|
-
|
|
308
|
-
if (
|
|
309
|
-
typeof key === "string" &&
|
|
310
|
-
context.reader.backstop.includes(key) &&
|
|
311
|
-
levelOf(evaluate(node.value, module, context.chain)) !== "off"
|
|
312
|
-
)
|
|
313
|
-
result.push(UNKNOWN_LAYER);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function charge(keys: Iterable<string>, work: Context["work"]): void {
|
|
318
|
-
for (const key of keys) {
|
|
319
|
-
for (const reached of work.reaching) reached.add(key);
|
|
320
|
-
|
|
321
|
-
if (work.charged.has(key)) continue;
|
|
322
|
-
|
|
323
|
-
work.charged.add(key);
|
|
324
|
-
work.count += exclusiveCost.get(key)!;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (work.count > EXPANSION_BUDGET) work.exceeded = true;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export function fileLayers(file: string, context: Context): { layers: Layer[]; root: Value } {
|
|
331
|
-
const module = moduleAt(file);
|
|
332
|
-
if (!module || context.chain.includes(module.file) || context.chain.length >= 32)
|
|
333
|
-
return { layers: [UNKNOWN_LAYER], root: undefined };
|
|
334
|
-
|
|
335
|
-
const key = JSON.stringify([file, dirname(file), context.reader.family, context.shared]);
|
|
336
|
-
const cached = layerCache.get(key);
|
|
337
|
-
if (cached) {
|
|
338
|
-
charge(cached.reached, context.work);
|
|
339
|
-
return cached;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const work = context.work;
|
|
343
|
-
for (const reached of work.reaching) reached.add(key);
|
|
344
|
-
|
|
345
|
-
const reached = new Set([key]);
|
|
346
|
-
work.reaching.push(reached);
|
|
347
|
-
const cycles = work.cycles;
|
|
348
|
-
const count = work.count;
|
|
349
|
-
const charged = new Set(work.charged);
|
|
350
|
-
|
|
351
|
-
let result: { layers: Layer[]; root: Value };
|
|
352
|
-
try {
|
|
353
|
-
result = readFileLayers(file, module, context);
|
|
354
|
-
} finally {
|
|
355
|
-
work.reaching.pop();
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!work.exceeded && work.cycles === cycles) {
|
|
359
|
-
let cost = work.count - count;
|
|
360
|
-
for (const entry of work.charged)
|
|
361
|
-
if (entry !== key && !charged.has(entry)) cost -= exclusiveCost.get(entry)!;
|
|
362
|
-
|
|
363
|
-
layerCache.set(key, { ...result, reached });
|
|
364
|
-
exclusiveCost.set(key, cost);
|
|
365
|
-
work.charged.add(key);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return result;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const manifestConfigs = new Map<string, Value>();
|
|
372
|
-
export function eslintConfig(manifest: string): Value {
|
|
373
|
-
if (manifestConfigs.has(manifest)) return manifestConfigs.get(manifest);
|
|
374
|
-
|
|
375
|
-
let config: Value;
|
|
376
|
-
try {
|
|
377
|
-
const text = readFileSync(manifest, "utf8").replace(/^\uFEFF/, "");
|
|
378
|
-
config = property(JSON.parse(text) as Value, "eslintConfig");
|
|
379
|
-
} catch {
|
|
380
|
-
config = UNKNOWN;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
manifestConfigs.set(manifest, config);
|
|
384
|
-
return config;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function readFileLayers(
|
|
388
|
-
file: string,
|
|
389
|
-
module: ConfigModule,
|
|
390
|
-
context: Context,
|
|
391
|
-
): { layers: Layer[]; root: Value } {
|
|
392
|
-
const next = { ...context, file, chain: [...context.chain, module.file] };
|
|
393
|
-
next.modules.add(module);
|
|
394
|
-
|
|
395
|
-
if (module.yaml) {
|
|
396
|
-
const setting = yamlSetting(module.text);
|
|
397
|
-
return {
|
|
398
|
-
layers: setting === null ? [] : [{ reach: "all", setting }],
|
|
399
|
-
root: /^root:\s*true\s*$/m.test(module.text),
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
const manifest = context.reader.family === "legacy" && basename(file) === "package.json";
|
|
404
|
-
const value = manifest ? eslintConfig(file) : exported(module.file, "default", context.chain);
|
|
405
|
-
|
|
406
|
-
const result = [...context.reader.layers(value, next)];
|
|
407
|
-
if (manifest) return { layers: result, root: property(value, "root") };
|
|
408
|
-
|
|
409
|
-
if (context.reader.backstopImports)
|
|
410
|
-
for (const candidate of next.modules)
|
|
411
|
-
backstop(candidate, { ...next, file: candidate.file, chain: [] }, result);
|
|
412
|
-
else backstop(module, next, result);
|
|
413
|
-
|
|
414
|
-
return { layers: result, root: property(value, "root") };
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export function configAt(
|
|
418
|
-
file: string,
|
|
419
|
-
dir: string,
|
|
420
|
-
extension: string | undefined,
|
|
421
|
-
reader: Reader,
|
|
422
|
-
): Found {
|
|
423
|
-
const work: Context["work"] = {
|
|
424
|
-
count: 0,
|
|
425
|
-
exceeded: false,
|
|
426
|
-
cycles: 0,
|
|
427
|
-
memo: new Map<Value, Map<string, Layer[]>>(),
|
|
428
|
-
charged: new Set<string>(),
|
|
429
|
-
reaching: [],
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
const result = fileLayers(file, {
|
|
433
|
-
reader,
|
|
434
|
-
file,
|
|
435
|
-
shared: false,
|
|
436
|
-
chain: [],
|
|
437
|
-
consumed: new Set(),
|
|
438
|
-
ancestors: [],
|
|
439
|
-
modules: new Set(),
|
|
440
|
-
work,
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
return {
|
|
444
|
-
setting: work.exceeded ? "unknown" : fold(result.layers, dir, extension),
|
|
445
|
-
root: result.root,
|
|
446
|
-
file,
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
export function decided(reader: Reader, found: Found | null): Decision | null {
|
|
451
|
-
return found && found.setting !== null
|
|
452
|
-
? { family: reader.family, setting: found.setting, files: [found.file] }
|
|
453
|
-
: null;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
export function everyConfig(dir: string, extension: string | undefined, reader: Reader): Found[] {
|
|
457
|
-
return [...configDirectories(dir, reader)].flatMap((files) =>
|
|
458
|
-
files.map((file) => configAt(file, dir, extension, reader)),
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// ESLint 9 uses the cwd config; ESLint 10 uses the nearest config.
|
|
463
|
-
export function enforcing(found: Found[]): Found | null {
|
|
464
|
-
const nearest = found.find((item) => item.setting !== null);
|
|
465
|
-
return (
|
|
466
|
-
found.find((item) => item.setting === "on" || item.setting === "unknown") ?? nearest ?? null
|
|
467
|
-
);
|
|
468
|
-
}
|