@r_masseater/fu4 0.1.0 → 0.2.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.
@@ -0,0 +1,635 @@
1
+ import { createRequire } from "node:module";
2
+ import { Array as Array$1, Boolean, Console, Effect, FileSystem, Function, Layer, Match, Option, Order, Path, Predicate, Record, Schema, String as String$1, pipe } from "effect";
3
+ import { runMain } from "@effect/platform-node/NodeRuntime";
4
+ import { layer } from "@effect/platform-node/NodeServices";
5
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
6
+ import { FetchHttpClient } from "effect/http";
7
+ import { Otlp, OtlpSerialization } from "effect/observability";
8
+ import { resolveConfigFromFile } from "vite-plus";
9
+ import { minimatch } from "minimatch";
10
+ // src/app/format.ts
11
+ const format = (diagnostic) => `${diagnostic.path}:${String(diagnostic.line)}:${String(diagnostic.column)}: ${diagnostic.message} [${diagnostic.rule}]`;
12
+ // ../lint-host/src/entities/rule/model/setting.ts
13
+ const NO_OPTIONS = {};
14
+ const settingOf = (entry) => Match.value(entry).pipe(Match.when(Match.string, (severity) => ({
15
+ severity,
16
+ options: NO_OPTIONS
17
+ })), Match.orElse(([severity, options]) => ({
18
+ severity,
19
+ options: options ?? NO_OPTIONS
20
+ })));
21
+ // ../lint-host/src/shared/lib/target.ts
22
+ const abiOf = (platform) => Match.value(platform).pipe(Match.when("linux", () => "-gnu"), Match.when("win32", () => "-msvc"), Match.orElse(() => ""));
23
+ const platformTarget = `${process.platform}-${process.arch}${abiOf(process.platform)}`;
24
+ const addonFileOf = (binary) => `${binary}.${platformTarget}.node`;
25
+ // ../lint-host/src/features/build-addon/model/build.ts
26
+ const taggedError$1 = Schema.TaggedError;
27
+ var AddonBuildFailed = class extends taggedError$1()("AddonBuildFailed", { message: Schema.String }) {};
28
+ const LIBRARY = {
29
+ linux: (name) => `lib${name}.so`,
30
+ darwin: (name) => `lib${name}.dylib`,
31
+ win32: (name) => `${name}.dll`
32
+ };
33
+ const SUCCESS = 0;
34
+ const cargo = Effect.fn("cargo")(function* cargo(crate, workspace) {
35
+ const exitCode = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make("cargo", [
36
+ "build",
37
+ "--release",
38
+ "--locked",
39
+ "-p",
40
+ crate
41
+ ], {
42
+ cwd: workspace,
43
+ stdout: "inherit",
44
+ stderr: "inherit"
45
+ }));
46
+ const failure = AddonBuildFailed.make({ message: `cargo exited with ${String(exitCode)}` });
47
+ yield* Effect.when(Effect.fail(failure), Effect.sync(() => Number(exitCode) !== SUCCESS));
48
+ });
49
+ Effect.fn("buildAddon")(function* build(options) {
50
+ const fileSystem = yield* FileSystem.FileSystem;
51
+ const path = yield* Path.Path;
52
+ const library = yield* Effect.fromOption(Record.get(LIBRARY, process.platform)).pipe(Effect.mapError(() => AddonBuildFailed.make({ message: `no native build for ${process.platform}` })));
53
+ yield* cargo(options.crate, options.workspaceDir);
54
+ const output = path.join(options.packageDir, "native");
55
+ yield* fileSystem.makeDirectory(output, { recursive: true });
56
+ const built = library(String$1.replaceAll("-", "_")(options.crate));
57
+ yield* fileSystem.copyFile(path.join(options.workspaceDir, "target", "release", built), path.join(output, addonFileOf(options.binary)));
58
+ });
59
+ // ../lint-host/src/features/load-addon/model/load.ts
60
+ const loadAddon = ({ packageName, binary, from, isAddon, failWith }) => {
61
+ const requireFrom = createRequire(from);
62
+ const loadFrom = (specifier) => Effect.try({
63
+ try: () => requireFrom(specifier),
64
+ catch: failWith(`could not load ${specifier}`)
65
+ });
66
+ return loadFrom(`${packageName}-${platformTarget}`).pipe(Effect.catchCause(() => loadFrom(`${packageName}/native/${addonFileOf(binary)}`)), Effect.filterOrFail(isAddon, (found) => failWith(`no ${binary} addon for ${platformTarget}`)(found)));
67
+ };
68
+ const callAddon = ({ addon, name, files, call, failWith }) => addon.pipe(Effect.flatMap((loaded) => Effect.try({
69
+ try: () => call(loaded),
70
+ catch: failWith(`${name} could not lint`)
71
+ }).pipe(Effect.tap(() => Effect.promise(() => loaded.flushTelemetry())))), Effect.withSpan(`${name}.native`, { attributes: { [`${name}.files`]: files } }));
72
+ // ../lint-host/src/features/load-addon/model/guard.ts
73
+ const hasFunction = (value) => (name) => Predicate.hasProperty(value, name) && Predicate.isFunction(value[name]);
74
+ const exposes = (names) => (value) => pipe(names, Array$1.every(hasFunction(value)));
75
+ // ../lint-host/src/features/run-cli/model/cli.ts
76
+ const CONFIG_FILES = [
77
+ "vite.config.ts",
78
+ "vite.config.mts",
79
+ "vite.config.js",
80
+ "vite.config.mjs"
81
+ ];
82
+ const FAILED = 1;
83
+ const DATA_FIRST_ARITY$1 = 2;
84
+ const ARGUMENTS_START = 2;
85
+ const readSectionIn = (source, root) => Effect.gen(function* readConfig() {
86
+ const fileSystem = yield* FileSystem.FileSystem;
87
+ const path = yield* Path.Path;
88
+ const found = yield* pipe(CONFIG_FILES, Array$1.map((name) => path.join(root, name)), Effect.filter((file) => fileSystem.exists(file).pipe(Effect.orElseSucceed(() => false))));
89
+ const loaded = yield* Option.match(Array$1.head(found), {
90
+ onNone: () => Effect.succeed({}),
91
+ onSome: (file) => Effect.tryPromise({
92
+ try: () => resolveConfigFromFile(file),
93
+ catch: source.failWith(`could not load ${file}`)
94
+ })
95
+ });
96
+ return source.section(loaded);
97
+ }).pipe(Effect.withSpan(`${source.name}.config`));
98
+ Function.dual(DATA_FIRST_ARITY$1, readSectionIn);
99
+ const trackedFiles = (root, pathspecs) => Effect.gen(function* listFiles() {
100
+ const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
101
+ "ls-files",
102
+ "-co",
103
+ "--exclude-standard",
104
+ "-z",
105
+ "--",
106
+ ...pathspecs
107
+ ], { cwd: root }));
108
+ return pipe(String$1.split(output, "\0"), Array$1.filter(String$1.isNonEmpty));
109
+ });
110
+ const requestOf = (config, patterns) => Array$1.match(patterns, {
111
+ onEmpty: () => ({ config }),
112
+ onNonEmpty: (given) => ({
113
+ config,
114
+ patterns: given
115
+ })
116
+ });
117
+ const hasError = (found) => pipe(found, Array$1.some(({ severity }) => severity === "error"));
118
+ const failWhen = (failed) => Effect.when(Effect.sync(() => {
119
+ process.exitCode = FAILED;
120
+ }), Effect.succeed(failed)).pipe(Effect.asVoid);
121
+ const printAll = (found, format) => Array$1.match(found, {
122
+ onEmpty: () => Effect.void,
123
+ onNonEmpty: (all) => Console.log(pipe(all, Array$1.map(format), Array$1.join("\n")))
124
+ });
125
+ const readerIn = (root, failWith) => Effect.gen(function* reader() {
126
+ const fileSystem = yield* FileSystem.FileSystem;
127
+ const path = yield* Path.Path;
128
+ return (file) => fileSystem.readFileString(path.resolve(root, file)).pipe(Effect.mapError(failWith(`could not read ${file}`)));
129
+ });
130
+ const mainOf = (cli) => Effect.gen(function* main() {
131
+ const root = process.cwd();
132
+ const config = yield* readSectionIn(cli, root);
133
+ const patterns = process.argv.slice(ARGUMENTS_START);
134
+ const pathspecs = cli.pathspecs(requestOf(config, patterns));
135
+ const { files, projectFiles } = yield* Effect.all({
136
+ files: trackedFiles(root, pathspecs).pipe(Effect.withSpan(`${cli.name}.files`)),
137
+ projectFiles: trackedFiles(root, []).pipe(Effect.withSpan(`${cli.name}.project`))
138
+ }, { concurrency: "unbounded" });
139
+ const read = yield* readerIn(root, cli.failWith);
140
+ const found = yield* cli.lint({
141
+ root,
142
+ files,
143
+ projectFiles,
144
+ config,
145
+ read
146
+ });
147
+ yield* printAll(found, cli.format);
148
+ yield* failWhen(hasError(found));
149
+ });
150
+ const runTraced = (name, program) => {
151
+ const services = Otlp.layerFromConfig({ resource: { serviceName: name } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer), Layer.provideMerge(layer));
152
+ runMain(program.pipe(Effect.provide(services)));
153
+ };
154
+ const runCli = (cli) => {
155
+ runTraced(cli.name, mainOf(cli));
156
+ };
157
+ Function.dual(2, (value, build) => Option.match(value, {
158
+ onNone: () => ({}),
159
+ onSome: build
160
+ }));
161
+ // ../lint-host/src/shared/lib/trace.ts
162
+ const SAMPLED = "01";
163
+ const NOT_SAMPLED = "00";
164
+ const LINE_START = 0;
165
+ const flagsOf = (sampled) => Boolean.match(sampled, {
166
+ onFalse: () => NOT_SAMPLED,
167
+ onTrue: () => SAMPLED
168
+ });
169
+ const traceparent = Effect.currentSpan.pipe(Effect.map((span) => `00-${span.traceId}-${span.spanId}-${flagsOf(span.sampled)}`), Effect.option);
170
+ Order.combine(Order.mapInput(Order.String, (found) => found.path), Order.combine(Order.mapInput(Order.Number, (found) => found.line), Order.mapInput(Order.Number, (found) => found.column ?? LINE_START)));
171
+ // ../lint-host/src/shared/lib/layers.ts
172
+ const mergedRecords = (records) => pipe(records, Array$1.flatMap((record) => Record.toEntries(record ?? {})), Record.fromEntries);
173
+ const layersOf = (config) => {
174
+ const { extends: bases = [], ...own } = config;
175
+ return [...pipe(bases, Array$1.flatMap(layersOf)), own];
176
+ };
177
+ const mergedLayers = (layers) => ({
178
+ plugins: mergedRecords(pipe(layers, Array$1.map((layer) => layer.plugins))),
179
+ rules: mergedRecords(pipe(layers, Array$1.map((layer) => layer.rules))),
180
+ ignores: pipe(layers, Array$1.flatMap((layer) => layer.ignores ?? [])),
181
+ overrides: pipe(layers, Array$1.flatMap((layer) => layer.overrides ?? []))
182
+ });
183
+ // ../lint-host/src/shared/lib/words.ts
184
+ const WORD$1 = 4;
185
+ const EMPTY$1 = 0;
186
+ const aligned = (buffer) => Option.match(Option.liftPredicate(buffer, ({ byteOffset }) => byteOffset % WORD$1 === EMPTY$1), {
187
+ onNone: () => Uint8Array.from(buffer),
188
+ onSome: (value) => value
189
+ });
190
+ const wordAt = (words) => (index) => words[index] ?? EMPTY$1;
191
+ // src/entities/rule/model/define.ts
192
+ const defineRule = (rule) => rule;
193
+ const definePlugin = (plugin) => plugin;
194
+ // src/entities/rule/model/extend.ts
195
+ const flattenConfig = (config) => {
196
+ const layers = layersOf(config);
197
+ return {
198
+ ...mergedLayers(layers),
199
+ settings: mergedRecords(pipe(layers, Array$1.map((layer) => layer.settings)))
200
+ };
201
+ };
202
+ // src/entities/rule/model/resolve.ts
203
+ const NEGATION = "!";
204
+ const SEPARATOR$1 = "/";
205
+ const START = 0;
206
+ const enabled = ([id, entry]) => {
207
+ const { severity, options } = settingOf(entry);
208
+ if (severity === "off") return [];
209
+ return [{
210
+ id,
211
+ severity,
212
+ options
213
+ }];
214
+ };
215
+ const matches = (path) => (pattern) => minimatch(path, pattern, { dot: true });
216
+ const negated = String$1.startsWith(NEGATION);
217
+ const applies = (path) => (override) => pipe(override.files, Array$1.filter((pattern) => !negated(pattern)), Array$1.some(matches(path))) && !pipe(override.files, Array$1.filter(negated), Array$1.map(String$1.slice(1)), Array$1.some(matches(path)));
218
+ const isIgnored = (config) => (path) => pipe(config.ignores ?? [], Array$1.some(matches(path)));
219
+ const entriesFor = (config) => (path) => {
220
+ const merged = { ...config.rules };
221
+ for (const override of pipe(config.overrides ?? [], Array$1.filter(applies(path)))) Object.assign(merged, override.rules);
222
+ return merged;
223
+ };
224
+ const ruleOf = (config) => (id) => pipe(String$1.indexOf(SEPARATOR$1)(id), Option.flatMap((at) => pipe(Record.get(config.plugins ?? {}, String$1.slice(START, at)(id)), Option.flatMap((plugin) => Record.get(plugin.rules, String$1.slice(at + 1)(id))))));
225
+ const activate = (config) => (entry) => pipe(ruleOf(config)(entry.id), Option.map((rule) => ({
226
+ ...entry,
227
+ rule
228
+ })), Option.toArray);
229
+ const activeRules = (config) => (path) => pipe(Record.toEntries(entriesFor(config)(path)), Array$1.flatMap(enabled), Array$1.flatMap(activate(config)));
230
+ // src/entities/source/model/kind.ts
231
+ const SEPARATOR = "/";
232
+ const WORKFLOWS$1 = ".github/workflows/";
233
+ const YAML = /\.ya?ml$/u;
234
+ const ACTION = /^action\.ya?ml$/u;
235
+ const DEPENDABOT = /^\.github\/dependabot\.ya?ml$/u;
236
+ const PRE_COMMIT = /^\.pre-commit-(?:config|hooks)\.yaml$/u;
237
+ const baseName = (path) => pipe(String$1.split(SEPARATOR)(path), Array$1.last, Option.getOrElse(() => path));
238
+ const kindOf = (path) => {
239
+ if (DEPENDABOT.test(path)) return Option.some("dependabot");
240
+ if (PRE_COMMIT.test(path)) return Option.some("pre-commit");
241
+ if (ACTION.test(baseName(path))) return Option.some("action");
242
+ if (String$1.includes(WORKFLOWS$1)(path) && YAML.test(path)) return Option.some("workflow");
243
+ return Option.none();
244
+ };
245
+ // src/shared/lib/errors.ts
246
+ const taggedError = Schema.TaggedError;
247
+ var Fu4Error = class extends taggedError()("Fu4Error", { message: Schema.String }) {};
248
+ const failedWith = (message) => (cause) => Fu4Error.make({ message: `${message}: ${String(cause)}` });
249
+ // src/shared/native/source.ts
250
+ const WORD = 4;
251
+ const EMPTY = 0;
252
+ const NEXT = 1;
253
+ const STRING_WORDS = 2;
254
+ const NONE = 4294967295;
255
+ const HEADER = {
256
+ version: 0,
257
+ semanticCount: 1,
258
+ semanticRoot: 2,
259
+ concreteCount: 3,
260
+ concreteRoot: 4,
261
+ childCount: 5,
262
+ errorCount: 6,
263
+ stringCount: 7
264
+ };
265
+ const SEMANTIC = {
266
+ kind: 0,
267
+ tag: 1,
268
+ value: 2,
269
+ style: 3,
270
+ line: 4,
271
+ column: 5,
272
+ childStart: 6,
273
+ childCount: 7
274
+ };
275
+ const CONCRETE = {
276
+ kind: 0,
277
+ flags: 1,
278
+ start: 2,
279
+ end: 3,
280
+ field: 4,
281
+ parent: 5,
282
+ childStart: 6,
283
+ childCount: 7
284
+ };
285
+ const FLAG = {
286
+ named: 1,
287
+ error: 2,
288
+ missing: 4,
289
+ extra: 8
290
+ };
291
+ const utf16 = new TextDecoder("utf-16le");
292
+ const rootOf = (value) => Option.liftPredicate(value, (id) => id !== NONE);
293
+ const layoutOf = (header) => {
294
+ const semanticCount = wordAt(header)(HEADER.semanticCount);
295
+ const concreteCount = wordAt(header)(HEADER.concreteCount);
296
+ const errorCount = wordAt(header)(HEADER.errorCount);
297
+ const semanticAt = 8;
298
+ const concreteAt = semanticAt + semanticCount * 8;
299
+ const childAt = concreteAt + concreteCount * 8;
300
+ const errorAt = childAt + wordAt(header)(HEADER.childCount);
301
+ const spanAt = errorAt + errorCount * 3;
302
+ return {
303
+ semanticCount,
304
+ concreteCount,
305
+ errorCount,
306
+ semanticAt,
307
+ concreteAt,
308
+ childAt,
309
+ errorAt,
310
+ spanAt,
311
+ blobAt: (spanAt + wordAt(header)(HEADER.stringCount) * STRING_WORDS) * WORD
312
+ };
313
+ };
314
+ const stringsOf = (words, blob, spanAt) => {
315
+ const cache = /* @__PURE__ */ new Map();
316
+ const decode = (index) => {
317
+ const offset = wordAt(words)(spanAt + index * STRING_WORDS) * STRING_WORDS;
318
+ const length = wordAt(words)(spanAt + index * STRING_WORDS + NEXT) * STRING_WORDS;
319
+ const value = utf16.decode(blob.subarray(offset, offset + length));
320
+ cache.set(index, value);
321
+ return value;
322
+ };
323
+ return (index) => Option.getOrElse(Option.fromNullishOr(cache.get(index)), () => decode(index));
324
+ };
325
+ const sourceView = (raw) => {
326
+ const buffer = aligned(raw);
327
+ const header = new Uint32Array(buffer.buffer, buffer.byteOffset, 8);
328
+ const layout = layoutOf(header);
329
+ const words = new Uint32Array(buffer.buffer, buffer.byteOffset, layout.blobAt / WORD);
330
+ const stringAt = stringsOf(words, buffer.subarray(layout.blobAt), layout.spanAt);
331
+ return {
332
+ semanticCount: layout.semanticCount,
333
+ semanticRoot: rootOf(wordAt(header)(HEADER.semanticRoot)),
334
+ concreteCount: layout.concreteCount,
335
+ concreteRoot: rootOf(wordAt(header)(HEADER.concreteRoot)),
336
+ errorCount: layout.errorCount,
337
+ semantic: (id, field) => wordAt(words)(layout.semanticAt + id * 8 + field),
338
+ concrete: (id, field) => wordAt(words)(layout.concreteAt + id * 8 + field),
339
+ child: (index) => wordAt(words)(layout.childAt + index),
340
+ error: (index, field) => wordAt(words)(layout.errorAt + index * 3 + field),
341
+ stringAt,
342
+ text: stringAt(EMPTY)
343
+ };
344
+ };
345
+ // src/shared/native/index.ts
346
+ const isNative = exposes([
347
+ "parsePaths",
348
+ "parseText",
349
+ "parseScript",
350
+ "readText",
351
+ "pathExists",
352
+ "flushTelemetry"
353
+ ]);
354
+ const native = loadAddon({
355
+ packageName: "@r_masseater/fu4",
356
+ binary: "fu4",
357
+ from: import.meta.url,
358
+ isAddon: isNative,
359
+ failWith: failedWith
360
+ });
361
+ // src/entities/source/model/source.ts
362
+ const FIRST = 1;
363
+ const FIRST_LINE = 0;
364
+ const HALF = 2;
365
+ const BIT = 2;
366
+ const SET = 1;
367
+ const ERROR_FIELD = {
368
+ line: 0,
369
+ column: 1,
370
+ message: 2
371
+ };
372
+ const LINE_BREAK = /\r\n|\r|\n/u;
373
+ const NEWLINES = /\n/gu;
374
+ const KINDS = [
375
+ "scalar",
376
+ "sequence",
377
+ "mapping",
378
+ "alias"
379
+ ];
380
+ const STYLES = [
381
+ "plain",
382
+ "single-quoted",
383
+ "double-quoted",
384
+ "literal",
385
+ "folded"
386
+ ];
387
+ const pick = (values, index, fallback) => pipe(Array$1.get(values, index), Option.getOrElse(() => fallback));
388
+ const lazy = (make) => {
389
+ let made = Option.none();
390
+ return () => pipe(made, Option.getOrElse(() => {
391
+ const value = make();
392
+ made = Option.some(value);
393
+ return value;
394
+ }));
395
+ };
396
+ const memo = (make) => {
397
+ const made = /* @__PURE__ */ new Map();
398
+ return (id) => made.getOrInsertComputed(id, () => make(id));
399
+ };
400
+ const times = (count, make) => Array.from({ length: count }, (_empty, index) => make(index));
401
+ const childrenOf = (view, at) => (start, count) => times(count, (offset) => at(view.child(start + offset)));
402
+ const yamlTree = (view) => {
403
+ const at = memo((id) => {
404
+ const field = (name) => view.semantic(id, SEMANTIC[name]);
405
+ const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
406
+ return {
407
+ id,
408
+ kind: pick(KINDS, field("kind"), "scalar"),
409
+ tag: view.stringAt(field("tag")),
410
+ value: view.stringAt(field("value")),
411
+ style: pick(STYLES, field("style"), "plain"),
412
+ line: field("line"),
413
+ column: field("column"),
414
+ get children() {
415
+ return children();
416
+ }
417
+ };
418
+ });
419
+ return at;
420
+ };
421
+ const hasFlag = (flags, flag) => Math.floor(flags / flag) % BIT === SET;
422
+ const present = (index) => Option.liftPredicate(index, (value) => value !== NONE);
423
+ const syntaxNode = (view, at) => (id) => {
424
+ const field = (name) => view.concrete(id, CONCRETE[name]);
425
+ const flags = field("flags");
426
+ const start = field("start");
427
+ const end = field("end");
428
+ const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
429
+ return {
430
+ id,
431
+ type: view.stringAt(field("kind")),
432
+ named: hasFlag(flags, FLAG.named),
433
+ isError: hasFlag(flags, FLAG.error),
434
+ isMissing: hasFlag(flags, FLAG.missing),
435
+ isExtra: hasFlag(flags, FLAG.extra),
436
+ start,
437
+ end,
438
+ field: pipe(present(field("field")), Option.map(view.stringAt), Option.getOrUndefined),
439
+ get parent() {
440
+ return pipe(present(field("parent")), Option.map(at), Option.getOrUndefined);
441
+ },
442
+ get children() {
443
+ return children();
444
+ },
445
+ get namedChildren() {
446
+ return pipe(children(), Array$1.filter((child) => child.named));
447
+ },
448
+ get text() {
449
+ return String$1.slice(start, end)(view.text);
450
+ }
451
+ };
452
+ };
453
+ const syntaxTree = (view) => {
454
+ const at = memo((id) => syntaxNode(view, at)(id));
455
+ return at;
456
+ };
457
+ const lineStartsOf = (text) => [FIRST_LINE, ...Array.from(String$1.matchAll(NEWLINES)(text), (match) => (match.index ?? FIRST_LINE) + FIRST)];
458
+ const lineAt = (starts, offset) => {
459
+ let low = FIRST_LINE;
460
+ let high = starts.length - FIRST;
461
+ while (low < high) {
462
+ const middle = Math.ceil((low + high) / HALF);
463
+ if ((starts[middle] ?? FIRST_LINE) <= offset) low = middle;
464
+ else high = middle - FIRST;
465
+ }
466
+ return low;
467
+ };
468
+ const positionIn = (text) => {
469
+ const starts = lineStartsOf(text);
470
+ return (offset) => {
471
+ const line = lineAt(starts, offset);
472
+ return {
473
+ line: line + FIRST,
474
+ column: offset - (starts[line] ?? FIRST_LINE) + FIRST
475
+ };
476
+ };
477
+ };
478
+ const errorsOf = (view) => times(view.errorCount, (index) => ({
479
+ line: view.error(index, ERROR_FIELD.line),
480
+ column: view.error(index, ERROR_FIELD.column),
481
+ message: view.stringAt(view.error(index, ERROR_FIELD.message))
482
+ }));
483
+ const sourceOf = (view) => {
484
+ const yaml = yamlTree(view);
485
+ const syntax = syntaxTree(view);
486
+ const lines = lazy(() => String$1.split(LINE_BREAK)(view.text));
487
+ return {
488
+ text: view.text,
489
+ yaml: pipe(view.semanticRoot, Option.map(yaml), Option.getOrUndefined),
490
+ syntax: pipe(view.concreteRoot, Option.map(syntax), Option.getOrUndefined),
491
+ errors: errorsOf(view),
492
+ get lines() {
493
+ return lines();
494
+ },
495
+ positionOf: positionIn(view.text)
496
+ };
497
+ };
498
+ // src/features/run-rules/model/order.ts
499
+ const byPosition = Order.combineAll([
500
+ Order.mapInput(Order.String, (found) => found.path),
501
+ Order.mapInput(Order.Number, (found) => found.line),
502
+ Order.mapInput(Order.Number, (found) => found.column),
503
+ Order.mapInput(Order.String, (found) => found.message)
504
+ ]);
505
+ const same = (left, right) => left.path === right.path && left.line === right.line && left.column === right.column && left.message === right.message && left.rule === right.rule;
506
+ const ordered = (found) => Array$1.dedupeWith(Array$1.sort(found, byPosition), same);
507
+ // src/features/run-rules/model/run.ts
508
+ const CONCURRENT$1 = { concurrency: "unbounded" };
509
+ const appliesTo = (kind) => ({ rule }) => pipe(rule.meta.kinds ?? ["workflow"], Array$1.some((each) => each === kind));
510
+ const diagnosticOf = (input, active) => ({ rule, ...report }) => ({
511
+ path: input.path,
512
+ ...report,
513
+ rule: rule ?? active.id,
514
+ severity: active.severity
515
+ });
516
+ const checked = (active, context) => Effect.suspend(() => {
517
+ const result = active.rule.check(context);
518
+ if (Effect.isEffect(result)) return result;
519
+ return Effect.void;
520
+ });
521
+ const runRule = (input) => (active) => {
522
+ const reports = [];
523
+ const context = {
524
+ filename: input.path,
525
+ kind: input.kind,
526
+ source: input.source,
527
+ options: active.options,
528
+ settings: input.settings,
529
+ project: input.project,
530
+ parseScript: input.parseScript,
531
+ report: (report) => {
532
+ reports.push(report);
533
+ }
534
+ };
535
+ return checked(active, context).pipe(Effect.catchCause((cause) => Effect.fail(failedWith(`fu4 rule ${active.id} failed on ${input.path}`)(cause))), Effect.map(() => pipe(reports, Array$1.map(diagnosticOf(input, active)))), Effect.withSpan("fu4.rule", { attributes: {
536
+ "fu4.rule.id": active.id,
537
+ "code.file.path": input.path
538
+ } }));
539
+ };
540
+ const runFile = Effect.fn("fu4.runFile")(function* runFile(input) {
541
+ const active = pipe(input.rules, Array$1.filter(appliesTo(input.kind)));
542
+ const results = yield* Effect.forEach(active, runRule(input), CONCURRENT$1);
543
+ return Array$1.flatten(results);
544
+ });
545
+ // src/app/lint.ts
546
+ const CONCURRENT = { concurrency: "unbounded" };
547
+ const projectOf = (root, addon) => {
548
+ const parsed = /* @__PURE__ */ new Map();
549
+ const read = (file) => Option.fromNullishOr(addon.readText(root, file));
550
+ const parse = (file) => {
551
+ const source = pipe(read(file), Option.map((text) => sourceOf(sourceView(addon.parseText(text)))));
552
+ parsed.set(file, source);
553
+ return source;
554
+ };
555
+ return {
556
+ root,
557
+ exists: (file) => addon.pathExists(root, file),
558
+ read,
559
+ parse: (file) => Option.getOrElse(Option.fromNullishOr(parsed.get(file)), () => parse(file))
560
+ };
561
+ };
562
+ const scriptParser = (addon) => (language, text) => sourceOf(sourceView(addon.parseScript(language, text)));
563
+ const targetsOf = (config, files) => pipe(files, Array$1.filter((file) => Option.isSome(kindOf(file)) && !isIgnored(config)(file)));
564
+ const parsedFiles = Effect.fn("fu4.parse")(function* parsedFiles(root, targets) {
565
+ const parent = yield* traceparent;
566
+ return yield* callAddon({
567
+ addon: native,
568
+ name: "fu4",
569
+ files: targets.length,
570
+ call: (loaded) => loaded.parsePaths(root, targets, { traceparent: Option.getOrUndefined(parent) }),
571
+ failWith: failedWith
572
+ });
573
+ });
574
+ const lint = Effect.fn("fu4.lint")(function* lint(input) {
575
+ const config = flattenConfig(input.config ?? {});
576
+ const addon = yield* native;
577
+ const parsed = yield* parsedFiles(input.root, targetsOf(config, input.files));
578
+ const project = projectOf(input.root, addon);
579
+ const lintOne = (file) => runFile({
580
+ path: file.path,
581
+ kind: Option.getOrThrow(kindOf(file.path)),
582
+ source: sourceOf(sourceView(file.source)),
583
+ rules: activeRules(config)(file.path),
584
+ settings: config.settings ?? {},
585
+ project,
586
+ parseScript: scriptParser(addon)
587
+ });
588
+ const results = yield* Effect.forEach(parsed, lintOne, CONCURRENT);
589
+ return ordered(Array$1.flatten(results));
590
+ });
591
+ const kindFor = (input) => pipe(Option.fromNullishOr(input.kind), Option.orElse(() => kindOf(input.path)), Option.getOrElse(() => "workflow"));
592
+ const lintText = Effect.fn("fu4.lintText")(function* lintText(input) {
593
+ const config = flattenConfig(input.config ?? {});
594
+ const addon = yield* native;
595
+ const source = sourceOf(sourceView(addon.parseText(input.text)));
596
+ const results = yield* runFile({
597
+ path: input.path,
598
+ kind: kindFor(input),
599
+ source,
600
+ rules: activeRules(config)(input.path),
601
+ settings: config.settings ?? {},
602
+ project: projectOf(input.root, addon),
603
+ parseScript: scriptParser(addon)
604
+ });
605
+ return ordered(results);
606
+ });
607
+ // src/app/section.ts
608
+ const WORKFLOWS = [
609
+ ".github/workflows/*.yml",
610
+ ".github/workflows/*.yaml",
611
+ ":(glob)**/action.yml",
612
+ ":(glob)**/action.yaml",
613
+ ".github/dependabot.yml",
614
+ ".github/dependabot.yaml",
615
+ ".pre-commit-config.yaml",
616
+ ".pre-commit-hooks.yaml"
617
+ ];
618
+ const NOT_OWNED = [":(exclude,attr:linguist-vendored)", ":(exclude,attr:linguist-generated)"];
619
+ const hasSection = (value) => Predicate.hasProperty(value, "fu4") && Predicate.isObject(value.fu4);
620
+ const fu4Section = (config) => pipe(Option.liftPredicate(config, hasSection), Option.map((value) => flattenConfig(value.fu4)), Option.getOrElse(() => ({})));
621
+ const workflowPathspecs = ({ config, patterns = WORKFLOWS }) => [
622
+ ...patterns,
623
+ ...NOT_OWNED,
624
+ ...pipe(config.ignores ?? [], Array$1.map((glob) => `:(glob,exclude)${glob}`))
625
+ ];
626
+ // src/shared/config/types.ts
627
+ const INPUT_KINDS = [
628
+ "workflow",
629
+ "action",
630
+ "dependabot",
631
+ "pre-commit"
632
+ ];
633
+ export { lintText as a, definePlugin as c, format as d, lint as i, defineRule as l, fu4Section as n, Fu4Error as o, workflowPathspecs as r, failedWith as s, INPUT_KINDS as t, runCli as u };
634
+
635
+ //# sourceMappingURL=app-DheTFmZd.mjs.map