@r_masseater/y8 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,87 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 masseater
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ @tanstack/eslint-plugin-start
26
+
27
+ MIT License
28
+
29
+ Copyright (c) 2021-present Tanner Linsley
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy
32
+ of this software and associated documentation files (the "Software"), to deal
33
+ in the Software without restriction, including without limitation the rights
34
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35
+ copies of the Software, and to permit persons to whom the Software is
36
+ furnished to do so, subject to the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be included in all
39
+ copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47
+ SOFTWARE.
48
+
49
+ ---
50
+
51
+ @typescript-eslint/utils
52
+
53
+ MIT License
54
+
55
+ Copyright (c) 2019 typescript-eslint and other contributors
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining a copy
58
+ of this software and associated documentation files (the "Software"), to deal
59
+ in the Software without restriction, including without limitation the rights
60
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
+ copies of the Software, and to permit persons to whom the Software is
62
+ furnished to do so, subject to the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be included in all
65
+ copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73
+ SOFTWARE.
74
+
75
+ ---
76
+
77
+ globals
78
+
79
+ MIT License
80
+
81
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
82
+
83
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
84
+
85
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # @r_masseater/y8
2
+
3
+ ![y8 logo](logo.svg)
4
+
5
+ A Markdown linter written in Rust and configured from `vite.config.ts`.
6
+
7
+ Its built-in rules give the same results as markdownlint's MD001 to MD060.
8
+ Rules can also be written in TypeScript, and markdownlint custom rules run
9
+ unchanged.
10
+
11
+ ```ts
12
+ import { definePlugin, defineRule } from "@r_masseater/y8";
13
+ import "@r_masseater/y8/vite";
14
+ import { defineConfig } from "vite-plus";
15
+
16
+ const oneTitle = defineRule({
17
+ meta: { description: "A document has one top-level heading" },
18
+ create: (context) => ({
19
+ heading: (node) => {
20
+ if (node.data.level === 1 && node.start > 0) {
21
+ context.report({ node, message: "Use one top-level heading" });
22
+ }
23
+ },
24
+ }),
25
+ });
26
+
27
+ export default defineConfig({
28
+ y8: {
29
+ plugins: { local: definePlugin({ rules: { "one-title": oneTitle } }) },
30
+ rules: {
31
+ "markdownlint/MD013": "off",
32
+ "local/one-title": "error",
33
+ },
34
+ ignores: ["vendor/**"],
35
+ },
36
+ });
37
+ ```
38
+
39
+ Run `y8` to lint the Markdown files git tracks, or call `lint` from code.
40
+
41
+ ## Japanese tokenizer
42
+
43
+ `morphemesOf` splits Japanese text into morphemes with
44
+ [Lindera](https://github.com/lindera/lindera) and the IPADIC dictionary built
45
+ into the addon. `@r_masseater/y8/kuromojin` has the same exports as
46
+ `kuromojin`, so textlint rules that use kuromojin can run on it.
47
+
48
+ ## Agent skills
49
+
50
+ The package ships TanStack Intent skills for coding agents. Load one with `vp exec intent load @r_masseater/y8#<skill>`.
@@ -0,0 +1,466 @@
1
+ import { a as FIELD, c as Y8Error, d as traceparent, f as present, h as settingOf$1, i as native, l as failedWith, m as callAddon, o as TAGS, s as sourceView, u as sortByPosition } from "./split-morphemes-DC2pNnQU.mjs";
2
+ import { Array, Effect, Function, Match, Option, Predicate, Record, Schema, String as String$1, pipe } from "effect";
3
+ import { minimatch } from "minimatch";
4
+ import { parse } from "yaml";
5
+ // src/entities/rule/model/agnix.ts
6
+ const agnix = { builtin: "agnix" };
7
+ // src/entities/rule/model/define.ts
8
+ const defineRule = (rule) => rule;
9
+ const definePlugin = (plugin) => plugin;
10
+ // src/entities/rule/model/resolve.ts
11
+ const BUILTIN = "markdownlint";
12
+ const SEPARATOR$1 = "/";
13
+ const START = 0;
14
+ const reportedSeverity = (setting) => Match.value(setting.severity).pipe(Match.when("warn", () => "warn"), Match.orElse(() => "error"));
15
+ const ruleIdOf = (id) => pipe(String$1.indexOf(SEPARATOR$1)(id), Option.match({
16
+ onNone: () => ({
17
+ plugin: BUILTIN,
18
+ name: id
19
+ }),
20
+ onSome: (slash) => ({
21
+ plugin: String$1.slice(START, slash)(id),
22
+ name: String$1.slice(slash + 1)(id)
23
+ })
24
+ }));
25
+ const isOn = (setting) => setting.severity !== "off";
26
+ const coreSeverity = (severity) => Match.value(severity).pipe(Match.when("warn", () => "warning"), Match.orElse(() => "error"));
27
+ const coreEntry = (setting) => Match.value(setting.severity).pipe(Match.when("off", () => false), Match.orElse((severity) => ({
28
+ ...setting.options,
29
+ severity: coreSeverity(severity)
30
+ })));
31
+ const ENABLED = settingOf$1("error");
32
+ const configured = (config, plugin) => (name) => pipe(config.rules ?? {}, Record.get(`${plugin}${SEPARATOR$1}${name}`), Option.map(settingOf$1));
33
+ const scriptRules = (config) => ([plugin, value]) => pipe(Record.toEntries(value.rules ?? {}), Array.map(([name, rule]) => ({
34
+ id: `${plugin}${SEPARATOR$1}${name}`,
35
+ rule,
36
+ setting: Option.getOrElse(configured(config, plugin)(name), () => ENABLED)
37
+ })), Array.filter(({ setting }) => isOn(setting)));
38
+ const compatRule = (config, plugin) => (rule) => pipe(Array.head(rule.names), Option.map((name) => ({
39
+ id: `${plugin}${SEPARATOR$1}${name}`,
40
+ rule,
41
+ setting: pipe(rule.names, Array.findFirst(configured(config, plugin)), Option.getOrElse(() => ENABLED))
42
+ })));
43
+ const compatRules = (config) => ([plugin, value]) => pipe(value.markdownlintRules ?? [], Array.flatMap((rule) => Option.toArray(compatRule(config, plugin)(rule))), Array.filter(({ setting }) => isOn(setting)));
44
+ const builtinEntries = (config) => pipe(Record.toEntries(config.rules ?? {}), Array.map(([id, entry]) => ({
45
+ ...ruleIdOf(id),
46
+ setting: settingOf$1(entry)
47
+ })), Array.filter(({ plugin }) => plugin === BUILTIN), Array.map(({ name, setting }) => [name, coreEntry(setting)]), Record.fromEntries);
48
+ const severities = (config, plugin) => pipe(Record.toEntries(config.rules ?? {}), Array.map(([id, entry]) => ({
49
+ ...ruleIdOf(id),
50
+ setting: settingOf$1(entry)
51
+ })), Array.filter((rule) => rule.plugin === plugin), Array.map(({ name, setting }) => [name, setting.severity]), Record.fromEntries);
52
+ const builtinRules = (config) => ([prefix, value]) => pipe(Option.fromNullishOr(value.builtin), Option.map((name) => ({
53
+ name,
54
+ prefix,
55
+ rules: severities(config, prefix)
56
+ })), Option.toArray);
57
+ const resolve = (config) => {
58
+ const plugins = Record.toEntries(config.plugins ?? {});
59
+ return {
60
+ core: {
61
+ default: true,
62
+ ...builtinEntries(config)
63
+ },
64
+ scripts: pipe(plugins, Array.flatMap(scriptRules(config))),
65
+ compat: pipe(plugins, Array.flatMap(compatRules(config))),
66
+ builtins: pipe(plugins, Array.flatMap(builtinRules(config)))
67
+ };
68
+ };
69
+ const unknownPlugins = (config) => pipe(config.overrides ?? [], Array.flatMap((override) => Record.keys(override.rules)), Array.appendAll(Record.keys(config.rules ?? {})), Array.map((id) => ruleIdOf(id).plugin), Array.filter((plugin) => plugin !== "markdownlint" && !Record.has(config.plugins ?? {}, plugin)), Array.dedupe);
70
+ // src/entities/rule/model/extend.ts
71
+ const recordOf = (records) => pipe(records, Array.flatMap((record) => Record.toEntries(record ?? {})), Record.fromEntries);
72
+ const layersOf = (config) => {
73
+ const { extends: bases = [], ...own } = config;
74
+ return [...pipe(bases, Array.flatMap(layersOf)), own];
75
+ };
76
+ const lastInlineConfig = (layers) => pipe(layers, Array.findLast((layer) => Option.fromNullishOr(layer.inlineConfig)), Option.match({
77
+ onNone: () => ({}),
78
+ onSome: (inlineConfig) => ({ inlineConfig })
79
+ }));
80
+ const flattenConfig = (config) => {
81
+ const layers = layersOf(config);
82
+ return {
83
+ plugins: recordOf(pipe(layers, Array.map((layer) => layer.plugins))),
84
+ rules: recordOf(pipe(layers, Array.map((layer) => layer.rules))),
85
+ ignores: pipe(layers, Array.flatMap((layer) => layer.ignores ?? [])),
86
+ overrides: pipe(layers, Array.flatMap((layer) => layer.overrides ?? [])),
87
+ ...lastInlineConfig(layers)
88
+ };
89
+ };
90
+ // src/entities/rule/model/override.ts
91
+ const NEGATION = "!";
92
+ const KEY_SEPARATOR = ",";
93
+ const DATA_FIRST_ARITY = 2;
94
+ const isNegated = String$1.startsWith(NEGATION);
95
+ const isIncluded = (pattern) => !isNegated(pattern);
96
+ const matchesAny = (path) => (patterns) => pipe(patterns, Array.some((pattern) => minimatch(path, pattern, { dot: true })));
97
+ const excludedOf = (override) => pipe(override.files, Array.filter(isNegated), Array.map(String$1.slice(1)));
98
+ const applies = (path) => (override) => pipe(override.files, Array.filter(isIncluded), matchesAny(path)) && !matchesAny(path)(excludedOf(override));
99
+ const matchingIndexes = (config, path) => pipe(config.overrides ?? [], Array.flatMap((override, index) => Option.toArray(Option.liftPredicate(index, () => applies(path)(override)))));
100
+ const entriesOf = (override) => Record.toEntries(override.rules);
101
+ const rulesWith = (base, overrides) => pipe(overrides, Array.flatMap(entriesOf), Array.prependAll(Record.toEntries(base)), Record.fromEntries);
102
+ const overridesAt = (overrides) => (indexes) => pipe(indexes, Array.flatMap((index) => Option.toArray(Array.get(overrides, index))));
103
+ const configWith = (config, indexes) => {
104
+ const { overrides = [], ...base } = config;
105
+ return {
106
+ ...base,
107
+ rules: rulesWith(base.rules ?? {}, overridesAt(overrides)(indexes))
108
+ };
109
+ };
110
+ const keyOf = (member) => pipe(member.indexes, Array.map(String), Array.join(KEY_SEPARATOR));
111
+ const groupOf = (config) => (members) => ({
112
+ config: configWith(config, Array.headNonEmpty(members).indexes),
113
+ files: pipe(members, Array.map((member) => member.path))
114
+ });
115
+ const groupByOverrides = Function.dual(DATA_FIRST_ARITY, (config, files) => pipe(files, Array.map((path) => ({
116
+ path,
117
+ indexes: matchingIndexes(config, path)
118
+ })), Array.groupBy(keyOf), Record.values, Array.map(groupOf(config))));
119
+ // src/app/format.ts
120
+ const diagnosticDetail = (diagnostic) => pipe([diagnostic.detail, diagnostic.context], Array.flatMap((part) => Option.toArray(Option.fromNullishOr(part))), Array.filter((part) => part !== ""), Array.map((part) => ` [${part}]`), Array.join(""));
121
+ const format = (diagnostic) => {
122
+ const column = pipe(Option.fromNullishOr(diagnostic.column), Option.map((value) => `:${String(value)}`), Option.getOrElse(() => ""));
123
+ return `${diagnostic.path}:${String(diagnostic.line)}${column} ${diagnostic.severity} ${diagnostic.rule} ${diagnostic.message}${diagnosticDetail(diagnostic)}`;
124
+ };
125
+ // src/features/map-plugin-diagnostics/model/map.ts
126
+ const severityOf$1 = (diagnostic) => Match.value(diagnostic.severity).pipe(Match.when("error", () => "error"), Match.orElse(() => "warn"));
127
+ const diagnosticOf$2 = (path) => (diagnostic) => ({
128
+ path,
129
+ line: diagnostic.line,
130
+ column: diagnostic.column,
131
+ rule: diagnostic.rule,
132
+ message: diagnostic.message,
133
+ severity: severityOf$1(diagnostic),
134
+ ...present(Option.fromNullishOr(diagnostic.detail), (detail) => ({ detail }))
135
+ });
136
+ const pluginDiagnosticsOf = (result) => pipe(result.pluginDiagnostics ?? [], Array.map(diagnosticOf$2(result.path)));
137
+ // src/features/read-project/model/project.ts
138
+ const MANIFEST = "package.json";
139
+ const SEPARATOR = "/";
140
+ const ONE = 1;
141
+ const ancestorsOf = (file) => {
142
+ const parts = String$1.split(file, SEPARATOR);
143
+ return Array.makeBy(parts.length, (index) => pipe(parts, Array.take(parts.length - ONE - index), Array.join(SEPARATOR)));
144
+ };
145
+ const manifestFileOf = (directory) => pipe([directory, MANIFEST], Array.filter(String$1.isNonEmpty), Array.join(SEPARATOR));
146
+ const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
147
+ const manifestFrom = (directory) => (text) => pipe(Option.fromNullishOr(text), Option.flatMap(decodeJson), Option.filter(Predicate.isObject), Option.map((data) => ({
148
+ directory,
149
+ data
150
+ })));
151
+ const prefixOf = (directory) => pipe(Option.liftPredicate(directory, String$1.isNonEmpty), Option.map((value) => `${value}${SEPARATOR}`), Option.getOrElse(() => ""));
152
+ const isUnder = (directory) => String$1.startsWith(prefixOf(directory));
153
+ const readProject = Effect.fn("y8.project")(function* readProject(input) {
154
+ const listed = /* @__PURE__ */ new Set([...input.projectFiles, ...input.files]);
155
+ const all = Array.fromIterable(listed);
156
+ const directories = pipe(input.files, Array.flatMap(ancestorsOf), Array.dedupe, Array.filter((directory) => listed.has(manifestFileOf(directory))));
157
+ const addon = yield* native;
158
+ const texts = yield* Effect.try({
159
+ try: () => addon.readTexts(input.root, pipe(directories, Array.map(manifestFileOf))),
160
+ catch: failedWith("y8 could not read package.json")
161
+ });
162
+ const manifests = new Map(pipe(Array.zip(directories, texts), Array.flatMap(([directory, text]) => Option.toArray(manifestFrom(directory)(text))), Array.map((manifest) => [manifest.directory, manifest])));
163
+ return {
164
+ exists: (path) => listed.has(path) || pipe(all, Array.some(isUnder(path))),
165
+ under: (directory) => pipe(all, Array.filter(isUnder(directory))),
166
+ manifestOf: (file) => pipe(ancestorsOf(file), Array.findFirst((directory) => Option.fromNullishOr(manifests.get(directory))), Option.getOrUndefined)
167
+ };
168
+ });
169
+ // src/features/run-compat-rules/model/compat.ts
170
+ const MARKDOWNLINT = "markdownlint/promise";
171
+ const isMarkdownlint = (value) => Predicate.hasProperty(value, "lint") && Predicate.isFunction(value.lint);
172
+ const load = Effect.tryPromise({
173
+ try: () => import(MARKDOWNLINT),
174
+ catch: failedWith("markdownlint custom rules need the markdownlint package installed")
175
+ }).pipe(Effect.filterOrFail(isMarkdownlint, () => Y8Error.make({ message: `${MARKDOWNLINT} does not export lint` })));
176
+ const ruleOf = (rules, error) => pipe(Array.head(error.ruleNames), Option.flatMap((name) => pipe(rules, Array.findFirst(({ rule }) => pipe(rule.names, Array.contains(name))))));
177
+ const rangeFields = (error) => present(Option.fromNullishOr(error.errorRange), ([column, length]) => ({
178
+ column,
179
+ length
180
+ }));
181
+ const diagnosticOf$1 = (path, rules) => (error) => pipe(ruleOf(rules, error), Option.map((rule) => ({
182
+ path,
183
+ line: error.lineNumber,
184
+ rule: rule.id,
185
+ message: error.ruleDescription,
186
+ severity: reportedSeverity(rule.setting),
187
+ ...rangeFields(error),
188
+ ...present(Option.fromNullishOr(error.errorDetail), (detail) => ({ detail })),
189
+ ...present(Option.fromNullishOr(error.errorContext), (context) => ({ context }))
190
+ })));
191
+ const settingOf = (rule) => pipe(rule.setting.options, Option.liftPredicate((options) => !Record.isEmptyRecord(options)), Option.getOrElse(() => true));
192
+ const configOf = (rules) => pipe(rules, Array.flatMap((rule) => pipe(Array.head(rule.rule.names), Option.map((name) => [name, settingOf(rule)]), Option.toArray)), Record.fromEntries);
193
+ const optionsOf = (input) => ({
194
+ strings: pipe(input.files, Array.map(({ path, text }) => [path, text]), Record.fromEntries),
195
+ config: {
196
+ default: false,
197
+ ...configOf(input.rules)
198
+ },
199
+ customRules: pipe(input.rules, Array.map(({ rule }) => rule))
200
+ });
201
+ const diagnosticsOf = (rules) => ([path, errors]) => pipe(errors, Array.flatMap((found) => Option.toArray(diagnosticOf$1(path, rules)(found))));
202
+ const run = Effect.fn("y8.markdownlint_rules")(function* run(input) {
203
+ const markdownlint = yield* load;
204
+ const results = yield* Effect.tryPromise({
205
+ try: () => markdownlint.lint(optionsOf(input)),
206
+ catch: failedWith("a markdownlint custom rule failed")
207
+ });
208
+ return pipe(Record.toEntries(results), Array.flatMap(diagnosticsOf(input.rules)));
209
+ });
210
+ const runCompatRules = (input) => Array.match(input.rules, {
211
+ onEmpty: () => Effect.succeed([]),
212
+ onNonEmpty: () => run(input)
213
+ });
214
+ // src/features/run-rules/model/document.ts
215
+ const NONE = 0;
216
+ const ROOT = 0;
217
+ const NEXT = 1;
218
+ const SET = 1;
219
+ const TITLE = 1;
220
+ const LABEL = 2;
221
+ const LINKS = [
222
+ "inline",
223
+ "reference",
224
+ "collapsed",
225
+ "shortcut",
226
+ "autolink",
227
+ "email",
228
+ "wiki"
229
+ ];
230
+ const linkData = ({ view, first, second }) => ({
231
+ link: pipe(LINKS, Array.get(first), Option.getOrElse(() => LINKS[NONE])),
232
+ destination: view.stringAt(second),
233
+ title: view.stringAt(second + TITLE),
234
+ label: view.stringAt(second + LABEL)
235
+ });
236
+ const listData = ({ first, second }) => ({
237
+ ordered: first === SET,
238
+ ...pipe(Option.some(second), Option.filter((value) => value !== NONE), Option.match({
239
+ onNone: () => ({}),
240
+ onSome: (value) => ({ start: value - NEXT })
241
+ }))
242
+ });
243
+ const dataOf = (fields) => Match.value(fields.type).pipe(Match.when("heading", () => ({
244
+ level: fields.first,
245
+ setext: fields.second === SET
246
+ })), Match.when("codeBlock", () => ({
247
+ fenced: fields.first === SET,
248
+ info: fields.view.stringAt(fields.second)
249
+ })), Match.when("list", () => listData(fields)), Match.whenOr("footnoteDefinition", "footnoteReference", () => ({ label: fields.view.stringAt(fields.first) })), Match.whenOr("link", "image", () => linkData(fields)), Match.when("math", () => ({ display: fields.first === SET })), Match.when("taskListMarker", () => ({ checked: fields.first === SET })), Match.orElse(() => ({})));
250
+ const once = (make) => {
251
+ const made = [];
252
+ return () => pipe(Array.head(made), Option.getOrElse(() => {
253
+ const value = make();
254
+ made.push(value);
255
+ return value;
256
+ }));
257
+ };
258
+ const linked = (tree) => (plusOne) => pipe(Option.some(plusOne), Option.filter((value) => value !== NONE), Option.map((value) => tree.at(value - NEXT)));
259
+ const childrenOf = (tree, id) => {
260
+ const found = [];
261
+ for (let child = tree.field(id, FIELD.firstChild); child !== NONE; child = tree.field(child - NEXT, FIELD.nextSibling)) found.push(tree.at(child - NEXT));
262
+ return found;
263
+ };
264
+ const nodeOf = (tree, view, id) => {
265
+ const type = pipe(TAGS, Array.get(tree.field(id, FIELD.tag)), Option.getOrElse(() => "other"));
266
+ const children = once(() => childrenOf(tree, id));
267
+ const data = once(() => dataOf({
268
+ view,
269
+ type,
270
+ first: tree.field(id, FIELD.first),
271
+ second: tree.field(id, FIELD.second)
272
+ }));
273
+ return {
274
+ type,
275
+ id,
276
+ start: tree.field(id, FIELD.start),
277
+ end: tree.field(id, FIELD.end),
278
+ get parent() {
279
+ return pipe(linked(tree)(tree.field(id, FIELD.parent)), Option.getOrUndefined);
280
+ },
281
+ get children() {
282
+ return children();
283
+ },
284
+ get data() {
285
+ return data();
286
+ }
287
+ };
288
+ };
289
+ const treeOf = (view) => {
290
+ const made = /* @__PURE__ */ new Map();
291
+ const tree = {
292
+ field: (id, field) => view.nodes[id * 8 + field] ?? NONE,
293
+ at: (id) => pipe(Option.fromNullishOr(made.get(id)), Option.getOrElse(() => {
294
+ const node = nodeOf(tree, view, id);
295
+ made.set(id, node);
296
+ return node;
297
+ }))
298
+ };
299
+ return tree;
300
+ };
301
+ const positionIn = (view) => (offset) => {
302
+ const line = Math.max(view.lineStarts.findLastIndex((start) => start <= offset), ROOT);
303
+ const start = view.lineStarts[line] ?? NONE;
304
+ return {
305
+ line: line + NEXT,
306
+ column: view.slice(start, offset).length + NEXT
307
+ };
308
+ };
309
+ const documentOf = (view) => pipe(Option.some(view), Option.filter(({ nodeCount }) => nodeCount !== NONE), Option.map((source) => ({
310
+ root: treeOf(source).at(ROOT),
311
+ textOf: (node) => source.slice(node.start, node.end),
312
+ positionOf: positionIn(source)
313
+ })));
314
+ // src/features/run-rules/model/frontmatter.ts
315
+ const BLOCK = /^---\r?\n(?<body>[\s\S]*?)\r?\n---(?:\r?\n|$)/u;
316
+ const parsed = (body) => Option.liftThrowable(() => parse(body))();
317
+ const frontmatterOf = (text) => pipe(Option.fromNullishOr(BLOCK.exec(text)), Option.flatMap((match) => Option.fromNullishOr(match.groups)), Option.flatMap(Record.get("body")), Option.flatMap(parsed), Option.filter(Predicate.isObject), Option.getOrUndefined);
318
+ // src/features/run-rules/model/run.ts
319
+ const EXIT = ":exit";
320
+ const FIRST_LINE = 1;
321
+ const LINE_BREAK = /\r\n|\r|\n/u;
322
+ const handlerOf = (visitor, key) => Option.fromNullishOr(visitor[key]);
323
+ const visit = (visitors, key, node) => {
324
+ for (const visitor of visitors) for (const handler of Option.toArray(handlerOf(visitor, key))) handler(node);
325
+ };
326
+ const walk = (visitors, node) => {
327
+ visit(visitors, node.type, node);
328
+ for (const child of node.children) walk(visitors, child);
329
+ visit(visitors, `${node.type}${EXIT}`, node);
330
+ };
331
+ const extras = (report, position) => ({
332
+ ...present(pipe(Option.fromNullishOr(report.column), Option.orElse(() => pipe(position, Option.map(({ column }) => column)))), (column) => ({ column })),
333
+ ...present(Option.fromNullishOr(report.length), (length) => ({ length })),
334
+ ...present(Option.fromNullishOr(report.detail), (detail) => ({ detail }))
335
+ });
336
+ const diagnosticOf = (path, document, rule) => (report) => {
337
+ const position = pipe(Option.fromNullishOr(report.node), Option.map((node) => document.positionOf(node.start)));
338
+ return {
339
+ path,
340
+ line: pipe(Option.fromNullishOr(report.line), Option.orElse(() => pipe(position, Option.map(({ line: at }) => at))), Option.getOrElse(() => FIRST_LINE)),
341
+ rule: rule.id,
342
+ message: report.message,
343
+ severity: reportedSeverity(rule.setting),
344
+ ...extras(report, position)
345
+ };
346
+ };
347
+ const runOn = (input, document) => {
348
+ const found = [];
349
+ const text = input.source.text();
350
+ const lines = once(() => String$1.split(text, LINE_BREAK));
351
+ const frontmatter = once(() => frontmatterOf(text));
352
+ const visitors = pipe(input.rules, Array.map((rule) => {
353
+ const toDiagnostic = diagnosticOf(input.path, document, rule);
354
+ return rule.rule.create({
355
+ filename: input.path,
356
+ get frontmatter() {
357
+ return frontmatter();
358
+ },
359
+ exists: input.project.exists,
360
+ filesUnder: input.project.under,
361
+ manifest: input.project.manifestOf(input.path),
362
+ text,
363
+ get lines() {
364
+ return lines();
365
+ },
366
+ options: rule.setting.options,
367
+ root: document.root,
368
+ textOf: document.textOf,
369
+ positionOf: document.positionOf,
370
+ report: (report) => {
371
+ found.push(toDiagnostic(report));
372
+ }
373
+ });
374
+ }));
375
+ walk(visitors, document.root);
376
+ return found;
377
+ };
378
+ const runScriptRules = (input) => pipe(documentOf(input.source), Option.filter(() => Array.isReadonlyArrayNonEmpty(input.rules)), Option.map((document) => runOn(input, document)), Option.getOrElse(() => []));
379
+ // src/app/lint.ts
380
+ const rangeOf = (diagnostic) => present(Option.fromNullishOr(diagnostic.range), ([column, length]) => ({
381
+ column,
382
+ length
383
+ }));
384
+ const severityOf = (diagnostic) => Match.value(diagnostic.severity).pipe(Match.when("warning", () => "warn"), Match.orElse(() => "error"));
385
+ const fromNative = (path) => (diagnostic) => ({
386
+ path,
387
+ line: diagnostic.line,
388
+ rule: `${BUILTIN}/${Option.getOrElse(Array.head(diagnostic.ruleNames), () => "")}`,
389
+ message: diagnostic.description,
390
+ severity: severityOf(diagnostic),
391
+ ...rangeOf(diagnostic),
392
+ ...present(Option.fromNullishOr(diagnostic.detail), (detail) => ({ detail })),
393
+ ...present(Option.fromNullishOr(diagnostic.context), (context) => ({ context }))
394
+ });
395
+ const needsText = (resolved) => Array.isReadonlyArrayNonEmpty(resolved.scripts) || Array.isReadonlyArrayNonEmpty(resolved.compat);
396
+ const nativeOptions = (root, resolved, config) => traceparent.pipe(Effect.map((parent) => ({
397
+ config: resolved.core,
398
+ inlineConfig: config.inlineConfig ?? true,
399
+ keepTree: Array.isReadonlyArrayNonEmpty(resolved.scripts),
400
+ keepSource: needsText(resolved),
401
+ ...present(parent, (value) => ({ traceparent: value })),
402
+ root,
403
+ plugins: resolved.builtins
404
+ })));
405
+ const viewOf = (result) => pipe(Option.fromNullishOr(result.source), Option.map(sourceView));
406
+ const sourceOf = (result) => pipe(viewOf(result), Option.map((view) => ({
407
+ path: result.path,
408
+ text: view.text()
409
+ })));
410
+ const scriptedOne = (resolved, project) => (result) => pipe(viewOf(result), Option.map((source) => runScriptRules({
411
+ path: result.path,
412
+ source,
413
+ rules: resolved.scripts,
414
+ project
415
+ })), Option.getOrElse(() => []));
416
+ const builtinOf = (result) => pipe(result.diagnostics, Array.map(fromNative(result.path)));
417
+ const checkPlugins = (config) => Array.match(unknownPlugins(config), {
418
+ onEmpty: () => Effect.void,
419
+ onNonEmpty: (names) => Effect.fail(Y8Error.make({ message: `rules name plugins that are not configured: ${Array.join(names, ", ")}` }))
420
+ });
421
+ const lintGroup = (root, project) => Effect.fn("y8.lint.group")(function* group(input) {
422
+ const resolved = resolve(input.config);
423
+ const options = yield* nativeOptions(root, resolved, input.config);
424
+ const results = yield* callAddon({
425
+ addon: native,
426
+ name: "y8",
427
+ files: input.files.length,
428
+ call: (addon) => addon.lintPaths(root, input.files, options),
429
+ failWith: failedWith
430
+ });
431
+ const compat = yield* runCompatRules({
432
+ files: pipe(results, Array.flatMap((result) => Option.toArray(sourceOf(result)))),
433
+ rules: resolved.compat
434
+ });
435
+ const builtin = pipe(results, Array.flatMap(builtinOf));
436
+ const scripted = yield* Effect.sync(() => pipe(results, Array.flatMap(scriptedOne(resolved, project)))).pipe(Effect.withSpan("y8.script_rules", { attributes: {
437
+ "y8.files": results.length,
438
+ "y8.rules": resolved.scripts.length
439
+ } }));
440
+ const plugins = pipe(results, Array.flatMap(pluginDiagnosticsOf));
441
+ return [
442
+ ...builtin,
443
+ ...scripted,
444
+ ...compat,
445
+ ...plugins
446
+ ];
447
+ });
448
+ const lint = Effect.fn("y8.lint")(function* lint(input) {
449
+ const config = flattenConfig(input.config ?? {});
450
+ yield* checkPlugins(config);
451
+ const project = yield* readProject({
452
+ root: input.root,
453
+ files: input.files,
454
+ projectFiles: input.projectFiles ?? []
455
+ });
456
+ const found = yield* Effect.forEach(groupByOverrides(config, input.files), lintGroup(input.root, project), { concurrency: 1 });
457
+ return sortByPosition(Array.flatten(found));
458
+ });
459
+ // src/app/section.ts
460
+ const MARKDOWN = "*.md";
461
+ const hasSection = (value) => Predicate.hasProperty(value, "y8") && Predicate.isObject(value.y8);
462
+ const y8Section = (config) => pipe(Option.liftPredicate(config, hasSection), Option.map((value) => flattenConfig(value.y8)), Option.getOrElse(() => ({})));
463
+ const markdownPathspecs = ({ config, patterns = [MARKDOWN] }) => [...patterns, ...pipe(config.ignores ?? [], Array.map((glob) => `:(glob,exclude)${glob}`))];
464
+ export { format as a, agnix as c, diagnosticDetail as i, y8Section as n, definePlugin as o, lint as r, defineRule as s, markdownPathspecs as t };
465
+
466
+ //# sourceMappingURL=app-DJaOhWCw.mjs.map