@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.
Files changed (59) hide show
  1. package/README.md +15 -13
  2. package/package.json +19 -11
  3. package/src/launcher +102 -8
  4. package/src/cli.ts +0 -684
  5. package/src/compile/darwin-arm64.ts +0 -3
  6. package/src/compile/darwin-x64.ts +0 -3
  7. package/src/compile/linux-arm64-musl.ts +0 -3
  8. package/src/compile/linux-arm64.ts +0 -3
  9. package/src/compile/linux-x64-musl.ts +0 -3
  10. package/src/compile/linux-x64.ts +0 -3
  11. package/src/compiled.ts +0 -9
  12. package/src/depth.ts +0 -372
  13. package/src/directories.ts +0 -77
  14. package/src/engine/attach.ts +0 -62
  15. package/src/engine/directives.ts +0 -157
  16. package/src/engine/doc.ts +0 -93
  17. package/src/engine/edits.ts +0 -79
  18. package/src/engine/explain.ts +0 -337
  19. package/src/engine/gaps.ts +0 -361
  20. package/src/engine/hunks.ts +0 -319
  21. package/src/engine/index.ts +0 -273
  22. package/src/engine/model.ts +0 -103
  23. package/src/engine/rules.ts +0 -104
  24. package/src/engine/types.ts +0 -38
  25. package/src/files.ts +0 -1186
  26. package/src/format.ts +0 -159
  27. package/src/gitignore.ts +0 -280
  28. package/src/hook.ts +0 -380
  29. package/src/languages/index.ts +0 -34
  30. package/src/languages/javascript/ast.ts +0 -261
  31. package/src/languages/javascript/braces.ts +0 -374
  32. package/src/languages/javascript/config/biome.ts +0 -112
  33. package/src/languages/javascript/config/eslint.ts +0 -128
  34. package/src/languages/javascript/config/evaluate.ts +0 -278
  35. package/src/languages/javascript/config/find.ts +0 -105
  36. package/src/languages/javascript/config/glob.ts +0 -149
  37. package/src/languages/javascript/config/index.ts +0 -48
  38. package/src/languages/javascript/config/layers.ts +0 -468
  39. package/src/languages/javascript/config/module.ts +0 -327
  40. package/src/languages/javascript/config/oxlint.ts +0 -170
  41. package/src/languages/javascript/config/width.ts +0 -723
  42. package/src/languages/javascript/deserializers.ts +0 -17
  43. package/src/languages/javascript/embedded.ts +0 -7
  44. package/src/languages/javascript/entry.ts +0 -42
  45. package/src/languages/javascript/facts.ts +0 -294
  46. package/src/languages/javascript/index.ts +0 -20
  47. package/src/languages/javascript/lists.ts +0 -64
  48. package/src/languages/javascript/oracle.ts +0 -191
  49. package/src/languages/javascript/oxc-raw.d.ts +0 -31
  50. package/src/languages/javascript/parse.ts +0 -131
  51. package/src/languages/javascript/raw.ts +0 -95
  52. package/src/languages/javascript/scan.ts +0 -68
  53. package/src/languages/language.ts +0 -109
  54. package/src/native-file.d.ts +0 -4
  55. package/src/pool.ts +0 -473
  56. package/src/start.ts +0 -49
  57. package/src/step.ts +0 -113
  58. package/src/usage.ts +0 -35
  59. package/src/worker.ts +0 -5
@@ -1,374 +0,0 @@
1
- import type { BlockStatement, Node, Statement } from "oxc-parser";
2
- import type { BracePass, BraceScan } from "../language.ts";
3
- import { JUMP_TYPES, LOOP_TYPES, walk } from "./ast.ts";
4
- import { commentIndex, finding, lineAt, nextToken, source } from "../../engine/doc.ts";
5
- import type { OffsetEdit } from "../../engine/edits.ts";
6
- import type { Comment, Doc } from "../../engine/model.ts";
7
- import type { Finding } from "../../engine/types.ts";
8
-
9
- const REMOVABLE = new Set(["ExpressionStatement", ...JUMP_TYPES, "IfStatement", ...LOOP_TYPES]);
10
-
11
- function addOwned(owners: Map<BlockStatement, Node>, node: Node): void {
12
- switch (node.type) {
13
- case "IfStatement":
14
- if (node.consequent.type === "BlockStatement") owners.set(node.consequent, node);
15
- if (node.alternate?.type === "BlockStatement") owners.set(node.alternate, node);
16
- return;
17
-
18
- case "ForStatement":
19
- case "ForInStatement":
20
- case "ForOfStatement":
21
- case "WhileStatement":
22
- case "DoWhileStatement":
23
- if (node.body.type === "BlockStatement") owners.set(node.body, node);
24
- }
25
- }
26
-
27
- export function controlledBlocks(
28
- root: Node,
29
- enter: (node: Node, parent: Node | null) => void = () => {},
30
- ): Map<BlockStatement, Node> {
31
- const owners = new Map<BlockStatement, Node>();
32
- walk(root, enter, (node) => addOwned(owners, node));
33
- return owners;
34
- }
35
-
36
- function endsWithOpenIf(node: Statement, removed: ReadonlySet<BlockStatement>): boolean {
37
- let current = node;
38
- while (true) {
39
- switch (current.type) {
40
- case "IfStatement":
41
- if (!current.alternate) return true;
42
- current = current.alternate;
43
- continue;
44
-
45
- case "ForStatement":
46
- case "ForInStatement":
47
- case "ForOfStatement":
48
- case "WhileStatement":
49
- case "DoWhileStatement":
50
- case "LabeledStatement":
51
- case "WithStatement":
52
- current = current.body;
53
- continue;
54
-
55
- case "BlockStatement":
56
- if (!removed.has(current)) return false;
57
- current = current.body[0]!;
58
- continue;
59
-
60
- default:
61
- return false;
62
- }
63
- }
64
- }
65
-
66
- function openingEdit(doc: Doc, offset: number): OffsetEdit {
67
- const line = lineAt(doc, offset);
68
- const start = doc.lineStarts[line - 1]!;
69
- const end = start + doc.lines[line - 1]!.length;
70
- if (doc.lines[line - 1]!.trim() === "{") return { start, end: end + 1 };
71
- if (doc.text.slice(offset + 1, end).trim() === "") {
72
- const horizontal = /[^\S\r\n]*$/.exec(doc.text.slice(start, offset))![0].length;
73
- return { start: offset - horizontal, end: offset + 1 };
74
- }
75
-
76
- return { start: offset, end: offset + (doc.text[offset + 1] === " " ? 2 : 1) };
77
- }
78
-
79
- function closingEdit(doc: Doc, offset: number): OffsetEdit {
80
- const line = lineAt(doc, offset);
81
- const start = doc.lineStarts[line - 1]!;
82
- const end = start + doc.lines[line - 1]!.length;
83
- if (doc.lines[line - 1]!.trim() === "}") {
84
- const finalLine = end === doc.text.length;
85
- return { start, end: finalLine ? end : end + 1 };
86
- }
87
-
88
- if (/^ \w/.test(doc.text.slice(offset + 1))) return { start: offset, end: offset + 2 };
89
- return { start: offset - (doc.text[offset - 1] === " " ? 1 : 0), end: offset + 1 };
90
- }
91
-
92
- function continuation(doc: Doc, inner: Statement, block: BlockStatement): number | null {
93
- if (source(doc, inner).endsWith(";")) return null;
94
-
95
- const after = nextToken(doc, block.end);
96
- const separated = /[\r\n]/.test(doc.text.slice(block.end, after));
97
- const safe = after >= doc.text.length || (separated && !/^[([`+\-/.<;]/.test(doc.text[after]!));
98
- return safe ? null : after;
99
- }
100
-
101
- function fusesIdentifiers(doc: Doc, edit: OffsetEdit): boolean {
102
- return (
103
- /[$\\\p{ID_Continue}\u200C\u200D]$/u.test(
104
- doc.text.slice(Math.max(0, edit.start - 2), edit.start),
105
- ) && /^[$\\\p{ID_Continue}\u200C\u200D]/u.test(doc.text.slice(edit.end, edit.end + 2))
106
- );
107
- }
108
-
109
- export type BraceHold =
110
- | { kind: "count"; count: number }
111
- | { kind: "statement"; inner: Statement }
112
- | { kind: "continues"; inner: Statement; after: number }
113
- | { kind: "comment"; comment: Comment }
114
- | { kind: "closing"; comment: Comment }
115
- | { kind: "else"; inner: Statement }
116
- | { kind: "fuse" };
117
-
118
- export function braceHold(
119
- doc: Doc,
120
- block: BlockStatement,
121
- removed: ReadonlySet<BlockStatement>,
122
- chained = false,
123
- ): BraceHold | null {
124
- const inner = block.body[0];
125
- if (block.body.length !== 1 || !inner) return { kind: "count", count: block.body.length };
126
- if (!REMOVABLE.has(inner.type)) return { kind: "statement", inner };
127
-
128
- const after = chained ? null : continuation(doc, inner, block);
129
- if (after !== null) return { kind: "continues", inner, after };
130
-
131
- for (
132
- let index = commentIndex(doc, block.start + 1);
133
- index < commentIndex(doc, block.end);
134
- index++
135
- ) {
136
- const comment = doc.comments[index]!;
137
- if (comment.start < inner.start || comment.end > inner.end) return { kind: "comment", comment };
138
- }
139
-
140
- const comment = doc.comments[commentIndex(doc, block.end)];
141
- const line = lineAt(doc, block.end - 1);
142
- if (
143
- comment &&
144
- doc.text.slice(block.end, comment.start).trim() === "" &&
145
- lineAt(doc, comment.start) === line &&
146
- doc.text.slice(doc.lineStarts[line - 1], block.end - 1).trim() === ""
147
- )
148
- return { kind: "closing", comment };
149
-
150
- const next = nextToken(doc, block.end);
151
- if (/^else\b/.test(doc.text.slice(next)) && endsWithOpenIf(inner, removed))
152
- return { kind: "else", inner };
153
-
154
- const opening = openingEdit(doc, block.start);
155
- const closing = closingEdit(doc, block.end - 1);
156
- if (fusesIdentifiers(doc, opening) || fusesIdentifiers(doc, closing)) return { kind: "fuse" };
157
-
158
- return null;
159
- }
160
-
161
- function trailingBody(statement: Statement): Statement | null {
162
- switch (statement.type) {
163
- case "IfStatement":
164
- return statement.alternate ? null : statement.consequent;
165
-
166
- case "ForStatement":
167
- case "ForInStatement":
168
- case "ForOfStatement":
169
- case "WhileStatement":
170
- return statement.body;
171
-
172
- default:
173
- return null;
174
- }
175
- }
176
-
177
- function closersEndAtFixedBrace(
178
- doc: Doc,
179
- from: number,
180
- byClosing: ReadonlyMap<number, BlockStatement>,
181
- known: Map<number, boolean>,
182
- ): boolean {
183
- const visited: number[] = [];
184
-
185
- let at = from;
186
- let answer: boolean | undefined;
187
- while (answer === undefined) {
188
- while (at < doc.text.length && /\s/.test(doc.text[at]!)) at++;
189
- answer = known.get(at);
190
- if (answer !== undefined) break;
191
-
192
- if (at >= doc.text.length || (doc.text[at] === "}" && !byClosing.has(at))) answer = true;
193
- else if (doc.text[at] !== "}") answer = false;
194
- else visited.push(at++);
195
- }
196
-
197
- for (const offset of visited) known.set(offset, answer);
198
- return answer;
199
- }
200
-
201
- function closesChain(
202
- doc: Doc,
203
- block: BlockStatement,
204
- removed: ReadonlySet<BlockStatement>,
205
- outerGoes: boolean,
206
- settled: () => boolean,
207
- codeStart: (offset: number) => number,
208
- ): boolean {
209
- const inner = block.body.length === 1 ? trailingBody(block.body[0]!) : null;
210
- if (inner?.type !== "BlockStatement" || !removed.has(inner)) return false;
211
-
212
- return (
213
- doc.text.slice(inner.end, block.end - 1) === " " &&
214
- codeStart(inner.end - 1) < inner.end - 1 &&
215
- doc.text.slice(block.end, block.end + 2) === " }" &&
216
- !outerGoes &&
217
- settled() &&
218
- braceHold(doc, block, removed, true) === null
219
- );
220
- }
221
-
222
- export function braceEdits(doc: Doc, blocks: BlockStatement[], collapseChains: boolean): BracePass {
223
- const edits: OffsetEdit[] = [];
224
- const findings: Finding[] = [];
225
- const removed = new Set<BlockStatement>();
226
- const remove = (block: BlockStatement) => {
227
- removed.add(block);
228
- edits.push(openingEdit(doc, block.start), closingEdit(doc, block.end - 1));
229
- findings.push(finding(doc, block.start, "braces"));
230
- };
231
-
232
- for (const block of blocks) if (braceHold(doc, block, removed) === null) remove(block);
233
-
234
- if (!collapseChains) return { edits, findings };
235
-
236
- const standard = new Set(removed);
237
- const byClosing = new Map(blocks.map((block) => [block.end - 1, block]));
238
- const known = new Map<number, boolean>();
239
- const codeStarts = new Map<number, number>();
240
- const codeStart = (offset: number) => {
241
- const line = doc.lineStarts[lineAt(doc, offset) - 1]!;
242
-
243
- let start = codeStarts.get(line);
244
- if (start === undefined) {
245
- const code = /[^\s{}]|\n/g;
246
- code.lastIndex = line;
247
-
248
- const match = code.exec(doc.text);
249
- start = match && match[0] !== "\n" ? match.index : Infinity;
250
- codeStarts.set(line, start);
251
- }
252
-
253
- return start;
254
- };
255
-
256
- for (const block of blocks) {
257
- const outer = byClosing.get(block.end + 1);
258
- const outerGoes = outer !== undefined && standard.has(outer);
259
- const settled = () => closersEndAtFixedBrace(doc, block.end, byClosing, known);
260
- if (!standard.has(block) && closesChain(doc, block, removed, outerGoes, settled, codeStart))
261
- remove(block);
262
- }
263
-
264
- return { edits, findings };
265
- }
266
-
267
- function statementName(doc: Doc, inner: Statement): string {
268
- if (inner.type === "BlockStatement") return "a nested block";
269
- if (inner.type === "EmptyStatement") return "an empty statement";
270
- if (inner.type === "LabeledStatement") return "a labeled statement";
271
-
272
- const word = /^[\w$]+/.exec(source(doc, inner))?.[0];
273
- if (word) return `a \`${word}\` statement`;
274
-
275
- return `a ${inner.type.replaceAll(/(?<=[a-z])(?=[A-Z])/g, " ").toLowerCase()}`;
276
- }
277
-
278
- function holdReason(
279
- doc: Doc,
280
- block: BlockStatement,
281
- hold: BraceHold,
282
- at: (offset: number) => number,
283
- ): string {
284
- switch (hold.kind) {
285
- case "count":
286
- return hold.count === 0 ? "the body is empty" : `the body holds ${hold.count} statements`;
287
-
288
- case "statement":
289
- return `the body is ${statementName(doc, hold.inner)}, and only an expression, \`return\`, \`throw\`, \`break\`, \`continue\`, \`if\` or loop stands without braces`;
290
-
291
- case "continues": {
292
- const line = lineAt(doc, hold.after);
293
- const end = doc.lineStarts[line - 1]! + doc.lines[line - 1]!.length;
294
- const where =
295
- line === lineAt(doc, block.end - 1) ? "the same line" : `line ${at(hold.after)}`;
296
-
297
- return `\`${source(doc, hold.inner).split("\n")[0]!.trim()}\` has no semicolon, so without braces it could continue onto \`${doc.text.slice(hold.after, end).trim()}\` on ${where}`;
298
- }
299
-
300
- case "comment":
301
- return `a comment on line ${at(hold.comment.start)} sits inside the braces but outside the statement`;
302
-
303
- case "closing":
304
- return `a comment after the closing brace on line ${at(hold.comment.start)} would move onto the next line without it`;
305
-
306
- case "else":
307
- return `without braces, the \`else\` on line ${at(nextToken(doc, block.end))} would attach to the \`if\` inside them`;
308
-
309
- case "fuse":
310
- return "removing the braces would run two words together";
311
- }
312
- }
313
-
314
- export function braceScan(
315
- doc: Doc,
316
- blocks: BlockStatement[],
317
- owners: Map<BlockStatement, Node>,
318
- chains: Map<Node, Node>,
319
- ): BraceScan {
320
- return {
321
- pass(touches, touched, collapseChains) {
322
- const selected = new Set<Node>();
323
- for (const stmt of touched) {
324
- let node = stmt.node as Node;
325
- while (node.type === "LabeledStatement") node = node.body;
326
- selected.add(node);
327
- }
328
-
329
- return braceEdits(
330
- doc,
331
- blocks.filter((block) => {
332
- const owner = owners.get(block)!;
333
- return (
334
- touches(lineAt(doc, block.start), lineAt(doc, block.end - 1)) ||
335
- selected.has(chains.get(owner) ?? owner)
336
- );
337
- }),
338
- collapseChains,
339
- );
340
- },
341
- opening(line) {
342
- const opening = [...owners.keys()].filter((block) => lineAt(doc, block.start) === line);
343
- const selected =
344
- opening.length > 0
345
- ? opening
346
- : [...owners]
347
- .filter(([, owner]) => lineAt(doc, owner.start) === line)
348
- .map(([block]) => block);
349
-
350
- return selected.map((block) => {
351
- const [inner] = block.body;
352
- return {
353
- start: block.start,
354
- open: lineAt(doc, block.start),
355
- close: lineAt(doc, block.end - 1),
356
- inner:
357
- inner && block.body.length === 1
358
- ? [lineAt(doc, inner.start), lineAt(doc, inner.end - 1)]
359
- : null,
360
- };
361
- });
362
- },
363
- hold(start, at) {
364
- const survivor = [...owners.keys()].find((candidate) => candidate.start === start);
365
- if (!survivor || !blocks.includes(survivor)) return { kind: "directive" };
366
-
367
- const hold = braceHold(doc, survivor, new Set());
368
- if (hold?.kind === "count")
369
- return { kind: "inapplicable", reason: holdReason(doc, survivor, hold, at) };
370
-
371
- return { kind: "held", reason: hold ? holdReason(doc, survivor, hold, at) : null };
372
- },
373
- };
374
- }
@@ -1,112 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { UNKNOWN, type Value, object, property } from "./evaluate.ts";
4
- import {
5
- type Context,
6
- type Layer,
7
- type Reader,
8
- type Tree,
9
- type Setting,
10
- UNKNOWN_LAYER,
11
- decided,
12
- enforcing,
13
- everyConfig,
14
- excluding,
15
- fileLayers,
16
- levelOf,
17
- patterns,
18
- read,
19
- resolved,
20
- tree,
21
- } from "./layers.ts";
22
-
23
- interface BiomeFindings {
24
- rule: Setting[];
25
- group: Setting[];
26
- }
27
-
28
- function biomeSettings(
29
- value: Value,
30
- context: Context,
31
- inside = "",
32
- found: BiomeFindings = { rule: [], group: [] },
33
- ): BiomeFindings {
34
- if (value === UNKNOWN) found.rule.push("unknown");
35
- else if (Array.isArray(value))
36
- for (const item of value) biomeSettings(item, context, inside, found);
37
- else if (object(value))
38
- for (const key of Object.keys(value)) {
39
- if (["extends", "overrides", "includes", "include", "ignore"].includes(key)) continue;
40
-
41
- const item = read(value, key, context);
42
- if (key === "useBlockStatements") found.rule.push(levelOf(item));
43
- else if (key === "style" && inside === "rules" && typeof item === "string" && item !== "off")
44
- found.group.push("on");
45
- else if (key === "all" && item === true && (inside === "rules" || inside === "style"))
46
- found.group.push("on");
47
- else biomeSettings(item, context, key, found);
48
- }
49
-
50
- return found;
51
- }
52
-
53
- function ownLayers(value: Value, context: Context): Layer[] {
54
- const findings = biomeSettings(value, context);
55
- const found = findings.rule.length ? findings.rule : findings.group;
56
- return found.length
57
- ? [
58
- {
59
- reach: "all",
60
- setting: found.every((item) => item === "off")
61
- ? "off"
62
- : found.includes("unknown")
63
- ? "unknown"
64
- : "on",
65
- },
66
- ]
67
- : [];
68
- }
69
-
70
- const biomeTree: Tree = {
71
- scope(value, context) {
72
- const includes = property(value, "includes");
73
-
74
- let reach = patterns(includes, context, "anchored");
75
- if (includes === undefined) reach = patterns(property(value, "include"), context, "biome1");
76
-
77
- return excluding(reach, property(value, "ignore"), context, "anchored");
78
- },
79
- own: ownLayers,
80
- extend(entry, _parent, context) {
81
- if (entry === "//") {
82
- let dir = dirname(context.file);
83
- while (dirname(dir) !== dir) {
84
- dir = dirname(dir);
85
-
86
- for (const name of biome.files) {
87
- const file = join(dir, name);
88
- if (existsSync(file)) return fileLayers(file, { ...context, shared: false }).layers;
89
- }
90
- }
91
-
92
- return [UNKNOWN_LAYER];
93
- }
94
-
95
- return resolved(entry, context, "import");
96
- },
97
- };
98
-
99
- export const biome: Reader = {
100
- family: "biome",
101
- files: ["biome.json", "biome.jsonc"],
102
- backstop: ["useBlockStatements"],
103
- backstopImports: false,
104
- layers(value, context) {
105
- return tree(value, context, biomeTree);
106
- },
107
- decide(dir, extension) {
108
- const found = everyConfig(dir, extension, biome);
109
- const nearest = found.find((item) => item.setting !== null);
110
- return decided(biome, nearest?.root === false ? nearest : enforcing(found));
111
- },
112
- };
@@ -1,128 +0,0 @@
1
- import { basename } from "node:path";
2
- import { NO_SETTING, type Value, property } from "./evaluate.ts";
3
- import { configDirectories } from "./find.ts";
4
- import {
5
- type Context,
6
- type Layer,
7
- type Reader,
8
- type Tree,
9
- configAt,
10
- decided,
11
- enforcing,
12
- eslintConfig,
13
- everyConfig,
14
- excluding,
15
- levelOf,
16
- patterns,
17
- read,
18
- resolved,
19
- tree,
20
- } from "./layers.ts";
21
-
22
- function ownLayers(value: Value, context: Context): Layer[] {
23
- const rules = property(value, "rules");
24
- const curly = read(rules, "curly", context);
25
- return curly === undefined || curly === NO_SETTING
26
- ? []
27
- : [{ reach: "all", setting: levelOf(curly) }];
28
- }
29
-
30
- function packageName(name: string): string {
31
- if (name.startsWith("@")) {
32
- const [scope, pkg] = name.split("/");
33
- return `${scope}/${pkg?.startsWith("eslint-config") ? pkg : pkg ? `eslint-config-${pkg}` : "eslint-config"}`;
34
- }
35
-
36
- return name.startsWith("eslint-config-") ? name : `eslint-config-${name}`;
37
- }
38
-
39
- const flatTree: Tree = {
40
- scope(value, context) {
41
- if (property(value, "basePath") !== undefined) return "some";
42
- const reach = patterns(property(value, "files"), context, "anchored");
43
- return excluding(reach, property(value, "ignores"), context, "anchored");
44
- },
45
- own: ownLayers,
46
- extend(entry, parent, context) {
47
- if (!entry.startsWith(".") && !entry.startsWith("/")) {
48
- const slash = entry.lastIndexOf("/");
49
- const plugin = property(property(parent, "plugins"), entry.slice(0, slash));
50
- if (slash > 0 && plugin !== undefined)
51
- return context.reader.layers(
52
- property(property(plugin, "configs"), entry.slice(slash + 1)),
53
- {
54
- ...context,
55
- shared: true,
56
- },
57
- );
58
- }
59
-
60
- return resolved(entry, context, "import");
61
- },
62
- };
63
-
64
- const legacyTree: Tree = {
65
- scope(value, context) {
66
- const reach = patterns(property(value, "files"), context, "legacy");
67
- return excluding(reach, property(value, "excludedFiles"), context, "legacy");
68
- },
69
- own: ownLayers,
70
- extend(entry, _parent, context) {
71
- const specifier = !entry.startsWith(".") && !entry.startsWith("/") ? packageName(entry) : entry;
72
- return resolved(specifier, context, "require");
73
- },
74
- };
75
-
76
- function legacyCandidate(file: string): boolean {
77
- if (basename(file) !== "package.json") return true;
78
- return eslintConfig(file) !== undefined;
79
- }
80
-
81
- export const flat: Reader = {
82
- family: "flat",
83
- files: ["js", "mjs", "cjs", "ts", "mts", "cts"].map((ext) => `eslint.config.${ext}`),
84
- backstop: ["curly"],
85
- backstopImports: false,
86
- layers(value, context) {
87
- return tree(value, context, flatTree);
88
- },
89
- decide(dir, extension) {
90
- return decided(flat, enforcing(everyConfig(dir, extension, flat)));
91
- },
92
- };
93
-
94
- export const legacy: Reader = {
95
- family: "legacy",
96
- files: [
97
- ".eslintrc.js",
98
- ".eslintrc.cjs",
99
- ".eslintrc.yaml",
100
- ".eslintrc.yml",
101
- ".eslintrc.json",
102
- ".eslintrc",
103
- "package.json",
104
- ],
105
- candidate: legacyCandidate,
106
- backstop: ["curly"],
107
- backstopImports: false,
108
- layers(value, context) {
109
- return tree(value, context, legacyTree);
110
- },
111
- decide(dir, extension) {
112
- let hasFlatConfig: boolean | undefined;
113
- for (const files of configDirectories(dir, legacy)) {
114
- const file = files[0];
115
- if (file === undefined) continue;
116
-
117
- if (basename(file) === "package.json") {
118
- hasFlatConfig ??= [...configDirectories(dir, flat)].some((files) => files.length > 0);
119
- if (hasFlatConfig) continue;
120
- }
121
-
122
- const found = configAt(file, dir, extension, legacy);
123
- if (found.setting !== null || found.root === true) return decided(legacy, found);
124
- }
125
-
126
- return null;
127
- },
128
- };