@kutur-kit/oxc 0.1.0-alpha.3 → 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 (69) 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/prose/cli.js +1 -1
  38. package/dist/prose/cli.js.map +1 -1
  39. package/dist/rules/imports.d.ts +37 -0
  40. package/dist/rules/imports.d.ts.map +1 -0
  41. package/dist/rules/imports.js +72 -0
  42. package/dist/rules/imports.js.map +1 -0
  43. package/dist/rules/no-manual-effect-runtime-in-tests.d.ts +2 -0
  44. package/dist/rules/no-manual-effect-runtime-in-tests.d.ts.map +1 -0
  45. package/dist/rules/no-manual-effect-runtime-in-tests.js +74 -0
  46. package/dist/rules/no-manual-effect-runtime-in-tests.js.map +1 -0
  47. package/dist/rules/scope.d.ts +9 -0
  48. package/dist/rules/scope.d.ts.map +1 -0
  49. package/dist/rules/scope.js +15 -0
  50. package/dist/rules/scope.js.map +1 -0
  51. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.d.ts.map +1 -1
  52. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js +17 -1
  53. package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js.map +1 -1
  54. package/package.json +14 -4
  55. package/src/effect.ts +6 -0
  56. package/src/foldkit-stylex/attributes.ts +282 -0
  57. package/src/foldkit-stylex/components.ts +41 -0
  58. package/src/foldkit-stylex/condition-key.ts +321 -0
  59. package/src/foldkit-stylex/styles.ts +170 -0
  60. package/src/foldkit-stylex/unstyled-view.ts +116 -0
  61. package/src/foldkit-stylex/vite.ts +29 -0
  62. package/src/foldkit-stylex.ts +29 -0
  63. package/src/plugin.ts +12 -0
  64. package/src/prose/cli.ts +1 -1
  65. package/src/rules/imports.ts +99 -0
  66. package/src/rules/no-manual-effect-runtime-in-tests.ts +99 -0
  67. package/src/rules/scope.ts +24 -0
  68. package/src/vendor/anti-slop/UPSTREAM.md +2 -0
  69. package/src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts +22 -1
package/src/plugin.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { definePlugin } from "@oxlint/plugins";
2
2
 
3
+ import { attributes } from "./foldkit-stylex/attributes.ts";
4
+ import { conditionKey } from "./foldkit-stylex/condition-key.ts";
5
+ import { styles } from "./foldkit-stylex/styles.ts";
6
+ import { unstyledView } from "./foldkit-stylex/unstyled-view.ts";
7
+ import { vite } from "./foldkit-stylex/vite.ts";
3
8
  import { commentProse } from "./rules/comment-prose.ts";
9
+ import { noManualEffectRuntimeInTests } from "./rules/no-manual-effect-runtime-in-tests.ts";
4
10
  import { noSuppressionDirectives } from "./rules/no-suppression-directives.ts";
5
11
  import { noYieldInIf } from "./rules/no-yield-in-if.ts";
6
12
 
@@ -8,6 +14,12 @@ export default definePlugin({
8
14
  meta: { name: "@kutur-kit/oxc" },
9
15
  rules: {
10
16
  "comment-prose": commentProse,
17
+ "foldkit-stylex-attributes": attributes,
18
+ "foldkit-stylex-condition-key": conditionKey,
19
+ "foldkit-stylex-styles": styles,
20
+ "foldkit-stylex-unstyled-view": unstyledView,
21
+ "foldkit-stylex-vite": vite,
22
+ "no-manual-effect-runtime-in-tests": noManualEffectRuntimeInTests,
11
23
  "no-suppression-directives": noSuppressionDirectives,
12
24
  "no-yield-in-if": noYieldInIf,
13
25
  },
package/src/prose/cli.ts CHANGED
@@ -72,7 +72,7 @@ for (const file of Array.from(files).sort()) {
72
72
 
73
73
  if (budget !== undefined && characters > budget.limit) {
74
74
  failures.push(
75
- `${file}: ${characters} characters, over its budget of ${budget.limit}. Raising the budget needs the user. Fix: shorten it or move a rule into a check.`,
75
+ `${file}: ${characters} characters, over its budget of ${budget.limit}. Raising the budget needs the user. Fix: move a rule into a check or shorten it, and delete rules that a check or the code already holds.`,
76
76
  );
77
77
  }
78
78
  }
@@ -0,0 +1,99 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+
3
+ /**
4
+ * What a name refers to through an import: the module and the export path inside it. After
5
+ * `import { Popover } from "@foldkit/ui"`, `Popover.view` is `@foldkit/ui` with `Popover.view`.
6
+ */
7
+ export type Imported = Readonly<{ source: string; path: string }>;
8
+
9
+ export type Imports = ReadonlyMap<string, Imported>;
10
+
11
+ /**
12
+ * The import that each local name binds. Rules recognise calls such as `sx(...)` or
13
+ * `Effect.runSync(...)` by these, so a local function that happens to be called `sx` is not one.
14
+ */
15
+ export const importsOf = (program: ESTree.Program): Imports =>
16
+ new Map(
17
+ program.body.flatMap((statement) =>
18
+ statement.type === "ImportDeclaration"
19
+ ? statement.specifiers.map((specifier): [string, Imported] => [
20
+ specifier.local.name,
21
+ { source: statement.source.value, path: pathOf(specifier) },
22
+ ])
23
+ : [],
24
+ ),
25
+ );
26
+
27
+ const pathOf = (specifier: ESTree.ImportDeclarationSpecifier) => {
28
+ if (specifier.type === "ImportNamespaceSpecifier") return "";
29
+
30
+ if (specifier.type === "ImportDefaultSpecifier") return "default";
31
+
32
+ return specifier.imported.type === "Literal" ? specifier.imported.value : specifier.imported.name;
33
+ };
34
+
35
+ const join = (path: string, name: string) => (path === "" ? name : `${path}.${name}`);
36
+
37
+ /**
38
+ * Resolves an identifier, a member chain such as `Ui.Popover.view` or a qualified type name such as
39
+ * `PopoverStyle.Styles` to the import it starts from, or `undefined` for anything else.
40
+ */
41
+ export const resolve = (node: ESTree.Node, imports: Imports): Imported | undefined => {
42
+ if (node.type === "Identifier") return imports.get(node.name);
43
+
44
+ const [object, property] =
45
+ node.type === "MemberExpression" && !node.computed
46
+ ? [node.object, node.property]
47
+ : node.type === "TSQualifiedName"
48
+ ? [node.left, node.right]
49
+ : [];
50
+
51
+ if (object === undefined || property?.type !== "Identifier") return undefined;
52
+
53
+ const resolved = resolve(object, imports);
54
+
55
+ return resolved && { source: resolved.source, path: join(resolved.path, property.name) };
56
+ };
57
+
58
+ /** The export path `node` names in `source`, such as `create` for `stylex.create`. */
59
+ export const exportOf = (node: ESTree.Node, imports: Imports, source: string) => {
60
+ const resolved = resolve(node, imports);
61
+
62
+ return resolved?.source === source ? resolved.path : undefined;
63
+ };
64
+
65
+ /**
66
+ * The export `imported` names in an Effect module, read from the barrel (`Effect.runSync` from
67
+ * "effect") or the module's own path (`runSync` from "effect/Effect").
68
+ */
69
+ export const effectMemberOf = (imported: Imported | undefined, module: string) => {
70
+ if (imported?.source === `effect/${module}`) return imported.path;
71
+
72
+ return imported?.source === "effect" && imported.path.startsWith(`${module}.`)
73
+ ? imported.path.slice(module.length + 1)
74
+ : undefined;
75
+ };
76
+
77
+ /** The identifier a member chain such as `tab.tab.attributes` starts from. */
78
+ export const rootOf = (node: ESTree.Expression): ESTree.IdentifierReference | undefined => {
79
+ if (node.type === "Identifier") return node;
80
+
81
+ return node.type === "MemberExpression" ? rootOf(node.object) : undefined;
82
+ };
83
+
84
+ /** A call of a method named `name` on any object, such as `h.Class(...)`. */
85
+ export const isMethodCall = (node: ESTree.Node, name: string): node is ESTree.CallExpression =>
86
+ node.type === "CallExpression" &&
87
+ node.callee.type === "MemberExpression" &&
88
+ !node.callee.computed &&
89
+ node.callee.property.type === "Identifier" &&
90
+ node.callee.property.name === name;
91
+
92
+ /** A property's key as written, for identifier and string keys. */
93
+ export const keyOf = (property: Readonly<{ computed: boolean; key: ESTree.PropertyKey }>) => {
94
+ if (property.computed) return undefined;
95
+
96
+ if (property.key.type === "Identifier") return property.key.name;
97
+
98
+ return property.key.type === "Literal" ? String(property.key.value) : undefined;
99
+ };
@@ -0,0 +1,99 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+
3
+ import { defineRule } from "@oxlint/plugins";
4
+
5
+ import {
6
+ effectMemberOf,
7
+ type Imported,
8
+ type Imports,
9
+ importsOf,
10
+ keyOf,
11
+ resolve,
12
+ } from "./imports.ts";
13
+ import { variableOf } from "./scope.ts";
14
+
15
+ // The runners of Effect and of a ManagedRuntime. Effect's `<runner>With` forms take a Context.
16
+ const runners = new Set([
17
+ "runCallback",
18
+ "runFork",
19
+ "runPromise",
20
+ "runPromiseExit",
21
+ "runSync",
22
+ "runSyncExit",
23
+ ]);
24
+
25
+ const isEffectRunner = (imported: Imported | undefined) =>
26
+ runners.has(effectMemberOf(imported, "Effect")?.replace(/With$/, "") ?? "");
27
+
28
+ const makesRuntime = (node: ESTree.Node | null, imports: Imports) =>
29
+ node?.type === "CallExpression" &&
30
+ effectMemberOf(resolve(node.callee, imports), "ManagedRuntime") === "make";
31
+
32
+ export const noManualEffectRuntimeInTests = defineRule({
33
+ meta: {
34
+ type: "problem",
35
+ docs: { description: "Disallow running effects by hand in tests." },
36
+ schema: [],
37
+ messages: {
38
+ manualRuntime:
39
+ "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`.",
40
+ },
41
+ },
42
+ createOnce(context) {
43
+ let imports: Imports = new Map();
44
+
45
+ // `ManagedRuntime.make(...)`, or a variable it is assigned to, where it is declared or later, as
46
+ // in `beforeAll(() => { runtime = ManagedRuntime.make(layer); })`.
47
+ const isRuntime = (node: ESTree.Expression | null): boolean => {
48
+ if (node?.type !== "Identifier") return makesRuntime(node, imports);
49
+
50
+ const references = variableOf(context.sourceCode, node)?.references ?? [];
51
+
52
+ return references.some(({ writeExpr }) => makesRuntime(writeExpr, imports));
53
+ };
54
+
55
+ const report = (node: ESTree.Node) =>
56
+ context.report({
57
+ node,
58
+ messageId: "manualRuntime",
59
+ data: { runner: context.sourceCode.getText(node) },
60
+ });
61
+
62
+ return {
63
+ Program(program) {
64
+ imports = importsOf(program);
65
+ },
66
+ ImportSpecifier(node) {
67
+ if (isEffectRunner(imports.get(node.local.name))) report(node.imported);
68
+ },
69
+ // `const { runPromise } = runtime`.
70
+ VariableDeclarator({ id, init }) {
71
+ if (id.type !== "ObjectPattern" || !isRuntime(init)) return;
72
+
73
+ for (const property of id.properties) {
74
+ if (property.type === "Property" && runners.has(keyOf(property) ?? "")) {
75
+ report(property.key);
76
+ }
77
+ }
78
+ },
79
+ MemberExpression(node) {
80
+ if (isEffectRunner(resolve(node, imports))) {
81
+ report(node);
82
+
83
+ return;
84
+ }
85
+
86
+ const { object, property } = node;
87
+
88
+ if (
89
+ !node.computed &&
90
+ property.type === "Identifier" &&
91
+ runners.has(property.name) &&
92
+ isRuntime(object)
93
+ ) {
94
+ report(node);
95
+ }
96
+ },
97
+ };
98
+ },
99
+ });
@@ -0,0 +1,24 @@
1
+ import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
2
+
3
+ /**
4
+ * The variable an identifier refers to, from the innermost scope that declares its name, or
5
+ * `undefined` for a global. Rules that follow a value to where it was made, such as a parameter or
6
+ * a `const` initialiser, read the variable's `defs` and `references`, so a same-named binding
7
+ * elsewhere in the file is a different variable.
8
+ */
9
+ export const variableOf = (
10
+ sourceCode: SourceCode,
11
+ identifier: ESTree.IdentifierReference,
12
+ ): Variable | undefined => {
13
+ for (
14
+ let scope: Scope | null = sourceCode.getScope(identifier);
15
+ scope !== null;
16
+ scope = scope.upper
17
+ ) {
18
+ const variable = scope.set.get(identifier.name);
19
+
20
+ if (variable !== undefined) return variable;
21
+ }
22
+
23
+ return undefined;
24
+ };
@@ -8,3 +8,5 @@ Copied `src/` without upstream test files. Licenses, including the nested eslint
8
8
  Used by the `/anti-slop` preset. Vendored files are typechecked but excluded from linting and formatting. Keep `@oxlint/plugins` pinned to the Oxlint version.
9
9
 
10
10
  Local change: `shared/dictionary-types.ts` uses `?? null` for an indexed access to compile with `noUncheckedIndexedAccess`. Preserve this when updating.
11
+
12
+ Local change: `rules/no-shape-in-symbol-names.ts` skips a property key or JSX attribute that names a CSS or SVG property, such as `shapeOutside` or `cornerShape`, because CSS owns those names. Preserve this when updating.
@@ -14,6 +14,21 @@ function isBorrowedMemberName(node: ESTree.Node): boolean {
14
14
  return parent.property === node && parent.computed === false;
15
15
  }
16
16
 
17
+ // CSS and SVG properties whose names contain "shape", as StyleX, React and SVG write them.
18
+ const CSS_PROPERTY = /^(?:shape(?:Outside|Margin|ImageThreshold|Rendering)|corner(?:Top|Right|Bottom|Left|Start|End|Block|Inline)*Shape)$/;
19
+
20
+ /** Return whether an identifier is a key or attribute that names a CSS or SVG property. */
21
+ function isCssPropertyName(node: ESTree.Node & { name: string }): boolean {
22
+ const parent = node.parent;
23
+ if (parent === null || !CSS_PROPERTY.test(node.name)) return false;
24
+ if (parent.type === "JSXAttribute") return parent.name === node;
25
+ return (
26
+ (parent.type === "Property" || parent.type === "TSPropertySignature") &&
27
+ parent.key === node &&
28
+ parent.computed === false
29
+ );
30
+ }
31
+
17
32
  /** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
18
33
  export const noForbiddenTermInSymbolNamesRule = defineRule({
19
34
  meta: {
@@ -29,7 +44,13 @@ export const noForbiddenTermInSymbolNamesRule = defineRule({
29
44
  },
30
45
  createOnce(context) {
31
46
  const reportForbiddenSymbolName = (node: ESTree.Node & { name: string }) => {
32
- if (!containsForbiddenSymbolName(node.name) || isBorrowedMemberName(node)) return;
47
+ if (
48
+ !containsForbiddenSymbolName(node.name) ||
49
+ isBorrowedMemberName(node) ||
50
+ isCssPropertyName(node)
51
+ ) {
52
+ return;
53
+ }
33
54
  context.report({
34
55
  node,
35
56
  messageId: "forbiddenSymbolName",