@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.
- package/README.md +69 -21
- package/dist/app.d.ts +16 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +17 -0
- package/dist/app.js.map +1 -0
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +5 -1
- package/dist/base.js.map +1 -1
- package/dist/effect-ui-stylex/class.d.ts +2 -0
- package/dist/effect-ui-stylex/class.d.ts.map +1 -0
- package/dist/effect-ui-stylex/class.js +109 -0
- package/dist/effect-ui-stylex/class.js.map +1 -0
- package/dist/effect-ui-stylex/components.d.ts +30 -0
- package/dist/effect-ui-stylex/components.d.ts.map +1 -0
- package/dist/effect-ui-stylex/components.js +175 -0
- package/dist/effect-ui-stylex/components.js.map +1 -0
- package/dist/effect-ui-stylex/condition-key.d.ts.map +1 -0
- package/dist/{foldkit-stylex → effect-ui-stylex}/condition-key.js +7 -41
- package/dist/effect-ui-stylex/condition-key.js.map +1 -0
- package/dist/effect-ui-stylex/hover-gate.d.ts.map +1 -0
- package/dist/effect-ui-stylex/hover-gate.js.map +1 -0
- package/dist/effect-ui-stylex/internal-import.d.ts +2 -0
- package/dist/effect-ui-stylex/internal-import.d.ts.map +1 -0
- package/dist/effect-ui-stylex/internal-import.js +29 -0
- package/dist/effect-ui-stylex/internal-import.js.map +1 -0
- package/dist/effect-ui-stylex/layers.d.ts +14 -0
- package/dist/effect-ui-stylex/layers.d.ts.map +1 -0
- package/dist/effect-ui-stylex/layers.js +118 -0
- package/dist/effect-ui-stylex/layers.js.map +1 -0
- package/dist/effect-ui-stylex/look-level.d.ts +2 -0
- package/dist/effect-ui-stylex/look-level.d.ts.map +1 -0
- package/dist/effect-ui-stylex/look-level.js +83 -0
- package/dist/effect-ui-stylex/look-level.js.map +1 -0
- package/dist/effect-ui-stylex/modules.d.ts +36 -0
- package/dist/effect-ui-stylex/modules.d.ts.map +1 -0
- package/dist/effect-ui-stylex/modules.js +97 -0
- package/dist/effect-ui-stylex/modules.js.map +1 -0
- package/dist/effect-ui-stylex/parts.d.ts +17 -0
- package/dist/effect-ui-stylex/parts.d.ts.map +1 -0
- package/dist/effect-ui-stylex/parts.js +66 -0
- package/dist/effect-ui-stylex/parts.js.map +1 -0
- package/dist/effect-ui-stylex/raw-part.d.ts +2 -0
- package/dist/effect-ui-stylex/raw-part.d.ts.map +1 -0
- package/dist/effect-ui-stylex/raw-part.js +90 -0
- package/dist/effect-ui-stylex/raw-part.js.map +1 -0
- package/dist/effect-ui-stylex/state-attributes.d.ts +8 -0
- package/dist/effect-ui-stylex/state-attributes.d.ts.map +1 -0
- package/dist/effect-ui-stylex/state-attributes.js +141 -0
- package/dist/effect-ui-stylex/state-attributes.js.map +1 -0
- package/dist/effect-ui-stylex/state-key.d.ts +2 -0
- package/dist/effect-ui-stylex/state-key.d.ts.map +1 -0
- package/dist/effect-ui-stylex/state-key.js +103 -0
- package/dist/effect-ui-stylex/state-key.js.map +1 -0
- package/dist/effect-ui-stylex/subpath.d.ts +10 -0
- package/dist/effect-ui-stylex/subpath.d.ts.map +1 -0
- package/dist/effect-ui-stylex/subpath.js +53 -0
- package/dist/effect-ui-stylex/subpath.js.map +1 -0
- package/dist/effect-ui-stylex.d.ts +23 -0
- package/dist/effect-ui-stylex.d.ts.map +1 -0
- package/dist/{foldkit-stylex.js → effect-ui-stylex.js} +10 -9
- package/dist/effect-ui-stylex.js.map +1 -0
- package/dist/{foldkit-stylex.json → effect-ui-stylex.json} +7 -6
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +18 -12
- package/dist/plugin.js.map +1 -1
- package/dist/rules/imports.d.ts +5 -6
- package/dist/rules/imports.d.ts.map +1 -1
- package/dist/rules/imports.js +18 -14
- package/dist/rules/imports.js.map +1 -1
- package/dist/rules/module-sources.d.ts +33 -0
- package/dist/rules/module-sources.d.ts.map +1 -0
- package/dist/rules/module-sources.js +139 -0
- package/dist/rules/module-sources.js.map +1 -0
- package/dist/rules/no-suppression-directives.js +3 -3
- package/dist/rules/no-suppression-directives.js.map +1 -1
- package/dist/rules/scope.d.ts +3 -1
- package/dist/rules/scope.d.ts.map +1 -1
- package/dist/rules/scope.js.map +1 -1
- package/dist/vendor/anti-slop/rules/no-runtime-typeof.js +1 -1
- package/dist/vendor/anti-slop/rules/no-runtime-typeof.js.map +1 -1
- package/package.json +11 -7
- package/src/app.ts +19 -0
- package/src/base.ts +5 -1
- package/src/effect-ui-stylex/class.ts +140 -0
- package/src/effect-ui-stylex/components.ts +184 -0
- package/src/{foldkit-stylex → effect-ui-stylex}/condition-key.ts +6 -52
- package/src/effect-ui-stylex/internal-import.ts +32 -0
- package/src/effect-ui-stylex/layers.ts +161 -0
- package/src/effect-ui-stylex/look-level.ts +99 -0
- package/src/effect-ui-stylex/modules.ts +115 -0
- package/src/effect-ui-stylex/parts.ts +89 -0
- package/src/effect-ui-stylex/raw-part.ts +110 -0
- package/src/effect-ui-stylex/state-attributes.ts +140 -0
- package/src/effect-ui-stylex/state-key.ts +147 -0
- package/src/effect-ui-stylex/subpath.ts +65 -0
- package/src/{foldkit-stylex.ts → effect-ui-stylex.ts} +9 -8
- package/src/plugin.ts +18 -12
- package/src/rules/imports.ts +22 -15
- package/src/rules/module-sources.ts +179 -0
- package/src/rules/no-suppression-directives.ts +3 -3
- package/src/rules/scope.ts +1 -1
- package/src/vendor/anti-slop/UPSTREAM.md +2 -0
- package/src/vendor/anti-slop/rules/no-runtime-typeof.ts +1 -1
- package/dist/foldkit-stylex/attributes.d.ts +0 -2
- package/dist/foldkit-stylex/attributes.d.ts.map +0 -1
- package/dist/foldkit-stylex/attributes.js +0 -191
- package/dist/foldkit-stylex/attributes.js.map +0 -1
- package/dist/foldkit-stylex/components.d.ts +0 -12
- package/dist/foldkit-stylex/components.d.ts.map +0 -1
- package/dist/foldkit-stylex/components.js +0 -41
- package/dist/foldkit-stylex/components.js.map +0 -1
- package/dist/foldkit-stylex/condition-key.d.ts.map +0 -1
- package/dist/foldkit-stylex/condition-key.js.map +0 -1
- package/dist/foldkit-stylex/hover-gate.d.ts.map +0 -1
- package/dist/foldkit-stylex/hover-gate.js.map +0 -1
- package/dist/foldkit-stylex/styles.d.ts +0 -2
- package/dist/foldkit-stylex/styles.d.ts.map +0 -1
- package/dist/foldkit-stylex/styles.js +0 -131
- package/dist/foldkit-stylex/styles.js.map +0 -1
- package/dist/foldkit-stylex/unstyled-view.d.ts +0 -2
- package/dist/foldkit-stylex/unstyled-view.d.ts.map +0 -1
- package/dist/foldkit-stylex/unstyled-view.js +0 -94
- package/dist/foldkit-stylex/unstyled-view.js.map +0 -1
- package/dist/foldkit-stylex/vite.d.ts +0 -2
- package/dist/foldkit-stylex/vite.d.ts.map +0 -1
- package/dist/foldkit-stylex/vite.js +0 -26
- package/dist/foldkit-stylex/vite.js.map +0 -1
- package/dist/foldkit-stylex.d.ts +0 -22
- package/dist/foldkit-stylex.d.ts.map +0 -1
- package/dist/foldkit-stylex.js.map +0 -1
- package/src/foldkit-stylex/attributes.ts +0 -282
- package/src/foldkit-stylex/components.ts +0 -41
- package/src/foldkit-stylex/styles.ts +0 -170
- package/src/foldkit-stylex/unstyled-view.ts +0 -121
- package/src/foldkit-stylex/vite.ts +0 -29
- /package/dist/{foldkit-stylex → effect-ui-stylex}/condition-key.d.ts +0 -0
- /package/dist/{foldkit-stylex → effect-ui-stylex}/hover-gate.d.ts +0 -0
- /package/dist/{foldkit-stylex → effect-ui-stylex}/hover-gate.js +0 -0
- /package/src/{foldkit-stylex → effect-ui-stylex}/hover-gate.ts +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
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 { stateAttributes } from "./state-attributes.ts";
|
|
7
|
+
|
|
8
|
+
const written: ReadonlySet<string> = new Set(stateAttributes);
|
|
9
|
+
|
|
10
|
+
type Attribute = Readonly<{ name: string; value: string | undefined }>;
|
|
11
|
+
|
|
12
|
+
// A condition key that selects data attributes: the ones it needs, in `:is(...)`, and the ones
|
|
13
|
+
// it excludes, in `:not(...)`.
|
|
14
|
+
type StateKey = Readonly<{ needs: ReadonlyArray<Attribute>; excludes: ReadonlyArray<Attribute> }>;
|
|
15
|
+
|
|
16
|
+
const attributesIn = (selector: string): ReadonlyArray<Attribute> =>
|
|
17
|
+
Array.from(
|
|
18
|
+
selector.matchAll(
|
|
19
|
+
/\[\s*data-([a-z]+(?:-[a-z]+)*)\s*(?:[~|^$*]?=\s*["']?([^\]"']*)["']?\s*)?\]/g,
|
|
20
|
+
),
|
|
21
|
+
([, name = "", value]) => ({ name, value }),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Reads `:is([data-side="top"]):not([data-instant])`. `undefined` for a key with no data
|
|
25
|
+
// attribute in it, and for a bare `[data-x]`, which `effect-ui-stylex-condition-key` reports.
|
|
26
|
+
const stateKeyOf = (key: string): StateKey | undefined => {
|
|
27
|
+
if (!key.startsWith(":") || !key.includes("[data-")) return undefined;
|
|
28
|
+
|
|
29
|
+
const [first = "", ...negated] = key.split(":not(");
|
|
30
|
+
|
|
31
|
+
return { needs: attributesIn(first), excludes: attributesIn(negated.join(" ")) };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Whether no element matches both keys: one excludes an attribute the other needs, or both need
|
|
35
|
+
// one attribute at different values.
|
|
36
|
+
const exclusive = (a: StateKey, b: StateKey) =>
|
|
37
|
+
a.needs.some(({ name, value }) =>
|
|
38
|
+
b.needs.some(
|
|
39
|
+
(other) =>
|
|
40
|
+
other.name === name &&
|
|
41
|
+
value !== undefined &&
|
|
42
|
+
other.value !== undefined &&
|
|
43
|
+
other.value !== value,
|
|
44
|
+
),
|
|
45
|
+
) ||
|
|
46
|
+
a.needs.some(({ name }) => b.excludes.some((other) => other.name === name)) ||
|
|
47
|
+
b.needs.some(({ name }) => a.excludes.some((other) => other.name === name));
|
|
48
|
+
|
|
49
|
+
export const stateKey = defineRule({
|
|
50
|
+
meta: {
|
|
51
|
+
type: "problem",
|
|
52
|
+
docs: {
|
|
53
|
+
description:
|
|
54
|
+
"Hold a StyleX key on a data attribute to one effect/ui/kit writes, with a plain value, exclusive of the property's other such keys.",
|
|
55
|
+
},
|
|
56
|
+
schema: [],
|
|
57
|
+
messages: {
|
|
58
|
+
unknown:
|
|
59
|
+
"effect/ui/kit writes no data-{{name}}, so '{{key}}' matches none of its parts. Pass state as a value, as stylex.attrs(styles.base, isOpen && styles.open), from what the view gets. A key on an attribute is for one that effect/ui/kit writes and hands the view no value for.",
|
|
60
|
+
nested:
|
|
61
|
+
"Give '{{key}}' a plain value. StyleX's valid-styles rule takes no conditions under a key on an attribute. Put the other condition around it, as { '@media (…)': { default: …, '{{key}}': … } }.",
|
|
62
|
+
overlap:
|
|
63
|
+
"'{{key}}' and '{{other}}' can match one element, and StyleX ranks keys on attributes of one property equally, so the stylesheet's order picks between them. Exclude one from the other, as '{{key}}:not([data-{{name}}])'.",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
createOnce(context) {
|
|
67
|
+
let imports: Imports = new Map();
|
|
68
|
+
|
|
69
|
+
// The conditions of one property, or of one condition under it.
|
|
70
|
+
const checkConditions = (conditions: ESTree.ObjectExpression) => {
|
|
71
|
+
const keys = conditions.properties.flatMap((property) => {
|
|
72
|
+
const key = property.type === "Property" ? keyOf(property) : undefined;
|
|
73
|
+
const state = key === undefined ? undefined : stateKeyOf(key);
|
|
74
|
+
|
|
75
|
+
return property.type !== "Property" || key === undefined || state === undefined
|
|
76
|
+
? []
|
|
77
|
+
: [{ key, state, property }];
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
for (const [index, { key, state, property }] of keys.entries()) {
|
|
81
|
+
const unknown = [...state.needs, ...state.excludes].find(({ name }) => !written.has(name));
|
|
82
|
+
|
|
83
|
+
if (unknown !== undefined) {
|
|
84
|
+
context.report({
|
|
85
|
+
node: property.key,
|
|
86
|
+
messageId: "unknown",
|
|
87
|
+
data: { key, name: unknown.name },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (property.value.type === "ObjectExpression") {
|
|
92
|
+
context.report({ node: property.key, messageId: "nested", data: { key } });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const other = keys.slice(index + 1).find((later) => !exclusive(state, later.state));
|
|
96
|
+
const [needed] = other?.state.needs ?? [];
|
|
97
|
+
|
|
98
|
+
if (other !== undefined) {
|
|
99
|
+
context.report({
|
|
100
|
+
node: other.property.key,
|
|
101
|
+
messageId: "overlap",
|
|
102
|
+
data: { key: other.key, other: key, name: state.needs[0]?.name ?? needed?.name ?? "" },
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const property of conditions.properties) {
|
|
108
|
+
if (property.type === "Property" && property.value.type === "ObjectExpression") {
|
|
109
|
+
checkConditions(property.value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const checkStyle = (style: ESTree.Node) => {
|
|
115
|
+
// A dynamic style's conditions are in the object its function returns.
|
|
116
|
+
const object = style.type === "ArrowFunctionExpression" ? style.body : style;
|
|
117
|
+
|
|
118
|
+
if (object.type !== "ObjectExpression") return;
|
|
119
|
+
|
|
120
|
+
for (const property of object.properties) {
|
|
121
|
+
if (property.type === "Property" && property.value.type === "ObjectExpression") {
|
|
122
|
+
checkConditions(property.value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
Program(program) {
|
|
129
|
+
imports = importsOf(program);
|
|
130
|
+
},
|
|
131
|
+
CallExpression(node) {
|
|
132
|
+
const [styles] = node.arguments;
|
|
133
|
+
|
|
134
|
+
if (
|
|
135
|
+
exportOf(node.callee, imports, "@stylexjs/stylex") !== "create" ||
|
|
136
|
+
styles?.type !== "ObjectExpression"
|
|
137
|
+
) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const entry of styles.properties) {
|
|
142
|
+
if (entry.type === "Property") checkStyle(entry.value);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import { isPath, moduleSources, posixPath, resolveFrom } from "../rules/module-sources.ts";
|
|
4
|
+
import { exportedPlace, library, placeOf } from "./modules.ts";
|
|
5
|
+
|
|
6
|
+
// The library's files as an app can name them: through the package, or by a path, relative or
|
|
7
|
+
// absolute, into the directory it is installed or checked out in.
|
|
8
|
+
const throughPackage = new RegExp(`^${library}/(?:src|dist)/(.+)$`);
|
|
9
|
+
|
|
10
|
+
const byPath = /^(.*\/effect-ui-stylex)\/(?:src|dist)\/(.+)$/;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The file of the library an import names from `file`, as a path under its `src` or `dist`, or
|
|
14
|
+
* `undefined` for an import of anything else. A module of the library reaches its own files by
|
|
15
|
+
* path, so a path that stays inside the one checkout names none.
|
|
16
|
+
*/
|
|
17
|
+
export const libraryFile = (filename: string, source: string) => {
|
|
18
|
+
const file = posixPath(filename);
|
|
19
|
+
const [, through] = throughPackage.exec(posixPath(source)) ?? [];
|
|
20
|
+
|
|
21
|
+
if (through !== undefined || !isPath(source)) return through;
|
|
22
|
+
|
|
23
|
+
const [, root, path] = byPath.exec(resolveFrom(file, source)) ?? [];
|
|
24
|
+
|
|
25
|
+
return root === undefined || file.startsWith(`${root}/`) ? undefined : path;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** The module to import in place of a file of the library, if the library exports that file. */
|
|
29
|
+
export const exportedAs = (path: string) => {
|
|
30
|
+
const place = placeOf(path);
|
|
31
|
+
const exported = place && exportedPlace(place.name);
|
|
32
|
+
|
|
33
|
+
return exported?.layer === place?.layer ? exported?.name : undefined;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const subpath = defineRule({
|
|
37
|
+
meta: {
|
|
38
|
+
type: "problem",
|
|
39
|
+
docs: {
|
|
40
|
+
description: "Import @kutur-kit/effect-ui-stylex by the modules it exports, not by file.",
|
|
41
|
+
},
|
|
42
|
+
schema: [],
|
|
43
|
+
messages: {
|
|
44
|
+
exported:
|
|
45
|
+
"Import {{library}}/{{module}}. {{source}} names a file of the package, and the layout of its `src` and `dist` changes without a version.",
|
|
46
|
+
unexported:
|
|
47
|
+
"{{source}} names a file that {{library}} does not export, which changes without a version. Import one of the package's modules, such as {{library}}/button.",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
createOnce(context) {
|
|
51
|
+
return moduleSources(({ source, node }) => {
|
|
52
|
+
const path = libraryFile(context.filename, source);
|
|
53
|
+
|
|
54
|
+
if (path === undefined) return;
|
|
55
|
+
|
|
56
|
+
const module = exportedAs(path);
|
|
57
|
+
|
|
58
|
+
context.report({
|
|
59
|
+
node,
|
|
60
|
+
messageId: module === undefined ? "unexported" : "exported",
|
|
61
|
+
data: { library, module: module ?? "", source },
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
});
|
|
@@ -5,19 +5,20 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
const extension = import.meta.url.endsWith(".ts") ? "ts" : "js";
|
|
6
6
|
|
|
7
7
|
// `satisfies` keeps each plugin entry an object, which the build's JSON form relies on.
|
|
8
|
-
const
|
|
8
|
+
const effectUiStylex = {
|
|
9
9
|
jsPlugins: [
|
|
10
10
|
// `/base` registers the same plugin with the same specifier, so Oxlint loads it once.
|
|
11
11
|
{ name: "kit", specifier: fileURLToPath(new URL(`./plugin.${extension}`, import.meta.url)) },
|
|
12
12
|
{ name: "stylex", specifier: fileURLToPath(import.meta.resolve("@stylexjs/eslint-plugin")) },
|
|
13
13
|
],
|
|
14
14
|
rules: {
|
|
15
|
-
"kit/
|
|
16
|
-
"kit/
|
|
17
|
-
"kit/
|
|
18
|
-
"kit/
|
|
19
|
-
"kit/
|
|
20
|
-
"kit/
|
|
15
|
+
"kit/effect-ui-class": "error",
|
|
16
|
+
"kit/effect-ui-internal-import": "error",
|
|
17
|
+
"kit/effect-ui-raw-part": "error",
|
|
18
|
+
"kit/effect-ui-state-key": "error",
|
|
19
|
+
"kit/effect-ui-stylex-condition-key": "error",
|
|
20
|
+
"kit/effect-ui-stylex-hover-gate": "error",
|
|
21
|
+
"kit/effect-ui-stylex-subpath": "error",
|
|
21
22
|
"stylex/enforce-extension": "error",
|
|
22
23
|
"stylex/no-legacy-contextual-styles": "error",
|
|
23
24
|
"stylex/no-nonstandard-styles": "error",
|
|
@@ -27,4 +28,4 @@ const foldkitStylex = {
|
|
|
27
28
|
},
|
|
28
29
|
} satisfies OxlintConfig;
|
|
29
30
|
|
|
30
|
-
export default
|
|
31
|
+
export default effectUiStylex;
|
package/src/plugin.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { definePlugin } from "@oxlint/plugins";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { conditionKey } from "./
|
|
5
|
-
import { hoverGate } from "./
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { classRule } from "./effect-ui-stylex/class.ts";
|
|
4
|
+
import { conditionKey } from "./effect-ui-stylex/condition-key.ts";
|
|
5
|
+
import { hoverGate } from "./effect-ui-stylex/hover-gate.ts";
|
|
6
|
+
import { internalImport } from "./effect-ui-stylex/internal-import.ts";
|
|
7
|
+
import { layers } from "./effect-ui-stylex/layers.ts";
|
|
8
|
+
import { lookLevel } from "./effect-ui-stylex/look-level.ts";
|
|
9
|
+
import { rawPart } from "./effect-ui-stylex/raw-part.ts";
|
|
10
|
+
import { stateKey } from "./effect-ui-stylex/state-key.ts";
|
|
11
|
+
import { subpath } from "./effect-ui-stylex/subpath.ts";
|
|
9
12
|
import { commentProse } from "./rules/comment-prose.ts";
|
|
10
13
|
import { noManualEffectRuntimeInTests } from "./rules/no-manual-effect-runtime-in-tests.ts";
|
|
11
14
|
import { noSuppressionDirectives } from "./rules/no-suppression-directives.ts";
|
|
@@ -16,12 +19,15 @@ export default definePlugin({
|
|
|
16
19
|
meta: { name: "@kutur-kit/oxc" },
|
|
17
20
|
rules: {
|
|
18
21
|
"comment-prose": commentProse,
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
22
|
+
"effect-ui-class": classRule,
|
|
23
|
+
"effect-ui-internal-import": internalImport,
|
|
24
|
+
"effect-ui-look-level": lookLevel,
|
|
25
|
+
"effect-ui-raw-part": rawPart,
|
|
26
|
+
"effect-ui-state-key": stateKey,
|
|
27
|
+
"effect-ui-stylex-condition-key": conditionKey,
|
|
28
|
+
"effect-ui-stylex-hover-gate": hoverGate,
|
|
29
|
+
"effect-ui-stylex-layers": layers,
|
|
30
|
+
"effect-ui-stylex-subpath": subpath,
|
|
25
31
|
"no-manual-effect-runtime-in-tests": noManualEffectRuntimeInTests,
|
|
26
32
|
"no-suppression-directives": noSuppressionDirectives,
|
|
27
33
|
"no-yield-in-if": noYieldInIf,
|
package/src/rules/imports.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { ESTree } from "@oxlint/plugins";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What a name refers to through an import: the module and the export path inside it. After
|
|
5
|
-
* `import {
|
|
5
|
+
* `import { DialogStyle } from "@kutur-kit/effect-ui-stylex"`, `DialogStyle.styled` is
|
|
6
|
+
* `@kutur-kit/effect-ui-stylex` with `DialogStyle.styled`.
|
|
6
7
|
*/
|
|
7
8
|
export type Imported = Readonly<{ source: string; path: string }>;
|
|
8
9
|
|
|
@@ -18,25 +19,38 @@ export const importsOf = (program: ESTree.Program): Imports =>
|
|
|
18
19
|
statement.type === "ImportDeclaration"
|
|
19
20
|
? statement.specifiers.map((specifier): [string, Imported] => [
|
|
20
21
|
specifier.local.name,
|
|
21
|
-
{
|
|
22
|
+
{
|
|
23
|
+
source: statement.source.value,
|
|
24
|
+
path: pathOf(specifier, statement.source.value),
|
|
25
|
+
},
|
|
22
26
|
])
|
|
23
27
|
: [],
|
|
24
28
|
),
|
|
25
29
|
);
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
// Modules whose default export holds what their namespace does. StyleX's compiler takes
|
|
32
|
+
// `import stylex from "@stylexjs/stylex"` as it takes `import * as stylex`, so `stylex.create`
|
|
33
|
+
// is the same export either way.
|
|
34
|
+
const namespaceAsDefault: ReadonlySet<string> = new Set(["@stylexjs/stylex"]);
|
|
35
|
+
|
|
36
|
+
const pathOf = (specifier: ESTree.ImportDeclarationSpecifier, source: string) => {
|
|
28
37
|
if (specifier.type === "ImportNamespaceSpecifier") return "";
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
const name =
|
|
40
|
+
specifier.type === "ImportDefaultSpecifier"
|
|
41
|
+
? "default"
|
|
42
|
+
: specifier.imported.type === "Literal"
|
|
43
|
+
? specifier.imported.value
|
|
44
|
+
: specifier.imported.name;
|
|
31
45
|
|
|
32
|
-
return
|
|
46
|
+
return name === "default" && namespaceAsDefault.has(source) ? "" : name;
|
|
33
47
|
};
|
|
34
48
|
|
|
35
49
|
const join = (path: string, name: string) => (path === "" ? name : `${path}.${name}`);
|
|
36
50
|
|
|
37
51
|
/**
|
|
38
|
-
* Resolves an identifier, a member chain such as `
|
|
39
|
-
* `PopoverStyle.Styles` to the import it starts from, or `undefined` for anything else.
|
|
52
|
+
* Resolves an identifier, a member chain such as `Kit.DialogStyle.styled` or a qualified type name
|
|
53
|
+
* such as `PopoverStyle.Styles` to the import it starts from, or `undefined` for anything else.
|
|
40
54
|
*/
|
|
41
55
|
export const resolve = (node: ESTree.Node, imports: Imports): Imported | undefined => {
|
|
42
56
|
if (node.type === "Identifier") return imports.get(node.name);
|
|
@@ -74,14 +88,7 @@ export const effectMemberOf = (imported: Imported | undefined, module: string) =
|
|
|
74
88
|
: undefined;
|
|
75
89
|
};
|
|
76
90
|
|
|
77
|
-
/**
|
|
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(...)`. */
|
|
91
|
+
/** A call of a method named `name` on any object, such as `h.div.class(...)`. */
|
|
85
92
|
export const isMethodCall = (node: ESTree.Node, name: string): node is ESTree.CallExpression =>
|
|
86
93
|
node.type === "CallExpression" &&
|
|
87
94
|
node.callee.type === "MemberExpression" &&
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { ESTree, Visitor } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A place where a file names another module, with the specifier as written. `named` is true for
|
|
5
|
+
* an import declaration that binds named exports alone, as `import { a, type B } from "./c.ts"`.
|
|
6
|
+
*/
|
|
7
|
+
export type ModuleSource = Readonly<{ source: string; node: ESTree.Node; named: boolean }>;
|
|
8
|
+
|
|
9
|
+
// A literal, or a template without expressions, which names a module as a literal does. A literal
|
|
10
|
+
// that is no string, as in `import(1)`, reads as text that names no module.
|
|
11
|
+
const textOf = (node: ESTree.Node | undefined) => {
|
|
12
|
+
if (node?.type === "Literal") return String(node.value);
|
|
13
|
+
|
|
14
|
+
return node?.type === "TemplateLiteral" && node.expressions.length === 0
|
|
15
|
+
? (node.quasis[0]?.value.cooked ?? undefined)
|
|
16
|
+
: undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const isImportMeta = (node: ESTree.Node) =>
|
|
20
|
+
node.type === "MetaProperty" && node.meta.name === "import" && node.property.name === "meta";
|
|
21
|
+
|
|
22
|
+
/** The name of a member read with a dot, as `glob` in `import.meta.glob`. */
|
|
23
|
+
const memberName = (node: ESTree.Node) =>
|
|
24
|
+
node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier"
|
|
25
|
+
? node.property.name
|
|
26
|
+
: undefined;
|
|
27
|
+
|
|
28
|
+
// Vite's and Node's loaders on `import.meta`. A glob names every file it matches.
|
|
29
|
+
const metaLoaders = new Set(["glob", "resolve"]);
|
|
30
|
+
|
|
31
|
+
// The Vitest and Jest calls that load or replace a module by its specifier.
|
|
32
|
+
const testLoaders = new Set([
|
|
33
|
+
"doMock",
|
|
34
|
+
"doUnmock",
|
|
35
|
+
"importActual",
|
|
36
|
+
"importMock",
|
|
37
|
+
"mock",
|
|
38
|
+
"requireActual",
|
|
39
|
+
"requireMock",
|
|
40
|
+
"unmock",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const testRunners = new Set(["jest", "vi", "vitest"]);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Whether a call's first argument names a module: `require`, `require.resolve`, a function
|
|
47
|
+
* `createRequire` returns, `import.meta.glob`, `import.meta.resolve`, and the loaders of `vi` and
|
|
48
|
+
* `jest`.
|
|
49
|
+
*/
|
|
50
|
+
const loads = (callee: ESTree.Node): boolean => {
|
|
51
|
+
if (callee.type === "Identifier") return callee.name === "require";
|
|
52
|
+
|
|
53
|
+
if (callee.type === "CallExpression") {
|
|
54
|
+
return callee.callee.type === "Identifier" && callee.callee.name === "createRequire";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const name = memberName(callee);
|
|
58
|
+
|
|
59
|
+
if (callee.type !== "MemberExpression" || name === undefined) return false;
|
|
60
|
+
|
|
61
|
+
const { object } = callee;
|
|
62
|
+
|
|
63
|
+
if (isImportMeta(object)) return metaLoaders.has(name);
|
|
64
|
+
|
|
65
|
+
if (object.type === "Identifier" && testRunners.has(object.name)) return testLoaders.has(name);
|
|
66
|
+
|
|
67
|
+
return name === "resolve" && loads(object);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A visitor that hands `visit` every module a file names with a literal: static and type-only
|
|
72
|
+
* imports, re-exports, `import()`, `import("…")` types, `import x = require("…")`, the calls
|
|
73
|
+
* `loads` lists and `new URL("…", import.meta.url)`. `import.meta.glob` hands each of its
|
|
74
|
+
* patterns as written, so a rule reads `./*.ts` as a module named `*`. A specifier computed at
|
|
75
|
+
* run time names no module a rule can read.
|
|
76
|
+
*/
|
|
77
|
+
export const moduleSources = (visit: (found: ModuleSource) => void): Visitor => {
|
|
78
|
+
const found = (node: ESTree.Node | undefined | null, named = false) => {
|
|
79
|
+
const source = textOf(node ?? undefined);
|
|
80
|
+
|
|
81
|
+
if (node !== undefined && node !== null && source !== undefined) {
|
|
82
|
+
visit({ source, node, named });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
ImportDeclaration(node) {
|
|
88
|
+
found(
|
|
89
|
+
node.source,
|
|
90
|
+
node.specifiers.length > 0 &&
|
|
91
|
+
node.specifiers.every(
|
|
92
|
+
(specifier) =>
|
|
93
|
+
specifier.type === "ImportSpecifier" &&
|
|
94
|
+
(specifier.imported.type === "Literal"
|
|
95
|
+
? specifier.imported.value
|
|
96
|
+
: specifier.imported.name) !== "default",
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
ExportNamedDeclaration(node) {
|
|
101
|
+
found(node.source);
|
|
102
|
+
},
|
|
103
|
+
ExportAllDeclaration(node) {
|
|
104
|
+
found(node.source);
|
|
105
|
+
},
|
|
106
|
+
ImportExpression(node) {
|
|
107
|
+
found(node.source);
|
|
108
|
+
},
|
|
109
|
+
TSImportType(node) {
|
|
110
|
+
found(node.source);
|
|
111
|
+
},
|
|
112
|
+
TSExternalModuleReference(node) {
|
|
113
|
+
found(node.expression);
|
|
114
|
+
},
|
|
115
|
+
CallExpression(node) {
|
|
116
|
+
if (!loads(node.callee)) return;
|
|
117
|
+
|
|
118
|
+
const [first] = node.arguments;
|
|
119
|
+
|
|
120
|
+
// `import.meta.glob` takes one pattern or a list of them.
|
|
121
|
+
for (const argument of first?.type === "ArrayExpression" ? first.elements : [first]) {
|
|
122
|
+
found(argument);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
NewExpression(node) {
|
|
126
|
+
const [path, base] = node.arguments;
|
|
127
|
+
|
|
128
|
+
if (
|
|
129
|
+
node.callee.type === "Identifier" &&
|
|
130
|
+
node.callee.name === "URL" &&
|
|
131
|
+
base !== undefined &&
|
|
132
|
+
memberName(base) === "url" &&
|
|
133
|
+
base.type === "MemberExpression" &&
|
|
134
|
+
isImportMeta(base.object)
|
|
135
|
+
) {
|
|
136
|
+
found(path);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** A file name with `/` between its segments, whichever the platform wrote. */
|
|
143
|
+
export const posixPath = (path: string) => path.replaceAll("\\", "/");
|
|
144
|
+
|
|
145
|
+
// A path from the root of a file system: `/a`, `C:/a`, or either as a `file:` URL.
|
|
146
|
+
const absolute = /^(?:file:\/\/)?(?:\/(?=[A-Za-z]:\/))?(\/|[A-Za-z]:\/)/;
|
|
147
|
+
|
|
148
|
+
/** Whether a specifier is a path from the importing file, not a package or an alias. */
|
|
149
|
+
export const isRelative = (specifier: string) => /^\.\.?(?:[/\\]|$)/.test(specifier);
|
|
150
|
+
|
|
151
|
+
/** Whether a specifier is a path from the root of a file system, as a path or a `file:` URL. */
|
|
152
|
+
export const isAbsolute = (specifier: string) => absolute.test(posixPath(specifier));
|
|
153
|
+
|
|
154
|
+
/** Whether a specifier names a file by its path, not a package or an alias. */
|
|
155
|
+
export const isPath = (specifier: string) => isRelative(specifier) || isAbsolute(specifier);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The file a path specifier names from `file`, both with `/` between segments. The segments are
|
|
159
|
+
* joined as text, so a path with a Windows drive resolves like any other. An absolute specifier
|
|
160
|
+
* names the same file from any `file`.
|
|
161
|
+
*/
|
|
162
|
+
export const resolveFrom = (file: string, specifier: string) => {
|
|
163
|
+
const path = posixPath(specifier);
|
|
164
|
+
const [prefix, root] = absolute.exec(path) ?? [];
|
|
165
|
+
|
|
166
|
+
const from =
|
|
167
|
+
prefix === undefined || root === undefined
|
|
168
|
+
? [...file.split("/").slice(0, -1), ...path.split("/")]
|
|
169
|
+
: `${root}${path.slice(prefix.length)}`.split("/");
|
|
170
|
+
|
|
171
|
+
const segments: Array<string> = [];
|
|
172
|
+
|
|
173
|
+
for (const segment of from) {
|
|
174
|
+
if (segment === "..") segments.pop();
|
|
175
|
+
else if (segment !== "." && (segment !== "" || segments.length === 0)) segments.push(segment);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return segments.join("/");
|
|
179
|
+
};
|
|
@@ -42,16 +42,16 @@ const words = (list: string, separator: RegExp) =>
|
|
|
42
42
|
|
|
43
43
|
const directivesIn = (comment: string): Directive[] => {
|
|
44
44
|
const effect = Array.from(comment.matchAll(effectDirective), (match): Directive => {
|
|
45
|
-
const { list, reason } = splitReason(match.groups?.text ?? "");
|
|
45
|
+
const { list, reason } = splitReason(match.groups?.["text"] ?? "");
|
|
46
46
|
|
|
47
47
|
return { kind: "effect-diagnostics", entries: words(list, effectEntrySeparator), reason };
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
const lint = lintDirective.exec(comment);
|
|
51
51
|
|
|
52
|
-
if (lint?.groups?.disable === undefined) return effect;
|
|
52
|
+
if (lint?.groups?.["disable"] === undefined) return effect;
|
|
53
53
|
|
|
54
|
-
const { list, reason } = splitReason(lint.groups
|
|
54
|
+
const { list, reason } = splitReason(lint.groups["text"] ?? "");
|
|
55
55
|
|
|
56
56
|
return [{ kind: "lint-disable", rules: words(list, lintRuleSeparator), reason }, ...effect];
|
|
57
57
|
};
|
package/src/rules/scope.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
|
|
|
8
8
|
*/
|
|
9
9
|
export const variableOf = (
|
|
10
10
|
sourceCode: SourceCode,
|
|
11
|
-
identifier: ESTree.
|
|
11
|
+
identifier: Extract<ESTree.Node, Readonly<{ type: "Identifier" }>>,
|
|
12
12
|
): Variable | undefined => {
|
|
13
13
|
for (
|
|
14
14
|
let scope: Scope | null = sourceCode.getScope(identifier);
|
|
@@ -10,3 +10,5 @@ Used by the `/anti-slop` preset. Vendored files are typechecked but excluded fro
|
|
|
10
10
|
Local change: `shared/dictionary-types.ts` uses `?? null` for an indexed access to compile with `noUncheckedIndexedAccess`. Preserve this when updating.
|
|
11
11
|
|
|
12
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.
|
|
13
|
+
|
|
14
|
+
Local change: `rules/no-runtime-typeof.ts` reads its option as `option["allowInTypeGuards"]` to compile with `noPropertyAccessFromIndexSignature`. Preserve this when updating.
|
|
@@ -63,7 +63,7 @@ export const noRuntimeTypeofRule = defineRule({
|
|
|
63
63
|
typeof option === "object" &&
|
|
64
64
|
option !== null &&
|
|
65
65
|
!Array.isArray(option) &&
|
|
66
|
-
option
|
|
66
|
+
option["allowInTypeGuards"] === true;
|
|
67
67
|
if (
|
|
68
68
|
node.operator === "typeof" &&
|
|
69
69
|
!isExistenceProbe(node) &&
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sources":["../../src/foldkit-stylex/attributes.ts"],"names":[],"mappings":"AA2DA,eAAO,MAAM,UAAU,gCA8NrB,CAAC"}
|