@milkenjoyer/toolchain 0.14.1 → 0.16.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.
Files changed (53) hide show
  1. package/README.md +17 -17
  2. package/STARTS.md +11 -0
  3. package/dist/effect-plugin-BsrW5_nI.mjs +79 -0
  4. package/dist/effect-plugin.d.mts +2 -3966
  5. package/dist/effect-plugin.mjs +1 -1
  6. package/dist/fmt-BaECz64m.mjs +8 -0
  7. package/dist/fmt.mjs +1 -8
  8. package/dist/formal.mjs +1 -1
  9. package/dist/guard-Doqk4Fju.mjs +143 -0
  10. package/dist/guard.mjs +1 -96
  11. package/dist/{lint-IhmtnBbx.mjs → lint-CfztB4u8.mjs} +1 -1
  12. package/dist/lint.mjs +1 -1
  13. package/dist/standard.mjs +557 -4
  14. package/dist/starts.d.mts +100 -0
  15. package/dist/starts.mjs +385 -0
  16. package/package.json +11 -9
  17. package/src/arithmetic.ts +60 -0
  18. package/src/compatible.ts +512 -0
  19. package/src/conformance.ts +56 -0
  20. package/src/effect-plugin.ts +24 -0
  21. package/src/effect-tsgo.ts +44 -0
  22. package/src/exceptions.ts +17 -0
  23. package/src/fmt.ts +13 -0
  24. package/src/foldkit-plugin.ts +51 -0
  25. package/src/guard.ts +307 -0
  26. package/src/hooks.ts +205 -0
  27. package/src/index.ts +1 -0
  28. package/src/knip.ts +25 -0
  29. package/src/lint.ts +170 -0
  30. package/src/plugin.ts +21 -0
  31. package/src/rules/no-comments.ts +36 -0
  32. package/src/rules/no-process-env.ts +68 -0
  33. package/src/rules/prefer-accessible-scene-locators.ts +227 -0
  34. package/src/rules/require-command-answer-names.ts +144 -0
  35. package/src/rules/require-past-tense-messages.ts +201 -0
  36. package/src/rules/use-temp-file-scoped.ts +132 -0
  37. package/src/rules.ts +121 -0
  38. package/src/shared/foldkit-api.ts +51 -0
  39. package/src/shared/member-path.ts +106 -0
  40. package/src/shared/syntax.ts +47 -0
  41. package/src/standard/alchemy.ts +70 -0
  42. package/src/standard/checks.ts +10 -1
  43. package/src/standard/config.ts +84 -0
  44. package/src/standard/domain-rules.ts +204 -0
  45. package/src/standard/domain.ts +296 -0
  46. package/src/standard/infra.ts +486 -0
  47. package/src/starts/boat.ts +140 -0
  48. package/src/starts/budget.ts +151 -0
  49. package/src/starts/policy.ts +171 -0
  50. package/src/starts.ts +84 -0
  51. package/src/versions.ts +221 -0
  52. package/dist/effect-plugin-BXUx9PPu.mjs +0 -3561
  53. package/dist/manifest-xQwgnYI1.mjs +0 -53
package/src/lint.ts ADDED
@@ -0,0 +1,170 @@
1
+ import foldkitRecommended from "@foldkit/oxlint-plugin/recommended.json" with { type: "json" };
2
+ import * as Arr from "effect/Array";
3
+ import * as Option from "effect/Option";
4
+ import * as R from "effect/Record";
5
+ import * as Schema from "effect/Schema";
6
+ import * as Str from "effect/String";
7
+ import ultraciteCore from "ultracite/oxlint/core";
8
+ import type { OxlintConfig, OxlintOverride } from "vite-plus/lint";
9
+
10
+ import effectPlugin from "./effect-plugin.ts";
11
+ import { effectTsgoPlugin, effectTsgoRules } from "./effect-tsgo.ts";
12
+ import { type Exception, exceptions } from "./exceptions.ts";
13
+ import birbprophetPlugin from "./plugin.ts";
14
+ import { staticRules } from "./rules.ts";
15
+
16
+ export type LintOptions = {
17
+ readonly ignores?: ReadonlyArray<string>;
18
+ };
19
+
20
+ const plugins: OxlintConfig["plugins"] = [
21
+ "typescript",
22
+ "import",
23
+ "promise",
24
+ "unicorn",
25
+ "oxc",
26
+ "eslint",
27
+ "node",
28
+ "vitest",
29
+ effectTsgoPlugin,
30
+ ];
31
+
32
+ const categories: OxlintConfig["categories"] = {
33
+ correctness: "error",
34
+ suspicious: "error",
35
+ pedantic: "off",
36
+ perf: "off",
37
+ style: "off",
38
+ restriction: "off",
39
+ nursery: "off",
40
+ };
41
+
42
+ const PresetRules = Schema.Record(
43
+ Schema.String,
44
+ Schema.Literals(["error", "off"])
45
+ );
46
+
47
+ const Globs = Schema.mutable(Schema.Array(Schema.String));
48
+
49
+ const FoldkitPreset = Schema.Struct({
50
+ jsPlugins: Schema.Array(
51
+ Schema.Struct({ name: Schema.String, specifier: Schema.String })
52
+ ),
53
+ rules: PresetRules,
54
+ overrides: Schema.Array(
55
+ Schema.Struct({
56
+ files: Globs,
57
+ excludeFiles: Schema.optionalKey(Globs),
58
+ rules: PresetRules,
59
+ })
60
+ ),
61
+ });
62
+
63
+ export const foldkitPreset =
64
+ Schema.decodeUnknownSync(FoldkitPreset)(foldkitRecommended);
65
+
66
+ const testFiles = [
67
+ "**/*.test.ts",
68
+ "**/*.test.tsx",
69
+ "**/*.spec.ts",
70
+ "**/*.spec.tsx",
71
+ "**/*.fake.ts",
72
+ "**/*.fake.tsx",
73
+ "**/tests/**",
74
+ "**/test/**",
75
+ ];
76
+
77
+ export const toolchainScopes: ReadonlyArray<OxlintOverride> = [
78
+ { files: ["**/*.astro"], rules: { "unicorn/prefer-module": "off" } },
79
+ ...Arr.map(
80
+ Arr.filter(
81
+ foldkitPreset.overrides,
82
+ (scope) =>
83
+ scope.files.includes("**/*.test.ts") && scope.excludeFiles === undefined
84
+ ),
85
+ ({ rules }) => ({ files: ["**/tests/**", "**/test/**"], rules })
86
+ ),
87
+ {
88
+ files: testFiles,
89
+ rules: {
90
+ "effecttsgo/lazy-effect": "off",
91
+ "eslint/no-extend-native": "off",
92
+ "typescript/unbound-method": "off",
93
+ "typescript/no-deprecated": "off",
94
+ "effect/use-temp-file-scoped": "off",
95
+ "birbprophet/no-process-env": "off",
96
+ },
97
+ },
98
+ {
99
+ files: [
100
+ "**/*.config.ts",
101
+ "**/*.config.mts",
102
+ "**/*.config.js",
103
+ "**/*.config.mjs",
104
+ ],
105
+ rules: { "birbprophet/no-process-env": "off" },
106
+ },
107
+ ];
108
+
109
+ const atError = (
110
+ prefix: string,
111
+ rules: ReadonlyArray<string>
112
+ ): Record<string, "error"> =>
113
+ R.fromEntries(
114
+ Arr.map(rules, (rule) => [`${prefix}/${rule}`, "error"] as const)
115
+ );
116
+
117
+ export const effectRules = atError(
118
+ effectPlugin.meta.name,
119
+ R.keys(effectPlugin.rules)
120
+ );
121
+
122
+ export const birbprophetRules = atError(
123
+ birbprophetPlugin.meta.name,
124
+ R.keys(birbprophetPlugin.rules)
125
+ );
126
+
127
+ const { ignorePatterns: coreIgnores = [] } = ultraciteCore;
128
+
129
+ const resolved = (specifier: string): string =>
130
+ decodeURIComponent(new URL(import.meta.resolve(specifier)).pathname);
131
+
132
+ const ownExtension = Str.slice(
133
+ Str.lastIndexOf(".")(import.meta.filename).pipe(Option.getOrElse(() => -1))
134
+ )(import.meta.filename);
135
+
136
+ const sibling = (module: string): string =>
137
+ resolved(`./${module}${ownExtension}`);
138
+
139
+ const exceptionTier = (exception: Exception): OxlintOverride => ({
140
+ files: [...exception.files],
141
+ rules: R.fromEntries(
142
+ Arr.map(exception.rules, (rule) => [rule, "off"] as const)
143
+ ),
144
+ });
145
+
146
+ export const lint = ({ ignores = [] }: LintOptions = {}): OxlintConfig => ({
147
+ plugins,
148
+ categories,
149
+ jsPlugins: [
150
+ { name: "vite-plus", specifier: resolved("vite-plus/oxlint-plugin") },
151
+ { name: "foldkit", specifier: sibling("foldkit-plugin") },
152
+ { name: effectPlugin.meta.name, specifier: sibling("effect-plugin") },
153
+ { name: birbprophetPlugin.meta.name, specifier: sibling("plugin") },
154
+ ],
155
+ options: { typeAware: true, typeCheck: true },
156
+ rules: {
157
+ ...foldkitPreset.rules,
158
+ ...staticRules,
159
+ "vite-plus/prefer-vite-plus-imports": "error",
160
+ ...effectRules,
161
+ ...birbprophetRules,
162
+ ...effectTsgoRules,
163
+ },
164
+ overrides: [
165
+ ...foldkitPreset.overrides,
166
+ ...toolchainScopes,
167
+ ...Arr.map(exceptions, exceptionTier),
168
+ ],
169
+ ignorePatterns: [...coreIgnores, ...ignores],
170
+ });
package/src/plugin.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Plugin } from "effect-oxlint";
2
+
3
+ import { noCommentsRule } from "./rules/no-comments.ts";
4
+ import { noProcessEnvRule } from "./rules/no-process-env.ts";
5
+ import { preferAccessibleSceneLocatorsRule } from "./rules/prefer-accessible-scene-locators.ts";
6
+ import { requireCommandAnswerNamesRule } from "./rules/require-command-answer-names.ts";
7
+ import { requirePastTenseMessagesRule } from "./rules/require-past-tense-messages.ts";
8
+
9
+ const plugin = Plugin.define({
10
+ name: "birbprophet",
11
+ rules: {
12
+ "no-comments": noCommentsRule,
13
+ "no-process-env": noProcessEnvRule,
14
+ "prefer-accessible-scene-locators": preferAccessibleSceneLocatorsRule,
15
+ "require-command-answer-names": requireCommandAnswerNamesRule,
16
+ "require-past-tense-messages": requirePastTenseMessagesRule,
17
+ },
18
+ specifier: "@milkenjoyer/toolchain/plugin",
19
+ });
20
+
21
+ export default plugin;
@@ -0,0 +1,36 @@
1
+ import { Comment, Diagnostic, Rule, RuleContext } from "effect-oxlint";
2
+ import * as Arr from "effect/Array";
3
+ import * as Effect from "effect/Effect";
4
+
5
+ export const noCommentsRule = Rule.define({
6
+ *create() {
7
+ const context = yield* RuleContext;
8
+
9
+ return {
10
+ Program: (): Effect.Effect<void, never, RuleContext> =>
11
+ Effect.forEach(
12
+ Arr.filter(
13
+ context.sourceCode.getAllComments(),
14
+ (comment) =>
15
+ !Comment.isShebang(comment) &&
16
+ !/^\s*@vite-ignore\s*$/u.test(Comment.text(comment))
17
+ ),
18
+ (comment) =>
19
+ context.report(
20
+ Diagnostic.fromId({ messageId: "comment", node: comment })
21
+ ),
22
+ { concurrency: 1, discard: true }
23
+ ),
24
+ };
25
+ },
26
+ meta: Rule.meta({
27
+ description:
28
+ "No comments except shebangs and exact @vite-ignore directives: meaning lives in names, types and test names",
29
+ messages: {
30
+ comment:
31
+ "Delete this comment. Put its meaning in a name, a type or a test name. Only shebangs and exact @vite-ignore directives are allowed.",
32
+ },
33
+ type: "problem",
34
+ }),
35
+ name: "no-comments",
36
+ });
@@ -0,0 +1,68 @@
1
+ import {
2
+ Diagnostic,
3
+ type ESTree,
4
+ type OxlintSourceCode,
5
+ Rule,
6
+ RuleContext,
7
+ } from "effect-oxlint";
8
+ import * as Arr from "effect/Array";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Option from "effect/Option";
11
+
12
+ import { memberPropertyName } from "../shared/syntax.ts";
13
+
14
+ const passesEnvironment = (node: ESTree.MemberExpression): boolean => {
15
+ const parent = node.parent;
16
+ return (
17
+ parent.type === "SpreadElement" ||
18
+ ((parent.type === "CallExpression" || parent.type === "NewExpression") &&
19
+ parent.arguments.includes(node)) ||
20
+ (parent.type === "VariableDeclarator" &&
21
+ parent.init === node &&
22
+ parent.id.type === "ObjectPattern" &&
23
+ Arr.some(
24
+ parent.id.properties,
25
+ (property) => property.type === "RestElement"
26
+ ))
27
+ );
28
+ };
29
+
30
+ const isGlobalProcess = (
31
+ source: OxlintSourceCode,
32
+ node: Extract<ESTree.Node, { readonly type: "Identifier" }>
33
+ ): boolean => {
34
+ const lookup = (scope: ReturnType<OxlintSourceCode["getScope"]>): boolean => {
35
+ const variable = scope.set.get(node.name);
36
+ if (variable !== undefined && variable.defs.length > 0) {
37
+ return false;
38
+ }
39
+ return scope.upper === null ? true : lookup(scope.upper);
40
+ };
41
+ return lookup(source.getScope(node));
42
+ };
43
+
44
+ export const noProcessEnvRule = Rule.define({
45
+ name: "no-process-env",
46
+ meta: Rule.meta({
47
+ type: "suggestion",
48
+ description: "Read configuration through Effect Config",
49
+ messages: {
50
+ config:
51
+ "Read configuration through Effect Config. Passing the whole environment through is allowed.",
52
+ },
53
+ }),
54
+ *create() {
55
+ const context = yield* RuleContext;
56
+ return {
57
+ MemberExpression: (node: ESTree.Node): Effect.Effect<void> =>
58
+ node.type === "MemberExpression" &&
59
+ node.object.type === "Identifier" &&
60
+ node.object.name === "process" &&
61
+ isGlobalProcess(context.sourceCode, node.object) &&
62
+ Option.contains(memberPropertyName(node), "env") &&
63
+ !passesEnvironment(node)
64
+ ? context.report(Diagnostic.fromId({ node, messageId: "config" }))
65
+ : Effect.void,
66
+ };
67
+ },
68
+ });
@@ -0,0 +1,227 @@
1
+ import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
2
+ import type { ESTree } from "effect-oxlint";
3
+ import * as Arr from "effect/Array";
4
+ import * as Effect from "effect/Effect";
5
+ import * as HashSet from "effect/HashSet";
6
+ import * as Option from "effect/Option";
7
+ import * as Str from "effect/String";
8
+
9
+ import { isFoldkitCall, textWithHoles } from "../shared/foldkit-api.ts";
10
+ import { memberPropertyName } from "../shared/syntax.ts";
11
+
12
+ const ROLE_TAGS = HashSet.make(
13
+ "a",
14
+ "article",
15
+ "aside",
16
+ "button",
17
+ "datalist",
18
+ "dd",
19
+ "details",
20
+ "dialog",
21
+ "dt",
22
+ "fieldset",
23
+ "figure",
24
+ "footer",
25
+ "form",
26
+ "h1",
27
+ "h2",
28
+ "h3",
29
+ "h4",
30
+ "h5",
31
+ "h6",
32
+ "header",
33
+ "hr",
34
+ "img",
35
+ "input",
36
+ "li",
37
+ "main",
38
+ "menu",
39
+ "meter",
40
+ "nav",
41
+ "ol",
42
+ "option",
43
+ "output",
44
+ "progress",
45
+ "select",
46
+ "summary",
47
+ "table",
48
+ "tbody",
49
+ "td",
50
+ "textarea",
51
+ "tfoot",
52
+ "th",
53
+ "thead",
54
+ "tr",
55
+ "ul"
56
+ );
57
+
58
+ const ACCESSIBLE_ATTRIBUTES =
59
+ /\[\s*(?:role|aria-label|aria-labelledby|alt|placeholder|title)\s*(?:[~|^$*]?=|\])/iu;
60
+
61
+ const QUOTED = /"[^"]*"|'[^']*'/gu;
62
+
63
+ const COMBINATOR = /[\s>+~]/u;
64
+
65
+ const TAG = /^[a-z][a-z0-9-]*/iu;
66
+
67
+ const SUBJECT_PSEUDO = /^(?:is|where|matches)\(/u;
68
+
69
+ type Split = {
70
+ readonly depth: number;
71
+ readonly parts: ReadonlyArray<string>;
72
+ };
73
+
74
+ const splitTopLevel = (
75
+ text: string,
76
+ isSeparator: (char: string) => boolean
77
+ ): ReadonlyArray<string> =>
78
+ Arr.reduce(
79
+ Arr.filter(Str.split(text, ""), Str.isNonEmpty),
80
+ { depth: 0, parts: [""] } satisfies Split,
81
+ ({ depth, parts }: Split, char): Split => {
82
+ if (depth === 0 && isSeparator(char)) {
83
+ return { depth, parts: [...parts, ""] };
84
+ }
85
+
86
+ const opened = char === "(" || char === "[" ? 1 : 0;
87
+ const closed = char === ")" || char === "]" ? 1 : 0;
88
+
89
+ return {
90
+ depth: depth + opened - closed,
91
+ parts: [...parts.slice(0, -1), `${parts.at(-1) ?? ""}${char}`],
92
+ };
93
+ }
94
+ ).parts;
95
+
96
+ const fitsAccessibleLocator = (selector: string): boolean =>
97
+ Arr.some(
98
+ splitTopLevel(selector, (char) => char === ","),
99
+ (part) => {
100
+ const compound = Option.getOrElse(
101
+ Arr.last(
102
+ Arr.filter(
103
+ splitTopLevel(Str.trim(part), (char) => COMBINATOR.test(char)),
104
+ (piece) => piece !== ""
105
+ )
106
+ ),
107
+ () => ""
108
+ );
109
+
110
+ const [tag = ""] = TAG.exec(compound) ?? [];
111
+
112
+ return (
113
+ HashSet.has(ROLE_TAGS, Str.toLowerCase(tag)) ||
114
+ Arr.some(
115
+ splitTopLevel(compound, (char) => char === ":"),
116
+ (piece) => {
117
+ const open = Str.indexOf("(")(piece);
118
+
119
+ if (Option.isNone(open)) {
120
+ return ACCESSIBLE_ATTRIBUTES.test(piece);
121
+ }
122
+
123
+ const close = Str.lastIndexOf(")")(piece).pipe(
124
+ Option.getOrElse(() => -1)
125
+ );
126
+
127
+ return (
128
+ ACCESSIBLE_ATTRIBUTES.test(
129
+ `${Str.slice(0, open.value)(piece)}${Str.slice(close + 1)(piece)}`
130
+ ) ||
131
+ (SUBJECT_PSEUDO.test(piece) &&
132
+ fitsAccessibleLocator(Str.slice(open.value + 1, close)(piece)))
133
+ );
134
+ }
135
+ )
136
+ );
137
+ }
138
+ );
139
+
140
+ export const preferAccessibleSceneLocatorsRule = Rule.define({
141
+ *create() {
142
+ const context = yield* RuleContext;
143
+
144
+ return {
145
+ CallExpression: (
146
+ node: ESTree.Node
147
+ ): Effect.Effect<void, never, RuleContext> => {
148
+ if (
149
+ node.type !== "CallExpression" ||
150
+ !isFoldkitCall(
151
+ context.sourceCode,
152
+ node,
153
+ ["Scene", "selector"],
154
+ ["Scene", "allSelector"],
155
+ ["Scene", "all", "selector"]
156
+ )
157
+ ) {
158
+ return Effect.void;
159
+ }
160
+
161
+ const assertion = node.parent;
162
+ if (
163
+ assertion.type === "CallExpression" &&
164
+ assertion.arguments[0] === node &&
165
+ isFoldkitCall(context.sourceCode, assertion, ["Scene", "expect"])
166
+ ) {
167
+ const member = assertion.parent;
168
+ if (
169
+ member.type === "MemberExpression" &&
170
+ member.object === assertion
171
+ ) {
172
+ const absent =
173
+ Option.contains(memberPropertyName(member), "toBeAbsent") &&
174
+ member.parent.type === "CallExpression" &&
175
+ member.parent.callee === member;
176
+ const negated = member.parent;
177
+ const matcher = negated.parent;
178
+ if (
179
+ absent ||
180
+ (Option.contains(memberPropertyName(member), "not") &&
181
+ negated.type === "MemberExpression" &&
182
+ negated.object === member &&
183
+ Option.contains(memberPropertyName(negated), "toExist") &&
184
+ matcher?.type === "CallExpression" &&
185
+ matcher.callee === negated)
186
+ ) {
187
+ return Effect.void;
188
+ }
189
+ }
190
+ }
191
+
192
+ const [css] = node.arguments;
193
+
194
+ if (css === undefined) {
195
+ return Effect.void;
196
+ }
197
+
198
+ return Option.match(
199
+ Option.filter(textWithHoles(css, "x"), (text) =>
200
+ fitsAccessibleLocator(Str.replaceAll(QUOTED, '""')(text))
201
+ ),
202
+ {
203
+ onNone: () => Effect.void,
204
+ onSome: () =>
205
+ context.report(
206
+ Diagnostic.fromId({
207
+ data: { target: context.sourceCode.getText(css) },
208
+ messageId: "accessibleLocator",
209
+ node,
210
+ })
211
+ ),
212
+ }
213
+ );
214
+ },
215
+ };
216
+ },
217
+ meta: Rule.meta({
218
+ description:
219
+ "Scene tests find elements by role, label or text, keeping selector() for targets no accessible locator fits",
220
+ messages: {
221
+ accessibleLocator:
222
+ "{{target}} targets an element with an accessible name or role. Find it with Scene.role, Scene.label, Scene.text, Scene.altText or Scene.title instead of a CSS selector.",
223
+ },
224
+ type: "suggestion",
225
+ }),
226
+ name: "prefer-accessible-scene-locators",
227
+ });
@@ -0,0 +1,144 @@
1
+ import { Diagnostic, Rule, RuleContext } from "effect-oxlint";
2
+ import type { ESTree } from "effect-oxlint";
3
+ import * as Arr from "effect/Array";
4
+ import * as Effect from "effect/Effect";
5
+ import * as HashSet from "effect/HashSet";
6
+ import * as Option from "effect/Option";
7
+
8
+ import { isFoldkitCall } from "../shared/foldkit-api.ts";
9
+ import { lastName } from "../shared/member-path.ts";
10
+ import {
11
+ isStringLiteral,
12
+ propertyName,
13
+ unwrapExpression,
14
+ } from "../shared/syntax.ts";
15
+
16
+ const OUTCOMES: ReadonlyArray<string> = ["Completed", "Succeeded", "Failed"];
17
+
18
+ type Answer = {
19
+ readonly name: string;
20
+ readonly node: ESTree.Node;
21
+ readonly outcome: Option.Option<string>;
22
+ };
23
+
24
+ type Answers = {
25
+ readonly command: string;
26
+ readonly list: ESTree.ArrayExpression;
27
+ readonly answers: ReadonlyArray<Answer>;
28
+ };
29
+
30
+ const answersOf = (call: ESTree.CallExpression): Option.Option<Answers> => {
31
+ const [name] = call.arguments;
32
+
33
+ const list = Option.flatMap(
34
+ Option.map(Arr.get(call.arguments, 1), unwrapExpression),
35
+ (settings) =>
36
+ Arr.findFirst(
37
+ settings.type === "ObjectExpression" ? settings.properties : [],
38
+ (property) => {
39
+ const value =
40
+ property.type === "Property" &&
41
+ Option.contains(propertyName(property), "messages")
42
+ ? unwrapExpression(property.value)
43
+ : property;
44
+
45
+ return value.type === "ArrayExpression"
46
+ ? Option.some(value)
47
+ : Option.none();
48
+ }
49
+ )
50
+ );
51
+
52
+ const command =
53
+ name !== undefined && isStringLiteral(name)
54
+ ? Option.some(name.value)
55
+ : Option.none();
56
+
57
+ return Option.map(Option.all([command, list]), ([text, array]) => ({
58
+ command: text,
59
+ list: array,
60
+ answers: Arr.flatMap(array.elements, (element) =>
61
+ element === null || element.type === "SpreadElement"
62
+ ? []
63
+ : Arr.fromOption(
64
+ Option.map(lastName(element), (answer) => ({
65
+ name: answer,
66
+ node: element,
67
+ outcome: Arr.findFirst(
68
+ OUTCOMES,
69
+ (outcome) => answer === `${outcome}${text}`
70
+ ),
71
+ }))
72
+ )
73
+ ),
74
+ }));
75
+ };
76
+
77
+ export const requireCommandAnswerNamesRule = Rule.define({
78
+ *create() {
79
+ const context = yield* RuleContext;
80
+
81
+ const check = ({
82
+ command,
83
+ list,
84
+ answers,
85
+ }: Answers): Effect.Effect<void, never, RuleContext> => {
86
+ const outcomes = HashSet.fromIterable(
87
+ Arr.flatMap(answers, ({ outcome }) => Arr.fromOption(outcome))
88
+ );
89
+
90
+ const mixed =
91
+ HashSet.has(outcomes, "Completed") &&
92
+ (HashSet.has(outcomes, "Succeeded") || HashSet.has(outcomes, "Failed"));
93
+
94
+ return Effect.andThen(
95
+ Effect.forEach(
96
+ Arr.filter(answers, ({ outcome }) => Option.isNone(outcome)),
97
+ ({ name, node }) =>
98
+ context.report(
99
+ Diagnostic.fromId({
100
+ data: { command, name },
101
+ messageId: "wrongAnswer",
102
+ node,
103
+ })
104
+ ),
105
+ { concurrency: 1, discard: true }
106
+ ),
107
+ mixed
108
+ ? context.report(
109
+ Diagnostic.fromId({
110
+ data: { command },
111
+ messageId: "mixedAnswers",
112
+ node: list,
113
+ })
114
+ )
115
+ : Effect.void
116
+ );
117
+ };
118
+
119
+ return {
120
+ CallExpression: (
121
+ node: ESTree.Node
122
+ ): Effect.Effect<void, never, RuleContext> =>
123
+ node.type === "CallExpression" &&
124
+ isFoldkitCall(context.sourceCode, node, ["Command", "define"])
125
+ ? Option.match(answersOf(node), {
126
+ onNone: () => Effect.void,
127
+ onSome: check,
128
+ })
129
+ : Effect.void,
130
+ };
131
+ },
132
+ meta: Rule.meta({
133
+ description:
134
+ "A Command X is answered only by CompletedX, or by SucceededX and FailedX",
135
+ messages: {
136
+ mixedAnswers:
137
+ "Command `{{command}}` answers both Completed{{command}} and Succeeded{{command}} or Failed{{command}}. An infallible Command answers Completed{{command}}; a fallible one answers Succeeded{{command}} or Failed{{command}}.",
138
+ wrongAnswer:
139
+ "Command `{{command}}` answers `{{name}}`. Name its result Completed{{command}} if it can't fail, or Succeeded{{command}} and Failed{{command}} if it can.",
140
+ },
141
+ type: "suggestion",
142
+ }),
143
+ name: "require-command-answer-names",
144
+ });