@kutur-kit/oxc 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +59 -7
- package/dist/effect.d.ts.map +1 -1
- package/dist/effect.js +6 -0
- package/dist/effect.js.map +1 -1
- package/dist/foldkit-stylex/attributes.d.ts +2 -0
- package/dist/foldkit-stylex/attributes.d.ts.map +1 -0
- package/dist/foldkit-stylex/attributes.js +191 -0
- package/dist/foldkit-stylex/attributes.js.map +1 -0
- package/dist/foldkit-stylex/components.d.ts +12 -0
- package/dist/foldkit-stylex/components.d.ts.map +1 -0
- package/dist/foldkit-stylex/components.js +41 -0
- package/dist/foldkit-stylex/components.js.map +1 -0
- package/dist/foldkit-stylex/condition-key.d.ts +16 -0
- package/dist/foldkit-stylex/condition-key.d.ts.map +1 -0
- package/dist/foldkit-stylex/condition-key.js +255 -0
- package/dist/foldkit-stylex/condition-key.js.map +1 -0
- package/dist/foldkit-stylex/hover-gate.d.ts +2 -0
- package/dist/foldkit-stylex/hover-gate.d.ts.map +1 -0
- package/dist/foldkit-stylex/hover-gate.js +78 -0
- package/dist/foldkit-stylex/hover-gate.js.map +1 -0
- package/dist/foldkit-stylex/styles.d.ts +2 -0
- package/dist/foldkit-stylex/styles.d.ts.map +1 -0
- package/dist/foldkit-stylex/styles.js +131 -0
- package/dist/foldkit-stylex/styles.js.map +1 -0
- package/dist/foldkit-stylex/unstyled-view.d.ts +2 -0
- package/dist/foldkit-stylex/unstyled-view.d.ts.map +1 -0
- package/dist/foldkit-stylex/unstyled-view.js +94 -0
- package/dist/foldkit-stylex/unstyled-view.js.map +1 -0
- package/dist/foldkit-stylex/vite.d.ts +2 -0
- package/dist/foldkit-stylex/vite.d.ts.map +1 -0
- package/dist/foldkit-stylex/vite.js +26 -0
- package/dist/foldkit-stylex/vite.js.map +1 -0
- package/dist/foldkit-stylex.d.ts +22 -0
- package/dist/foldkit-stylex.d.ts.map +1 -0
- package/dist/foldkit-stylex.js +26 -0
- package/dist/foldkit-stylex.js.map +1 -0
- package/dist/foldkit-stylex.json +26 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +16 -0
- package/dist/plugin.js.map +1 -1
- package/dist/rules/imports.d.ts +37 -0
- package/dist/rules/imports.d.ts.map +1 -0
- package/dist/rules/imports.js +72 -0
- package/dist/rules/imports.js.map +1 -0
- package/dist/rules/no-manual-effect-runtime-in-tests.d.ts +2 -0
- package/dist/rules/no-manual-effect-runtime-in-tests.d.ts.map +1 -0
- package/dist/rules/no-manual-effect-runtime-in-tests.js +74 -0
- package/dist/rules/no-manual-effect-runtime-in-tests.js.map +1 -0
- package/dist/rules/scope.d.ts +9 -0
- package/dist/rules/scope.d.ts.map +1 -0
- package/dist/rules/scope.js +15 -0
- package/dist/rules/scope.js.map +1 -0
- package/dist/rules/self-contained-function.d.ts +2 -0
- package/dist/rules/self-contained-function.d.ts.map +1 -0
- package/dist/rules/self-contained-function.js +56 -0
- package/dist/rules/self-contained-function.js.map +1 -0
- package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.d.ts.map +1 -1
- package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js +17 -1
- package/dist/vendor/anti-slop/rules/no-shape-in-symbol-names.js.map +1 -1
- package/package.json +14 -4
- package/src/effect.ts +6 -0
- package/src/foldkit-stylex/attributes.ts +282 -0
- package/src/foldkit-stylex/components.ts +41 -0
- package/src/foldkit-stylex/condition-key.ts +321 -0
- package/src/foldkit-stylex/hover-gate.ts +96 -0
- package/src/foldkit-stylex/styles.ts +170 -0
- package/src/foldkit-stylex/unstyled-view.ts +121 -0
- package/src/foldkit-stylex/vite.ts +29 -0
- package/src/foldkit-stylex.ts +30 -0
- package/src/plugin.ts +16 -0
- package/src/rules/imports.ts +99 -0
- package/src/rules/no-manual-effect-runtime-in-tests.ts +99 -0
- package/src/rules/scope.ts +24 -0
- package/src/rules/self-contained-function.ts +76 -0
- package/src/vendor/anti-slop/UPSTREAM.md +2 -0
- package/src/vendor/anti-slop/rules/no-shape-in-symbol-names.ts +22 -1
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ESTree, Reference } from "@oxlint/plugins";
|
|
2
|
+
|
|
3
|
+
import { defineRule } from "@oxlint/plugins";
|
|
4
|
+
|
|
5
|
+
type PageFunction = ESTree.Function | ESTree.ArrowFunctionExpression;
|
|
6
|
+
|
|
7
|
+
const isFunction = (node: ESTree.Node | null | undefined): node is PageFunction =>
|
|
8
|
+
node?.type === "FunctionDeclaration" ||
|
|
9
|
+
node?.type === "FunctionExpression" ||
|
|
10
|
+
node?.type === "ArrowFunctionExpression";
|
|
11
|
+
|
|
12
|
+
// The functions a module exports where it declares them: `export const f = () => …`,
|
|
13
|
+
// `export function f() {}` and `export default …`.
|
|
14
|
+
const exportedFunctions = (
|
|
15
|
+
node: ESTree.ExportNamedDeclaration | ESTree.ExportDefaultDeclaration,
|
|
16
|
+
): ReadonlyArray<PageFunction> => {
|
|
17
|
+
const { declaration } = node;
|
|
18
|
+
|
|
19
|
+
if (isFunction(declaration)) return [declaration];
|
|
20
|
+
|
|
21
|
+
if (declaration?.type !== "VariableDeclaration") return [];
|
|
22
|
+
|
|
23
|
+
return declaration.declarations.flatMap(({ init }) => (isFunction(init) ? [init] : []));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// `typeof value` and `typeof value.key` in a type, which compile away.
|
|
27
|
+
const inTypeQuery = (node: ESTree.Node): boolean =>
|
|
28
|
+
node.parent?.type === "TSTypeQuery" ||
|
|
29
|
+
(node.parent?.type === "TSQualifiedName" && inTypeQuery(node.parent));
|
|
30
|
+
|
|
31
|
+
// Oxlint runs TS-ESLint's scope manager, which flags a reference in a type position, but the
|
|
32
|
+
// plugin's types leave the flag out. Without it, every reference counts as a value.
|
|
33
|
+
const readsValue = (reference: Reference) =>
|
|
34
|
+
(!("isValueReference" in reference) || reference.isValueReference !== false) &&
|
|
35
|
+
!inTypeQuery(reference.identifier);
|
|
36
|
+
|
|
37
|
+
export const selfContainedFunction = defineRule({
|
|
38
|
+
meta: {
|
|
39
|
+
type: "problem",
|
|
40
|
+
docs: {
|
|
41
|
+
description:
|
|
42
|
+
"Disallow exported functions that read the module's bindings, for functions sent to a page as source.",
|
|
43
|
+
},
|
|
44
|
+
schema: [],
|
|
45
|
+
messages: {
|
|
46
|
+
outside:
|
|
47
|
+
"Playwright sends this function to the page as source, so it cannot reach `{{name}}` outside its body. Move the helper inside the function.",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
createOnce(context) {
|
|
51
|
+
const check = (node: ESTree.ExportNamedDeclaration | ESTree.ExportDefaultDeclaration) => {
|
|
52
|
+
for (const fn of exportedFunctions(node)) {
|
|
53
|
+
// `through` holds the references the function's scopes leave unresolved: outer bindings
|
|
54
|
+
// and globals. Only the module's own bindings are missing from the page; a function
|
|
55
|
+
// declaration still reaches its own name there.
|
|
56
|
+
for (const reference of context.sourceCode.getScope(fn).through) {
|
|
57
|
+
const variable = reference.resolved;
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
variable?.scope.type === "module" &&
|
|
61
|
+
!variable.defs.some((definition) => definition.node === fn) &&
|
|
62
|
+
readsValue(reference)
|
|
63
|
+
) {
|
|
64
|
+
context.report({
|
|
65
|
+
node: reference.identifier,
|
|
66
|
+
messageId: "outside",
|
|
67
|
+
data: { name: reference.identifier.name },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return { ExportNamedDeclaration: check, ExportDefaultDeclaration: check };
|
|
75
|
+
},
|
|
76
|
+
});
|
|
@@ -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 (
|
|
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",
|