@kutur-kit/oxc 0.1.0-alpha.7 → 0.1.0-alpha.8

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 (139) hide show
  1. package/README.md +69 -21
  2. package/dist/app.d.ts +16 -0
  3. package/dist/app.d.ts.map +1 -0
  4. package/dist/app.js +17 -0
  5. package/dist/app.js.map +1 -0
  6. package/dist/base.d.ts.map +1 -1
  7. package/dist/base.js +5 -1
  8. package/dist/base.js.map +1 -1
  9. package/dist/effect-ui-stylex/class.d.ts +2 -0
  10. package/dist/effect-ui-stylex/class.d.ts.map +1 -0
  11. package/dist/effect-ui-stylex/class.js +109 -0
  12. package/dist/effect-ui-stylex/class.js.map +1 -0
  13. package/dist/effect-ui-stylex/components.d.ts +30 -0
  14. package/dist/effect-ui-stylex/components.d.ts.map +1 -0
  15. package/dist/effect-ui-stylex/components.js +175 -0
  16. package/dist/effect-ui-stylex/components.js.map +1 -0
  17. package/dist/effect-ui-stylex/condition-key.d.ts.map +1 -0
  18. package/dist/{foldkit-stylex → effect-ui-stylex}/condition-key.js +7 -41
  19. package/dist/effect-ui-stylex/condition-key.js.map +1 -0
  20. package/dist/effect-ui-stylex/hover-gate.d.ts.map +1 -0
  21. package/dist/effect-ui-stylex/hover-gate.js.map +1 -0
  22. package/dist/effect-ui-stylex/internal-import.d.ts +2 -0
  23. package/dist/effect-ui-stylex/internal-import.d.ts.map +1 -0
  24. package/dist/effect-ui-stylex/internal-import.js +29 -0
  25. package/dist/effect-ui-stylex/internal-import.js.map +1 -0
  26. package/dist/effect-ui-stylex/layers.d.ts +14 -0
  27. package/dist/effect-ui-stylex/layers.d.ts.map +1 -0
  28. package/dist/effect-ui-stylex/layers.js +118 -0
  29. package/dist/effect-ui-stylex/layers.js.map +1 -0
  30. package/dist/effect-ui-stylex/look-level.d.ts +2 -0
  31. package/dist/effect-ui-stylex/look-level.d.ts.map +1 -0
  32. package/dist/effect-ui-stylex/look-level.js +83 -0
  33. package/dist/effect-ui-stylex/look-level.js.map +1 -0
  34. package/dist/effect-ui-stylex/modules.d.ts +36 -0
  35. package/dist/effect-ui-stylex/modules.d.ts.map +1 -0
  36. package/dist/effect-ui-stylex/modules.js +97 -0
  37. package/dist/effect-ui-stylex/modules.js.map +1 -0
  38. package/dist/effect-ui-stylex/parts.d.ts +17 -0
  39. package/dist/effect-ui-stylex/parts.d.ts.map +1 -0
  40. package/dist/effect-ui-stylex/parts.js +66 -0
  41. package/dist/effect-ui-stylex/parts.js.map +1 -0
  42. package/dist/effect-ui-stylex/raw-part.d.ts +2 -0
  43. package/dist/effect-ui-stylex/raw-part.d.ts.map +1 -0
  44. package/dist/effect-ui-stylex/raw-part.js +90 -0
  45. package/dist/effect-ui-stylex/raw-part.js.map +1 -0
  46. package/dist/effect-ui-stylex/state-attributes.d.ts +8 -0
  47. package/dist/effect-ui-stylex/state-attributes.d.ts.map +1 -0
  48. package/dist/effect-ui-stylex/state-attributes.js +141 -0
  49. package/dist/effect-ui-stylex/state-attributes.js.map +1 -0
  50. package/dist/effect-ui-stylex/state-key.d.ts +2 -0
  51. package/dist/effect-ui-stylex/state-key.d.ts.map +1 -0
  52. package/dist/effect-ui-stylex/state-key.js +103 -0
  53. package/dist/effect-ui-stylex/state-key.js.map +1 -0
  54. package/dist/effect-ui-stylex/subpath.d.ts +10 -0
  55. package/dist/effect-ui-stylex/subpath.d.ts.map +1 -0
  56. package/dist/effect-ui-stylex/subpath.js +53 -0
  57. package/dist/effect-ui-stylex/subpath.js.map +1 -0
  58. package/dist/effect-ui-stylex.d.ts +23 -0
  59. package/dist/effect-ui-stylex.d.ts.map +1 -0
  60. package/dist/{foldkit-stylex.js → effect-ui-stylex.js} +10 -9
  61. package/dist/effect-ui-stylex.js.map +1 -0
  62. package/dist/{foldkit-stylex.json → effect-ui-stylex.json} +7 -6
  63. package/dist/plugin.d.ts.map +1 -1
  64. package/dist/plugin.js +18 -12
  65. package/dist/plugin.js.map +1 -1
  66. package/dist/rules/imports.d.ts +5 -6
  67. package/dist/rules/imports.d.ts.map +1 -1
  68. package/dist/rules/imports.js +18 -14
  69. package/dist/rules/imports.js.map +1 -1
  70. package/dist/rules/module-sources.d.ts +33 -0
  71. package/dist/rules/module-sources.d.ts.map +1 -0
  72. package/dist/rules/module-sources.js +139 -0
  73. package/dist/rules/module-sources.js.map +1 -0
  74. package/dist/rules/no-suppression-directives.js +3 -3
  75. package/dist/rules/no-suppression-directives.js.map +1 -1
  76. package/dist/rules/scope.d.ts +3 -1
  77. package/dist/rules/scope.d.ts.map +1 -1
  78. package/dist/rules/scope.js.map +1 -1
  79. package/dist/vendor/anti-slop/rules/no-runtime-typeof.js +1 -1
  80. package/dist/vendor/anti-slop/rules/no-runtime-typeof.js.map +1 -1
  81. package/package.json +11 -7
  82. package/src/app.ts +19 -0
  83. package/src/base.ts +5 -1
  84. package/src/effect-ui-stylex/class.ts +140 -0
  85. package/src/effect-ui-stylex/components.ts +184 -0
  86. package/src/{foldkit-stylex → effect-ui-stylex}/condition-key.ts +6 -52
  87. package/src/effect-ui-stylex/internal-import.ts +32 -0
  88. package/src/effect-ui-stylex/layers.ts +161 -0
  89. package/src/effect-ui-stylex/look-level.ts +99 -0
  90. package/src/effect-ui-stylex/modules.ts +115 -0
  91. package/src/effect-ui-stylex/parts.ts +89 -0
  92. package/src/effect-ui-stylex/raw-part.ts +110 -0
  93. package/src/effect-ui-stylex/state-attributes.ts +140 -0
  94. package/src/effect-ui-stylex/state-key.ts +147 -0
  95. package/src/effect-ui-stylex/subpath.ts +65 -0
  96. package/src/{foldkit-stylex.ts → effect-ui-stylex.ts} +9 -8
  97. package/src/plugin.ts +18 -12
  98. package/src/rules/imports.ts +22 -15
  99. package/src/rules/module-sources.ts +179 -0
  100. package/src/rules/no-suppression-directives.ts +3 -3
  101. package/src/rules/scope.ts +1 -1
  102. package/src/vendor/anti-slop/UPSTREAM.md +2 -0
  103. package/src/vendor/anti-slop/rules/no-runtime-typeof.ts +1 -1
  104. package/dist/foldkit-stylex/attributes.d.ts +0 -2
  105. package/dist/foldkit-stylex/attributes.d.ts.map +0 -1
  106. package/dist/foldkit-stylex/attributes.js +0 -191
  107. package/dist/foldkit-stylex/attributes.js.map +0 -1
  108. package/dist/foldkit-stylex/components.d.ts +0 -12
  109. package/dist/foldkit-stylex/components.d.ts.map +0 -1
  110. package/dist/foldkit-stylex/components.js +0 -41
  111. package/dist/foldkit-stylex/components.js.map +0 -1
  112. package/dist/foldkit-stylex/condition-key.d.ts.map +0 -1
  113. package/dist/foldkit-stylex/condition-key.js.map +0 -1
  114. package/dist/foldkit-stylex/hover-gate.d.ts.map +0 -1
  115. package/dist/foldkit-stylex/hover-gate.js.map +0 -1
  116. package/dist/foldkit-stylex/styles.d.ts +0 -2
  117. package/dist/foldkit-stylex/styles.d.ts.map +0 -1
  118. package/dist/foldkit-stylex/styles.js +0 -131
  119. package/dist/foldkit-stylex/styles.js.map +0 -1
  120. package/dist/foldkit-stylex/unstyled-view.d.ts +0 -2
  121. package/dist/foldkit-stylex/unstyled-view.d.ts.map +0 -1
  122. package/dist/foldkit-stylex/unstyled-view.js +0 -94
  123. package/dist/foldkit-stylex/unstyled-view.js.map +0 -1
  124. package/dist/foldkit-stylex/vite.d.ts +0 -2
  125. package/dist/foldkit-stylex/vite.d.ts.map +0 -1
  126. package/dist/foldkit-stylex/vite.js +0 -26
  127. package/dist/foldkit-stylex/vite.js.map +0 -1
  128. package/dist/foldkit-stylex.d.ts +0 -22
  129. package/dist/foldkit-stylex.d.ts.map +0 -1
  130. package/dist/foldkit-stylex.js.map +0 -1
  131. package/src/foldkit-stylex/attributes.ts +0 -282
  132. package/src/foldkit-stylex/components.ts +0 -41
  133. package/src/foldkit-stylex/styles.ts +0 -170
  134. package/src/foldkit-stylex/unstyled-view.ts +0 -121
  135. package/src/foldkit-stylex/vite.ts +0 -29
  136. /package/dist/{foldkit-stylex → effect-ui-stylex}/condition-key.d.ts +0 -0
  137. /package/dist/{foldkit-stylex → effect-ui-stylex}/hover-gate.d.ts +0 -0
  138. /package/dist/{foldkit-stylex → effect-ui-stylex}/hover-gate.js +0 -0
  139. /package/src/{foldkit-stylex → effect-ui-stylex}/hover-gate.ts +0 -0
@@ -0,0 +1,140 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+
3
+ import { defineRule } from "@oxlint/plugins";
4
+
5
+ import { exportOf, type Imports, importsOf, keyOf } from "../rules/imports.ts";
6
+ import { drawnOf } from "./components.ts";
7
+ import { elementOf } from "./parts.ts";
8
+
9
+ const stylex = "@stylexjs/stylex";
10
+
11
+ // `stylex.attrs(...)` or `stylex.props(...)`, whose result holds a class.
12
+ const isStylexAttributes = (node: ESTree.Node, imports: Imports) => {
13
+ const runtime = node.type === "CallExpression" ? exportOf(node.callee, imports, stylex) : "";
14
+
15
+ return runtime === "attrs" || runtime === "props";
16
+ };
17
+
18
+ // Whether the argument of `.attrs(...)` holds a class: `stylex.attrs(...)` itself, or an object
19
+ // with a `class` key or a spread of `stylex.attrs(...)`.
20
+ const holdsClass = (argument: ESTree.Node | undefined, imports: Imports) => {
21
+ if (argument === undefined) return false;
22
+
23
+ if (isStylexAttributes(argument, imports)) return true;
24
+
25
+ return (
26
+ argument.type === "ObjectExpression" &&
27
+ argument.properties.some((property) =>
28
+ property.type === "Property"
29
+ ? keyOf(property) === "class"
30
+ : isStylexAttributes(property.argument, imports),
31
+ )
32
+ );
33
+ };
34
+
35
+ // A call that sets an element's class: `.class(...)`, `.attr("class", ...)` or `.attrs(...)`
36
+ // with a class in it. Effect UI's `class` is `attr("class", ...)`, so each replaces the class the
37
+ // builder had.
38
+ const setsClass = (node: ESTree.Node, imports: Imports): node is ESTree.CallExpression => {
39
+ if (node.type !== "CallExpression") return false;
40
+
41
+ const { callee } = node;
42
+ const [first] = node.arguments;
43
+
44
+ const method =
45
+ callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier"
46
+ ? callee.property.name
47
+ : undefined;
48
+
49
+ if (method === "attr") return first?.type === "Literal" && first.value === "class";
50
+
51
+ if (method === "attrs") return holdsClass(first, imports);
52
+
53
+ return method === "class";
54
+ };
55
+
56
+ // What a builder is written as, under what only changes its type or guards a missing one.
57
+ const unwrapped = (node: ESTree.Node | undefined): ESTree.Node | undefined =>
58
+ node?.type === "ChainExpression" || node?.type === "TSNonNullExpression"
59
+ ? unwrapped(node.expression)
60
+ : node;
61
+
62
+ export const classRule = defineRule({
63
+ meta: {
64
+ type: "problem",
65
+ docs: {
66
+ description:
67
+ "Keep one class call per element, and pass styles for a drawn element as its style option.",
68
+ },
69
+ schema: [],
70
+ messages: {
71
+ look: "Pass these styles as the `style` option of {{drawn}}, which applies them after its look in one stylex.attrs call. Effect UI keeps the last class a builder gets, so this call replaces the look {{drawn}} drew.",
72
+ element:
73
+ "Pass these styles as the `style` option of {{drawn}}. It sets the class of the element it is given, so the class this element has is replaced.",
74
+ oneCall:
75
+ "Pass every style of this element to one stylex.attrs(...) call, conditions included. Effect UI keeps the last class a builder gets, so this call replaces the class before it, and StyleX resolves two styles that set one property only within one call.",
76
+ },
77
+ },
78
+ createOnce(context) {
79
+ let imports: Imports = new Map();
80
+
81
+ // The call before `node` in the chain of one element: the receiver of a method, as `h.div` in
82
+ // `h.div.children(...)`, or the builder a part or a view function took.
83
+ const before = (node: ESTree.CallExpression) => {
84
+ const { callee } = node;
85
+ const isChained = callee.type === "MemberExpression" && callee.object.type !== "Identifier";
86
+
87
+ return unwrapped(isChained ? callee.object : elementOf(context.sourceCode, node));
88
+ };
89
+
90
+ // The drawn function that made the builder `node` evaluates to: `Button` for `Button(h)`, for
91
+ // what is chained on it and for a part that took it, as `dialog.trigger(Button(h))`.
92
+ const drawnBy = (node: ESTree.Node | undefined): string | undefined => {
93
+ if (node?.type !== "CallExpression") return undefined;
94
+
95
+ return drawnOf(node.callee, imports) ?? drawnBy(before(node));
96
+ };
97
+
98
+ // The call in the chain of `node` that sets its class, if one does.
99
+ const classCallIn = (node: ESTree.Node | undefined): ESTree.CallExpression | undefined => {
100
+ if (node?.type !== "CallExpression") return undefined;
101
+
102
+ return setsClass(node, imports) ? node : classCallIn(before(node));
103
+ };
104
+
105
+ const nameOf = (node: ESTree.CallExpression) =>
106
+ node.callee.type === "MemberExpression" ? node.callee.property : node;
107
+
108
+ return {
109
+ Program(program) {
110
+ imports = importsOf(program);
111
+ },
112
+ CallExpression(node) {
113
+ const drawn = drawnOf(node.callee, imports);
114
+
115
+ // The element a drawn function is given: its look replaces a class set on it.
116
+ if (drawn !== undefined) {
117
+ const given = classCallIn(unwrapped(elementOf(context.sourceCode, node)));
118
+
119
+ if (given !== undefined) {
120
+ context.report({ node: nameOf(given), messageId: "element", data: { drawn } });
121
+ }
122
+
123
+ return;
124
+ }
125
+
126
+ if (!setsClass(node, imports)) return;
127
+
128
+ const earlier = before(node);
129
+ const look = drawnBy(earlier);
130
+
131
+ // At the method's name: the call itself starts where the element's whole chain does.
132
+ if (look !== undefined) {
133
+ context.report({ node: nameOf(node), messageId: "look", data: { drawn: look } });
134
+ } else if (classCallIn(earlier) !== undefined) {
135
+ context.report({ node: nameOf(node), messageId: "oneCall" });
136
+ }
137
+ },
138
+ };
139
+ },
140
+ });
@@ -0,0 +1,184 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+
3
+ import { type Imports, resolve } from "../rules/imports.ts";
4
+ import { library } from "./modules.ts";
5
+
6
+ /**
7
+ * For each component a module of the library exports from effect/ui/kit, the parts its `view`
8
+ * gets that the module has a drawn function for: `DialogPopup` draws `dialog.popup`. A test
9
+ * derives the table from the library's source, so add a part in the change that adds its
10
+ * function.
11
+ */
12
+ export const drawnParts: ReadonlyMap<string, ReadonlyArray<string>> = new Map([
13
+ ["Accordion", ["root"]],
14
+ ["AccordionItem", ["header", "panel", "root", "trigger"]],
15
+ ["AlertDialog", ["backdrop", "description", "popup", "title", "viewport"]],
16
+ [
17
+ "Autocomplete",
18
+ [
19
+ "clear",
20
+ "empty",
21
+ "group",
22
+ "groupLabel",
23
+ "input",
24
+ "inputGroup",
25
+ "item",
26
+ "label",
27
+ "list",
28
+ "popup",
29
+ "positioner",
30
+ "row",
31
+ "separator",
32
+ "status",
33
+ "trigger",
34
+ ],
35
+ ],
36
+ ["Avatar", ["fallback", "image", "root"]],
37
+ ["Calendar", ["cell", "day", "grid", "heading", "next", "previous", "root", "weekday"]],
38
+ ["Checkbox", ["indicator", "root"]],
39
+ ["CheckboxGroup", ["root"]],
40
+ ["Collapsible", ["panel", "root", "trigger"]],
41
+ [
42
+ "Combobox",
43
+ [
44
+ "chip",
45
+ "chipRemove",
46
+ "chips",
47
+ "clear",
48
+ "empty",
49
+ "group",
50
+ "groupLabel",
51
+ "input",
52
+ "inputGroup",
53
+ "item",
54
+ "label",
55
+ "list",
56
+ "popup",
57
+ "positioner",
58
+ "row",
59
+ "separator",
60
+ "status",
61
+ "trigger",
62
+ ],
63
+ ],
64
+ [
65
+ "ContextMenu",
66
+ [
67
+ "backdrop",
68
+ "checkboxItem",
69
+ "checkboxItemIndicator",
70
+ "clear",
71
+ "empty",
72
+ "group",
73
+ "groupLabel",
74
+ "input",
75
+ "item",
76
+ "linkItem",
77
+ "list",
78
+ "popup",
79
+ "positioner",
80
+ "radioGroup",
81
+ "radioItem",
82
+ "radioItemIndicator",
83
+ "separator",
84
+ "submenuTrigger",
85
+ ],
86
+ ],
87
+ ["DateField", ["input"]],
88
+ ["DatePicker", ["input", "popup", "positioner", "trigger"]],
89
+ ["Dialog", ["backdrop", "close", "description", "popup", "title", "viewport"]],
90
+ [
91
+ "Drawer",
92
+ ["backdrop", "close", "content", "description", "popup", "swipeArea", "title", "viewport"],
93
+ ],
94
+ ["DrawerProvider", ["indent", "indentBackground"]],
95
+ ["Field", ["description", "error", "label", "root"]],
96
+ ["Fieldset", ["legend", "root"]],
97
+ ["FileDrop", ["root"]],
98
+ ["Form", ["root"]],
99
+ [
100
+ "Menu",
101
+ [
102
+ "backdrop",
103
+ "checkboxItem",
104
+ "checkboxItemIndicator",
105
+ "clear",
106
+ "empty",
107
+ "group",
108
+ "groupLabel",
109
+ "input",
110
+ "item",
111
+ "linkItem",
112
+ "list",
113
+ "popup",
114
+ "positioner",
115
+ "radioGroup",
116
+ "radioItem",
117
+ "radioItemIndicator",
118
+ "separator",
119
+ "submenuTrigger",
120
+ ],
121
+ ],
122
+ ["Menubar", ["root"]],
123
+ ["Meter", ["indicator", "label", "root", "track", "value"]],
124
+ ["NavigationMenu", ["item", "link", "list", "root"]],
125
+ [
126
+ "NumberField",
127
+ ["decrement", "group", "increment", "input", "root", "scrubArea", "scrubAreaCursor"],
128
+ ],
129
+ ["OTPField", ["input", "root"]],
130
+ ["Popover", ["arrow", "backdrop", "description", "popup", "positioner", "title"]],
131
+ ["PreviewCard", ["arrow", "popup", "positioner"]],
132
+ ["Progress", ["indicator", "label", "root", "track", "value"]],
133
+ ["RadioGroup", ["indicator", "radio", "root"]],
134
+ ["RangeCalendar", ["day"]],
135
+ ["ScrollArea", ["content", "corner", "root", "scrollbar", "viewport"]],
136
+ [
137
+ "Select",
138
+ ["group", "groupLabel", "item", "label", "popup", "positioner", "separator", "trigger"],
139
+ ],
140
+ ["Slider", ["control", "indicator", "root", "thumb", "track", "value"]],
141
+ ["Switch", ["root", "thumb"]],
142
+ ["Tabs", ["indicator", "list", "panel", "root", "tab"]],
143
+ ["TimeField", ["input"]],
144
+ ["ToastProvider", ["action", "close", "content", "description", "root", "title", "viewport"]],
145
+ ["ToggleGroup", ["item", "root"]],
146
+ ["Toolbar", ["button", "group", "input", "link", "root", "separator"]],
147
+ ["Tooltip", ["arrow", "popup", "positioner"]],
148
+ ["VirtualList", ["item", "list", "table", "viewport"]],
149
+ ]);
150
+
151
+ /**
152
+ * The components whose parts another component's functions draw: a `ContextMenu` is a menu at the
153
+ * pointer, drawn with `Menu`'s, and a `ToastProvider`'s parts are the toasts', named `Toast`.
154
+ */
155
+ export const drawnAs: ReadonlyMap<string, string> = new Map([
156
+ ["ContextMenu", "Menu"],
157
+ ["ToastProvider", "Toast"],
158
+ ]);
159
+
160
+ /** The function that draws a component's part: `DialogPopup` for `Dialog` and `popup`. */
161
+ export const drawnFunction = (component: string, part: string) =>
162
+ `${drawnAs.get(component) ?? component}${part.slice(0, 1).toUpperCase()}${part.slice(1)}`;
163
+
164
+ /**
165
+ * The export of the library `node` names, with its module: `Button` and
166
+ * `@kutur-kit/effect-ui-stylex/button` for the callee of `Button(h)`.
167
+ */
168
+ export const libraryExportOf = (node: ESTree.Node, imports: Imports) => {
169
+ const resolved = resolve(node, imports);
170
+
171
+ return resolved?.source.startsWith(`${library}/`) === true
172
+ ? { name: resolved.path, module: resolved.source }
173
+ : undefined;
174
+ };
175
+
176
+ /**
177
+ * The drawn function a call's callee names: an export of the library that starts with a capital,
178
+ * as `Button`, `DialogPopup` and the icons do. `buttonStyles` returns styles, not an element.
179
+ */
180
+ export const drawnOf = (node: ESTree.Node, imports: Imports) => {
181
+ const exported = libraryExportOf(node, imports);
182
+
183
+ return exported !== undefined && /^[A-Z]\w*$/.test(exported.name) ? exported.name : undefined;
184
+ };
@@ -4,15 +4,6 @@ import { defineRule } from "@oxlint/plugins";
4
4
 
5
5
  import { exportOf, type Imports, importsOf, keyOf } from "../rules/imports.ts";
6
6
 
7
- // Hooks @foldkit/ui derives from state that the kit exposes as flags, native states that
8
- // @foldkit/ui's aria-disabled controls never enter, and ARIA attributes.
9
- const stateHook =
10
- /data-(checked|indeterminate|open|active|selected|disabled|readonly|invalid|focused|current|drag-over|dragging|today|outside-month|state|variant|closed|swipe)\b|:(disabled|enabled|checked|indeterminate|read-only|read-write|invalid|open)\b|\[aria-/;
11
-
12
- // Every Toast entry shares one class, which cannot take state, so its animation and swipe key on
13
- // these hooks.
14
- const toastEntryHooks = /data-(closed|swipe)\b/g;
15
-
16
7
  type Bound = Readonly<{ value: number; inclusive: boolean }>;
17
8
 
18
9
  // The viewport widths a media query matches, in px.
@@ -162,8 +153,6 @@ const intendedRank = new Map([
162
153
 
163
154
  const rankOf = (key: string) => pseudoClassRank.get(key.replace(/\(.*/, "")) ?? 40;
164
155
 
165
- type Candidate = Readonly<{ entry: string; key: string; node: ESTree.Node }>;
166
-
167
156
  export const conditionKey = defineRule({
168
157
  meta: {
169
158
  type: "problem",
@@ -174,8 +163,6 @@ export const conditionKey = defineRule({
174
163
  hasSuggestions: true,
175
164
  schema: [],
176
165
  messages: {
177
- stateAttribute:
178
- "Style '{{key}}' from state: (state) => [styles.base, state.isChecked && styles.checked] in a part's styles, or sx(styles.base, isChecked && styles.checked) on your own element. @foldkit/ui's hooks differ across components (Checkbox, Switch, Button and Listbox use aria-disabled, so :disabled never matches them), and StyleX ranks ':is()' keys of one property equally.",
179
166
  bareAttribute:
180
167
  "Write ':is({{key}})' instead of '{{key}}'. StyleX adds 3000 to a bare attribute condition's priority, above :hover (+130) and media queries (+200), and types its value as unknown, which typed style props reject. The :is() form ranks with pseudo-classes, so check which condition wins where they overlap.",
181
168
  mediaOrder:
@@ -187,10 +174,6 @@ export const conditionKey = defineRule({
187
174
  },
188
175
  createOnce(context) {
189
176
  let imports: Imports = new Map();
190
- // State hook keys, reported at the end of the file once every Toast entry is known.
191
- let candidates: Array<Candidate> = [];
192
- // Style keys passed as a Toast `entry`, such as `entry` in `entry: styles.entry`.
193
- let toastEntries = new Set<string>();
194
177
 
195
178
  const checkMediaOrder = (properties: ReadonlyArray<ESTree.ObjectProperty>) => {
196
179
  const queries = properties.flatMap((property) => {
@@ -233,10 +216,8 @@ export const conditionKey = defineRule({
233
216
  }
234
217
  };
235
218
 
236
- const checkKey = (entry: string, key: string, property: ESTree.ObjectProperty) => {
237
- if (stateHook.test(key)) {
238
- candidates.push({ entry, key, node: property.key });
239
- } else if (key.startsWith("[")) {
219
+ const checkKey = (key: string, property: ESTree.ObjectProperty) => {
220
+ if (key.startsWith("[")) {
240
221
  context.report({
241
222
  node: property.key,
242
223
  messageId: "bareAttribute",
@@ -251,7 +232,7 @@ export const conditionKey = defineRule({
251
232
  }
252
233
  };
253
234
 
254
- const checkStyle = (entry: string, style: ESTree.Node) => {
235
+ const checkStyle = (style: ESTree.Node) => {
255
236
  // A dynamic style's conditions are in the object its function returns.
256
237
  const object = style.type === "ArrowFunctionExpression" ? style.body : style;
257
238
 
@@ -265,17 +246,15 @@ export const conditionKey = defineRule({
265
246
  for (const property of properties) {
266
247
  const key = keyOf(property);
267
248
 
268
- if (key !== undefined) checkKey(entry, key, property);
249
+ if (key !== undefined) checkKey(key, property);
269
250
 
270
- checkStyle(entry, property.value);
251
+ checkStyle(property.value);
271
252
  }
272
253
  };
273
254
 
274
255
  return {
275
256
  Program(program) {
276
257
  imports = importsOf(program);
277
- candidates = [];
278
- toastEntries = new Set();
279
258
  },
280
259
  CallExpression(node) {
281
260
  const [styles] = node.arguments;
@@ -288,32 +267,7 @@ export const conditionKey = defineRule({
288
267
  }
289
268
 
290
269
  for (const entry of styles.properties) {
291
- const name = entry.type === "Property" ? keyOf(entry) : undefined;
292
-
293
- if (entry.type === "Property" && name !== undefined) checkStyle(name, entry.value);
294
- }
295
- },
296
- MemberExpression(node) {
297
- if (node.computed || node.property.type !== "Identifier") return;
298
-
299
- for (
300
- let parent: ESTree.Node | null = node.parent;
301
- parent !== null;
302
- parent = parent.parent
303
- ) {
304
- if (parent.type === "Property" && keyOf(parent) === "entry") {
305
- toastEntries.add(node.property.name);
306
-
307
- return;
308
- }
309
- }
310
- },
311
- "Program:exit"() {
312
- for (const { entry, key, node } of candidates) {
313
- const entryOnly =
314
- toastEntries.has(entry) && !stateHook.test(key.replaceAll(toastEntryHooks, ""));
315
-
316
- if (!entryOnly) context.report({ node, messageId: "stateAttribute", data: { key } });
270
+ if (entry.type === "Property") checkStyle(entry.value);
317
271
  }
318
272
  },
319
273
  };
@@ -0,0 +1,32 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { moduleSources, posixPath } from "../rules/module-sources.ts";
4
+
5
+ // A module under an `internal` directory of effect/ui, at any depth: effect/ui/internal,
6
+ // effect/ui/html/internal and effect/ui/kit/internal today.
7
+ const internal = /^effect\/ui\/(?:[^/]+\/)*internal(?:\/|$)/;
8
+
9
+ // A file of the effect package's build or source, named through the package or by a path into
10
+ // node_modules.
11
+ const file = /(?:^|\/)effect\/(?:dist|src)\/ui(?:\/|$)/;
12
+
13
+ export const internalImport = defineRule({
14
+ meta: {
15
+ type: "problem",
16
+ docs: { description: "Import effect/ui by the modules its package exports." },
17
+ schema: [],
18
+ messages: {
19
+ internal:
20
+ "Import the module of effect/ui that exports this, such as effect/ui/kit/Dialog or effect/ui/html/Html. effect exports nothing under an `internal` directory, so {{source}} is no part of its API and changes without a version.",
21
+ file: "Import effect/ui by a module its package exports, such as effect/ui/kit/Dialog. {{source}} names a file of the package, which another build of effect lays out differently.",
22
+ },
23
+ },
24
+ createOnce(context) {
25
+ return moduleSources(({ source, node }) => {
26
+ const path = posixPath(source);
27
+
28
+ if (internal.test(path)) context.report({ node, messageId: "internal", data: { source } });
29
+ else if (file.test(path)) context.report({ node, messageId: "file", data: { source } });
30
+ });
31
+ },
32
+ });
@@ -0,0 +1,161 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { isPath, moduleSources, posixPath, resolveFrom } from "../rules/module-sources.ts";
4
+ import {
5
+ directories,
6
+ exportedPlace,
7
+ type Layer,
8
+ library,
9
+ modules,
10
+ type Place,
11
+ placeOf,
12
+ } from "./modules.ts";
13
+
14
+ // The modules of another layer that a layer imports, with `*` for all of one. A layer also
15
+ // imports its own, and a component imports those beside it by name, which `crossing` checks.
16
+ const routes: Readonly<Record<Layer, ReadonlyArray<string>>> = {
17
+ mechanism: [],
18
+ design: ["mechanism/style", "mechanism/compiled"],
19
+ component: ["design/looks", "design/tokens.stylex", "design/icons", "mechanism/style"],
20
+ testing: ["mechanism/*"],
21
+ };
22
+
23
+ // What the message says a layer imports, with the reason where the layout does not show it.
24
+ const allowed: Readonly<Record<Layer, string>> = {
25
+ mechanism:
26
+ "The mechanism imports src/mechanism alone. It knows no look, and takes what it needs of one as an option, as `audit` takes `hairline`.",
27
+ design:
28
+ "The design imports src/design, and `style.ts` and `compiled.ts` of src/mechanism. A component draws with the design, so the design imports none.",
29
+ component:
30
+ "A component imports `looks.ts`, `tokens.stylex.ts` and `icons.ts` of src/design, `style.ts` of src/mechanism and the named exports of the components beside it.",
31
+ testing:
32
+ "src/testing.ts imports src/mechanism alone. An app's Playwright tests load it in Node, where StyleX has compiled no module of the design or the components.",
33
+ };
34
+
35
+ const reaches = (from: Layer, { layer, name }: Place) =>
36
+ from === layer ||
37
+ routes[from].includes(`${layer}/${name}`) ||
38
+ routes[from].includes(`${layer}/*`);
39
+
40
+ /** A module's path under `src`, without its extension, for a message. */
41
+ const shown = ({ layer, name }: Place) =>
42
+ layer === "testing" ? "src/testing" : `src/${directories[layer]}/${name}`;
43
+
44
+ /** Where a file is in a package laid out in layers: the package's directory and the path in `src`. */
45
+ const inSrc = (file: string) => {
46
+ const [, root, path] = /^(.*)\/src\/(.+)$/.exec(file) ?? [];
47
+
48
+ return root === undefined || path === undefined ? undefined : { root, path };
49
+ };
50
+
51
+ type Report = Readonly<{
52
+ messageId: "layer" | "named" | "noLayer" | "outside" | "unexported";
53
+ data: Readonly<Record<string, string>>;
54
+ }>;
55
+
56
+ /**
57
+ * What is wrong with the place of `filename`, or `undefined` for a module of a layer and for a
58
+ * file under no `src`. A component is a module the package exports, so a file of `src/components`
59
+ * that is no export is a helper two components would share out of an app's sight.
60
+ */
61
+ const misplaced = (filename: string): Report | undefined => {
62
+ const file = inSrc(posixPath(filename));
63
+
64
+ if (file === undefined) return undefined;
65
+
66
+ const place = placeOf(file.path);
67
+
68
+ if (place === undefined) return { messageId: "noLayer", data: { source: `src/${file.path}` } };
69
+
70
+ return place.layer === "component" && !modules.has(place.name)
71
+ ? { messageId: "unexported", data: { target: `src/${file.path}` } }
72
+ : undefined;
73
+ };
74
+
75
+ /**
76
+ * The module an import of `source` in `file` names: one the package exports, by its name, or a
77
+ * file of the importing package's `src`, by a path. `undefined` is another package's module, and a
78
+ * report a path that names no module of a layer.
79
+ */
80
+ const targetOf = (file: string, root: string, source: string): Place | Report | undefined => {
81
+ if (source.startsWith(`${library}/`)) {
82
+ return (
83
+ exportedPlace(source.slice(library.length + 1)) ?? { messageId: "noLayer", data: { source } }
84
+ );
85
+ }
86
+
87
+ if (!isPath(source)) return undefined;
88
+
89
+ const resolved = inSrc(resolveFrom(file, source));
90
+
91
+ if (resolved?.root !== root) return { messageId: "outside", data: { source } };
92
+
93
+ return placeOf(resolved.path) ?? { messageId: "noLayer", data: { source } };
94
+ };
95
+
96
+ /**
97
+ * What is wrong with an import of `source` in `file`, a module under a `src` laid out in layers,
98
+ * or `undefined` for an import the layers allow and for one of another package. A path names a
99
+ * file of the package or leaves it, whether it starts at the importing file or at the root of the
100
+ * file system. `named` is whether the import binds named exports alone.
101
+ */
102
+ export const crossing = (filename: string, source: string, named: boolean): Report | undefined => {
103
+ const file = posixPath(filename);
104
+ const from = inSrc(file);
105
+ const place = from && placeOf(from.path);
106
+
107
+ if (from === undefined || place === undefined) return undefined;
108
+
109
+ const target = targetOf(file, from.root, source);
110
+
111
+ if (target === undefined || "messageId" in target) return target;
112
+
113
+ if (target.layer === "component" && place.layer === "component") {
114
+ if (!modules.has(target.name)) return { messageId: "unexported", data: { target: source } };
115
+
116
+ return named ? undefined : { messageId: "named", data: { target: shown(target) } };
117
+ }
118
+
119
+ return reaches(place.layer, target)
120
+ ? undefined
121
+ : {
122
+ messageId: "layer",
123
+ data: { from: shown(place), target: shown(target), allowed: allowed[place.layer] },
124
+ };
125
+ };
126
+
127
+ export const layers = defineRule({
128
+ meta: {
129
+ type: "problem",
130
+ docs: {
131
+ description:
132
+ "Hold the modules of @kutur-kit/effect-ui-stylex to their layers: mechanism, design and components.",
133
+ },
134
+ schema: [],
135
+ messages: {
136
+ layer: "{{from}} cannot import {{target}}. {{allowed}}",
137
+ named:
138
+ 'Import the names you use of {{target}}, as `import { Button, type ButtonOptions } from "./button.ts"`. A component takes from another the types, drawn functions, styles and helpers it exports by name: no namespace, default or side-effect import, no re-export and no `import()`.',
139
+ noLayer:
140
+ "{{source}} is in no layer. A module of this package is under src/mechanism, a file of src/design or a file of src/components, and src/testing.ts is the one module beside them.",
141
+ outside:
142
+ "{{source}} is not under this package's src. A module of src imports files of src alone: the package publishes `src` and the `dist` built from it, so a path to anything else resolves in this checkout and not once installed.",
143
+ unexported:
144
+ "{{target}} is no module the package exports. Each file of src/components is a component an app imports, as `@kutur-kit/effect-ui-stylex/button`, and a component takes from another what an app can. Move what two components share into one of them, or export the module in package.json and add it to `modules` in @kutur-kit/oxc.",
145
+ },
146
+ },
147
+ createOnce(context) {
148
+ return {
149
+ Program(program) {
150
+ const report = misplaced(context.filename);
151
+
152
+ if (report !== undefined) context.report({ node: program, ...report });
153
+ },
154
+ ...moduleSources(({ source, node, named }) => {
155
+ const report = crossing(context.filename, source, named);
156
+
157
+ if (report !== undefined) context.report({ node, ...report });
158
+ }),
159
+ };
160
+ },
161
+ });