@r_masseater/fu4 0.3.0 → 0.3.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/dist/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as Fu4Config } from "./index-DFaQsB5x.mjs";
1
+ import { n as Fu4Config } from "./index-DM3Q3-YV.mjs";
2
2
  declare module "vite" {
3
3
  interface UserConfig {
4
4
  readonly fu4?: Fu4Config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r_masseater/fu4",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "The engine of a GitHub Actions linter: Rust parses workflows and TypeScript rules from its presets subpath check them, configured from vite.config.ts.",
5
5
  "keywords": [
6
6
  "actionlint",
@@ -64,7 +64,7 @@
64
64
  "@r_masseater/vitest-otlp": "0.2.2",
65
65
  "@types/hast": "3.0.5",
66
66
  "@types/mdast": "4.0.4",
67
- "@types/node": "26.6.6",
67
+ "@types/node": "26.6.10",
68
68
  "effect": "4.1.5",
69
69
  "hast-util-from-html": "2.1.0",
70
70
  "hast-util-select": "6.0.5",
@@ -95,8 +95,7 @@
95
95
  ]
96
96
  },
97
97
  "optionalDependencies": {
98
- "@r_masseater/fu4-linux-x64-gnu": "0.3.0",
99
- "@r_masseater/fu4-win32-x64-msvc": "0.3.0"
100
- },
101
- "scripts": {}
98
+ "@r_masseater/fu4-linux-x64-gnu": "0.3.1",
99
+ "@r_masseater/fu4-win32-x64-msvc": "0.3.1"
100
+ }
102
101
  }
@@ -7,7 +7,6 @@ description: >
7
7
  metadata:
8
8
  type: core
9
9
  library: "@r_masseater/fu4"
10
- library_version: 0.1.0
11
10
  sources:
12
11
  - src/app/presets.ts
13
12
  ---
@@ -7,7 +7,6 @@ description: >
7
7
  metadata:
8
8
  type: core
9
9
  library: "@r_masseater/fu4"
10
- library_version: 0.1.0
11
10
  sources:
12
11
  - src/app/index.ts
13
12
  - src/shared/config/types.ts
@@ -1,632 +0,0 @@
1
- import { a as baseName, n as matcher, r as selects } from "./types-CsheTVso.mjs";
2
- import { createRequire } from "node:module";
3
- 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";
4
- import { runMain } from "@effect/platform-node/NodeRuntime";
5
- import { layer } from "@effect/platform-node/NodeServices";
6
- import { ChildProcess, ChildProcessSpawner } from "effect/process";
7
- import { FetchHttpClient } from "effect/http";
8
- import { Otlp, OtlpSerialization } from "effect/observability";
9
- import { resolveConfigFromFile } from "vite-plus";
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
- const EMPTY$1 = 0;
184
- const LENGTH = 1;
185
- const aligned = (buffer) => Option.match(Option.liftPredicate(buffer, ({ byteOffset }) => byteOffset % 4 === EMPTY$1), {
186
- onNone: () => Uint8Array.from(buffer),
187
- onSome: (value) => value
188
- });
189
- const wordAt = (words) => (index) => words[index] ?? EMPTY$1;
190
- const fieldsOf = (header) => (fields) => pipe(fields, Record.map((index) => wordAt(header)(index)));
191
- const wordsOf = (buffer) => (at, count) => new Uint32Array(buffer.buffer, buffer.byteOffset + at * 4, count);
192
- const spanText = (words) => (blob, encoding) => (spansAt, unit) => {
193
- const decoder = new TextDecoder(encoding);
194
- const cache = /* @__PURE__ */ new Map();
195
- const read = (index) => {
196
- const at = spansAt + index * 2;
197
- const offset = wordAt(words)(at) * unit;
198
- const value = decoder.decode(blob.subarray(offset, offset + wordAt(words)(at + LENGTH) * unit));
199
- cache.set(index, value);
200
- return value;
201
- };
202
- return (index) => Option.getOrElse(Option.fromNullishOr(cache.get(index)), () => read(index));
203
- };
204
- // ../lint-host/src/shared/lib/section.ts
205
- const sectionOf = ({ name, fallback, prepare = Function.identity }) => {
206
- const hasSection = (value) => Predicate.hasProperty(value, name) && Predicate.isObject(value[name]);
207
- return (config) => pipe(Option.liftPredicate(config, hasSection), Option.flatMapNullishOr((value) => value[name]), Option.map(prepare), Option.getOrElse(() => fallback));
208
- };
209
- const pathspecsOf = ({ defaults, unowned = [] }) => ({ config, patterns = [] }) => [
210
- ...Array$1.match(patterns, {
211
- onEmpty: () => defaults,
212
- onNonEmpty: Function.identity
213
- }),
214
- ...unowned,
215
- ...pipe(config.ignores ?? [], Array$1.map((glob) => `:(glob,exclude)${glob}`))
216
- ];
217
- // src/entities/rule/model/extend.ts
218
- const flattenConfig = (config) => {
219
- const layers = layersOf(config);
220
- return {
221
- ...mergedLayers(layers),
222
- settings: mergedRecords(pipe(layers, Array$1.map((layer) => layer.settings)))
223
- };
224
- };
225
- // src/entities/rule/model/resolve.ts
226
- const SEPARATOR = "/";
227
- const START$1 = 0;
228
- const enabled = ([id, entry]) => {
229
- const { severity, options } = settingOf(entry);
230
- if (severity === "off") return [];
231
- return [{
232
- id,
233
- severity,
234
- options
235
- }];
236
- };
237
- const applies = (path) => (override) => selects(override.files)(path);
238
- const isIgnored = (config) => (path) => matcher(config.ignores ?? [])(path);
239
- const entriesFor = (config) => (path) => {
240
- const merged = { ...config.rules };
241
- for (const override of pipe(config.overrides ?? [], Array$1.filter(applies(path)))) Object.assign(merged, override.rules);
242
- return merged;
243
- };
244
- const ruleOf = (config) => (id) => pipe(String$1.indexOf(SEPARATOR)(id), Option.flatMap((at) => pipe(Record.get(config.plugins ?? {}, String$1.slice(START$1, at)(id)), Option.flatMap((plugin) => Record.get(plugin.rules, String$1.slice(at + 1)(id))))));
245
- const activate = (config) => (entry) => pipe(ruleOf(config)(entry.id), Option.map((rule) => ({
246
- ...entry,
247
- rule
248
- })), Option.toArray);
249
- const activeRules = (config) => (path) => pipe(Record.toEntries(entriesFor(config)(path)), Array$1.flatMap(enabled), Array$1.flatMap(activate(config)));
250
- // src/entities/source/model/kind.ts
251
- const WORKFLOWS = ".github/workflows/";
252
- const YAML = /\.ya?ml$/u;
253
- const ACTION = /^action\.ya?ml$/u;
254
- const DEPENDABOT = /^\.github\/dependabot\.ya?ml$/u;
255
- const PRE_COMMIT = /^\.pre-commit-(?:config|hooks)\.yaml$/u;
256
- const kindOf = (path) => {
257
- if (DEPENDABOT.test(path)) return Option.some("dependabot");
258
- if (PRE_COMMIT.test(path)) return Option.some("pre-commit");
259
- if (ACTION.test(baseName(path))) return Option.some("action");
260
- if (String$1.includes(WORKFLOWS)(path) && YAML.test(path)) return Option.some("workflow");
261
- return Option.none();
262
- };
263
- // src/shared/lib/errors.ts
264
- const taggedError = Schema.TaggedError;
265
- var Fu4Error = class extends taggedError()("Fu4Error", { message: Schema.String }) {};
266
- const failedWith = (message) => (cause) => Fu4Error.make({ message: `${message}: ${String(cause)}` });
267
- // src/shared/native/source.ts
268
- const EMPTY = 0;
269
- const START = 0;
270
- const NONE = 4294967295;
271
- const HEADER = {
272
- version: 0,
273
- semanticCount: 1,
274
- semanticRoot: 2,
275
- concreteCount: 3,
276
- concreteRoot: 4,
277
- childCount: 5,
278
- errorCount: 6,
279
- stringCount: 7
280
- };
281
- const SEMANTIC = {
282
- kind: 0,
283
- tag: 1,
284
- value: 2,
285
- style: 3,
286
- line: 4,
287
- column: 5,
288
- childStart: 6,
289
- childCount: 7
290
- };
291
- const CONCRETE = {
292
- kind: 0,
293
- flags: 1,
294
- start: 2,
295
- end: 3,
296
- field: 4,
297
- parent: 5,
298
- childStart: 6,
299
- childCount: 7
300
- };
301
- const FLAG = {
302
- named: 1,
303
- error: 2,
304
- missing: 4,
305
- extra: 8
306
- };
307
- const UTF16 = "utf-16le";
308
- const rootOf = (value) => Option.liftPredicate(value, (id) => id !== NONE);
309
- const layoutOf = (header) => {
310
- const fields = fieldsOf(header)(HEADER);
311
- const { semanticCount, concreteCount, errorCount } = fields;
312
- const semanticAt = 8;
313
- const concreteAt = semanticAt + semanticCount * 8;
314
- const childAt = concreteAt + concreteCount * 8;
315
- const errorAt = childAt + fields.childCount;
316
- const spanAt = errorAt + errorCount * 3;
317
- return {
318
- semanticCount,
319
- concreteCount,
320
- errorCount,
321
- semanticAt,
322
- concreteAt,
323
- childAt,
324
- errorAt,
325
- spanAt,
326
- blobAt: (spanAt + fields.stringCount * 2) * 4
327
- };
328
- };
329
- const sourceView = (raw) => {
330
- const buffer = aligned(raw);
331
- const header = wordsOf(buffer)(START, 8);
332
- const layout = layoutOf(header);
333
- const words = wordsOf(buffer)(START, layout.blobAt / 4);
334
- const stringAt = spanText(words)(buffer.subarray(layout.blobAt), UTF16)(layout.spanAt, 2);
335
- return {
336
- semanticCount: layout.semanticCount,
337
- semanticRoot: rootOf(wordAt(header)(HEADER.semanticRoot)),
338
- concreteCount: layout.concreteCount,
339
- concreteRoot: rootOf(wordAt(header)(HEADER.concreteRoot)),
340
- errorCount: layout.errorCount,
341
- semantic: (id, field) => wordAt(words)(layout.semanticAt + id * 8 + field),
342
- concrete: (id, field) => wordAt(words)(layout.concreteAt + id * 8 + field),
343
- child: (index) => wordAt(words)(layout.childAt + index),
344
- error: (index, field) => wordAt(words)(layout.errorAt + index * 3 + field),
345
- stringAt,
346
- text: stringAt(EMPTY)
347
- };
348
- };
349
- // src/shared/native/index.ts
350
- const isNative = exposes([
351
- "parsePaths",
352
- "parseText",
353
- "parseScript",
354
- "readText",
355
- "pathExists",
356
- "flushTelemetry"
357
- ]);
358
- const native = loadAddon({
359
- packageName: "@r_masseater/fu4",
360
- binary: "fu4",
361
- from: import.meta.url,
362
- isAddon: isNative,
363
- failWith: failedWith
364
- });
365
- // src/entities/source/model/source.ts
366
- const FIRST = 1;
367
- const FIRST_LINE = 0;
368
- const HALF = 2;
369
- const BIT = 2;
370
- const SET = 1;
371
- const ERROR_FIELD = {
372
- line: 0,
373
- column: 1,
374
- message: 2
375
- };
376
- const LINE_BREAK = /\r\n|\r|\n/u;
377
- const NEWLINES = /\n/gu;
378
- const KINDS = [
379
- "scalar",
380
- "sequence",
381
- "mapping",
382
- "alias"
383
- ];
384
- const STYLES = [
385
- "plain",
386
- "single-quoted",
387
- "double-quoted",
388
- "literal",
389
- "folded"
390
- ];
391
- const pick = (values, index, fallback) => pipe(Array$1.get(values, index), Option.getOrElse(() => fallback));
392
- const lazy = (make) => {
393
- let made = Option.none();
394
- return () => pipe(made, Option.getOrElse(() => {
395
- const value = make();
396
- made = Option.some(value);
397
- return value;
398
- }));
399
- };
400
- const memo = (make) => {
401
- const made = /* @__PURE__ */ new Map();
402
- return (id) => made.getOrInsertComputed(id, () => make(id));
403
- };
404
- const times = (count, make) => Array.from({ length: count }, (_empty, index) => make(index));
405
- const childrenOf = (view, at) => (start, count) => times(count, (offset) => at(view.child(start + offset)));
406
- const yamlTree = (view) => {
407
- const at = memo((id) => {
408
- const field = (name) => view.semantic(id, SEMANTIC[name]);
409
- const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
410
- return {
411
- id,
412
- kind: pick(KINDS, field("kind"), "scalar"),
413
- tag: view.stringAt(field("tag")),
414
- value: view.stringAt(field("value")),
415
- style: pick(STYLES, field("style"), "plain"),
416
- line: field("line"),
417
- column: field("column"),
418
- get children() {
419
- return children();
420
- }
421
- };
422
- });
423
- return at;
424
- };
425
- const hasFlag = (flags, flag) => Math.floor(flags / flag) % BIT === SET;
426
- const present = (index) => Option.liftPredicate(index, (value) => value !== NONE);
427
- const syntaxNode = (view, at) => (id) => {
428
- const field = (name) => view.concrete(id, CONCRETE[name]);
429
- const flags = field("flags");
430
- const start = field("start");
431
- const end = field("end");
432
- const children = lazy(() => childrenOf(view, at)(field("childStart"), field("childCount")));
433
- return {
434
- id,
435
- type: view.stringAt(field("kind")),
436
- named: hasFlag(flags, FLAG.named),
437
- isError: hasFlag(flags, FLAG.error),
438
- isMissing: hasFlag(flags, FLAG.missing),
439
- isExtra: hasFlag(flags, FLAG.extra),
440
- start,
441
- end,
442
- field: pipe(present(field("field")), Option.map(view.stringAt), Option.getOrUndefined),
443
- get parent() {
444
- return pipe(present(field("parent")), Option.map(at), Option.getOrUndefined);
445
- },
446
- get children() {
447
- return children();
448
- },
449
- get namedChildren() {
450
- return pipe(children(), Array$1.filter((child) => child.named));
451
- },
452
- get text() {
453
- return String$1.slice(start, end)(view.text);
454
- }
455
- };
456
- };
457
- const syntaxTree = (view) => {
458
- const at = memo((id) => syntaxNode(view, at)(id));
459
- return at;
460
- };
461
- const lineStartsOf = (text) => [FIRST_LINE, ...Array.from(String$1.matchAll(NEWLINES)(text), (match) => (match.index ?? FIRST_LINE) + FIRST)];
462
- const lineAt = (starts, offset) => {
463
- let low = FIRST_LINE;
464
- let high = starts.length - FIRST;
465
- while (low < high) {
466
- const middle = Math.ceil((low + high) / HALF);
467
- if ((starts[middle] ?? FIRST_LINE) <= offset) low = middle;
468
- else high = middle - FIRST;
469
- }
470
- return low;
471
- };
472
- const positionIn = (text) => {
473
- const starts = lineStartsOf(text);
474
- return (offset) => {
475
- const line = lineAt(starts, offset);
476
- return {
477
- line: line + FIRST,
478
- column: offset - (starts[line] ?? FIRST_LINE) + FIRST
479
- };
480
- };
481
- };
482
- const errorsOf = (view) => times(view.errorCount, (index) => ({
483
- line: view.error(index, ERROR_FIELD.line),
484
- column: view.error(index, ERROR_FIELD.column),
485
- message: view.stringAt(view.error(index, ERROR_FIELD.message))
486
- }));
487
- const sourceOf = (view) => {
488
- const yaml = yamlTree(view);
489
- const syntax = syntaxTree(view);
490
- const lines = lazy(() => String$1.split(LINE_BREAK)(view.text));
491
- return {
492
- text: view.text,
493
- yaml: pipe(view.semanticRoot, Option.map(yaml), Option.getOrUndefined),
494
- syntax: pipe(view.concreteRoot, Option.map(syntax), Option.getOrUndefined),
495
- errors: errorsOf(view),
496
- get lines() {
497
- return lines();
498
- },
499
- positionOf: positionIn(view.text)
500
- };
501
- };
502
- // src/features/run-rules/model/order.ts
503
- const byPosition = Order.combineAll([
504
- Order.mapInput(Order.String, (found) => found.path),
505
- Order.mapInput(Order.Number, (found) => found.line),
506
- Order.mapInput(Order.Number, (found) => found.column),
507
- Order.mapInput(Order.String, (found) => found.message)
508
- ]);
509
- const same = (left, right) => left.path === right.path && left.line === right.line && left.column === right.column && left.message === right.message && left.rule === right.rule;
510
- const ordered = (found) => Array$1.dedupeWith(Array$1.sort(found, byPosition), same);
511
- // src/features/run-rules/model/run.ts
512
- const CONCURRENT$1 = { concurrency: "unbounded" };
513
- const appliesTo = (kind) => ({ rule }) => pipe(rule.meta.kinds ?? ["workflow"], Array$1.some((each) => each === kind));
514
- const diagnosticOf = (input, active) => ({ rule, ...report }) => ({
515
- path: input.path,
516
- ...report,
517
- rule: rule ?? active.id,
518
- severity: active.severity
519
- });
520
- const checked = (active, context) => Effect.suspend(() => {
521
- const result = active.rule.check(context);
522
- if (Effect.isEffect(result)) return result;
523
- return Effect.void;
524
- });
525
- const runRule = (input) => (active) => {
526
- const reports = [];
527
- const context = {
528
- filename: input.path,
529
- kind: input.kind,
530
- source: input.source,
531
- options: active.options,
532
- settings: input.settings,
533
- project: input.project,
534
- parseScript: input.parseScript,
535
- report: (report) => {
536
- reports.push(report);
537
- }
538
- };
539
- 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: {
540
- "fu4.rule.id": active.id,
541
- "code.file.path": input.path
542
- } }));
543
- };
544
- const runFile = Effect.fn("fu4.runFile")(function* runFile(input) {
545
- const active = pipe(input.rules, Array$1.filter(appliesTo(input.kind)));
546
- const results = yield* Effect.forEach(active, runRule(input), CONCURRENT$1);
547
- return Array$1.flatten(results);
548
- });
549
- // src/app/lint.ts
550
- const CONCURRENT = { concurrency: "unbounded" };
551
- const projectOf = (root, addon) => {
552
- const parsed = /* @__PURE__ */ new Map();
553
- const read = (file) => Option.fromNullishOr(addon.readText(root, file));
554
- const parse = (file) => {
555
- const source = pipe(read(file), Option.map((text) => sourceOf(sourceView(addon.parseText(text)))));
556
- parsed.set(file, source);
557
- return source;
558
- };
559
- return {
560
- root,
561
- exists: (file) => addon.pathExists(root, file),
562
- read,
563
- parse: (file) => Option.getOrElse(Option.fromNullishOr(parsed.get(file)), () => parse(file))
564
- };
565
- };
566
- const scriptParser = (addon) => (language, text) => sourceOf(sourceView(addon.parseScript(language, text)));
567
- const targetsOf = (config, files) => pipe(files, Array$1.filter((file) => Option.isSome(kindOf(file)) && !isIgnored(config)(file)));
568
- const parsedFiles = Effect.fn("fu4.parse")(function* parsedFiles(root, targets) {
569
- const parent = yield* traceparent;
570
- return yield* callAddon({
571
- addon: native,
572
- name: "fu4",
573
- files: targets.length,
574
- call: (loaded) => loaded.parsePaths(root, targets, { traceparent: Option.getOrUndefined(parent) }),
575
- failWith: failedWith
576
- });
577
- });
578
- const lint = Effect.fn("fu4.lint")(function* lint(input) {
579
- const config = flattenConfig(input.config ?? {});
580
- const addon = yield* native;
581
- const parsed = yield* parsedFiles(input.root, targetsOf(config, input.files));
582
- const project = projectOf(input.root, addon);
583
- const lintOne = (file) => runFile({
584
- path: file.path,
585
- kind: Option.getOrThrow(kindOf(file.path)),
586
- source: sourceOf(sourceView(file.source)),
587
- rules: activeRules(config)(file.path),
588
- settings: config.settings ?? {},
589
- project,
590
- parseScript: scriptParser(addon)
591
- });
592
- const results = yield* Effect.forEach(parsed, lintOne, CONCURRENT);
593
- return ordered(Array$1.flatten(results));
594
- });
595
- const kindFor = (input) => pipe(Option.fromNullishOr(input.kind), Option.orElse(() => kindOf(input.path)), Option.getOrElse(() => "workflow"));
596
- const lintText = Effect.fn("fu4.lintText")(function* lintText(input) {
597
- const config = flattenConfig(input.config ?? {});
598
- const addon = yield* native;
599
- const source = sourceOf(sourceView(addon.parseText(input.text)));
600
- const results = yield* runFile({
601
- path: input.path,
602
- kind: kindFor(input),
603
- source,
604
- rules: activeRules(config)(input.path),
605
- settings: config.settings ?? {},
606
- project: projectOf(input.root, addon),
607
- parseScript: scriptParser(addon)
608
- });
609
- return ordered(results);
610
- });
611
- // src/app/section.ts
612
- const fu4Section = sectionOf({
613
- name: "fu4",
614
- prepare: flattenConfig,
615
- fallback: {}
616
- });
617
- const workflowPathspecs = pathspecsOf({
618
- defaults: [
619
- ".github/workflows/*.yml",
620
- ".github/workflows/*.yaml",
621
- ":(glob)**/action.yml",
622
- ":(glob)**/action.yaml",
623
- ".github/dependabot.yml",
624
- ".github/dependabot.yaml",
625
- ".pre-commit-config.yaml",
626
- ".pre-commit-hooks.yaml"
627
- ],
628
- unowned: [":(exclude,attr:linguist-vendored)", ":(exclude,attr:linguist-generated)"]
629
- });
630
- export { Fu4Error as a, format as c, lintText as i, workflowPathspecs as n, failedWith as o, lint as r, runCli as s, fu4Section as t };
631
-
632
- //# sourceMappingURL=app-KgCbMsJa.mjs.map