@r_masseater/fu4 0.3.1 → 0.3.3

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.
@@ -1,12 +1,8 @@
1
+ import { n as sourceOf, o as baseName, r as sourceView } from "./source-CLFOyvUG.mjs";
1
2
  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 { Argument, Command } from "effect/cli";
7
- import { FetchHttpClient } from "effect/http";
8
- import { Otlp, OtlpSerialization } from "effect/observability";
9
- import { resolveConfigFromFile } from "vite-plus";
3
+ import { Array as Array$1, Boolean, Effect, Function, Match, Option, Order, Predicate, Record, Schema, String as String$1, pipe } from "effect";
4
+ // src/app/format.ts
5
+ const format = (diagnostic) => `${diagnostic.path}:${String(diagnostic.line)}:${String(diagnostic.column)}: ${diagnostic.message} [${diagnostic.rule}]`;
10
6
  // ../lint-host/src/entities/rule/model/setting.ts
11
7
  const NO_OPTIONS = {};
12
8
  const settingOf = (entry) => Match.value(entry).pipe(Match.when(Match.string, (severity) => ({
@@ -20,40 +16,6 @@ const settingOf = (entry) => Match.value(entry).pipe(Match.when(Match.string, (s
20
16
  const abiOf = (platform) => Match.value(platform).pipe(Match.when("linux", () => "-gnu"), Match.when("win32", () => "-msvc"), Match.orElse(() => ""));
21
17
  const platformTarget = `${process.platform}-${process.arch}${abiOf(process.platform)}`;
22
18
  const addonFileOf = (binary) => `${binary}.${platformTarget}.node`;
23
- // ../lint-host/src/features/build-addon/model/build.ts
24
- const taggedError$1 = Schema.TaggedError;
25
- var AddonBuildFailed = class extends taggedError$1()("AddonBuildFailed", { message: Schema.String }) {};
26
- const LIBRARY = {
27
- linux: (name) => `lib${name}.so`,
28
- darwin: (name) => `lib${name}.dylib`,
29
- win32: (name) => `${name}.dll`
30
- };
31
- const SUCCESS = 0;
32
- const cargo = Effect.fn("cargo")(function* cargo(crate, workspace) {
33
- const exitCode = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make("cargo", [
34
- "build",
35
- "--release",
36
- "--locked",
37
- "-p",
38
- crate
39
- ], {
40
- cwd: workspace,
41
- stdout: "inherit",
42
- stderr: "inherit"
43
- }));
44
- const failure = AddonBuildFailed.make({ message: `cargo exited with ${String(exitCode)}` });
45
- yield* Effect.when(Effect.fail(failure), Effect.sync(() => Number(exitCode) !== SUCCESS));
46
- });
47
- Effect.fn("buildAddon")(function* build(options) {
48
- const fileSystem = yield* FileSystem.FileSystem;
49
- const path = yield* Path.Path;
50
- const library = yield* Effect.fromOption(Record.get(LIBRARY, process.platform)).pipe(Effect.mapError(() => AddonBuildFailed.make({ message: `no native build for ${process.platform}` })));
51
- yield* cargo(options.crate, options.workspaceDir);
52
- const output = path.join(options.packageDir, "native");
53
- yield* fileSystem.makeDirectory(output, { recursive: true });
54
- const built = library(String$1.replaceAll("-", "_")(options.crate));
55
- yield* fileSystem.copyFile(path.join(options.workspaceDir, "target", "release", built), path.join(output, addonFileOf(options.binary)));
56
- });
57
19
  // ../lint-host/src/features/load-addon/model/load.ts
58
20
  const loadAddon = ({ packageName, binary, from, isAddon, failWith }) => {
59
21
  const requireFrom = createRequire(from);
@@ -70,103 +32,6 @@ const callAddon = ({ addon, name, files, call, failWith }) => addon.pipe(Effect.
70
32
  // ../lint-host/src/features/load-addon/model/guard.ts
71
33
  const hasFunction = (value) => (name) => Predicate.hasProperty(value, name) && Predicate.isFunction(value[name]);
72
34
  const exposes = (names) => (value) => pipe(names, Array$1.every(hasFunction(value)));
73
- // ../lint-host/src/shared/lib/fail.ts
74
- const taggedError = Schema.TaggedError;
75
- var NotUtf8Error = class extends taggedError()("NotUtf8Error", { path: Schema.String }) {};
76
- // ../lint-host/src/features/run-cli/model/cli.ts
77
- const CONFIG_FILES = [
78
- "vite.config.ts",
79
- "vite.config.mts",
80
- "vite.config.js",
81
- "vite.config.mjs"
82
- ];
83
- const FAILED = 1;
84
- const DATA_FIRST_ARITY$1 = 2;
85
- const STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true });
86
- const readSectionIn = (source, root) => Effect.gen(function* readConfig() {
87
- const fileSystem = yield* FileSystem.FileSystem;
88
- const path = yield* Path.Path;
89
- const found = yield* pipe(CONFIG_FILES, Array$1.map((name) => path.join(root, name)), Effect.filter((file) => fileSystem.exists(file).pipe(Effect.orElseSucceed(() => false))));
90
- const loaded = yield* Option.match(Array$1.head(found), {
91
- onNone: () => Effect.succeed({}),
92
- onSome: (file) => Effect.tryPromise({
93
- try: () => resolveConfigFromFile(file),
94
- catch: source.failWith(`could not load ${file}`)
95
- })
96
- });
97
- return source.section(loaded);
98
- }).pipe(Effect.withSpan(`${source.name}.config`));
99
- Function.dual(DATA_FIRST_ARITY$1, readSectionIn);
100
- const trackedFiles = (root, pathspecs) => Effect.gen(function* listFiles() {
101
- const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
102
- "ls-files",
103
- "-co",
104
- "--exclude-standard",
105
- "-z",
106
- "--",
107
- ...pathspecs
108
- ], { cwd: root }));
109
- return pipe(String$1.split(output, "\0"), Array$1.filter(String$1.isNonEmpty));
110
- });
111
- const requestOf = (config, patterns) => Array$1.match(patterns, {
112
- onEmpty: () => ({ config }),
113
- onNonEmpty: (given) => ({
114
- config,
115
- patterns: given
116
- })
117
- });
118
- const hasError = (found) => pipe(found, Array$1.some(({ severity }) => severity === "error"));
119
- const failWhen = (failed) => Effect.when(Effect.sync(() => {
120
- process.exitCode = FAILED;
121
- }), Effect.succeed(failed)).pipe(Effect.asVoid);
122
- const printAll = (found, format) => Array$1.match(found, {
123
- onEmpty: () => Effect.void,
124
- onNonEmpty: (all) => Console.log(pipe(all, Array$1.map(format), Array$1.join("\n")))
125
- });
126
- const readerIn = (root, failWith) => Effect.gen(function* reader() {
127
- const fileSystem = yield* FileSystem.FileSystem;
128
- const path = yield* Path.Path;
129
- return (file) => fileSystem.readFile(path.resolve(root, file)).pipe(Effect.mapError(failWith(`could not read ${file}`)), Effect.flatMap((bytes) => Effect.try({
130
- try: () => STRICT_UTF8.decode(bytes),
131
- catch: () => NotUtf8Error.make({ path: file })
132
- })));
133
- });
134
- const mainOf = (cli, patterns) => Effect.gen(function* main() {
135
- const root = process.cwd();
136
- const config = yield* readSectionIn(cli, root);
137
- const pathspecs = cli.pathspecs(requestOf(config, patterns));
138
- const { files, projectFiles } = yield* Effect.all({
139
- files: trackedFiles(root, pathspecs).pipe(Effect.withSpan(`${cli.name}.files`)),
140
- projectFiles: trackedFiles(root, []).pipe(Effect.withSpan(`${cli.name}.project`))
141
- }, { concurrency: "unbounded" });
142
- const read = yield* readerIn(root, cli.failWith);
143
- const found = yield* cli.lint({
144
- root,
145
- files,
146
- projectFiles,
147
- config,
148
- read
149
- });
150
- yield* printAll(found, cli.format);
151
- yield* failWhen(hasError(found));
152
- });
153
- const runTraced = (name, program) => {
154
- const services = Otlp.layerFromConfig({ resource: { serviceName: name } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer), Layer.provideMerge(layer));
155
- runMain(program.pipe(Effect.provide(services)));
156
- };
157
- const variadicOf = ({ name, description }) => Argument.String(name).pipe(Argument.withDescription(description), Argument.variadic());
158
- const pathspecArgument = () => variadicOf({
159
- name: "pathspec",
160
- description: "Git pathspecs of the files to lint, in place of the configured ones"
161
- });
162
- const runCli = (cli) => {
163
- const command = Command.make(cli.name, { pathspecs: pathspecArgument() }, ({ pathspecs }) => mainOf(cli, pathspecs)).pipe(Command.withDescription(cli.description));
164
- runTraced(cli.name, Command.run(command, { version: cli.version }));
165
- };
166
- Function.dual(2, (value, build) => Option.match(value, {
167
- onNone: () => ({}),
168
- onSome: build
169
- }));
170
35
  // ../lint-host/src/shared/lib/trace.ts
171
36
  const SAMPLED = "01";
172
37
  const NOT_SAMPLED = "00";
@@ -189,27 +54,6 @@ const mergedLayers = (layers) => ({
189
54
  ignores: pipe(layers, Array$1.flatMap((layer) => layer.ignores ?? [])),
190
55
  overrides: pipe(layers, Array$1.flatMap((layer) => layer.overrides ?? []))
191
56
  });
192
- const EMPTY$1 = 0;
193
- const LENGTH = 1;
194
- const aligned = (buffer) => Option.match(Option.liftPredicate(buffer, ({ byteOffset }) => byteOffset % 4 === EMPTY$1), {
195
- onNone: () => Uint8Array.from(buffer),
196
- onSome: (value) => value
197
- });
198
- const wordAt = (words) => (index) => words[index] ?? EMPTY$1;
199
- const fieldsOf = (header) => (fields) => pipe(fields, Record.map((index) => wordAt(header)(index)));
200
- const wordsOf = (buffer) => (at, count) => new Uint32Array(buffer.buffer, buffer.byteOffset + at * 4, count);
201
- const spanText = (words) => (blob, encoding) => (spansAt, unit) => {
202
- const decoder = new TextDecoder(encoding);
203
- const cache = /* @__PURE__ */ new Map();
204
- const read = (index) => {
205
- const at = spansAt + index * 2;
206
- const offset = wordAt(words)(at) * unit;
207
- const value = decoder.decode(blob.subarray(offset, offset + wordAt(words)(at + LENGTH) * unit));
208
- cache.set(index, value);
209
- return value;
210
- };
211
- return (index) => Option.getOrElse(Option.fromNullishOr(cache.get(index)), () => read(index));
212
- };
213
57
  // ../lint-host/src/shared/lib/diagnostic.ts
214
58
  const notUtf8 = (tool) => (path) => ({
215
59
  path,
@@ -232,13 +76,14 @@ const pathspecsOf = ({ defaults, unowned = [] }) => ({ config, patterns = [] })
232
76
  ...unowned,
233
77
  ...pipe(config.ignores ?? [], Array$1.map((glob) => `:(glob,exclude)${glob}`))
234
78
  ];
235
- // src/entities/rule/model/define.ts
236
- const defineRule = (rule) => rule;
237
- const definePlugin = (plugin) => plugin;
238
- String$1.replaceAll("\\", "/");
239
- const segments = (path) => String$1.split(path, "/");
240
- const baseName = (path) => pipe(segments(path), Array$1.filter(String$1.isNonEmpty), Array$1.last, Option.getOrElse(() => ""));
241
- const afterPrefix = (prefix) => (text) => pipe(Option.liftPredicate(text, String$1.startsWith(prefix)), Option.map(String$1.slice(prefix.length)));
79
+ // src/entities/rule/model/extend.ts
80
+ const flattenConfig = (config) => {
81
+ const layers = layersOf(config);
82
+ return {
83
+ ...mergedLayers(layers),
84
+ settings: mergedRecords(pipe(layers, Array$1.map((layer) => layer.settings)))
85
+ };
86
+ };
242
87
  // ../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js
243
88
  const balanced = (a, b, str) => {
244
89
  const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
@@ -2352,232 +2197,195 @@ const selects = (patterns) => {
2352
2197
  const excluded = pipe(patterns, Array$1.filter(isNegated), Array$1.map(withoutNegation), matcher);
2353
2198
  return (path) => included(path) && !excluded(path);
2354
2199
  };
2355
- // src/shared/config/types.ts
2356
- const INPUT_KINDS = [
2357
- "workflow",
2358
- "action",
2359
- "dependabot",
2360
- "pre-commit"
2361
- ];
2362
- // src/shared/native/source.ts
2363
- const EMPTY = 0;
2200
+ // src/entities/rule/model/resolve.ts
2201
+ const SEPARATOR = "/";
2364
2202
  const START = 0;
2365
- const NONE = 4294967295;
2366
- const HEADER = {
2367
- version: 0,
2368
- semanticCount: 1,
2369
- semanticRoot: 2,
2370
- concreteCount: 3,
2371
- concreteRoot: 4,
2372
- childCount: 5,
2373
- errorCount: 6,
2374
- stringCount: 7
2375
- };
2376
- const SEMANTIC = {
2377
- kind: 0,
2378
- tag: 1,
2379
- value: 2,
2380
- style: 3,
2381
- line: 4,
2382
- column: 5,
2383
- childStart: 6,
2384
- childCount: 7
2385
- };
2386
- const CONCRETE = {
2387
- kind: 0,
2388
- flags: 1,
2389
- start: 2,
2390
- end: 3,
2391
- field: 4,
2392
- parent: 5,
2393
- childStart: 6,
2394
- childCount: 7
2395
- };
2396
- const FLAG = {
2397
- named: 1,
2398
- error: 2,
2399
- missing: 4,
2400
- extra: 8
2401
- };
2402
- const UTF16 = "utf-16le";
2403
- const rootOf = (value) => Option.liftPredicate(value, (id) => id !== NONE);
2404
- const layoutOf = (header) => {
2405
- const fields = fieldsOf(header)(HEADER);
2406
- const { semanticCount, concreteCount, errorCount } = fields;
2407
- const semanticAt = 8;
2408
- const concreteAt = semanticAt + semanticCount * 8;
2409
- const childAt = concreteAt + concreteCount * 8;
2410
- const errorAt = childAt + fields.childCount;
2411
- const spanAt = errorAt + errorCount * 3;
2412
- return {
2413
- semanticCount,
2414
- concreteCount,
2415
- errorCount,
2416
- semanticAt,
2417
- concreteAt,
2418
- childAt,
2419
- errorAt,
2420
- spanAt,
2421
- blobAt: (spanAt + fields.stringCount * 2) * 4
2422
- };
2423
- };
2424
- const sourceView = (raw) => {
2425
- const buffer = aligned(raw);
2426
- const header = wordsOf(buffer)(START, 8);
2427
- const layout = layoutOf(header);
2428
- const words = wordsOf(buffer)(START, layout.blobAt / 4);
2429
- const stringAt = spanText(words)(buffer.subarray(layout.blobAt), UTF16)(layout.spanAt, 2);
2430
- return {
2431
- semanticCount: layout.semanticCount,
2432
- semanticRoot: rootOf(wordAt(header)(HEADER.semanticRoot)),
2433
- concreteCount: layout.concreteCount,
2434
- concreteRoot: rootOf(wordAt(header)(HEADER.concreteRoot)),
2435
- errorCount: layout.errorCount,
2436
- semantic: (id, field) => wordAt(words)(layout.semanticAt + id * 8 + field),
2437
- concrete: (id, field) => wordAt(words)(layout.concreteAt + id * 8 + field),
2438
- child: (index) => wordAt(words)(layout.childAt + index),
2439
- error: (index, field) => wordAt(words)(layout.errorAt + index * 3 + field),
2440
- stringAt,
2441
- text: stringAt(EMPTY)
2442
- };
2443
- };
2444
- // src/entities/source/model/source.ts
2445
- const FIRST = 1;
2446
- const FIRST_LINE = 0;
2447
- const HALF = 2;
2448
- const BIT = 2;
2449
- const SET = 1;
2450
- const ERROR_FIELD = {
2451
- line: 0,
2452
- column: 1,
2453
- message: 2
2454
- };
2455
- const LINE_BREAK = /\r\n|\r|\n/u;
2456
- const NEWLINES = /\n/gu;
2457
- const KINDS = [
2458
- "scalar",
2459
- "sequence",
2460
- "mapping",
2461
- "alias"
2462
- ];
2463
- const STYLES = [
2464
- "plain",
2465
- "single-quoted",
2466
- "double-quoted",
2467
- "literal",
2468
- "folded"
2469
- ];
2470
- const pick = (values, index, fallback) => pipe(Array$1.get(values, index), Option.getOrElse(() => fallback));
2471
- const lazy = (make) => {
2472
- let made = Option.none();
2473
- return () => pipe(made, Option.getOrElse(() => {
2474
- const value = make();
2475
- made = Option.some(value);
2476
- return value;
2477
- }));
2478
- };
2479
- const memo = (make) => {
2480
- const made = /* @__PURE__ */ new Map();
2481
- return (id) => made.getOrInsertComputed(id, () => make(id));
2482
- };
2483
- const times = (count, make) => Array.from({ length: count }, (_empty, index) => make(index));
2484
- const childrenOf = (view, at) => (start, count) => times(count, (offset) => at(view.child(start + offset)));
2485
- const yamlTree = (view) => {
2486
- const at = memo((id) => {
2487
- const field = (name) => view.semantic(id, SEMANTIC[name]);
2488
- const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
2489
- return {
2490
- id,
2491
- kind: pick(KINDS, field("kind"), "scalar"),
2492
- tag: view.stringAt(field("tag")),
2493
- value: view.stringAt(field("value")),
2494
- style: pick(STYLES, field("style"), "plain"),
2495
- line: field("line"),
2496
- column: field("column"),
2497
- get children() {
2498
- return children();
2499
- }
2500
- };
2501
- });
2502
- return at;
2503
- };
2504
- const hasFlag = (flags, flag) => Math.floor(flags / flag) % BIT === SET;
2505
- const present = (index) => Option.liftPredicate(index, (value) => value !== NONE);
2506
- const syntaxNode = (view, at) => (id) => {
2507
- const field = (name) => view.concrete(id, CONCRETE[name]);
2508
- const flags = field("flags");
2509
- const start = field("start");
2510
- const end = field("end");
2511
- const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
2512
- return {
2203
+ const enabled = ([id, entry]) => {
2204
+ const { severity, options } = settingOf(entry);
2205
+ if (severity === "off") return [];
2206
+ return [{
2513
2207
  id,
2514
- type: view.stringAt(field("kind")),
2515
- named: hasFlag(flags, FLAG.named),
2516
- isError: hasFlag(flags, FLAG.error),
2517
- isMissing: hasFlag(flags, FLAG.missing),
2518
- isExtra: hasFlag(flags, FLAG.extra),
2519
- start,
2520
- end,
2521
- field: pipe(present(field("field")), Option.map(view.stringAt), Option.getOrUndefined),
2522
- get parent() {
2523
- return pipe(present(field("parent")), Option.map(at), Option.getOrUndefined);
2524
- },
2525
- get children() {
2526
- return children();
2527
- },
2528
- get namedChildren() {
2529
- return pipe(children(), Array$1.filter((child) => child.named));
2530
- },
2531
- get text() {
2532
- return String$1.slice(start, end)(view.text);
2208
+ severity,
2209
+ options
2210
+ }];
2211
+ };
2212
+ const applies = (path) => (override) => selects(override.files)(path);
2213
+ const isIgnored = (config) => (path) => matcher(config.ignores ?? [])(path);
2214
+ const entriesFor = (config) => (path) => {
2215
+ const merged = { ...config.rules };
2216
+ for (const override of pipe(config.overrides ?? [], Array$1.filter(applies(path)))) Object.assign(merged, override.rules);
2217
+ return merged;
2218
+ };
2219
+ const ruleOf = (config) => (id) => pipe(String$1.indexOf(SEPARATOR)(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))))));
2220
+ const activate = (config) => (entry) => pipe(ruleOf(config)(entry.id), Option.map((rule) => ({
2221
+ ...entry,
2222
+ rule
2223
+ })), Option.toArray);
2224
+ const activeRules = (config) => (path) => pipe(Record.toEntries(entriesFor(config)(path)), Array$1.flatMap(enabled), Array$1.flatMap(activate(config)));
2225
+ // src/entities/source/model/kind.ts
2226
+ const WORKFLOWS = ".github/workflows/";
2227
+ const YAML = /\.ya?ml$/u;
2228
+ const ACTION = /^action\.ya?ml$/u;
2229
+ const DEPENDABOT = /^\.github\/dependabot\.ya?ml$/u;
2230
+ const PRE_COMMIT = /^\.pre-commit-(?:config|hooks)\.yaml$/u;
2231
+ const kindOf = (path) => {
2232
+ if (DEPENDABOT.test(path)) return Option.some("dependabot");
2233
+ if (PRE_COMMIT.test(path)) return Option.some("pre-commit");
2234
+ if (ACTION.test(baseName(path))) return Option.some("action");
2235
+ if (String$1.includes(WORKFLOWS)(path) && YAML.test(path)) return Option.some("workflow");
2236
+ return Option.none();
2237
+ };
2238
+ // src/shared/lib/errors.ts
2239
+ const taggedError = Schema.TaggedError;
2240
+ var Fu4Error = class extends taggedError()("Fu4Error", { message: Schema.String }) {};
2241
+ const failedWith = (message) => (cause) => Fu4Error.make({ message: `${message}: ${String(cause)}` });
2242
+ // src/shared/native/index.ts
2243
+ const isNative = exposes([
2244
+ "parsePaths",
2245
+ "parseText",
2246
+ "parseScript",
2247
+ "readText",
2248
+ "pathExists",
2249
+ "flushTelemetry"
2250
+ ]);
2251
+ const native = loadAddon({
2252
+ packageName: "@r_masseater/fu4",
2253
+ binary: "fu4",
2254
+ from: import.meta.url,
2255
+ isAddon: isNative,
2256
+ failWith: failedWith
2257
+ });
2258
+ // src/features/run-rules/model/order.ts
2259
+ const byPosition = Order.combineAll([
2260
+ Order.mapInput(Order.String, (found) => found.path),
2261
+ Order.mapInput(Order.Number, (found) => found.line),
2262
+ Order.mapInput(Order.Number, (found) => found.column),
2263
+ Order.mapInput(Order.String, (found) => found.message)
2264
+ ]);
2265
+ const same = (left, right) => left.path === right.path && left.line === right.line && left.column === right.column && left.message === right.message && left.rule === right.rule;
2266
+ const ordered = (found) => Array$1.dedupeWith(Array$1.sort(found, byPosition), same);
2267
+ // src/features/run-rules/model/run.ts
2268
+ const CONCURRENT$1 = { concurrency: "unbounded" };
2269
+ const appliesTo = (kind) => ({ rule }) => pipe(rule.meta.kinds ?? ["workflow"], Array$1.some((each) => each === kind));
2270
+ const diagnosticOf = (input, active) => ({ rule, ...report }) => ({
2271
+ path: input.path,
2272
+ ...report,
2273
+ rule: rule ?? active.id,
2274
+ severity: active.severity
2275
+ });
2276
+ const checked = (active, context) => Effect.suspend(() => {
2277
+ const result = active.rule.check(context);
2278
+ if (Effect.isEffect(result)) return result;
2279
+ return Effect.void;
2280
+ });
2281
+ const runRule = (input) => (active) => {
2282
+ const reports = [];
2283
+ const context = {
2284
+ filename: input.path,
2285
+ kind: input.kind,
2286
+ source: input.source,
2287
+ options: active.options,
2288
+ settings: input.settings,
2289
+ project: input.project,
2290
+ parseScript: input.parseScript,
2291
+ report: (report) => {
2292
+ reports.push(report);
2533
2293
  }
2534
2294
  };
2535
- };
2536
- const syntaxTree = (view) => {
2537
- const at = memo((id) => syntaxNode(view, at)(id));
2538
- return at;
2539
- };
2540
- const lineStartsOf = (text) => [FIRST_LINE, ...Array.from(String$1.matchAll(NEWLINES)(text), (match) => (match.index ?? FIRST_LINE) + FIRST)];
2541
- const lineAt = (starts, offset) => {
2542
- let low = FIRST_LINE;
2543
- let high = starts.length - FIRST;
2544
- while (low < high) {
2545
- const middle = Math.ceil((low + high) / HALF);
2546
- if ((starts[middle] ?? FIRST_LINE) <= offset) low = middle;
2547
- else high = middle - FIRST;
2548
- }
2549
- return low;
2550
- };
2551
- const positionIn = (text) => {
2552
- const starts = lineStartsOf(text);
2553
- return (offset) => {
2554
- const line = lineAt(starts, offset);
2555
- return {
2556
- line: line + FIRST,
2557
- column: offset - (starts[line] ?? FIRST_LINE) + FIRST
2558
- };
2295
+ return checked(active, context).pipe(Effect.catchCause((cause) => cause.pipe(failedWith(`fu4 rule ${active.id} failed on ${input.path}`), Effect.fail)), Effect.map(() => pipe(reports, Array$1.map(diagnosticOf(input, active)))), Effect.withSpan("fu4.rule", { attributes: {
2296
+ "fu4.rule.id": active.id,
2297
+ "code.file.path": input.path
2298
+ } }));
2299
+ };
2300
+ const runFile = Effect.fn("fu4.runFile")(function* runFile(input) {
2301
+ const active = pipe(input.rules, Array$1.filter(appliesTo(input.kind)));
2302
+ const results = yield* Effect.forEach(active, runRule(input), CONCURRENT$1);
2303
+ return Array$1.flatten(results);
2304
+ });
2305
+ // src/app/lint.ts
2306
+ const CONCURRENT = { concurrency: "unbounded" };
2307
+ const projectOf = (root, addon) => {
2308
+ const parsed = /* @__PURE__ */ new Map();
2309
+ const read = (file) => Option.fromNullishOr(addon.readText(root, file));
2310
+ const parse = (file) => {
2311
+ const source = pipe(read(file), Option.map((text) => sourceOf(sourceView(addon.parseText(text)))));
2312
+ parsed.set(file, source);
2313
+ return source;
2559
2314
  };
2560
- };
2561
- const errorsOf = (view) => times(view.errorCount, (index) => ({
2562
- line: view.error(index, ERROR_FIELD.line),
2563
- column: view.error(index, ERROR_FIELD.column),
2564
- message: view.stringAt(view.error(index, ERROR_FIELD.message))
2565
- }));
2566
- const sourceOf = (view) => {
2567
- const yaml = yamlTree(view);
2568
- const syntax = syntaxTree(view);
2569
- const lines = lazy(() => String$1.split(LINE_BREAK)(view.text));
2570
2315
  return {
2571
- text: view.text,
2572
- yaml: pipe(view.semanticRoot, Option.map(yaml), Option.getOrUndefined),
2573
- syntax: pipe(view.concreteRoot, Option.map(syntax), Option.getOrUndefined),
2574
- errors: errorsOf(view),
2575
- get lines() {
2576
- return lines();
2577
- },
2578
- positionOf: positionIn(view.text)
2316
+ root,
2317
+ exists: (file) => addon.pathExists(root, file),
2318
+ read,
2319
+ parse: (file) => Option.getOrElse(Option.fromNullishOr(parsed.get(file)), () => parse(file))
2579
2320
  };
2580
2321
  };
2581
- export { settingOf as S, traceparent as _, matcher as a, callAddon as b, baseName as c, pathspecsOf as d, sectionOf as f, mergedRecords as g, mergedLayers as h, INPUT_KINDS as i, definePlugin as l, layersOf as m, sourceOf as n, selects as o, notUtf8 as p, sourceView as r, afterPrefix as s, lineStartsOf as t, defineRule as u, runCli as v, loadAddon as x, exposes as y };
2322
+ const scriptParser = (addon) => (language, text) => sourceOf(sourceView(addon.parseScript(language, text)));
2323
+ const targetsOf = (config, files) => pipe(files, Array$1.filter((file) => Option.isSome(kindOf(file)) && !isIgnored(config)(file)));
2324
+ const parsedFiles = Effect.fn("fu4.parse")(function* parsedFiles(root, targets) {
2325
+ const parent = yield* traceparent;
2326
+ return yield* callAddon({
2327
+ addon: native,
2328
+ name: "fu4",
2329
+ files: targets.length,
2330
+ call: (loaded) => loaded.parsePaths(root, targets, { traceparent: Option.getOrUndefined(parent) }),
2331
+ failWith: failedWith
2332
+ });
2333
+ });
2334
+ const lint = Effect.fn("fu4.lint")(function* lint(input) {
2335
+ const config = flattenConfig(input.config ?? {});
2336
+ const addon = yield* native;
2337
+ const parsed = yield* parsedFiles(input.root, targetsOf(config, input.files));
2338
+ const project = projectOf(input.root, addon);
2339
+ const lintOne = (file) => Option.match(Option.fromUndefinedOr(file.source), {
2340
+ onNone: () => Effect.succeed([notUtf8("fu4")(file.path)]),
2341
+ onSome: (source) => runFile({
2342
+ path: file.path,
2343
+ kind: Option.getOrThrow(kindOf(file.path)),
2344
+ source: sourceOf(sourceView(source)),
2345
+ rules: activeRules(config)(file.path),
2346
+ settings: config.settings ?? {},
2347
+ project,
2348
+ parseScript: scriptParser(addon)
2349
+ })
2350
+ });
2351
+ const results = yield* Effect.forEach(parsed, lintOne, CONCURRENT);
2352
+ return ordered(Array$1.flatten(results));
2353
+ });
2354
+ const kindFor = (input) => pipe(Option.fromNullishOr(input.kind), Option.orElse(() => kindOf(input.path)), Option.getOrElse(() => "workflow"));
2355
+ const lintText = Effect.fn("fu4.lintText")(function* lintText(input) {
2356
+ const config = flattenConfig(input.config ?? {});
2357
+ const addon = yield* native;
2358
+ const source = sourceOf(sourceView(addon.parseText(input.text)));
2359
+ const results = yield* runFile({
2360
+ path: input.path,
2361
+ kind: kindFor(input),
2362
+ source,
2363
+ rules: activeRules(config)(input.path),
2364
+ settings: config.settings ?? {},
2365
+ project: projectOf(input.root, addon),
2366
+ parseScript: scriptParser(addon)
2367
+ });
2368
+ return ordered(results);
2369
+ });
2370
+ // src/app/section.ts
2371
+ const fu4Section = sectionOf({
2372
+ name: "fu4",
2373
+ prepare: flattenConfig,
2374
+ fallback: {}
2375
+ });
2376
+ const workflowPathspecs = pathspecsOf({
2377
+ defaults: [
2378
+ ".github/workflows/*.yml",
2379
+ ".github/workflows/*.yaml",
2380
+ ":(glob)**/action.yml",
2381
+ ":(glob)**/action.yaml",
2382
+ ".github/dependabot.yml",
2383
+ ".github/dependabot.yaml",
2384
+ ".pre-commit-config.yaml",
2385
+ ".pre-commit-hooks.yaml"
2386
+ ],
2387
+ unowned: [":(exclude,attr:linguist-vendored)", ":(exclude,attr:linguist-generated)"]
2388
+ });
2389
+ export { Fu4Error as a, lintText as i, workflowPathspecs as n, failedWith as o, lint as r, format as s, fu4Section as t };
2582
2390
 
2583
- //# sourceMappingURL=source-BRZXj75b.mjs.map
2391
+ //# sourceMappingURL=app-BkrdDFcT.mjs.map