@milkenjoyer/toolchain 0.6.5 → 0.7.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/README.md CHANGED
@@ -1,11 +1,3 @@
1
- # Shared lint boundaries
2
-
3
- Shared lint rules resolve imported Effect and runtime bindings through unchanged `const` identifier and member aliases. Mutable aliases, destructuring aliases and arbitrary wrapper return values do not establish runtime identity. A runtime boundary permits provision only as the direct first argument of genuine BunRuntime or NodeRuntime `runMain`, or as a direct operator in that argument's `.pipe`.
4
-
5
- Raw Promise detection follows global `Promise`, `globalThis.Promise`, unchanged `const` and `let` Promise bindings, native Promise factories including `Promise.try`, global `fetch` calls and their unchanged `const` aliases, chains, `Promise<T>` bindings, and calls to local async or explicitly Promise-returning functions. It does not infer arbitrary library return types or object methods. Construction and each chain invocation report separately; a factory call alone does not report.
6
-
7
- A runtime value import from exactly `vite-plus/test/browser` or `vitest/browser` establishes a browser execution target for Foldkit's server-global rule. Type imports, filenames, DOM compiler libraries, providers and configuration imports do not establish that target. Other Foldkit rules retain their upstream behavior.
8
-
9
1
  # Configure pre-push hooks
10
2
 
11
3
  A shared absolute Git hooks path must dispatch through the invoking worktree. `@milkenjoyer/toolchain/hooks` supplies `configurePrePush` to run native Vite+ setup and install that dispatcher as one operation.
@@ -2,6 +2,7 @@ import * as Arr from "effect/Array";
2
2
  import { pipe } from "effect/Function";
3
3
  import * as HashSet from "effect/HashSet";
4
4
  import * as Option from "effect/Option";
5
+ import * as R from "effect/Record";
5
6
  import * as Schema from "effect/Schema";
6
7
  import * as Str from "effect/String";
7
8
  import { AST, Diagnostic, Plugin, Rule, RuleContext, Scope, SourceCode, Visitor } from "effect-oxlint";
@@ -3486,8 +3487,19 @@ const plugin$1 = Plugin.define({
3486
3487
  rules
3487
3488
  });
3488
3489
  // src/effect-plugin.ts
3490
+ const kept = [
3491
+ "avoid-mutable-state",
3492
+ "avoid-option-getorthrow",
3493
+ "effect-run-in-body",
3494
+ "no-chained-type-assertions",
3495
+ "no-module-mocking",
3496
+ "prefer-redacted-config",
3497
+ "require-effect-concurrency",
3498
+ "throw-in-effect-gen",
3499
+ "use-temp-file-scoped"
3500
+ ];
3489
3501
  const plugin = {
3490
3502
  meta: plugin$1.meta,
3491
- rules: plugin$1.rules
3503
+ rules: R.filter(plugin$1.rules, (_rule, name) => kept.includes(name))
3492
3504
  };
3493
3505
  export { plugin as t };
@@ -1 +1 @@
1
- export { t as default } from "./effect-plugin-DARbVmA3.mjs";
1
+ export { t as default } from "./effect-plugin-ByuWwyB8.mjs";
@@ -1,10 +1,4 @@
1
1
  export declare const patchCommand = "effect-tsgo patch --oxlint";
2
2
  export declare const effectTsgoPlugin = "effecttsgo";
3
- export type HeldRules = {
4
- readonly issue: string;
5
- readonly rules: ReadonlyArray<string>;
6
- };
7
- export declare const held: HeldRules;
8
- export declare const effectTsgoCatalog: ReadonlyArray<string>;
9
3
  export declare const enforcedTsgoRules: ReadonlyArray<string>;
10
- export declare const effectTsgoRules: Readonly<Record<string, "error" | "off">>;
4
+ export declare const effectTsgoRules: Readonly<Record<string, "error">>;
@@ -6,11 +6,18 @@ import * as Struct from "effect/Struct";
6
6
  // src/effect-tsgo.ts
7
7
  const patchCommand = "effect-tsgo patch --oxlint";
8
8
  const effectTsgoPlugin = "effecttsgo";
9
- const held = {
10
- issue: "https://github.com/birbprophet/agent-kit/issues/122",
11
- rules: ["effecttsgo/api-stability-leak"]
12
- };
13
- const effectTsgoCatalog = Arr.sort(Arr.dedupe(Arr.flatMap(R.values(presets), ({ rules = {} }) => Struct.keys(rules))), Order.String);
14
- const enforcedTsgoRules = Arr.filter(effectTsgoCatalog, (rule) => !held.rules.includes(rule));
15
- const effectTsgoRules = R.fromEntries([...Arr.map(held.rules, (rule) => [rule, "off"]), ...Arr.map(enforcedTsgoRules, (rule) => [rule, "error"])]);
16
- export { effectTsgoCatalog, effectTsgoPlugin, effectTsgoRules, enforcedTsgoRules, held, patchCommand };
9
+ const beyondRecommended = [
10
+ "effecttsgo/any-unknown-in-error-context",
11
+ "effecttsgo/crypto-random-uuid-in-effect",
12
+ "effecttsgo/effect-try-without-catch",
13
+ "effecttsgo/global-date-in-effect",
14
+ "effecttsgo/global-fetch-in-effect",
15
+ "effecttsgo/global-json-in-effect",
16
+ "effecttsgo/global-random-in-effect",
17
+ "effecttsgo/global-timers-in-effect",
18
+ "effecttsgo/missing-effect-service-dependency",
19
+ "effecttsgo/unsafe-effect-type-assertion"
20
+ ];
21
+ const enforcedTsgoRules = Arr.sort(Arr.dedupe([...Struct.keys(presets.recommended.rules ?? {}), ...beyondRecommended]), Order.String);
22
+ const effectTsgoRules = R.fromEntries(Arr.map(enforcedTsgoRules, (rule) => [rule, "error"]));
23
+ export { effectTsgoPlugin, effectTsgoRules, enforcedTsgoRules, patchCommand };
@@ -1,16 +1,3 @@
1
1
  // src/exceptions.ts
2
- const exceptions = [{
3
- files: [
4
- "packages/repo-lint/src/rules/import-allowlist.ts",
5
- "packages/repo-lint/src/rules/no-test-clock-real-io.ts",
6
- "packages/repo-lint/src/workspace-guard.config.ts",
7
- "packages/repo-lint/tests/design-system.test.ts"
8
- ],
9
- rules: ["effecttsgo/node-builtin-import"],
10
- issue: "https://github.com/birbprophet/agent-kit/issues/171"
11
- }, {
12
- files: ["vite.config.ts"],
13
- rules: ["effecttsgo/process-env"],
14
- issue: "https://github.com/birbprophet/agent-kit/issues/171"
15
- }];
2
+ const exceptions = [];
16
3
  export { exceptions };
package/dist/guard.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Packuments } from "./compatible.mjs";
2
- import { HeldRules } from "./effect-tsgo.mjs";
3
2
  import { Exception } from "./exceptions.mjs";
4
3
  import { Catalog } from "./versions.mjs";
5
4
  import { OxlintConfig } from "vite-plus/lint";
@@ -20,11 +19,6 @@ export declare const ruleFindings: {
20
19
  (config: OxlintConfig, list?: ReadonlyArray<Exception>): ReadonlyArray<string>;
21
20
  };
22
21
  export declare const exceptionFindings: (list?: ReadonlyArray<Exception>) => ReadonlyArray<string>;
23
- export declare const heldFindings: {
24
- (list?: undefined): ReadonlyArray<string>;
25
- (catalog?: ReadonlyArray<string>): (list?: HeldRules) => ReadonlyArray<string>;
26
- (list?: HeldRules, catalog?: ReadonlyArray<string>): ReadonlyArray<string>;
27
- };
28
22
  export declare const tagFindings: {
29
23
  (registry: Packuments): (current: Catalog) => ReadonlyArray<string>;
30
24
  (current: Catalog, registry: Packuments): ReadonlyArray<string>;
package/dist/guard.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import { latestOf, onLatestLine, otherTags } from "./compatible.mjs";
2
- import { effectTsgoCatalog, enforcedTsgoRules, held } from "./effect-tsgo.mjs";
2
+ import { enforcedTsgoRules } from "./effect-tsgo.mjs";
3
3
  import { exceptions } from "./exceptions.mjs";
4
- import { birbprophetRules, effectRules, foldkitRules } from "./lint.mjs";
5
- import { n as rikalabsRules } from "./rikalabs-hPKWFZ1P.mjs";
4
+ import { birbprophetRules, effectRules, foldkitPreset } from "./lint.mjs";
6
5
  import { lead, versionOf } from "./versions.mjs";
7
6
  import * as Arr from "effect/Array";
8
7
  import { dual } from "effect/Function";
@@ -88,14 +87,25 @@ const atError = (setting) => [
88
87
  ].includes(severityOf(setting));
89
88
  const settingOf = (rules, rule) => Option.fromNullishOr(rules?.[rule]);
90
89
  const guarded = [
91
- ...R.keys(foldkitRules),
90
+ ...R.keys(R.filter(foldkitPreset.rules, (setting) => setting === "error")),
92
91
  ...R.keys(effectRules),
93
92
  ...R.keys(birbprophetRules),
94
- ...R.keys(rikalabsRules),
95
93
  ...enforcedTsgoRules
96
94
  ];
97
- const excepted = (override, rule, list) => Arr.some(list, (exception) => exception.rules.includes(rule) && override.files.length === exception.files.length && Arr.every(override.files, (file) => exception.files.includes(file)));
98
- const overrideFindings = (where, overrides, list) => Arr.flatMap(overrides, (override) => Arr.flatMap(guarded, (rule) => Option.match(settingOf(override.rules, rule), {
95
+ const presetScopes = Arr.map(foldkitPreset.overrides, ({ files, rules }) => ({
96
+ files,
97
+ rules: R.keys(R.filter(rules, (setting) => setting === "off"))
98
+ }));
99
+ const scopedGuards = Arr.map(foldkitPreset.overrides, ({ files, excludeFiles = [], rules }) => ({
100
+ files,
101
+ excludeFiles,
102
+ rules: R.keys(R.filter(rules, (setting) => setting === "error"))
103
+ }));
104
+ const guardedInOverrides = Arr.dedupe([...guarded, ...Arr.flatMap(scopedGuards, ({ rules }) => rules)]);
105
+ const sameFiles = (files, other) => files.length === other.length && Arr.every(files, (file) => other.includes(file));
106
+ const excepted = (override, rule, list) => Arr.some([...presetScopes, ...list], (exception) => exception.rules.includes(rule) && sameFiles(override.files, exception.files));
107
+ const scopeFindings = (overrides) => Arr.flatMap(scopedGuards, ({ files, excludeFiles, rules }) => Arr.flatMap(rules, (rule) => Arr.some(overrides, (override) => sameFiles(override.files, files) && sameFiles(override.excludeFiles ?? [], excludeFiles) && Option.exists(settingOf(override.rules, rule), atError)) ? [] : [`${rule} is not at error for ${Arr.join(files, ", ")}`]));
108
+ const overrideFindings = (where, overrides, list) => Arr.flatMap(overrides, (override) => Arr.flatMap(guardedInOverrides, (rule) => Option.match(settingOf(override.rules, rule), {
99
109
  onNone: () => [],
100
110
  onSome: (setting) => atError(setting) || excepted(override, rule, list) ? [] : [`${where} override for ${Arr.join(override.files, ", ")} sets ${rule} to ${severityOf(setting)} outside a named-file exception`]
101
111
  })));
@@ -109,6 +119,7 @@ const ruleFindings = dual((args) => args[0] !== void 0 && !Schema.is(Schema.Arra
109
119
  onSome: (setting) => atError(setting) ? [] : [`${rule} is ${severityOf(setting)}`]
110
120
  })),
111
121
  ...overrideFindings("the config's", overrides, list),
122
+ ...scopeFindings(overrides),
112
123
  ...inheritedFindings("", config)
113
124
  ]);
114
125
  const GLOB = /[*?[\]{}!]/u;
@@ -119,7 +130,6 @@ const exceptionFindings = (list = exceptions) => Arr.flatMap(list, (exception, i
119
130
  ...Arr.isReadonlyArrayEmpty(exception.rules) ? [`exception ${index} names no rule`] : [],
120
131
  ...ISSUE.test(exception.issue) ? [] : [`exception ${index} has no issue link: ${exception.issue}`]
121
132
  ]);
122
- const heldFindings = dual((args) => !Schema.is(Schema.Array(Schema.Unknown))(args[0]), (list = held, catalog = effectTsgoCatalog) => [...ISSUE.test(list.issue) ? [] : [`the held @effect/tsgo rules have no issue link: ${list.issue}`], ...Arr.flatMap(list.rules, (rule) => catalog.includes(rule) ? [] : [`${rule} is held but is not in the @effect/tsgo catalog`])]);
123
133
  const familyTagFindings = (registry, family) => Option.match(latestOf(registry, family), {
124
134
  onNone: () => [`${lead(family)} has no latest tag in the registry record`],
125
135
  onSome: (latest) => family.version === latest ? [] : Option.match(Arr.findFirst(otherTags(registry, family), ([, version]) => version === family.version), {
@@ -128,4 +138,4 @@ const familyTagFindings = (registry, family) => Option.match(latestOf(registry,
128
138
  })
129
139
  });
130
140
  const tagFindings = dual(2, (current, registry) => Arr.flatMap(current.families, (family) => familyTagFindings(registry, family)));
131
- export { exactFindings, exceptionFindings, foldkitViteFindings, heldFindings, isFoldkitViteInput, manifestRanges, pinFindings, ruleFindings, tagFindings };
141
+ export { exactFindings, exceptionFindings, foldkitViteFindings, isFoldkitViteInput, manifestRanges, pinFindings, ruleFindings, tagFindings };
package/dist/lint.d.mts CHANGED
@@ -1,9 +1,23 @@
1
1
  import { OxlintConfig } from "vite-plus/lint";
2
2
  export type LintOptions = {
3
3
  readonly ignores?: ReadonlyArray<string>;
4
- readonly domainPackages?: ReadonlyArray<string>;
5
4
  };
6
- export declare const foldkitRules: Record<string, "error">;
5
+ export declare const foldkitPreset: {
6
+ readonly jsPlugins: readonly {
7
+ readonly name: string;
8
+ readonly specifier: string;
9
+ }[];
10
+ readonly rules: {
11
+ readonly [x: string]: "error" | "off";
12
+ };
13
+ readonly overrides: readonly {
14
+ readonly files: string[];
15
+ readonly excludeFiles?: string[];
16
+ readonly rules: {
17
+ readonly [x: string]: "error" | "off";
18
+ };
19
+ }[];
20
+ };
7
21
  export declare const effectRules: Record<string, "error">;
8
22
  export declare const birbprophetRules: Record<string, "error">;
9
- export declare const lint: ({ ignores, domainPackages }?: LintOptions) => OxlintConfig;
23
+ export declare const lint: ({ ignores }?: LintOptions) => OxlintConfig;
package/dist/lint.mjs CHANGED
@@ -1,17 +1,15 @@
1
- import { t as plugin } from "./effect-plugin-DARbVmA3.mjs";
1
+ import { t as plugin } from "./effect-plugin-ByuWwyB8.mjs";
2
2
  import { effectTsgoPlugin, effectTsgoRules } from "./effect-tsgo.mjs";
3
3
  import { exceptions } from "./exceptions.mjs";
4
- import plugin$1 from "./foldkit.mjs";
5
- import { t as plugin$2 } from "./plugin-CBUJ7Tgd.mjs";
6
- import { n as rikalabsRules, t as plugin$3 } from "./rikalabs-hPKWFZ1P.mjs";
4
+ import { t as plugin$1 } from "./plugin-C3DDlAbr.mjs";
7
5
  import { staticRules } from "./rules.mjs";
8
6
  import * as Arr from "effect/Array";
9
- import * as HashSet from "effect/HashSet";
10
7
  import * as Option from "effect/Option";
11
8
  import * as R from "effect/Record";
9
+ import * as Schema from "effect/Schema";
12
10
  import * as Str from "effect/String";
11
+ import foldkitRecommended from "@foldkit/oxlint-plugin/recommended.json" with { type: "json" };
13
12
  import ultraciteCore from "ultracite/oxlint/core";
14
- import ultraciteVitest from "ultracite/oxlint/vitest";
15
13
  // src/lint.ts
16
14
  const plugins = [
17
15
  "typescript",
@@ -22,76 +20,62 @@ const plugins = [
22
20
  "eslint",
23
21
  "node",
24
22
  "vitest",
25
- "jsdoc",
26
23
  effectTsgoPlugin
27
24
  ];
28
25
  const categories = {
29
26
  correctness: "error",
30
27
  suspicious: "error",
31
- pedantic: "error",
32
- perf: "error",
33
- style: "error",
28
+ pedantic: "off",
29
+ perf: "off",
30
+ style: "off",
34
31
  restriction: "off",
35
32
  nursery: "off"
36
33
  };
34
+ const PresetRules = Schema.Record(Schema.String, Schema.Literals(["error", "off"]));
35
+ const Globs = Schema.mutable(Schema.Array(Schema.String));
36
+ const FoldkitPreset = Schema.Struct({
37
+ jsPlugins: Schema.Array(Schema.Struct({
38
+ name: Schema.String,
39
+ specifier: Schema.String
40
+ })),
41
+ rules: PresetRules,
42
+ overrides: Schema.Array(Schema.Struct({
43
+ files: Globs,
44
+ excludeFiles: Schema.optionalKey(Globs),
45
+ rules: PresetRules
46
+ }))
47
+ });
48
+ const foldkitPreset = Schema.decodeUnknownSync(FoldkitPreset)(foldkitRecommended);
37
49
  const atError = (prefix, rules) => R.fromEntries(Arr.map(rules, (rule) => [`${prefix}/${rule}`, "error"]));
38
- const foldkitRules = atError(plugin$1.meta.name, R.keys(plugin$1.rules));
39
50
  const effectRules = atError(plugin.meta.name, R.keys(plugin.rules));
40
- const birbprophetRules = atError(plugin$2.meta.name, R.keys(plugin$2.rules));
41
- const offEverywhere = HashSet.fromIterable(Arr.flatMap(R.toEntries(staticRules), ([rule, setting]) => setting === "off" ? [rule] : []));
42
- const { overrides: vitestOverrides = [] } = ultraciteVitest;
51
+ const birbprophetRules = atError(plugin$1.meta.name, R.keys(plugin$1.rules));
43
52
  const { ignorePatterns: coreIgnores = [] } = ultraciteCore;
44
- const vitestPreset = {
45
- ...ultraciteVitest,
46
- overrides: Arr.map(vitestOverrides, ({ rules = {}, ...override }) => ({
47
- ...override,
48
- rules: R.filter(rules, (_setting, rule) => !HashSet.has(offEverywhere, rule))
49
- }))
50
- };
51
53
  const resolved = (specifier) => decodeURIComponent(new URL(import.meta.resolve(specifier)).pathname);
52
54
  const ownExtension = Str.slice(Str.lastIndexOf(".")(import.meta.filename).pipe(Option.getOrElse(() => -1)))(import.meta.filename);
53
55
  const sibling = (module) => resolved(`./${module}${ownExtension}`);
54
- const domainTiers = (roots) => Arr.match(roots, {
55
- onEmpty: () => [],
56
- onNonEmpty: () => [{
57
- files: Arr.map(roots, (root) => `${root}/src/**`),
58
- rules: { "unicorn/filename-case": ["error", {
59
- case: "pascalCase",
60
- multipleFileExtensions: true
61
- }] }
62
- }, {
63
- files: Arr.map(roots, (root) => `${root}/src/**/*.command.ts`),
64
- rules: { "eslint/max-classes-per-file": "off" }
65
- }]
66
- });
67
56
  const exceptionTier = (exception) => ({
68
57
  files: [...exception.files],
69
58
  rules: R.fromEntries(Arr.map(exception.rules, (rule) => [rule, "off"]))
70
59
  });
71
- const lint = ({ ignores = [], domainPackages = [] } = {}) => ({
60
+ const lint = ({ ignores = [] } = {}) => ({
72
61
  plugins,
73
62
  categories,
74
- extends: [ultraciteCore, vitestPreset],
75
63
  jsPlugins: [
76
64
  {
77
65
  name: "vite-plus",
78
66
  specifier: resolved("vite-plus/oxlint-plugin")
79
67
  },
80
- {
81
- name: plugin$1.meta.name,
82
- specifier: sibling("foldkit")
83
- },
68
+ ...Arr.map(foldkitPreset.jsPlugins, ({ name, specifier }) => ({
69
+ name,
70
+ specifier: resolved(specifier)
71
+ })),
84
72
  {
85
73
  name: plugin.meta.name,
86
74
  specifier: sibling("effect-plugin")
87
75
  },
88
76
  {
89
- name: plugin$2.meta.name,
77
+ name: plugin$1.meta.name,
90
78
  specifier: sibling("plugin")
91
- },
92
- {
93
- name: plugin$3.meta.name,
94
- specifier: sibling("rikalabs")
95
79
  }
96
80
  ],
97
81
  options: {
@@ -99,15 +83,14 @@ const lint = ({ ignores = [], domainPackages = [] } = {}) => ({
99
83
  typeCheck: true
100
84
  },
101
85
  rules: {
86
+ ...foldkitPreset.rules,
102
87
  ...staticRules,
103
88
  "vite-plus/prefer-vite-plus-imports": "error",
104
- ...foldkitRules,
105
89
  ...effectRules,
106
90
  ...birbprophetRules,
107
- ...rikalabsRules,
108
91
  ...effectTsgoRules
109
92
  },
110
- overrides: [...domainTiers(domainPackages), ...Arr.map(exceptions, exceptionTier)],
93
+ overrides: [...foldkitPreset.overrides, ...Arr.map(exceptions, exceptionTier)],
111
94
  ignorePatterns: [...coreIgnores, ...ignores]
112
95
  });
113
- export { birbprophetRules, effectRules, foldkitRules, lint };
96
+ export { birbprophetRules, effectRules, foldkitPreset, lint };
@@ -0,0 +1,268 @@
1
+ import * as Arr from "effect/Array";
2
+ import { dual } from "effect/Function";
3
+ import * as HashSet from "effect/HashSet";
4
+ import * as Option from "effect/Option";
5
+ import * as Schema from "effect/Schema";
6
+ import * as Str from "effect/String";
7
+ import { Comment, Diagnostic, Plugin, Rule, RuleContext } from "effect-oxlint";
8
+ import * as Effect from "effect/Effect";
9
+ import * as HashMap from "effect/HashMap";
10
+ // src/rules/no-comments.ts
11
+ const noCommentsRule = Rule.define({
12
+ *create() {
13
+ const context = yield* RuleContext;
14
+ return { Program: () => Effect.forEach(Arr.filter(context.sourceCode.getAllComments(), (comment) => !Comment.isShebang(comment) && !/^\s*@vite-ignore\s*$/u.test(Comment.text(comment))), (comment) => context.report(Diagnostic.fromId({
15
+ messageId: "comment",
16
+ node: comment
17
+ })), {
18
+ concurrency: 1,
19
+ discard: true
20
+ }) };
21
+ },
22
+ meta: Rule.meta({
23
+ description: "No comments except shebangs and exact @vite-ignore directives: meaning lives in names, types and test names",
24
+ messages: { comment: "Delete this comment. Put its meaning in a name, a type or a test name. Only shebangs and exact @vite-ignore directives are allowed." },
25
+ type: "problem"
26
+ }),
27
+ name: "no-comments"
28
+ });
29
+ // src/shared/syntax.ts
30
+ const unwrapExpression = (node) => {
31
+ if (node.type === "ParenthesizedExpression" || node.type === "ChainExpression" || node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression") return unwrapExpression(node.expression);
32
+ return node;
33
+ };
34
+ const isStringLiteral = (node) => node.type === "Literal" && Schema.is(Schema.String)(node.value);
35
+ const memberPropertyName = (node) => {
36
+ if (!node.computed && node.property.type === "Identifier") return Option.some(node.property.name);
37
+ return node.computed && isStringLiteral(node.property) ? Option.some(node.property.value) : Option.none();
38
+ };
39
+ const propertyName = (property) => {
40
+ if (!property.computed && property.key.type === "Identifier") return Option.some(property.key.name);
41
+ return isStringLiteral(property.key) ? Option.some(property.key.value) : Option.none();
42
+ };
43
+ // src/shared/member-path.ts
44
+ const resolveBinding = (sourceCode, node) => {
45
+ const findBinding = (scope) => Option.flatMap(scope, (current) => Option.orElse(Option.fromUndefinedOr(current.set.get(node.name)), () => findBinding(Option.fromNullishOr(current.upper))));
46
+ return findBinding(Option.fromNullishOr(sourceCode.getScope(node)));
47
+ };
48
+ const memberPath = (node) => {
49
+ const current = unwrapExpression(node);
50
+ if (current.type === "Identifier") return Option.some({
51
+ root: current,
52
+ members: []
53
+ });
54
+ if (current.type !== "MemberExpression") return Option.none();
55
+ return Option.flatMap(memberPath(current.object), (path) => Option.map(memberPropertyName(current), (name) => ({
56
+ root: path.root,
57
+ members: [...path.members, name]
58
+ })));
59
+ };
60
+ const lastName = (node) => Option.map(memberPath(node), (path) => Option.getOrElse(Arr.last(path.members), () => path.root.name));
61
+ const importedPath = dual(2, (sourceCode, node) => Option.gen(function* () {
62
+ const path = yield* memberPath(node);
63
+ const variable = yield* resolveBinding(sourceCode, path.root);
64
+ const definition = yield* Arr.findFirst(variable.defs, (candidate) => candidate.type === "ImportBinding");
65
+ const declaration = definition.parent;
66
+ const specifier = definition.node;
67
+ if (declaration?.type !== "ImportDeclaration") return yield* Option.none();
68
+ if (specifier.type === "ImportNamespaceSpecifier") return {
69
+ source: declaration.source.value,
70
+ members: path.members
71
+ };
72
+ if (specifier.type !== "ImportSpecifier") return yield* Option.none();
73
+ const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
74
+ return {
75
+ source: declaration.source.value,
76
+ members: [imported, ...path.members]
77
+ };
78
+ }));
79
+ // src/shared/foldkit-api.ts
80
+ const NAMESPACES = HashMap.make(["foldkit", []], ["foldkit/command", ["Command"]], ["foldkit/html", ["Html"]], ["foldkit/message", ["Message"]], ["foldkit/scene", ["Scene"]], ["foldkit/schema", ["Schema"]], ["foldkit/test", []]);
81
+ const isFoldkitCall = (sourceCode, node, ...wanted) => Option.exists(importedPath(sourceCode, node.callee), (path) => Option.exists(HashMap.get(NAMESPACES, path.source), (prefix) => {
82
+ const full = Arr.join([...prefix, ...path.members], ".");
83
+ return Arr.some(wanted, (candidate) => Arr.join(candidate, ".") === full);
84
+ }));
85
+ const textWithHoles = dual(2, (node, hole) => {
86
+ if (isStringLiteral(node)) return Option.some(node.value);
87
+ return node.type === "TemplateLiteral" ? Option.some(Arr.join(Arr.map(node.quasis, (quasi) => quasi.value.raw), hole)) : Option.none();
88
+ });
89
+ // src/rules/prefer-accessible-scene-locators.ts
90
+ const ROLE_TAGS = HashSet.make("a", "article", "aside", "button", "datalist", "dd", "details", "dialog", "dt", "fieldset", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hr", "img", "input", "li", "main", "menu", "meter", "nav", "ol", "option", "output", "progress", "select", "summary", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "tr", "ul");
91
+ const ACCESSIBLE_ATTRIBUTES = /\[\s*(?:role|aria-label|aria-labelledby|alt|placeholder|title)\s*(?:[~|^$*]?=|\])/iu;
92
+ const QUOTED = /"[^"]*"|'[^']*'/gu;
93
+ const COMBINATOR = /[\s>+~]/u;
94
+ const TAG = /^[a-z][a-z0-9-]*/iu;
95
+ const SUBJECT_PSEUDO = /^(?:is|where|matches)\(/u;
96
+ const splitTopLevel = (text, isSeparator) => Arr.reduce(Arr.filter(Str.split(text, ""), Str.isNonEmpty), {
97
+ depth: 0,
98
+ parts: [""]
99
+ }, ({ depth, parts }, char) => {
100
+ if (depth === 0 && isSeparator(char)) return {
101
+ depth,
102
+ parts: [...parts, ""]
103
+ };
104
+ const opened = char === "(" || char === "[" ? 1 : 0;
105
+ const closed = char === ")" || char === "]" ? 1 : 0;
106
+ return {
107
+ depth: depth + opened - closed,
108
+ parts: [...parts.slice(0, -1), `${parts.at(-1) ?? ""}${char}`]
109
+ };
110
+ }).parts;
111
+ const fitsAccessibleLocator = (selector) => Arr.some(splitTopLevel(selector, (char) => char === ","), (part) => {
112
+ const compound = Option.getOrElse(Arr.last(Arr.filter(splitTopLevel(Str.trim(part), (char) => COMBINATOR.test(char)), (piece) => piece !== "")), () => "");
113
+ const [tag = ""] = TAG.exec(compound) ?? [];
114
+ return HashSet.has(ROLE_TAGS, Str.toLowerCase(tag)) || Arr.some(splitTopLevel(compound, (char) => char === ":"), (piece) => {
115
+ const open = Str.indexOf("(")(piece);
116
+ if (Option.isNone(open)) return ACCESSIBLE_ATTRIBUTES.test(piece);
117
+ const close = Str.lastIndexOf(")")(piece).pipe(Option.getOrElse(() => -1));
118
+ return ACCESSIBLE_ATTRIBUTES.test(`${Str.slice(0, open.value)(piece)}${Str.slice(close + 1)(piece)}`) || SUBJECT_PSEUDO.test(piece) && fitsAccessibleLocator(Str.slice(open.value + 1, close)(piece));
119
+ });
120
+ });
121
+ const preferAccessibleSceneLocatorsRule = Rule.define({
122
+ *create() {
123
+ const context = yield* RuleContext;
124
+ return { CallExpression: (node) => {
125
+ if (node.type !== "CallExpression" || !isFoldkitCall(context.sourceCode, node, ["Scene", "selector"], ["Scene", "allSelector"], [
126
+ "Scene",
127
+ "all",
128
+ "selector"
129
+ ])) return Effect.void;
130
+ const [css] = node.arguments;
131
+ if (css === void 0) return Effect.void;
132
+ return Option.match(Option.filter(textWithHoles(css, "x"), (text) => fitsAccessibleLocator(Str.replaceAll(QUOTED, "\"\"")(text))), {
133
+ onNone: () => Effect.void,
134
+ onSome: () => context.report(Diagnostic.fromId({
135
+ data: { target: context.sourceCode.getText(css) },
136
+ messageId: "accessibleLocator",
137
+ node
138
+ }))
139
+ });
140
+ } };
141
+ },
142
+ meta: Rule.meta({
143
+ description: "Scene tests find elements by role, label or text, keeping selector() for targets no accessible locator fits",
144
+ messages: { accessibleLocator: "{{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." },
145
+ type: "suggestion"
146
+ }),
147
+ name: "prefer-accessible-scene-locators"
148
+ });
149
+ // src/rules/require-command-answer-names.ts
150
+ const OUTCOMES = [
151
+ "Completed",
152
+ "Succeeded",
153
+ "Failed"
154
+ ];
155
+ const answersOf = (call) => {
156
+ const [name] = call.arguments;
157
+ const list = Option.flatMap(Option.map(Arr.get(call.arguments, 1), unwrapExpression), (settings) => Arr.findFirst(settings.type === "ObjectExpression" ? settings.properties : [], (property) => {
158
+ const value = property.type === "Property" && Option.contains(propertyName(property), "messages") ? unwrapExpression(property.value) : property;
159
+ return value.type === "ArrayExpression" ? Option.some(value) : Option.none();
160
+ }));
161
+ const command = name !== void 0 && isStringLiteral(name) ? Option.some(name.value) : Option.none();
162
+ return Option.map(Option.all([command, list]), ([text, array]) => ({
163
+ command: text,
164
+ list: array,
165
+ answers: Arr.flatMap(array.elements, (element) => element === null || element.type === "SpreadElement" ? [] : Arr.fromOption(Option.map(lastName(element), (answer) => ({
166
+ name: answer,
167
+ node: element,
168
+ outcome: Arr.findFirst(OUTCOMES, (outcome) => answer === `${outcome}${text}`)
169
+ }))))
170
+ }));
171
+ };
172
+ const requireCommandAnswerNamesRule = Rule.define({
173
+ *create() {
174
+ const context = yield* RuleContext;
175
+ const check = ({ command, list, answers }) => {
176
+ const outcomes = HashSet.fromIterable(Arr.flatMap(answers, ({ outcome }) => Arr.fromOption(outcome)));
177
+ const mixed = HashSet.has(outcomes, "Completed") && (HashSet.has(outcomes, "Succeeded") || HashSet.has(outcomes, "Failed"));
178
+ return Effect.andThen(Effect.forEach(Arr.filter(answers, ({ outcome }) => Option.isNone(outcome)), ({ name, node }) => context.report(Diagnostic.fromId({
179
+ data: {
180
+ command,
181
+ name
182
+ },
183
+ messageId: "wrongAnswer",
184
+ node
185
+ })), {
186
+ concurrency: 1,
187
+ discard: true
188
+ }), mixed ? context.report(Diagnostic.fromId({
189
+ data: { command },
190
+ messageId: "mixedAnswers",
191
+ node: list
192
+ })) : Effect.void);
193
+ };
194
+ return { CallExpression: (node) => node.type === "CallExpression" && isFoldkitCall(context.sourceCode, node, ["Command", "define"]) ? Option.match(answersOf(node), {
195
+ onNone: () => Effect.void,
196
+ onSome: check
197
+ }) : Effect.void };
198
+ },
199
+ meta: Rule.meta({
200
+ description: "A Command X is answered only by CompletedX, or by SucceededX and FailedX",
201
+ messages: {
202
+ mixedAnswers: "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}}.",
203
+ wrongAnswer: "Command `{{command}}` answers `{{name}}`. Name its result Completed{{command}} if it can't fail, or Succeeded{{command}} and Failed{{command}} if it can."
204
+ },
205
+ type: "suggestion"
206
+ }),
207
+ name: "require-command-answer-names"
208
+ });
209
+ // src/rules/require-past-tense-messages.ts
210
+ const IRREGULAR_PAST = HashSet.make("Ate", "Became", "Began", "Bought", "Broke", "Brought", "Built", "Came", "Caught", "Chose", "Did", "Drew", "Drove", "Fell", "Felt", "Fled", "Flew", "Forgot", "Found", "Froze", "Gave", "Got", "Grew", "Had", "Heard", "Held", "Hid", "Hung", "Kept", "Knew", "Laid", "Led", "Left", "Lent", "Lost", "Made", "Meant", "Met", "Paid", "Ran", "Rang", "Rode", "Rose", "Said", "Sang", "Sank", "Sat", "Saw", "Sent", "Shook", "Shot", "Slept", "Slid", "Sold", "Sought", "Spent", "Spoke", "Stole", "Stood", "Struck", "Stuck", "Swept", "Swung", "Taught", "Thought", "Threw", "Told", "Took", "Tore", "Understood", "Undid", "Went", "Withdrew", "Woke", "Won", "Wore", "Wrote");
211
+ const PRESENT_ENDING_IN_ED = HashSet.make("Bed", "Bleed", "Breed", "Embed", "Exceed", "Feed", "Heed", "Need", "Proceed", "Red", "Seed", "Shed", "Shred", "Speed", "Succeed", "Weed");
212
+ const IMPERATIVE = /^(?:Set|Mutate)(?![a-z])/u;
213
+ const FIRST_WORD = /^[A-Z][a-z]*/u;
214
+ const problemOf = (name) => {
215
+ if (IMPERATIVE.test(name)) return Option.some("imperative");
216
+ const [word = ""] = FIRST_WORD.exec(name) ?? [];
217
+ return HashSet.has(IRREGULAR_PAST, word) || Str.endsWith("ed")(word) && !HashSet.has(PRESENT_ENDING_IN_ED, word) ? Option.none() : Option.some("notPastTense");
218
+ };
219
+ const requirePastTenseMessagesRule = Rule.define({
220
+ *create() {
221
+ const context = yield* RuleContext;
222
+ const reportKey = (property) => {
223
+ if (property.type !== "Property") return Effect.void;
224
+ return Option.match(Option.flatMap(propertyName(property), (name) => Option.map(problemOf(name), (messageId) => ({
225
+ messageId,
226
+ name
227
+ }))), {
228
+ onNone: () => Effect.void,
229
+ onSome: ({ messageId, name }) => context.report(Diagnostic.fromId({
230
+ data: { name },
231
+ messageId,
232
+ node: property.key
233
+ }))
234
+ });
235
+ };
236
+ return { CallExpression: (node) => {
237
+ if (node.type !== "CallExpression" || !isFoldkitCall(context.sourceCode, node, ["Message", "defineMessageUnion"], ["Schema", "defineMessageUnion"])) return Effect.void;
238
+ return Option.match(Option.map(Arr.head(node.arguments), unwrapExpression), {
239
+ onNone: () => Effect.void,
240
+ onSome: (cases) => cases.type === "ObjectExpression" ? Effect.forEach(cases.properties, reportKey, {
241
+ concurrency: 1,
242
+ discard: true
243
+ }) : Effect.void
244
+ });
245
+ } };
246
+ },
247
+ meta: Rule.meta({
248
+ description: "Every Message union key is a past-tense fact with its source prefix, never Set* or Mutate*",
249
+ messages: {
250
+ imperative: "`{{name}}` is an imperative name. Name the Message for the fact that happened, with its source prefix: Clicked*, Updated*, Pressed*, Submitted*, Got*, Completed*, Succeeded* or Failed*.",
251
+ notPastTense: "`{{name}}` doesn't start with a past-tense source prefix. Name the Message for the fact that happened: Clicked*, Updated*, Pressed*, Submitted*, Got*, Completed*, Succeeded* or Failed*."
252
+ },
253
+ type: "suggestion"
254
+ }),
255
+ name: "require-past-tense-messages"
256
+ });
257
+ // src/plugin.ts
258
+ const plugin = Plugin.define({
259
+ name: "birbprophet",
260
+ rules: {
261
+ "no-comments": noCommentsRule,
262
+ "prefer-accessible-scene-locators": preferAccessibleSceneLocatorsRule,
263
+ "require-command-answer-names": requireCommandAnswerNamesRule,
264
+ "require-past-tense-messages": requirePastTenseMessagesRule
265
+ },
266
+ specifier: "@milkenjoyer/toolchain/plugin"
267
+ });
268
+ export { plugin as t };
package/dist/plugin.d.mts CHANGED
@@ -1,19 +1,8 @@
1
1
  import { Plugin } from "effect-oxlint";
2
2
  declare const plugin: Plugin.DefinedPlugin<{
3
- readonly "no-ambient-crypto": import("effect-oxlint").CreateRule;
4
- readonly "no-array-filter-map": import("effect-oxlint").CreateRule;
5
3
  readonly "no-comments": import("effect-oxlint").CreateRule;
6
- readonly "no-impure-update-file": import("effect-oxlint").CreateRule;
7
- readonly "no-impure-view-file": import("effect-oxlint").CreateRule;
8
- readonly "no-inline-exported-object-types": import("effect-oxlint").CreateRule;
9
- readonly "no-keyed-row-index": import("effect-oxlint").CreateRule;
10
- readonly "no-manual-tagged-construction": import("effect-oxlint").CreateRule;
11
- readonly "no-reexports": import("effect-oxlint").CreateRule;
12
- readonly "no-silent-error-swallow": import("effect-oxlint").CreateRule;
13
- readonly "no-single-use-trivial-helpers": import("effect-oxlint").CreateRule;
14
4
  readonly "prefer-accessible-scene-locators": import("effect-oxlint").CreateRule;
15
5
  readonly "require-command-answer-names": import("effect-oxlint").CreateRule;
16
6
  readonly "require-past-tense-messages": import("effect-oxlint").CreateRule;
17
- readonly "require-readable-spacing": import("effect-oxlint").CreateRule;
18
7
  }>;
19
8
  export { plugin as default };
package/dist/plugin.mjs CHANGED
@@ -1 +1 @@
1
- export { t as default } from "./plugin-CBUJ7Tgd.mjs";
1
+ export { t as default } from "./plugin-C3DDlAbr.mjs";