@kutur-kit/oxc 0.1.0-alpha.4 → 0.1.0-alpha.5

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 (66) hide show
  1. package/README.md +45 -7
  2. package/dist/effect.d.ts.map +1 -1
  3. package/dist/effect.js +6 -0
  4. package/dist/effect.js.map +1 -1
  5. package/dist/foldkit-stylex/attributes.d.ts +2 -0
  6. package/dist/foldkit-stylex/attributes.d.ts.map +1 -0
  7. package/dist/foldkit-stylex/attributes.js +191 -0
  8. package/dist/foldkit-stylex/attributes.js.map +1 -0
  9. package/dist/foldkit-stylex/components.d.ts +12 -0
  10. package/dist/foldkit-stylex/components.d.ts.map +1 -0
  11. package/dist/foldkit-stylex/components.js +41 -0
  12. package/dist/foldkit-stylex/components.js.map +1 -0
  13. package/dist/foldkit-stylex/condition-key.d.ts +2 -0
  14. package/dist/foldkit-stylex/condition-key.d.ts.map +1 -0
  15. package/dist/foldkit-stylex/condition-key.js +255 -0
  16. package/dist/foldkit-stylex/condition-key.js.map +1 -0
  17. package/dist/foldkit-stylex/styles.d.ts +2 -0
  18. package/dist/foldkit-stylex/styles.d.ts.map +1 -0
  19. package/dist/foldkit-stylex/styles.js +131 -0
  20. package/dist/foldkit-stylex/styles.js.map +1 -0
  21. package/dist/foldkit-stylex/unstyled-view.d.ts +2 -0
  22. package/dist/foldkit-stylex/unstyled-view.d.ts.map +1 -0
  23. package/dist/foldkit-stylex/unstyled-view.js +89 -0
  24. package/dist/foldkit-stylex/unstyled-view.js.map +1 -0
  25. package/dist/foldkit-stylex/vite.d.ts +2 -0
  26. package/dist/foldkit-stylex/vite.d.ts.map +1 -0
  27. package/dist/foldkit-stylex/vite.js +26 -0
  28. package/dist/foldkit-stylex/vite.js.map +1 -0
  29. package/dist/foldkit-stylex.d.ts +21 -0
  30. package/dist/foldkit-stylex.d.ts.map +1 -0
  31. package/dist/foldkit-stylex.js +25 -0
  32. package/dist/foldkit-stylex.js.map +1 -0
  33. package/dist/foldkit-stylex.json +25 -0
  34. package/dist/plugin.d.ts.map +1 -1
  35. package/dist/plugin.js +12 -0
  36. package/dist/plugin.js.map +1 -1
  37. package/dist/rules/imports.d.ts +37 -0
  38. package/dist/rules/imports.d.ts.map +1 -0
  39. package/dist/rules/imports.js +72 -0
  40. package/dist/rules/imports.js.map +1 -0
  41. package/dist/rules/no-manual-effect-runtime-in-tests.d.ts +2 -0
  42. package/dist/rules/no-manual-effect-runtime-in-tests.d.ts.map +1 -0
  43. package/dist/rules/no-manual-effect-runtime-in-tests.js +74 -0
  44. package/dist/rules/no-manual-effect-runtime-in-tests.js.map +1 -0
  45. package/dist/rules/scope.d.ts +9 -0
  46. package/dist/rules/scope.d.ts.map +1 -0
  47. package/dist/rules/scope.js +15 -0
  48. package/dist/rules/scope.js.map +1 -0
  49. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.d.ts.map +1 -1
  50. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js +17 -1
  51. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js.map +1 -1
  52. package/package.json +14 -4
  53. package/src/effect.ts +6 -0
  54. package/src/foldkit-stylex/attributes.ts +282 -0
  55. package/src/foldkit-stylex/components.ts +41 -0
  56. package/src/foldkit-stylex/condition-key.ts +321 -0
  57. package/src/foldkit-stylex/styles.ts +170 -0
  58. package/src/foldkit-stylex/unstyled-view.ts +116 -0
  59. package/src/foldkit-stylex/vite.ts +29 -0
  60. package/src/foldkit-stylex.ts +29 -0
  61. package/src/plugin.ts +12 -0
  62. package/src/rules/imports.ts +99 -0
  63. package/src/rules/no-manual-effect-runtime-in-tests.ts +99 -0
  64. package/src/rules/scope.ts +24 -0
  65. package/src/vendor/anti-slop/UPSTREAM.md +2 -0
  66. package/src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts +22 -1
@@ -0,0 +1,74 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { effectMemberOf, importsOf, keyOf, resolve, } from "./imports.js";
3
+ import { variableOf } from "./scope.js";
4
+ // The runners of Effect and of a ManagedRuntime. Effect's `<runner>With` forms take a Context.
5
+ const runners = new Set([
6
+ "runCallback",
7
+ "runFork",
8
+ "runPromise",
9
+ "runPromiseExit",
10
+ "runSync",
11
+ "runSyncExit",
12
+ ]);
13
+ const isEffectRunner = (imported) => runners.has(effectMemberOf(imported, "Effect")?.replace(/With$/, "") ?? "");
14
+ const makesRuntime = (node, imports) => node?.type === "CallExpression" &&
15
+ effectMemberOf(resolve(node.callee, imports), "ManagedRuntime") === "make";
16
+ export const noManualEffectRuntimeInTests = defineRule({
17
+ meta: {
18
+ type: "problem",
19
+ docs: { description: "Disallow running effects by hand in tests." },
20
+ schema: [],
21
+ messages: {
22
+ manualRuntime: "Manual Effect runner `{{runner}}` in a test. It runs the effect on the real clock and outside the test's Layers and scope, so time-based code waits for real time and each test wires its services by hand. Fix: write the test with `it.effect` from `@effect/vitest`, provide services with Layers and control time with `TestClock` from `effect/testing`.",
23
+ },
24
+ },
25
+ createOnce(context) {
26
+ let imports = new Map();
27
+ // `ManagedRuntime.make(...)`, or a variable it is assigned to, where it is declared or later, as
28
+ // in `beforeAll(() => { runtime = ManagedRuntime.make(layer); })`.
29
+ const isRuntime = (node) => {
30
+ if (node?.type !== "Identifier")
31
+ return makesRuntime(node, imports);
32
+ const references = variableOf(context.sourceCode, node)?.references ?? [];
33
+ return references.some(({ writeExpr }) => makesRuntime(writeExpr, imports));
34
+ };
35
+ const report = (node) => context.report({
36
+ node,
37
+ messageId: "manualRuntime",
38
+ data: { runner: context.sourceCode.getText(node) },
39
+ });
40
+ return {
41
+ Program(program) {
42
+ imports = importsOf(program);
43
+ },
44
+ ImportSpecifier(node) {
45
+ if (isEffectRunner(imports.get(node.local.name)))
46
+ report(node.imported);
47
+ },
48
+ // `const { runPromise } = runtime`.
49
+ VariableDeclarator({ id, init }) {
50
+ if (id.type !== "ObjectPattern" || !isRuntime(init))
51
+ return;
52
+ for (const property of id.properties) {
53
+ if (property.type === "Property" && runners.has(keyOf(property) ?? "")) {
54
+ report(property.key);
55
+ }
56
+ }
57
+ },
58
+ MemberExpression(node) {
59
+ if (isEffectRunner(resolve(node, imports))) {
60
+ report(node);
61
+ return;
62
+ }
63
+ const { object, property } = node;
64
+ if (!node.computed &&
65
+ property.type === "Identifier" &&
66
+ runners.has(property.name) &&
67
+ isRuntime(object)) {
68
+ report(node);
69
+ }
70
+ },
71
+ };
72
+ },
73
+ });
74
+ //# sourceMappingURL=no-manual-effect-runtime-in-tests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-manual-effect-runtime-in-tests.js","sources":["../../src/rules/no-manual-effect-runtime-in-tests.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EACL,cAAc,EAGd,SAAS,EACT,KAAK,EACL,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,+FAA+F;AAC/F,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC;IACtB,aAAa;IACb,SAAS;IACT,YAAY;IACZ,gBAAgB;IAChB,SAAS;IACT,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,CAAC,QAA8B,EAAE,EAAE,CACxD,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAE9E,MAAM,YAAY,GAAG,CAAC,IAAwB,EAAE,OAAgB,EAAE,EAAE,CAClE,IAAI,EAAE,IAAI,KAAK,gBAAgB;IAC/B,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,MAAM,CAAC;AAE7E,MAAM,CAAC,MAAM,4BAA4B,GAAG,UAAU,CAAC;IACrD,IAAI,EAA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E,CAAC,IAAI,KAAK,eAAe,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;oBAAE,OAAO;gBAE5D,KAAK,MAAM,QAAQ,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC;oBACrC,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;wBACvE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;oBACvB,CAAC;gBACH,CAAC;YACH,CAAC;YACD,gBAAgB,CAAC,IAAI;gBACnB,IAAI,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;oBAC3C,MAAM,CAAC,IAAI,CAAC,CAAC;oBAEb,OAAO;gBACT,CAAC;gBAED,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;gBAElC,IACE,CAAC,IAAI,CAAC,QAAQ;oBACd,QAAQ,CAAC,IAAI,KAAK,YAAY;oBAC9B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAC1B,SAAS,CAAC,MAAM,CAAC,EACjB,CAAC;oBACD,MAAM,CAAC,IAAI,CAAC,CAAC;gBACf,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ESTree, SourceCode, Variable } from "@oxlint/plugins";
2
+ /**
3
+ * The variable an identifier refers to, from the innermost scope that declares its name, or
4
+ * `undefined` for a global. Rules that follow a value to where it was made, such as a parameter or
5
+ * a `const` initialiser, read the variable's `defs` and `references`, so a same-named binding
6
+ * elsewhere in the file is a different variable.
7
+ */
8
+ export declare const variableOf: (sourceCode: SourceCode, identifier: ESTree.IdentifierReference) => Variable | undefined;
9
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sources":["../../src/rules/scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3E;;;;;GAKG;AACH,eAAO,MAAM,UAAU,eACT,UAAU,cACV,MAAM,CAAC,mBAAmB,KACrC,QAAQ,GAAG,SAYb,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The variable an identifier refers to, from the innermost scope that declares its name, or
3
+ * `undefined` for a global. Rules that follow a value to where it was made, such as a parameter or
4
+ * a `const` initialiser, read the variable's `defs` and `references`, so a same-named binding
5
+ * elsewhere in the file is a different variable.
6
+ */
7
+ export const variableOf = (sourceCode, identifier) => {
8
+ for (let scope = sourceCode.getScope(identifier); scope !== null; scope = scope.upper) {
9
+ const variable = scope.set.get(identifier.name);
10
+ if (variable !== undefined)
11
+ return variable;
12
+ }
13
+ return undefined;
14
+ };
15
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sources":["../../src/rules/scope.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,UAAsB,EACtB,UAAsC,EAChB,EAAE;IACxB,KACE,IAAI,KAAK,GAAiB,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,EACzD,KAAK,KAAK,IAAI,EACd,KAAK,GAAG,KAAK,CAAC,KAAK,EACnB,CAAC;QACD,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEhD,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,QAAQ,CAAC;IAC9C,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-shape-in-symbol-names.d.ts","sources":["../../../../src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts"],"names":[],"mappings":"AAgBA,iGAAiG;AACjG,eAAO,MAAM,gCAAgC,gCA4B3C,CAAC"}
1
+ {"version":3,"file":"no-shape-in-symbol-names.d.ts","sources":["../../../../src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts"],"names":[],"mappings":"AA+BA,iGAAiG;AACjG,eAAO,MAAM,gCAAgC,gCAkC3C,CAAC"}
@@ -10,6 +10,19 @@ function isBorrowedMemberName(node) {
10
10
  return false;
11
11
  return parent.property === node && parent.computed === false;
12
12
  }
13
+ // CSS and SVG properties whose names contain "shape", as StyleX, React and SVG write them.
14
+ const CSS_PROPERTY = /^(?:shape(?:Outside|Margin|ImageThreshold|Rendering)|corner(?:Top|Right|Bottom|Left|Start|End|Block|Inline)*Shape)$/;
15
+ /** Return whether an identifier is a key or attribute that names a CSS or SVG property. */
16
+ function isCssPropertyName(node) {
17
+ const parent = node.parent;
18
+ if (parent === null || !CSS_PROPERTY.test(node.name))
19
+ return false;
20
+ if (parent.type === "JSXAttribute")
21
+ return parent.name === node;
22
+ return ((parent.type === "Property" || parent.type === "TSPropertySignature") &&
23
+ parent.key === node &&
24
+ parent.computed === false);
25
+ }
13
26
  /** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
14
27
  export const noForbiddenTermInSymbolNamesRule = defineRule({
15
28
  meta: {
@@ -23,8 +36,11 @@ export const noForbiddenTermInSymbolNamesRule = defineRule({
23
36
  },
24
37
  createOnce(context) {
25
38
  const reportForbiddenSymbolName = (node) => {
26
- if (!containsForbiddenSymbolName(node.name) || isBorrowedMemberName(node))
39
+ if (!containsForbiddenSymbolName(node.name) ||
40
+ isBorrowedMemberName(node) ||
41
+ isCssPropertyName(node)) {
27
42
  return;
43
+ }
28
44
  context.report({
29
45
  node,
30
46
  messageId: "forbiddenSymbolName",
@@ -1 +1 @@
1
- {"version":3,"file":"no-shape-in-symbol-names.js","sources":["../../../../src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBA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AC9G;QACD,QAAQ,EAAE;YACR,mBAAmB,EACjB,kGAAkG;SACrG;KACF;IACD,UAAU,CAAC,OAAO;QAChB,MAAM,yBAAyB,GAAG,CAAC,IAAoC,EAAE,EAAE;YACzE,IACE,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC;gBACvC,oBAAoB,CAAC,IAAI,CAAC;gBAC1B,iBAAiB,CAAC,IAAI,CAAC,EACvB,CAAC;gBACD,OAAO;YACT,CAAC;YACD,OAAO,CAAC,MAAM,CAAC;gBACb,IAAI;gBACJ,SAAS,EAAE,qBAAqB;gBAChC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;aAC1B,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,OAAO;YACL,UAAU,EAAE,yBAAyB;YACrC,iBAAiB,EAAE,yBAAyB;YAC5C,aAAa,EAAE,yBAAyB;SACzC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kutur-kit/oxc",
3
- "version": "0.1.0-alpha.4",
4
- "description": "Oxlint and Oxfmt presets for TypeScript, with optional Effect rules and a prose check for Markdown.",
3
+ "version": "0.1.0-alpha.5",
4
+ "description": "Oxlint and Oxfmt presets for TypeScript, with optional Effect and @kutur-kit/foldkit-stylex rules and a prose check for Markdown.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,6 +32,10 @@
32
32
  "./anti-slop": {
33
33
  "types": "./dist/anti-slop.d.ts",
34
34
  "default": "./dist/anti-slop.js"
35
+ },
36
+ "./foldkit-stylex": {
37
+ "types": "./dist/foldkit-stylex.d.ts",
38
+ "default": "./dist/foldkit-stylex.js"
35
39
  }
36
40
  },
37
41
  "publishConfig": {
@@ -44,7 +48,9 @@
44
48
  },
45
49
  "devDependencies": {
46
50
  "@effect/tsgo": "0.67.4",
51
+ "@kutur-kit/foldkit-stylex": "0.1.0-alpha.0",
47
52
  "@kutur-kit/tsconfig": "0.1.0-alpha.1",
53
+ "@stylexjs/eslint-plugin": "0.19.1",
48
54
  "@types/node": "26.6.6",
49
55
  "oxfmt": "0.77.0",
50
56
  "oxlint": "1.91.0",
@@ -53,6 +59,7 @@
53
59
  },
54
60
  "peerDependencies": {
55
61
  "@effect/tsgo": "~0.67.4",
62
+ "@stylexjs/eslint-plugin": "~0.19.1",
56
63
  "oxfmt": "~0.77.0",
57
64
  "oxlint": "~1.91.0"
58
65
  },
@@ -60,15 +67,18 @@
60
67
  "@effect/tsgo": {
61
68
  "optional": true
62
69
  },
63
- "oxlint": {
70
+ "@stylexjs/eslint-plugin": {
64
71
  "optional": true
65
72
  },
66
73
  "oxfmt": {
67
74
  "optional": true
75
+ },
76
+ "oxlint": {
77
+ "optional": true
68
78
  }
69
79
  },
70
80
  "scripts": {
71
- "build": "node --input-type=module -e 'import { rmSync } from \"node:fs\"; rmSync(\"dist\", { recursive: true, force: true });' && tsrs -p tsconfig.build.json",
81
+ "build": "node --input-type=module -e 'import { rmSync } from \"node:fs\"; rmSync(\"dist\", { recursive: true, force: true });' && tsrs -p tsconfig.build.json && node scripts/write-json-preset.ts",
72
82
  "lint:package": "publint --pack pnpm --strict",
73
83
  "test": "node --test test/*.test.ts",
74
84
  "typecheck": "effect-tsgo tsrs -p tsconfig.json --noEmit"
package/src/effect.ts CHANGED
@@ -25,6 +25,12 @@ const effect: OxlintConfig = {
25
25
  // Effect's documented form for a service is a class that extends `Context.Service`.
26
26
  "effecttsgo/service-not-as-class": "warn",
27
27
  },
28
+ overrides: [
29
+ {
30
+ files: ["**/*.test.*", "**/*.spec.*", "**/test/**", "**/tests/**"],
31
+ rules: { "kit/no-manual-effect-runtime-in-tests": "error" },
32
+ },
33
+ ],
28
34
  options: { typeAware: true },
29
35
  };
30
36
 
@@ -0,0 +1,282 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+
3
+ import { defineRule } from "@oxlint/plugins";
4
+
5
+ import {
6
+ effectMemberOf,
7
+ exportOf,
8
+ type Imports,
9
+ importsOf,
10
+ isMethodCall,
11
+ keyOf,
12
+ resolve,
13
+ rootOf,
14
+ } from "../rules/imports.ts";
15
+ import { variableOf } from "../rules/scope.ts";
16
+
17
+ const kit = "@kutur-kit/foldkit-stylex";
18
+
19
+ // Callbacks through which @foldkit/ui hands the app attribute bundles for its parts.
20
+ const bundleCallbacks = new Set(["toView", "entryToView", "toCalendarView"]);
21
+
22
+ // View inputs whose attributes @foldkit/ui applies to a part after the part's class, such as
23
+ // `buttonAttributes`.
24
+ const attributesInput = /^(attributes|\w+Attributes)$/;
25
+
26
+ // Array methods and Effect Array functions that call a callback with each item of an array.
27
+ const iterators = new Set(["map", "flatMap"]);
28
+
29
+ // Array methods and Effect Array functions that return some items of an array.
30
+ const filters = new Set(["filter"]);
31
+
32
+ // The value of a `toView`-like property, as in `toView: (attributes) => ...` or `toView: view`.
33
+ const isBundleCallback = (node: ESTree.Node) =>
34
+ node.parent?.type === "Property" &&
35
+ node.parent.value === node &&
36
+ bundleCallbacks.has(keyOf(node.parent) ?? "");
37
+
38
+ const isSx = (node: ESTree.Node, imports: Imports) =>
39
+ node.type === "CallExpression" && exportOf(node.callee, imports, kit) === "sx";
40
+
41
+ // Whether `node` writes an element's class or its style, of which Foldkit keeps one each, and
42
+ // whether it writes it raw, as `h.Attribute("class", ...)`.
43
+ const writtenBy = (
44
+ node: ESTree.Node,
45
+ imports: Imports,
46
+ ): Readonly<{ attribute: "class" | "style"; raw: boolean }> | undefined => {
47
+ if (isMethodCall(node, "Attribute")) {
48
+ const [name] = node.arguments;
49
+
50
+ return name?.type === "Literal" && (name.value === "class" || name.value === "style")
51
+ ? { attribute: name.value, raw: true }
52
+ : undefined;
53
+ }
54
+
55
+ if (isSx(node, imports) || isMethodCall(node, "Class")) return { attribute: "class", raw: false };
56
+
57
+ return isMethodCall(node, "Style") ? { attribute: "style", raw: false } : undefined;
58
+ };
59
+
60
+ export const attributes = defineRule({
61
+ meta: {
62
+ type: "problem",
63
+ docs: {
64
+ description:
65
+ "Keep one Class per element: styles in one sx(...) call, after every spread, and never on a @foldkit/ui part.",
66
+ },
67
+ schema: [],
68
+ messages: {
69
+ partClass:
70
+ "This element is a @foldkit/ui part, whose Class its XStyle wrapper sets. Put these styles in that part's entry of its styles: Foldkit keeps one Class per element, so this replaces the part's styles and the functional ones.",
71
+ partStyle:
72
+ "This element is a @foldkit/ui part, whose inline style @foldkit/ui owns, and Foldkit keeps one Style per element, so this replaces it. Put static styles in that part's entry of its styles. For a runtime value, set a custom property with h.Style on your own element around the part and read it with var() in the part's styles; a portaled panel inherits from none of your elements, so set it on an element you render inside the panel and style that element.",
73
+ oneCall:
74
+ "Pass every style of this element to one sx(...) call, conditions included. Foldkit keeps one Class per element, and StyleX resolves conflicting properties only within one call.",
75
+ oneClass:
76
+ "Join these class names into one Class. Foldkit keeps one Class per element, so this one replaces the ones before it.",
77
+ last: "Put sx(...) last in the attribute list. Foldkit keeps the last Class, so a bundle spread after it replaces these styles.",
78
+ rawClass:
79
+ "Use sx(...) for StyleX styles or h.Class(...) for class names. Scene's toHaveClass cannot see a raw class attribute.",
80
+ rawStyle:
81
+ "Use h.Style(...). A raw style attribute throws when the element also gets a Style, as @foldkit/ui panels do.",
82
+ stylexRuntime:
83
+ "Use sx(...). stylex.props returns numbers that h.Style rejects and omits className when no style applies; stylex.attrs kebab-cases custom properties and returns a raw attribute Scene cannot see.",
84
+ notInElement:
85
+ "Write sx(...) directly in the attribute list of the element it styles, so this rule sees every Class that element gets. Put conditions inside the call: sx(isOpen ? styles.open : styles.closed).",
86
+ },
87
+ },
88
+ createOnce(context) {
89
+ let imports: Imports = new Map();
90
+
91
+ // A binding made by `DragAndDropStyle.draggable(...)`, which returns the draggable's attributes
92
+ // with its Class.
93
+ const isStyledDraggable = (callee: ESTree.Expression) =>
94
+ callee.type === "Identifier" &&
95
+ (variableOf(context.sourceCode, callee)?.defs.some(
96
+ ({ node }) =>
97
+ node.type === "VariableDeclarator" &&
98
+ node.init?.type === "CallExpression" &&
99
+ exportOf(node.init.callee, imports, kit) === "DragAndDropStyle.draggable",
100
+ ) ??
101
+ false);
102
+
103
+ // The Effect Array function `callee` names, such as `map` for `Array.map`.
104
+ const arrayFunctionOf = (callee: ESTree.Node) =>
105
+ effectMemberOf(resolve(callee, imports), "Array");
106
+
107
+ // Effect's `pipe`, from effect or effect/Function.
108
+ const isPipe = (callee: ESTree.Node) => {
109
+ const imported = resolve(callee, imports);
110
+
111
+ return (
112
+ (imported?.source === "effect" && imported.path === "pipe") ||
113
+ effectMemberOf(imported, "Function") === "pipe"
114
+ );
115
+ };
116
+
117
+ // The array a call of one of `names` reads: the receiver of `tabs.map(...)`, or the first
118
+ // argument of Effect's `Array.map(tabs, ...)`.
119
+ const arrayOf = (call: ESTree.CallExpression, names: ReadonlySet<string>) => {
120
+ const { callee } = call;
121
+ const effect = arrayFunctionOf(callee);
122
+
123
+ if (effect !== undefined) return names.has(effect) ? call.arguments[0] : undefined;
124
+
125
+ return callee.type === "MemberExpression" &&
126
+ !callee.computed &&
127
+ callee.property.type === "Identifier" &&
128
+ names.has(callee.property.name)
129
+ ? callee.object
130
+ : undefined;
131
+ };
132
+
133
+ // A part's bundle: a parameter of a function @foldkit/ui calls with bundles, a member of one
134
+ // such as `tab.tab`, bundles filtered as in `tabs.filter(...)` or `Array.filter(tabs, ...)`, or
135
+ // the result of a styled draggable.
136
+ const isBundle = (node: ESTree.Argument | undefined): boolean => {
137
+ if (node === undefined || node.type === "SpreadElement") return false;
138
+
139
+ if (node.type === "CallExpression") {
140
+ return isBundle(arrayOf(node, filters)) || isStyledDraggable(node.callee);
141
+ }
142
+
143
+ const root = rootOf(node);
144
+ const variable = root === undefined ? undefined : variableOf(context.sourceCode, root);
145
+
146
+ return (
147
+ variable?.defs.some((def) => def.type === "Parameter" && takesBundles(def.node)) ?? false
148
+ );
149
+ };
150
+
151
+ // The `const` or `function` declaration that names `fn`.
152
+ const declarationOf = (fn: ESTree.Node) => {
153
+ if (fn.type === "FunctionDeclaration") return fn;
154
+
155
+ return fn.parent?.type === "VariableDeclarator" && fn.parent.init === fn
156
+ ? fn.parent
157
+ : undefined;
158
+ };
159
+
160
+ // A function @foldkit/ui calls with bundles: one written as a `toView`-like property, one
161
+ // declared by name and passed as one, as in `toView: checkboxView`, or a callback that iterates
162
+ // bundles, as in `tabs.map(cb)`, `Array.map(tabs, cb)` or `pipe(tabs, Array.map(cb))`.
163
+ const takesBundles = (fn: ESTree.Node): boolean => {
164
+ if (isBundleCallback(fn)) return true;
165
+
166
+ const declaration = declarationOf(fn);
167
+
168
+ if (declaration !== undefined) {
169
+ return context.sourceCode
170
+ .getDeclaredVariables(declaration)
171
+ .some(
172
+ ({ defs, references }) =>
173
+ defs.some(({ type }) => type !== "Parameter") &&
174
+ references.some(({ identifier }) => isBundleCallback(identifier)),
175
+ );
176
+ }
177
+
178
+ const { parent } = fn;
179
+
180
+ if (parent?.type !== "CallExpression") return false;
181
+
182
+ const pipeline = parent.parent;
183
+
184
+ // A data-last step of a pipe gets what flows from the pipe's first argument.
185
+ if (
186
+ pipeline.type === "CallExpression" &&
187
+ isPipe(pipeline.callee) &&
188
+ parent.arguments.length === 1 &&
189
+ iterators.has(arrayFunctionOf(parent.callee) ?? "")
190
+ ) {
191
+ return isBundle(pipeline.arguments[0]);
192
+ }
193
+
194
+ return isBundle(arrayOf(parent, iterators));
195
+ };
196
+
197
+ // An attribute list that ends up on a part: one that spreads a part's bundle, or the
198
+ // `childAttributes([...])` of a view input such as `buttonAttributes`.
199
+ const isPartList = (list: ESTree.ArrayExpression) => {
200
+ const { parent } = list;
201
+
202
+ if (
203
+ parent.type === "CallExpression" &&
204
+ exportOf(parent.callee, imports, "foldkit/html") === "childAttributes"
205
+ ) {
206
+ return (
207
+ parent.parent.type === "Property" && attributesInput.test(keyOf(parent.parent) ?? "")
208
+ );
209
+ }
210
+
211
+ return list.elements.some(
212
+ (item) => item?.type === "SpreadElement" && isBundle(item.argument),
213
+ );
214
+ };
215
+
216
+ return {
217
+ Program(program) {
218
+ imports = importsOf(program);
219
+ },
220
+ CallExpression(node) {
221
+ const runtime = exportOf(node.callee, imports, "@stylexjs/stylex");
222
+
223
+ // A result the code throws away, as in a compile guard, reaches no element.
224
+ if (
225
+ (runtime === "props" || runtime === "attrs") &&
226
+ node.parent.type !== "ExpressionStatement"
227
+ ) {
228
+ context.report({ node, messageId: "stylexRuntime" });
229
+ }
230
+
231
+ if (isSx(node, imports) && node.parent.type !== "ArrayExpression") {
232
+ context.report({ node, messageId: "notInElement" });
233
+ }
234
+ },
235
+ ArrayExpression(node) {
236
+ const written = node.elements.flatMap((item) => {
237
+ if (item === null) return [];
238
+
239
+ const writes = writtenBy(item, imports);
240
+
241
+ return writes === undefined ? [] : [{ item, ...writes }];
242
+ });
243
+
244
+ if (isPartList(node)) {
245
+ for (const { item, attribute } of written) {
246
+ context.report({
247
+ node: item,
248
+ messageId: attribute === "class" ? "partClass" : "partStyle",
249
+ });
250
+ }
251
+
252
+ return;
253
+ }
254
+
255
+ for (const { item, attribute } of written.filter(({ raw }) => raw)) {
256
+ context.report({
257
+ node: item,
258
+ messageId: attribute === "class" ? "rawClass" : "rawStyle",
259
+ });
260
+ }
261
+
262
+ const classWriters = written.flatMap(({ item, attribute, raw }) =>
263
+ attribute === "class" && !raw ? [item] : [],
264
+ );
265
+
266
+ const oneCall = classWriters.some((item) => isSx(item, imports)) ? "oneCall" : "oneClass";
267
+
268
+ for (const item of classWriters.slice(1)) {
269
+ context.report({ node: item, messageId: oneCall });
270
+ }
271
+
272
+ const items = node.elements.filter((item) => item !== null);
273
+
274
+ const lastSpread = items.map((item) => item.type).lastIndexOf("SpreadElement");
275
+
276
+ for (const item of items.slice(0, Math.max(lastSpread, 0))) {
277
+ if (isSx(item, imports)) context.report({ node: item, messageId: "last" });
278
+ }
279
+ },
280
+ };
281
+ },
282
+ });
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The @foldkit/ui namespaces that @kutur-kit/foldkit-stylex wraps, as `<Name>Style` namespaces.
3
+ * `foldkit-stylex-unstyled-view` asks for a wrapper only for these. A test compares the list with
4
+ * the core's `src/index.ts`, so add a name in the change that adds its namespace to the core.
5
+ */
6
+ export const components: ReadonlySet<string> = new Set([
7
+ "Animation",
8
+ "Button",
9
+ "Calendar",
10
+ "Checkbox",
11
+ "Combobox",
12
+ "DatePicker",
13
+ "Dialog",
14
+ "Disclosure",
15
+ "DragAndDrop",
16
+ "Fieldset",
17
+ "FileDrop",
18
+ "HoverIntent",
19
+ "Input",
20
+ "Listbox",
21
+ "Menu",
22
+ "Meter",
23
+ "Nav",
24
+ "Popover",
25
+ "Progress",
26
+ "RadioGroup",
27
+ "Select",
28
+ "Slider",
29
+ "Switch",
30
+ "Tabs",
31
+ "Textarea",
32
+ "Toast",
33
+ "Tooltip",
34
+ "VirtualList",
35
+ ]);
36
+
37
+ /**
38
+ * The view each `<Name>Style` namespace wraps under the same name. DragAndDrop has no `view`: its
39
+ * styled part is the bundle `draggable` returns.
40
+ */
41
+ export const viewOf = (component: string) => (component === "DragAndDrop" ? "draggable" : "view");