@r_masseater/y8 0.0.0 → 0.1.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 +87 -0
- package/README.md +50 -0
- package/dist/app-D5BcM070.mjs +458 -0
- package/dist/app-D5BcM070.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +19 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index-AoTF_uMY.d.mts +10 -0
- package/dist/index-CS7Sntk8.d.mts +90 -0
- package/dist/index-Dvd9WB0d.d.mts +25 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.mjs +3 -0
- package/dist/kuromojin.d.mts +3 -0
- package/dist/kuromojin.mjs +1 -0
- package/dist/split-morphemes-BS74IEHA.mjs +282 -0
- package/dist/split-morphemes-BS74IEHA.mjs.map +1 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.mjs +1 -0
- package/logo.svg +15 -0
- package/package.json +91 -6
- package/skills/lint-markdown/SKILL.md +96 -0
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
|
+

|
|
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,458 @@
|
|
|
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-BS74IEHA.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 = { agentConfig: true };
|
|
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$2 = "/";
|
|
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$2)(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$2}${name}`), Option.map(settingOf$1));
|
|
33
|
+
const scriptRules = (config) => ([plugin, value]) => pipe(Record.toEntries(value.rules ?? {}), Array.map(([name, rule]) => ({
|
|
34
|
+
id: `${plugin}${SEPARATOR$2}${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$2}${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 agentSettings = (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]), Record.fromEntries);
|
|
52
|
+
const agentRules = (config) => ([plugin]) => {
|
|
53
|
+
const settings = agentSettings(config, plugin);
|
|
54
|
+
return {
|
|
55
|
+
plugin,
|
|
56
|
+
settings,
|
|
57
|
+
disabled: pipe(Record.toEntries(settings), Array.filter(([, setting]) => !isOn(setting)), Array.map(([name]) => name))
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const resolve = (config) => {
|
|
61
|
+
const plugins = Record.toEntries(config.plugins ?? {});
|
|
62
|
+
return {
|
|
63
|
+
core: {
|
|
64
|
+
default: true,
|
|
65
|
+
...builtinEntries(config)
|
|
66
|
+
},
|
|
67
|
+
scripts: pipe(plugins, Array.flatMap(scriptRules(config))),
|
|
68
|
+
compat: pipe(plugins, Array.flatMap(compatRules(config))),
|
|
69
|
+
agent: pipe(plugins, Array.findFirst(([, value]) => value.agentConfig === true), Option.map(agentRules(config)))
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
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);
|
|
73
|
+
// src/entities/rule/model/override.ts
|
|
74
|
+
const NEGATION = "!";
|
|
75
|
+
const KEY_SEPARATOR = ",";
|
|
76
|
+
const DATA_FIRST_ARITY = 2;
|
|
77
|
+
const isNegated = String$1.startsWith(NEGATION);
|
|
78
|
+
const isIncluded = (pattern) => !isNegated(pattern);
|
|
79
|
+
const matchesAny = (path) => (patterns) => pipe(patterns, Array.some((pattern) => minimatch(path, pattern, { dot: true })));
|
|
80
|
+
const excludedOf = (override) => pipe(override.files, Array.filter(isNegated), Array.map(String$1.slice(1)));
|
|
81
|
+
const applies = (path) => (override) => pipe(override.files, Array.filter(isIncluded), matchesAny(path)) && !matchesAny(path)(excludedOf(override));
|
|
82
|
+
const matchingIndexes = (config, path) => pipe(config.overrides ?? [], Array.flatMap((override, index) => Option.toArray(Option.liftPredicate(index, () => applies(path)(override)))));
|
|
83
|
+
const entriesOf = (override) => Record.toEntries(override.rules);
|
|
84
|
+
const rulesWith = (base, overrides) => pipe(overrides, Array.flatMap(entriesOf), Array.prependAll(Record.toEntries(base)), Record.fromEntries);
|
|
85
|
+
const overridesAt = (overrides) => (indexes) => pipe(indexes, Array.flatMap((index) => Option.toArray(Array.get(overrides, index))));
|
|
86
|
+
const configWith = (config, indexes) => {
|
|
87
|
+
const { overrides = [], ...base } = config;
|
|
88
|
+
return {
|
|
89
|
+
...base,
|
|
90
|
+
rules: rulesWith(base.rules ?? {}, overridesAt(overrides)(indexes))
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const keyOf = (member) => pipe(member.indexes, Array.map(String), Array.join(KEY_SEPARATOR));
|
|
94
|
+
const groupOf = (config) => (members) => ({
|
|
95
|
+
config: configWith(config, Array.headNonEmpty(members).indexes),
|
|
96
|
+
files: pipe(members, Array.map((member) => member.path))
|
|
97
|
+
});
|
|
98
|
+
const groupByOverrides = Function.dual(DATA_FIRST_ARITY, (config, files) => pipe(files, Array.map((path) => ({
|
|
99
|
+
path,
|
|
100
|
+
indexes: matchingIndexes(config, path)
|
|
101
|
+
})), Array.groupBy(keyOf), Record.values, Array.map(groupOf(config))));
|
|
102
|
+
// src/app/format.ts
|
|
103
|
+
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(""));
|
|
104
|
+
const format = (diagnostic) => {
|
|
105
|
+
const column = pipe(Option.fromNullishOr(diagnostic.column), Option.map((value) => `:${String(value)}`), Option.getOrElse(() => ""));
|
|
106
|
+
return `${diagnostic.path}:${String(diagnostic.line)}${column} ${diagnostic.severity} ${diagnostic.rule} ${diagnostic.message}${diagnosticDetail(diagnostic)}`;
|
|
107
|
+
};
|
|
108
|
+
// src/features/map-agent-diagnostics/model/map.ts
|
|
109
|
+
const SEPARATOR$1 = "/";
|
|
110
|
+
const levelSeverity = (diagnostic) => Match.value(diagnostic.level).pipe(Match.when("error", () => "error"), Match.orElse(() => "warn"));
|
|
111
|
+
const diagnosticOf$2 = (rules, path) => (diagnostic) => ({
|
|
112
|
+
path,
|
|
113
|
+
line: diagnostic.line,
|
|
114
|
+
column: diagnostic.column,
|
|
115
|
+
rule: `${rules.plugin}${SEPARATOR$1}${diagnostic.rule}`,
|
|
116
|
+
message: diagnostic.message,
|
|
117
|
+
severity: pipe(Record.get(rules.settings, diagnostic.rule), Option.match({
|
|
118
|
+
onNone: () => levelSeverity(diagnostic),
|
|
119
|
+
onSome: reportedSeverity
|
|
120
|
+
})),
|
|
121
|
+
...present(Option.fromNullishOr(diagnostic.suggestion), (detail) => ({ detail }))
|
|
122
|
+
});
|
|
123
|
+
const agentDiagnosticsOf = (rules) => (result) => pipe(result.agentDiagnostics ?? [], Array.map(diagnosticOf$2(rules, result.path)));
|
|
124
|
+
// src/features/read-project/model/project.ts
|
|
125
|
+
const MANIFEST = "package.json";
|
|
126
|
+
const SEPARATOR = "/";
|
|
127
|
+
const ONE = 1;
|
|
128
|
+
const ancestorsOf = (file) => {
|
|
129
|
+
const parts = String$1.split(file, SEPARATOR);
|
|
130
|
+
return Array.makeBy(parts.length, (index) => pipe(parts, Array.take(parts.length - ONE - index), Array.join(SEPARATOR)));
|
|
131
|
+
};
|
|
132
|
+
const manifestFileOf = (directory) => pipe([directory, MANIFEST], Array.filter(String$1.isNonEmpty), Array.join(SEPARATOR));
|
|
133
|
+
const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
134
|
+
const manifestFrom = (directory) => (text) => pipe(Option.fromNullishOr(text), Option.flatMap(decodeJson), Option.filter(Predicate.isObject), Option.map((data) => ({
|
|
135
|
+
directory,
|
|
136
|
+
data
|
|
137
|
+
})));
|
|
138
|
+
const prefixOf = (directory) => pipe(Option.liftPredicate(directory, String$1.isNonEmpty), Option.map((value) => `${value}${SEPARATOR}`), Option.getOrElse(() => ""));
|
|
139
|
+
const isUnder = (directory) => String$1.startsWith(prefixOf(directory));
|
|
140
|
+
const readProject = Effect.fn("y8.project")(function* readProject(input) {
|
|
141
|
+
const listed = /* @__PURE__ */ new Set([...input.projectFiles, ...input.files]);
|
|
142
|
+
const all = Array.fromIterable(listed);
|
|
143
|
+
const directories = pipe(input.files, Array.flatMap(ancestorsOf), Array.dedupe, Array.filter((directory) => listed.has(manifestFileOf(directory))));
|
|
144
|
+
const addon = yield* native;
|
|
145
|
+
const texts = yield* Effect.try({
|
|
146
|
+
try: () => addon.readTexts(input.root, pipe(directories, Array.map(manifestFileOf))),
|
|
147
|
+
catch: failedWith("y8 could not read package.json")
|
|
148
|
+
});
|
|
149
|
+
const manifests = new Map(pipe(Array.zip(directories, texts), Array.flatMap(([directory, text]) => Option.toArray(manifestFrom(directory)(text))), Array.map((manifest) => [manifest.directory, manifest])));
|
|
150
|
+
return {
|
|
151
|
+
exists: (path) => listed.has(path) || pipe(all, Array.some(isUnder(path))),
|
|
152
|
+
under: (directory) => pipe(all, Array.filter(isUnder(directory))),
|
|
153
|
+
manifestOf: (file) => pipe(ancestorsOf(file), Array.findFirst((directory) => Option.fromNullishOr(manifests.get(directory))), Option.getOrUndefined)
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
// src/features/run-compat-rules/model/compat.ts
|
|
157
|
+
const MARKDOWNLINT = "markdownlint/promise";
|
|
158
|
+
const isMarkdownlint = (value) => Predicate.hasProperty(value, "lint") && Predicate.isFunction(value.lint);
|
|
159
|
+
const load = Effect.tryPromise({
|
|
160
|
+
try: () => import(MARKDOWNLINT),
|
|
161
|
+
catch: failedWith("markdownlint custom rules need the markdownlint package installed")
|
|
162
|
+
}).pipe(Effect.filterOrFail(isMarkdownlint, () => Y8Error.make({ message: `${MARKDOWNLINT} does not export lint` })));
|
|
163
|
+
const ruleOf = (rules, error) => pipe(Array.head(error.ruleNames), Option.flatMap((name) => pipe(rules, Array.findFirst(({ rule }) => pipe(rule.names, Array.contains(name))))));
|
|
164
|
+
const rangeFields = (error) => present(Option.fromNullishOr(error.errorRange), ([column, length]) => ({
|
|
165
|
+
column,
|
|
166
|
+
length
|
|
167
|
+
}));
|
|
168
|
+
const diagnosticOf$1 = (path, rules) => (error) => pipe(ruleOf(rules, error), Option.map((rule) => ({
|
|
169
|
+
path,
|
|
170
|
+
line: error.lineNumber,
|
|
171
|
+
rule: rule.id,
|
|
172
|
+
message: error.ruleDescription,
|
|
173
|
+
severity: reportedSeverity(rule.setting),
|
|
174
|
+
...rangeFields(error),
|
|
175
|
+
...present(Option.fromNullishOr(error.errorDetail), (detail) => ({ detail })),
|
|
176
|
+
...present(Option.fromNullishOr(error.errorContext), (context) => ({ context }))
|
|
177
|
+
})));
|
|
178
|
+
const settingOf = (rule) => pipe(rule.setting.options, Option.liftPredicate((options) => !Record.isEmptyRecord(options)), Option.getOrElse(() => true));
|
|
179
|
+
const configOf = (rules) => pipe(rules, Array.flatMap((rule) => pipe(Array.head(rule.rule.names), Option.map((name) => [name, settingOf(rule)]), Option.toArray)), Record.fromEntries);
|
|
180
|
+
const optionsOf = (input) => ({
|
|
181
|
+
strings: pipe(input.files, Array.map(({ path, text }) => [path, text]), Record.fromEntries),
|
|
182
|
+
config: {
|
|
183
|
+
default: false,
|
|
184
|
+
...configOf(input.rules)
|
|
185
|
+
},
|
|
186
|
+
customRules: pipe(input.rules, Array.map(({ rule }) => rule))
|
|
187
|
+
});
|
|
188
|
+
const diagnosticsOf = (rules) => ([path, errors]) => pipe(errors, Array.flatMap((found) => Option.toArray(diagnosticOf$1(path, rules)(found))));
|
|
189
|
+
const run = Effect.fn("y8.markdownlint_rules")(function* run(input) {
|
|
190
|
+
const markdownlint = yield* load;
|
|
191
|
+
const results = yield* Effect.tryPromise({
|
|
192
|
+
try: () => markdownlint.lint(optionsOf(input)),
|
|
193
|
+
catch: failedWith("a markdownlint custom rule failed")
|
|
194
|
+
});
|
|
195
|
+
return pipe(Record.toEntries(results), Array.flatMap(diagnosticsOf(input.rules)));
|
|
196
|
+
});
|
|
197
|
+
const runCompatRules = (input) => Array.match(input.rules, {
|
|
198
|
+
onEmpty: () => Effect.succeed([]),
|
|
199
|
+
onNonEmpty: () => run(input)
|
|
200
|
+
});
|
|
201
|
+
// src/features/run-rules/model/document.ts
|
|
202
|
+
const NONE = 0;
|
|
203
|
+
const ROOT = 0;
|
|
204
|
+
const NEXT = 1;
|
|
205
|
+
const SET = 1;
|
|
206
|
+
const TITLE = 1;
|
|
207
|
+
const LABEL = 2;
|
|
208
|
+
const LINKS = [
|
|
209
|
+
"inline",
|
|
210
|
+
"reference",
|
|
211
|
+
"collapsed",
|
|
212
|
+
"shortcut",
|
|
213
|
+
"autolink",
|
|
214
|
+
"email",
|
|
215
|
+
"wiki"
|
|
216
|
+
];
|
|
217
|
+
const linkData = ({ view, first, second }) => ({
|
|
218
|
+
link: pipe(LINKS, Array.get(first), Option.getOrElse(() => LINKS[NONE])),
|
|
219
|
+
destination: view.stringAt(second),
|
|
220
|
+
title: view.stringAt(second + TITLE),
|
|
221
|
+
label: view.stringAt(second + LABEL)
|
|
222
|
+
});
|
|
223
|
+
const listData = ({ first, second }) => ({
|
|
224
|
+
ordered: first === SET,
|
|
225
|
+
...pipe(Option.some(second), Option.filter((value) => value !== NONE), Option.match({
|
|
226
|
+
onNone: () => ({}),
|
|
227
|
+
onSome: (value) => ({ start: value - NEXT })
|
|
228
|
+
}))
|
|
229
|
+
});
|
|
230
|
+
const dataOf = (fields) => Match.value(fields.type).pipe(Match.when("heading", () => ({
|
|
231
|
+
level: fields.first,
|
|
232
|
+
setext: fields.second === SET
|
|
233
|
+
})), Match.when("codeBlock", () => ({
|
|
234
|
+
fenced: fields.first === SET,
|
|
235
|
+
info: fields.view.stringAt(fields.second)
|
|
236
|
+
})), 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(() => ({})));
|
|
237
|
+
const once = (make) => {
|
|
238
|
+
const made = [];
|
|
239
|
+
return () => pipe(Array.head(made), Option.getOrElse(() => {
|
|
240
|
+
const value = make();
|
|
241
|
+
made.push(value);
|
|
242
|
+
return value;
|
|
243
|
+
}));
|
|
244
|
+
};
|
|
245
|
+
const linked = (tree) => (plusOne) => pipe(Option.some(plusOne), Option.filter((value) => value !== NONE), Option.map((value) => tree.at(value - NEXT)));
|
|
246
|
+
const childrenOf = (tree, id) => {
|
|
247
|
+
const found = [];
|
|
248
|
+
for (let child = tree.field(id, FIELD.firstChild); child !== NONE; child = tree.field(child - NEXT, FIELD.nextSibling)) found.push(tree.at(child - NEXT));
|
|
249
|
+
return found;
|
|
250
|
+
};
|
|
251
|
+
const nodeOf = (tree, view, id) => {
|
|
252
|
+
const type = pipe(TAGS, Array.get(tree.field(id, FIELD.tag)), Option.getOrElse(() => "other"));
|
|
253
|
+
const children = once(() => childrenOf(tree, id));
|
|
254
|
+
const data = once(() => dataOf({
|
|
255
|
+
view,
|
|
256
|
+
type,
|
|
257
|
+
first: tree.field(id, FIELD.first),
|
|
258
|
+
second: tree.field(id, FIELD.second)
|
|
259
|
+
}));
|
|
260
|
+
return {
|
|
261
|
+
type,
|
|
262
|
+
id,
|
|
263
|
+
start: tree.field(id, FIELD.start),
|
|
264
|
+
end: tree.field(id, FIELD.end),
|
|
265
|
+
get parent() {
|
|
266
|
+
return pipe(linked(tree)(tree.field(id, FIELD.parent)), Option.getOrUndefined);
|
|
267
|
+
},
|
|
268
|
+
get children() {
|
|
269
|
+
return children();
|
|
270
|
+
},
|
|
271
|
+
get data() {
|
|
272
|
+
return data();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
const treeOf = (view) => {
|
|
277
|
+
const made = /* @__PURE__ */ new Map();
|
|
278
|
+
const tree = {
|
|
279
|
+
field: (id, field) => view.nodes[id * 8 + field] ?? NONE,
|
|
280
|
+
at: (id) => pipe(Option.fromNullishOr(made.get(id)), Option.getOrElse(() => {
|
|
281
|
+
const node = nodeOf(tree, view, id);
|
|
282
|
+
made.set(id, node);
|
|
283
|
+
return node;
|
|
284
|
+
}))
|
|
285
|
+
};
|
|
286
|
+
return tree;
|
|
287
|
+
};
|
|
288
|
+
const positionIn = (view) => (offset) => {
|
|
289
|
+
const line = Math.max(view.lineStarts.findLastIndex((start) => start <= offset), ROOT);
|
|
290
|
+
const start = view.lineStarts[line] ?? NONE;
|
|
291
|
+
return {
|
|
292
|
+
line: line + NEXT,
|
|
293
|
+
column: view.slice(start, offset).length + NEXT
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
const documentOf = (view) => pipe(Option.some(view), Option.filter(({ nodeCount }) => nodeCount !== NONE), Option.map((source) => ({
|
|
297
|
+
root: treeOf(source).at(ROOT),
|
|
298
|
+
textOf: (node) => source.slice(node.start, node.end),
|
|
299
|
+
positionOf: positionIn(source)
|
|
300
|
+
})));
|
|
301
|
+
// src/features/run-rules/model/frontmatter.ts
|
|
302
|
+
const BLOCK = /^---\r?\n(?<body>[\s\S]*?)\r?\n---(?:\r?\n|$)/u;
|
|
303
|
+
const parsed = (body) => Option.liftThrowable(() => parse(body))();
|
|
304
|
+
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);
|
|
305
|
+
// src/features/run-rules/model/run.ts
|
|
306
|
+
const EXIT = ":exit";
|
|
307
|
+
const FIRST_LINE = 1;
|
|
308
|
+
const LINE_BREAK = /\r\n|\r|\n/u;
|
|
309
|
+
const handlerOf = (visitor, key) => Option.fromNullishOr(visitor[key]);
|
|
310
|
+
const visit = (visitors, key, node) => {
|
|
311
|
+
for (const visitor of visitors) for (const handler of Option.toArray(handlerOf(visitor, key))) handler(node);
|
|
312
|
+
};
|
|
313
|
+
const walk = (visitors, node) => {
|
|
314
|
+
visit(visitors, node.type, node);
|
|
315
|
+
for (const child of node.children) walk(visitors, child);
|
|
316
|
+
visit(visitors, `${node.type}${EXIT}`, node);
|
|
317
|
+
};
|
|
318
|
+
const extras = (report, position) => ({
|
|
319
|
+
...present(pipe(Option.fromNullishOr(report.column), Option.orElse(() => pipe(position, Option.map(({ column }) => column)))), (column) => ({ column })),
|
|
320
|
+
...present(Option.fromNullishOr(report.length), (length) => ({ length })),
|
|
321
|
+
...present(Option.fromNullishOr(report.detail), (detail) => ({ detail }))
|
|
322
|
+
});
|
|
323
|
+
const diagnosticOf = (path, document, rule) => (report) => {
|
|
324
|
+
const position = pipe(Option.fromNullishOr(report.node), Option.map((node) => document.positionOf(node.start)));
|
|
325
|
+
return {
|
|
326
|
+
path,
|
|
327
|
+
line: pipe(Option.fromNullishOr(report.line), Option.orElse(() => pipe(position, Option.map(({ line: at }) => at))), Option.getOrElse(() => FIRST_LINE)),
|
|
328
|
+
rule: rule.id,
|
|
329
|
+
message: report.message,
|
|
330
|
+
severity: reportedSeverity(rule.setting),
|
|
331
|
+
...extras(report, position)
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
const runOn = (input, document) => {
|
|
335
|
+
const found = [];
|
|
336
|
+
const text = input.source.text();
|
|
337
|
+
const lines = once(() => String$1.split(text, LINE_BREAK));
|
|
338
|
+
const frontmatter = once(() => frontmatterOf(text));
|
|
339
|
+
const visitors = pipe(input.rules, Array.map((rule) => {
|
|
340
|
+
const toDiagnostic = diagnosticOf(input.path, document, rule);
|
|
341
|
+
return rule.rule.create({
|
|
342
|
+
filename: input.path,
|
|
343
|
+
get frontmatter() {
|
|
344
|
+
return frontmatter();
|
|
345
|
+
},
|
|
346
|
+
exists: input.project.exists,
|
|
347
|
+
filesUnder: input.project.under,
|
|
348
|
+
manifest: input.project.manifestOf(input.path),
|
|
349
|
+
text,
|
|
350
|
+
get lines() {
|
|
351
|
+
return lines();
|
|
352
|
+
},
|
|
353
|
+
options: rule.setting.options,
|
|
354
|
+
root: document.root,
|
|
355
|
+
textOf: document.textOf,
|
|
356
|
+
positionOf: document.positionOf,
|
|
357
|
+
report: (report) => {
|
|
358
|
+
found.push(toDiagnostic(report));
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}));
|
|
362
|
+
walk(visitors, document.root);
|
|
363
|
+
return found;
|
|
364
|
+
};
|
|
365
|
+
const runScriptRules = (input) => pipe(documentOf(input.source), Option.filter(() => Array.isReadonlyArrayNonEmpty(input.rules)), Option.map((document) => runOn(input, document)), Option.getOrElse(() => []));
|
|
366
|
+
// src/app/lint.ts
|
|
367
|
+
const rangeOf = (diagnostic) => present(Option.fromNullishOr(diagnostic.range), ([column, length]) => ({
|
|
368
|
+
column,
|
|
369
|
+
length
|
|
370
|
+
}));
|
|
371
|
+
const severityOf = (diagnostic) => Match.value(diagnostic.severity).pipe(Match.when("warning", () => "warn"), Match.orElse(() => "error"));
|
|
372
|
+
const fromNative = (path) => (diagnostic) => ({
|
|
373
|
+
path,
|
|
374
|
+
line: diagnostic.line,
|
|
375
|
+
rule: `${BUILTIN}/${Option.getOrElse(Array.head(diagnostic.ruleNames), () => "")}`,
|
|
376
|
+
message: diagnostic.description,
|
|
377
|
+
severity: severityOf(diagnostic),
|
|
378
|
+
...rangeOf(diagnostic),
|
|
379
|
+
...present(Option.fromNullishOr(diagnostic.detail), (detail) => ({ detail })),
|
|
380
|
+
...present(Option.fromNullishOr(diagnostic.context), (context) => ({ context }))
|
|
381
|
+
});
|
|
382
|
+
const needsText = (resolved) => Array.isReadonlyArrayNonEmpty(resolved.scripts) || Array.isReadonlyArrayNonEmpty(resolved.compat);
|
|
383
|
+
const nativeOptions = (root, resolved, config) => traceparent.pipe(Effect.map((parent) => ({
|
|
384
|
+
config: resolved.core,
|
|
385
|
+
inlineConfig: config.inlineConfig ?? true,
|
|
386
|
+
keepTree: Array.isReadonlyArrayNonEmpty(resolved.scripts),
|
|
387
|
+
keepSource: needsText(resolved),
|
|
388
|
+
...present(parent, (value) => ({ traceparent: value })),
|
|
389
|
+
...present(resolved.agent, ({ disabled }) => ({ agnix: {
|
|
390
|
+
root,
|
|
391
|
+
disabled
|
|
392
|
+
} }))
|
|
393
|
+
})));
|
|
394
|
+
const viewOf = (result) => pipe(Option.fromNullishOr(result.source), Option.map(sourceView));
|
|
395
|
+
const sourceOf = (result) => pipe(viewOf(result), Option.map((view) => ({
|
|
396
|
+
path: result.path,
|
|
397
|
+
text: view.text()
|
|
398
|
+
})));
|
|
399
|
+
const scriptedOne = (resolved, project) => (result) => pipe(viewOf(result), Option.map((source) => runScriptRules({
|
|
400
|
+
path: result.path,
|
|
401
|
+
source,
|
|
402
|
+
rules: resolved.scripts,
|
|
403
|
+
project
|
|
404
|
+
})), Option.getOrElse(() => []));
|
|
405
|
+
const builtinOf = (result) => pipe(result.diagnostics, Array.map(fromNative(result.path)));
|
|
406
|
+
const checkPlugins = (config) => Array.match(unknownPlugins(config), {
|
|
407
|
+
onEmpty: () => Effect.void,
|
|
408
|
+
onNonEmpty: (names) => Effect.fail(Y8Error.make({ message: `rules name plugins that are not configured: ${Array.join(names, ", ")}` }))
|
|
409
|
+
});
|
|
410
|
+
const lintGroup = (root, project) => Effect.fn("y8.lint.group")(function* group(input) {
|
|
411
|
+
const resolved = resolve(input.config);
|
|
412
|
+
const options = yield* nativeOptions(root, resolved, input.config);
|
|
413
|
+
const results = yield* callAddon({
|
|
414
|
+
addon: native,
|
|
415
|
+
name: "y8",
|
|
416
|
+
files: input.files.length,
|
|
417
|
+
call: (addon) => addon.lintPaths(root, input.files, options),
|
|
418
|
+
failWith: failedWith
|
|
419
|
+
});
|
|
420
|
+
const compat = yield* runCompatRules({
|
|
421
|
+
files: pipe(results, Array.flatMap((result) => Option.toArray(sourceOf(result)))),
|
|
422
|
+
rules: resolved.compat
|
|
423
|
+
});
|
|
424
|
+
const builtin = pipe(results, Array.flatMap(builtinOf));
|
|
425
|
+
const scripted = yield* Effect.sync(() => pipe(results, Array.flatMap(scriptedOne(resolved, project)))).pipe(Effect.withSpan("y8.script_rules", { attributes: {
|
|
426
|
+
"y8.files": results.length,
|
|
427
|
+
"y8.rules": resolved.scripts.length
|
|
428
|
+
} }));
|
|
429
|
+
const agent = Option.match(resolved.agent, {
|
|
430
|
+
onNone: () => [],
|
|
431
|
+
onSome: (rules) => pipe(results, Array.flatMap(agentDiagnosticsOf(rules)))
|
|
432
|
+
});
|
|
433
|
+
return [
|
|
434
|
+
...builtin,
|
|
435
|
+
...scripted,
|
|
436
|
+
...compat,
|
|
437
|
+
...agent
|
|
438
|
+
];
|
|
439
|
+
});
|
|
440
|
+
const lint = Effect.fn("y8.lint")(function* lint(input) {
|
|
441
|
+
const config = input.config ?? {};
|
|
442
|
+
yield* checkPlugins(config);
|
|
443
|
+
const project = yield* readProject({
|
|
444
|
+
root: input.root,
|
|
445
|
+
files: input.files,
|
|
446
|
+
projectFiles: input.projectFiles ?? []
|
|
447
|
+
});
|
|
448
|
+
const found = yield* Effect.forEach(groupByOverrides(config, input.files), lintGroup(input.root, project), { concurrency: 1 });
|
|
449
|
+
return sortByPosition(Array.flatten(found));
|
|
450
|
+
});
|
|
451
|
+
// src/app/section.ts
|
|
452
|
+
const MARKDOWN = "*.md";
|
|
453
|
+
const hasSection = (value) => Predicate.hasProperty(value, "y8") && Predicate.isObject(value.y8);
|
|
454
|
+
const y8Section = (config) => pipe(Option.liftPredicate(config, hasSection), Option.map((value) => value.y8), Option.getOrElse(() => ({})));
|
|
455
|
+
const markdownPathspecs = ({ config, patterns = [MARKDOWN] }) => [...patterns, ...pipe(config.ignores ?? [], Array.map((glob) => `:(glob,exclude)${glob}`))];
|
|
456
|
+
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 };
|
|
457
|
+
|
|
458
|
+
//# sourceMappingURL=app-D5BcM070.mjs.map
|