@ref0/workspace 0.0.0-stage → 0.1.0

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 (73) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +69 -2
  3. package/dist/bin.d.mts +1 -0
  4. package/dist/bin.mjs +30 -0
  5. package/dist/docs-budget.mjs +122 -0
  6. package/dist/lint/anti-slop/LICENSE +21 -0
  7. package/dist/lint/anti-slop/UPSTREAM.md +11 -0
  8. package/dist/lint/anti-slop/effect/plugin.d.mts +3 -0
  9. package/dist/lint/anti-slop/effect/plugin.mjs +19 -0
  10. package/dist/lint/anti-slop/effect/rules/no-manual-effect-error-tag.mjs +33 -0
  11. package/dist/lint/anti-slop/effect/rules/no-manual-tag-comparison.mjs +32 -0
  12. package/dist/lint/anti-slop/effect/rules/no-manual-tagged-construction.mjs +22 -0
  13. package/dist/lint/anti-slop/effect/rules/no-service-constructor-imports.mjs +36 -0
  14. package/dist/lint/anti-slop/effect/rules/prefer-effect-match.mjs +40 -0
  15. package/dist/lint/anti-slop/effect/shared/tagged-values.mjs +40 -0
  16. package/dist/lint/anti-slop/plugin.d.mts +3 -0
  17. package/dist/lint/anti-slop/plugin.mjs +45 -0
  18. package/dist/lint/anti-slop/rules/no-array-filter-map.mjs +31 -0
  19. package/dist/lint/anti-slop/rules/no-chained-type-assertions.mjs +56 -0
  20. package/dist/lint/anti-slop/rules/no-conditional-empty-object-spread.mjs +32 -0
  21. package/dist/lint/anti-slop/rules/no-known-value-widening.mjs +236 -0
  22. package/dist/lint/anti-slop/rules/no-module-mocking.mjs +48 -0
  23. package/dist/lint/anti-slop/rules/no-object-parameters.mjs +48 -0
  24. package/dist/lint/anti-slop/rules/no-reduce-accumulator-copy.mjs +85 -0
  25. package/dist/lint/anti-slop/rules/no-reflect-apply.mjs +21 -0
  26. package/dist/lint/anti-slop/rules/no-reflect-get.mjs +21 -0
  27. package/dist/lint/anti-slop/rules/no-runtime-typeof.mjs +52 -0
  28. package/dist/lint/anti-slop/rules/no-shape-in-symbol-names.mjs +36 -0
  29. package/dist/lint/anti-slop/rules/no-unknown-parameters.mjs +44 -0
  30. package/dist/lint/anti-slop/rules/no-unknown-returns.mjs +47 -0
  31. package/dist/lint/anti-slop/rules/no-unknown-type-aliases.mjs +33 -0
  32. package/dist/lint/anti-slop/rules/no-unsafe-dictionary-type.mjs +121 -0
  33. package/dist/lint/anti-slop/rules/no-widen-then-assert.mjs +191 -0
  34. package/dist/lint/anti-slop/rules/require-readable-spacing.mjs +86 -0
  35. package/dist/lint/anti-slop/rules/require-safety-comment-for-type-assertion.mjs +82 -0
  36. package/dist/lint/anti-slop/shared/array-method.mjs +70 -0
  37. package/dist/lint/anti-slop/shared/child-nodes.mjs +24 -0
  38. package/dist/lint/anti-slop/shared/dictionary-types.mjs +248 -0
  39. package/dist/lint/anti-slop/shared/function-parameters.mjs +25 -0
  40. package/dist/lint/anti-slop/shared/lexical-type-parameters.mjs +21 -0
  41. package/dist/lint/anti-slop/shared/reflect-method.mjs +16 -0
  42. package/dist/lint/anti-slop/shared/scope.mjs +12 -0
  43. package/dist/lint/anti-slop/shared/string-literal.mjs +6 -0
  44. package/dist/lint/anti-slop/shared/type-alias-resolution.mjs +134 -0
  45. package/dist/lint/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
  46. package/dist/lint/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +29 -0
  47. package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-ast.mjs +32 -0
  48. package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.mjs +608 -0
  49. package/dist/lint/config.d.mts +20 -0
  50. package/dist/lint/config.mjs +135 -0
  51. package/dist/lint/generic/effect-encoding.mjs +45 -0
  52. package/dist/lint/generic/entry-reexports.mjs +81 -0
  53. package/dist/lint/generic/env-at-entrypoints.mjs +65 -0
  54. package/dist/lint/generic/export-type-side-effects.mjs +22 -0
  55. package/dist/lint/generic/index-barrel.mjs +14 -0
  56. package/dist/lint/generic/log-messages.mjs +39 -0
  57. package/dist/lint/generic/plugin.d.mts +6 -0
  58. package/dist/lint/generic/plugin.mjs +26 -0
  59. package/dist/lint/generic/seeded-properties.mjs +78 -0
  60. package/dist/lint/plugins.d.mts +9 -0
  61. package/dist/lint/plugins.mjs +14 -0
  62. package/dist/lint/t3code/LICENSE +21 -0
  63. package/dist/lint/t3code/UPSTREAM.md +24 -0
  64. package/dist/lint/t3code/plugin.d.mts +2 -0
  65. package/dist/lint/t3code/plugin.mjs +20 -0
  66. package/dist/lint/t3code/rules/no-global-process-runtime.mjs +76 -0
  67. package/dist/lint/t3code/rules/no-inline-schema-compile.mjs +112 -0
  68. package/dist/lint/t3code/rules/no-manual-effect-runtime-in-tests.mjs +67 -0
  69. package/dist/lint/t3code/rules/no-native-title-tooltip.mjs +33 -0
  70. package/dist/lint/t3code/rules/no-test-in-loop.mjs +69 -0
  71. package/dist/lint/t3code/rules/no-unscoped-has.mjs +147 -0
  72. package/dist/lint/t3code/utils.mjs +21 -0
  73. package/package.json +52 -3
@@ -0,0 +1,76 @@
1
+ import { getPropertyName, isIdentifier, unwrapExpression } from "../utils.mjs";
2
+ import { defineRule } from "vite-plus/lint/plugins";
3
+ import * as Option from "effect/Option";
4
+ // src/lint/t3code/rules/no-global-process-runtime.ts
5
+ const RUNTIME_PROPERTIES = /* @__PURE__ */ new Set(["platform", "arch"]);
6
+ const NODE_OS_MODULES = /* @__PURE__ */ new Set(["node:os", "os"]);
7
+ const isGlobalProcessObject = (node) => {
8
+ const expression = unwrapExpression(node);
9
+ if (isIdentifier(expression, "process")) return true;
10
+ if (Option.isNone(expression) || expression.value.type !== "MemberExpression") return false;
11
+ const object = unwrapExpression(expression.value.object);
12
+ const property = getPropertyName(expression.value.property);
13
+ return isIdentifier(object, "globalThis") && Option.isSome(property) && property.value === "process";
14
+ };
15
+ const message = (property) => `Read process.${property} through an Effect service instead, and provide it explicitly in tests.`;
16
+ var no_global_process_runtime_default = defineRule({
17
+ meta: {
18
+ type: "problem",
19
+ docs: { description: "Disallow direct host runtime platform/architecture reads; read them through an Effect service." }
20
+ },
21
+ createOnce(context) {
22
+ const nodeOsNamespaces = /* @__PURE__ */ new Set();
23
+ const nodeOsRuntimeImports = /* @__PURE__ */ new Map();
24
+ const resetBindings = () => {
25
+ nodeOsNamespaces.clear();
26
+ nodeOsRuntimeImports.clear();
27
+ };
28
+ const trackImportDeclaration = (node) => {
29
+ if (!NODE_OS_MODULES.has(node.source.value)) return;
30
+ for (const specifier of node.specifiers) {
31
+ const localName = specifier.local.name;
32
+ if (specifier.type === "ImportNamespaceSpecifier" || specifier.type === "ImportDefaultSpecifier") {
33
+ nodeOsNamespaces.add(localName);
34
+ continue;
35
+ }
36
+ const imported = getPropertyName(specifier.imported);
37
+ if (Option.isSome(imported) && RUNTIME_PROPERTIES.has(imported.value)) nodeOsRuntimeImports.set(localName, imported.value);
38
+ }
39
+ };
40
+ const getNodeOsRuntimeCall = (callee) => {
41
+ const expression = unwrapExpression(callee);
42
+ if (Option.isNone(expression)) return Option.none();
43
+ if (expression.value.type === "Identifier") {
44
+ const property = nodeOsRuntimeImports.get(expression.value.name);
45
+ return property === void 0 ? Option.none() : Option.some(property);
46
+ }
47
+ if (expression.value.type !== "MemberExpression") return Option.none();
48
+ const object = unwrapExpression(expression.value.object);
49
+ if (Option.isNone(object) || object.value.type !== "Identifier") return Option.none();
50
+ if (!nodeOsNamespaces.has(object.value.name)) return Option.none();
51
+ return Option.filter(getPropertyName(expression.value.property), (property) => RUNTIME_PROPERTIES.has(property));
52
+ };
53
+ return {
54
+ before: resetBindings,
55
+ ImportDeclaration: trackImportDeclaration,
56
+ MemberExpression(node) {
57
+ const property = getPropertyName(node.property);
58
+ if (Option.isNone(property) || !RUNTIME_PROPERTIES.has(property.value)) return;
59
+ if (!isGlobalProcessObject(node.object)) return;
60
+ context.report({
61
+ node,
62
+ message: message(property.value)
63
+ });
64
+ },
65
+ CallExpression(node) {
66
+ const property = getNodeOsRuntimeCall(node.callee);
67
+ if (Option.isNone(property)) return;
68
+ context.report({
69
+ node,
70
+ message: message(property.value)
71
+ });
72
+ }
73
+ };
74
+ }
75
+ });
76
+ export { no_global_process_runtime_default as default };
@@ -0,0 +1,112 @@
1
+ import { getPropertyName, isIdentifier, unwrapExpression } from "../utils.mjs";
2
+ import { defineRule } from "vite-plus/lint/plugins";
3
+ import "effect/Schema";
4
+ import * as Option from "effect/Option";
5
+ // src/lint/t3code/rules/no-inline-schema-compile.ts
6
+ const COMPILER_METHODS = /* @__PURE__ */ new Set([
7
+ "is",
8
+ "asserts",
9
+ "decodeEffect",
10
+ "decodeExit",
11
+ "decodeOption",
12
+ "decodePromise",
13
+ "decodeResult",
14
+ "decodeSync",
15
+ "decodeUnknownExit",
16
+ "decodeUnknownEffect",
17
+ "decodeUnknownOption",
18
+ "decodeUnknownPromise",
19
+ "decodeUnknownResult",
20
+ "decodeUnknownSync",
21
+ "encodeExit",
22
+ "encodeEffect",
23
+ "encodeOption",
24
+ "encodePromise",
25
+ "encodeResult",
26
+ "encodeSync",
27
+ "encodeUnknownExit",
28
+ "encodeUnknownEffect",
29
+ "encodeUnknownOption",
30
+ "encodeUnknownPromise",
31
+ "encodeUnknownResult",
32
+ "encodeUnknownSync"
33
+ ]);
34
+ const getSchemaCompilerMethod = (callee) => {
35
+ const expression = unwrapExpression(callee);
36
+ if (Option.isNone(expression) || expression.value.type !== "MemberExpression") return Option.none();
37
+ const object = unwrapExpression(expression.value.object);
38
+ if (!isIdentifier(object, "Schema")) return Option.none();
39
+ return Option.filter(getPropertyName(expression.value.property), (method) => COMPILER_METHODS.has(method));
40
+ };
41
+ const isStaticSchemaReference = (node) => {
42
+ const expression = unwrapExpression(node);
43
+ if (Option.isNone(expression)) return false;
44
+ if (expression.value.type === "Identifier") {
45
+ const [firstChar] = expression.value.name;
46
+ return firstChar !== void 0 && firstChar.toUpperCase() === firstChar;
47
+ }
48
+ return expression.value.type === "MemberExpression";
49
+ };
50
+ const isNestedStaticSchemaCall = (node) => {
51
+ const expression = unwrapExpression(node);
52
+ if (Option.isNone(expression) || expression.value.type !== "CallExpression") return false;
53
+ const callee = unwrapExpression(expression.value.callee);
54
+ if (Option.isNone(callee) || callee.value.type !== "MemberExpression") return false;
55
+ const object = unwrapExpression(callee.value.object);
56
+ if (!isIdentifier(object, "Schema")) return false;
57
+ const method = getPropertyName(callee.value.property);
58
+ if (Option.isSome(method) && method.value === "fromJsonString") {
59
+ const firstArg = expression.value.arguments[0];
60
+ return isStaticSchemaReference(firstArg) || isNestedStaticSchemaCall(firstArg);
61
+ }
62
+ return true;
63
+ };
64
+ const isImmediatelyInvoked = (node) => {
65
+ const expression = unwrapExpression(node);
66
+ if (Option.isNone(expression)) return false;
67
+ const parent = unwrapExpression(expression.value.parent);
68
+ return Option.isSome(parent) && parent.value.type === "CallExpression" && unwrapExpression(parent.value.callee).pipe(Option.exists((callee) => callee === expression.value));
69
+ };
70
+ const messageHigh = (method) => `Hoist Schema.${method}(...) to module scope: both the inline schema literal and the compiled function are rebuilt on every call. Move the compiled function to a module-level const.`;
71
+ const messageMedium = (method) => `Hoist Schema.${method}(...) to module scope: the compiled function is rebuilt on every call. Move it to a module-level const.`;
72
+ var no_inline_schema_compile_default = defineRule({
73
+ meta: {
74
+ type: "problem",
75
+ docs: { description: "Disallow Schema decoder/encoder compiler calls inside function bodies; hoist them to module scope." }
76
+ },
77
+ createOnce(context) {
78
+ let functionDepth = 0;
79
+ const resetFunctionDepth = () => {
80
+ functionDepth = 0;
81
+ };
82
+ const enterFunction = () => {
83
+ functionDepth++;
84
+ };
85
+ const exitFunction = () => {
86
+ functionDepth--;
87
+ };
88
+ return {
89
+ before: resetFunctionDepth,
90
+ FunctionDeclaration: enterFunction,
91
+ "FunctionDeclaration:exit": exitFunction,
92
+ FunctionExpression: enterFunction,
93
+ "FunctionExpression:exit": exitFunction,
94
+ ArrowFunctionExpression: enterFunction,
95
+ "ArrowFunctionExpression:exit": exitFunction,
96
+ CallExpression(node) {
97
+ if (functionDepth === 0) return;
98
+ const method = getSchemaCompilerMethod(node.callee);
99
+ if (Option.isNone(method)) return;
100
+ if (!isImmediatelyInvoked(node)) return;
101
+ const firstArg = node.arguments[0];
102
+ const high = firstArg && isNestedStaticSchemaCall(firstArg);
103
+ if (!high && !isStaticSchemaReference(firstArg)) return;
104
+ context.report({
105
+ node: node.callee,
106
+ message: high ? messageHigh(method.value) : messageMedium(method.value)
107
+ });
108
+ }
109
+ };
110
+ }
111
+ });
112
+ export { no_inline_schema_compile_default as default };
@@ -0,0 +1,67 @@
1
+ import { getPropertyName, isIdentifier, unwrapExpression } from "../utils.mjs";
2
+ import { defineRule } from "vite-plus/lint/plugins";
3
+ import * as Schema from "effect/Schema";
4
+ import * as Option from "effect/Option";
5
+ // src/lint/t3code/rules/no-manual-effect-runtime-in-tests.ts
6
+ const TEST_FILE_PATTERN = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
7
+ const EFFECT_RUNTIME_METHODS = /* @__PURE__ */ new Set([
8
+ "runCallback",
9
+ "runCallbackWith",
10
+ "runFork",
11
+ "runForkWith",
12
+ "runPromise",
13
+ "runPromiseExit",
14
+ "runPromiseExitWith",
15
+ "runPromiseWith",
16
+ "runSync",
17
+ "runSyncExit",
18
+ "runSyncExitWith",
19
+ "runSyncWith"
20
+ ]);
21
+ const hasMaxOccurrences = Schema.is(Schema.Struct({ maxOccurrences: Schema.Number }));
22
+ const readMaxOccurrences = (options) => {
23
+ const [first] = options;
24
+ return hasMaxOccurrences(first) ? first.maxOccurrences : 0;
25
+ };
26
+ const manualRunnerName = (callee) => {
27
+ const expression = unwrapExpression(callee);
28
+ if (Option.isNone(expression) || expression.value.type !== "MemberExpression") return Option.none();
29
+ const object = unwrapExpression(expression.value.object);
30
+ const property = getPropertyName(expression.value.property);
31
+ if (Option.isNone(property)) return Option.none();
32
+ if (isIdentifier(object, "Effect") && EFFECT_RUNTIME_METHODS.has(property.value)) return Option.some(`Effect.${property.value}`);
33
+ if (isIdentifier(object, "ManagedRuntime") && property.value === "make") return Option.some("ManagedRuntime.make");
34
+ return Option.none();
35
+ };
36
+ var no_manual_effect_runtime_in_tests_default = defineRule({
37
+ meta: {
38
+ type: "problem",
39
+ docs: { description: "Disallow manually creating or running Effect runtimes in tests; use @effect/vitest." },
40
+ schema: [{
41
+ type: "object",
42
+ properties: { maxOccurrences: {
43
+ type: "integer",
44
+ minimum: 0,
45
+ description: "Legacy debt ceiling for this file: occurrences beyond this count are reported."
46
+ } },
47
+ additionalProperties: false
48
+ }],
49
+ defaultOptions: [{ maxOccurrences: 0 }]
50
+ },
51
+ create(context) {
52
+ if (!TEST_FILE_PATTERN.test(context.filename)) return {};
53
+ const allowedCount = readMaxOccurrences(context.options);
54
+ let occurrenceCount = 0;
55
+ return { CallExpression(node) {
56
+ const runner = manualRunnerName(node.callee);
57
+ if (Option.isNone(runner)) return;
58
+ occurrenceCount++;
59
+ if (occurrenceCount <= allowedCount) return;
60
+ context.report({
61
+ node: node.callee,
62
+ message: `Do not use ${runner.value} in tests. Use @effect/vitest with it.effect(...) and test layers instead.`
63
+ });
64
+ } };
65
+ }
66
+ });
67
+ export { no_manual_effect_runtime_in_tests_default as default };
@@ -0,0 +1,33 @@
1
+ import { defineRule } from "vite-plus/lint/plugins";
2
+ // src/lint/t3code/rules/no-native-title-tooltip.ts
3
+ const INTRINSIC_ELEMENT_PATTERN = /^[a-z]/u;
4
+ const TITLE_IS_AN_ACCESSIBLE_NAME = /* @__PURE__ */ new Set([
5
+ "embed",
6
+ "frame",
7
+ "iframe",
8
+ "math",
9
+ "object"
10
+ ]);
11
+ var no_native_title_tooltip_default = defineRule({
12
+ meta: {
13
+ type: "problem",
14
+ docs: { description: "Disallow the native title attribute as a tooltip on intrinsic elements; use the styled Tooltip component." }
15
+ },
16
+ create(context) {
17
+ return { JSXOpeningElement(node) {
18
+ if (node.name.type !== "JSXIdentifier") return;
19
+ if (!INTRINSIC_ELEMENT_PATTERN.test(node.name.name)) return;
20
+ if (TITLE_IS_AN_ACCESSIBLE_NAME.has(node.name.name)) return;
21
+ for (const attribute of node.attributes) {
22
+ if (attribute.type !== "JSXAttribute") continue;
23
+ if (attribute.name.type !== "JSXIdentifier") continue;
24
+ if (attribute.name.name !== "title") continue;
25
+ context.report({
26
+ node: attribute,
27
+ message: "Do not use the native title attribute as a tooltip. Use the Tooltip component from components/ui/tooltip."
28
+ });
29
+ }
30
+ } };
31
+ }
32
+ });
33
+ export { no_native_title_tooltip_default as default };
@@ -0,0 +1,69 @@
1
+ import { getPropertyName, unwrapExpression } from "../utils.mjs";
2
+ import { defineRule } from "vite-plus/lint/plugins";
3
+ import * as Option from "effect/Option";
4
+ // src/lint/t3code/rules/no-test-in-loop.ts
5
+ const TEST_FILE_PATTERN = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
6
+ const NODE_TEST_IMPORT_PATTERN = /["']node:test["']/u;
7
+ const TEST_FUNCTIONS = /* @__PURE__ */ new Set([
8
+ "describe",
9
+ "it",
10
+ "suite",
11
+ "test"
12
+ ]);
13
+ const EACH_CAPABLE_MODIFIERS = /* @__PURE__ */ new Set(["effect", "live"]);
14
+ const LOOPS = /* @__PURE__ */ new Set([
15
+ "ForStatement",
16
+ "ForInStatement",
17
+ "ForOfStatement"
18
+ ]);
19
+ const FUNCTIONS = /* @__PURE__ */ new Set([
20
+ "ArrowFunctionExpression",
21
+ "FunctionExpression",
22
+ "FunctionDeclaration"
23
+ ]);
24
+ /** Returns the reported name for `it(…)`, `describe(…)`, `it.effect(…)`, and friends. */
25
+ const testCallName = (callee) => {
26
+ const expression = unwrapExpression(callee);
27
+ if (Option.isNone(expression)) return Option.none();
28
+ if (expression.value.type === "Identifier") return TEST_FUNCTIONS.has(expression.value.name) ? Option.some(expression.value.name) : Option.none();
29
+ if (expression.value.type !== "MemberExpression") return Option.none();
30
+ const object = unwrapExpression(expression.value.object);
31
+ const property = getPropertyName(expression.value.property);
32
+ if (Option.isNone(object) || Option.isNone(property)) return Option.none();
33
+ if (!EACH_CAPABLE_MODIFIERS.has(property.value)) return Option.none();
34
+ if (object.value.type !== "Identifier" || !TEST_FUNCTIONS.has(object.value.name)) return Option.none();
35
+ return Option.some(`${object.value.name}.${property.value}`);
36
+ };
37
+ /**
38
+ * Reports a test declaration that runs once per loop iteration. A loop around a
39
+ * `describe` is reported on the `describe`, so the tests inside it stay quiet.
40
+ */
41
+ const isInsideLoop = (node) => {
42
+ let current = node.parent;
43
+ while (current) {
44
+ if (LOOPS.has(current.type)) return true;
45
+ if (FUNCTIONS.has(current.type)) return false;
46
+ current = current.parent;
47
+ }
48
+ return false;
49
+ };
50
+ var no_test_in_loop_default = defineRule({
51
+ meta: {
52
+ type: "suggestion",
53
+ docs: { description: "Disallow declaring tests inside a for loop; use it.each / it.effect.each / describe.each instead." }
54
+ },
55
+ create(context) {
56
+ if (!TEST_FILE_PATTERN.test(context.filename)) return {};
57
+ if (NODE_TEST_IMPORT_PATTERN.test(context.sourceCode.text)) return {};
58
+ return { CallExpression(node) {
59
+ const name = testCallName(node.callee);
60
+ if (Option.isNone(name)) return;
61
+ if (!isInsideLoop(node)) return;
62
+ context.report({
63
+ node: node.callee,
64
+ message: `Do not call ${name.value}(…) inside a for loop. Use ${name.value}.each(cases)(name, …) instead.`
65
+ });
66
+ } };
67
+ }
68
+ });
69
+ export { no_test_in_loop_default as default };
@@ -0,0 +1,147 @@
1
+ import { isString } from "../utils.mjs";
2
+ import { defineRule } from "vite-plus/lint/plugins";
3
+ // src/lint/t3code/rules/no-unscoped-has.ts
4
+ const COMBINATOR_PATTERN = /[\s>+~]/u;
5
+ const NARROWING_PATTERN = /[.#[]|^[a-z]/iu;
6
+ const ROOT_COMPOUND_PATTERN = /^(?:html|body|:root)(?![\w-])/iu;
7
+ const GROUP_PREFIX_PATTERN = /(?:^|:)(?:group|peer)-$/u;
8
+ const ANCESTOR_PREFIX_PATTERN = /(?:^|:)in-$/u;
9
+ const ATTRIBUTE_PREFIX_PATTERN = /(?:^|:)(?:data|aria)-$/u;
10
+ const QUOTED_PATTERN = /(["'])(?:\\.|(?!\1).)*\1/gu;
11
+ const VARIANT_END_PATTERN = /^(?:\/[\w-]+)?:/u;
12
+ /** Tailwind arbitrary variants in a class token: top-level `[...]` groups used as variants. */
13
+ function variantGroups(token) {
14
+ const groups = [];
15
+ let depth = 0;
16
+ let start = -1;
17
+ for (let index = 0; index < token.length; index++) {
18
+ const char = token[index];
19
+ if (char === "[") {
20
+ if (depth === 0) start = index + 1;
21
+ depth++;
22
+ } else if (char === "]" && depth > 0) {
23
+ depth--;
24
+ if (depth === 0 && VARIANT_END_PATTERN.test(token.slice(index + 1))) groups.push({
25
+ prefix: token.slice(0, start - 1),
26
+ group: token.slice(start, index)
27
+ });
28
+ }
29
+ }
30
+ return groups;
31
+ }
32
+ /** Index of the ")" closing the "(" at `open`, or the selector's length. */
33
+ function closingParen(selector, open) {
34
+ let depth = 0;
35
+ for (let index = open; index < selector.length; index++) if (selector[index] === "(") depth++;
36
+ else if (selector[index] === ")" && --depth === 0) return index;
37
+ return selector.length;
38
+ }
39
+ /**
40
+ * Whether nothing after `from` in the enclosing branch is joined by a combinator,
41
+ * i.e. the element ending at `from` is the subject that its wrapper matches.
42
+ */
43
+ function isWrapperSubject(selector, from) {
44
+ let depth = 0;
45
+ for (let index = from; index < selector.length; index++) {
46
+ const char = selector[index] ?? "";
47
+ if (char === "(") depth++;
48
+ else if (char === ")") {
49
+ if (depth === 0) return true;
50
+ depth--;
51
+ } else if (depth > 0) continue;
52
+ else if (char === ",") return true;
53
+ else if (COMBINATOR_PATTERN.test(char)) {
54
+ const next = selector.slice(index).trimStart()[0];
55
+ if (/\s/u.test(char) && (next === void 0 || next === ")" || next === ",")) continue;
56
+ return false;
57
+ }
58
+ }
59
+ return true;
60
+ }
61
+ /** The compound selector each `:has(` in `selector` is attached to. */
62
+ function hasCompounds(selector) {
63
+ const compounds = [];
64
+ let index = selector.indexOf(":has(");
65
+ while (index !== -1) {
66
+ let compound = "";
67
+ let depth = 0;
68
+ let subjectEnd = closingParen(selector, index + 4) + 1;
69
+ let skippingBranch = false;
70
+ for (let position = index - 1; position >= 0; position--) {
71
+ const char = selector[position] ?? "";
72
+ if (char === ")") depth++;
73
+ else if (char === "(") {
74
+ if (depth > 0) depth--;
75
+ else {
76
+ if (!isWrapperSubject(selector, subjectEnd)) break;
77
+ skippingBranch = false;
78
+ subjectEnd = closingParen(selector, position) + 1;
79
+ }
80
+ } else if (depth === 0 && char === ",") {
81
+ skippingBranch = true;
82
+ continue;
83
+ } else if (depth === 0 && !skippingBranch && COMBINATOR_PATTERN.test(char)) break;
84
+ if (!skippingBranch) compound = char + compound;
85
+ }
86
+ compounds.push(compound);
87
+ index = selector.indexOf(":has(", index + 1);
88
+ }
89
+ return compounds;
90
+ }
91
+ /** `compound` without any `:not(...)`, including one left open around the `:has()`. */
92
+ function withoutNegations(compound) {
93
+ let result = "";
94
+ let index = 0;
95
+ while (index < compound.length) {
96
+ if (!compound.startsWith(":not(", index)) {
97
+ result += compound[index];
98
+ index++;
99
+ continue;
100
+ }
101
+ let depth = 0;
102
+ for (index += 4; index < compound.length; index++) if (compound[index] === "(") depth++;
103
+ else if (compound[index] === ")" && --depth === 0) break;
104
+ index++;
105
+ }
106
+ return result;
107
+ }
108
+ /** Arbitrary variants in `text` whose `:has()` is unanchored or anchored to the document root. */
109
+ function findUnscopedHasVariants(text) {
110
+ if (!text.toLowerCase().includes(":has(")) return [];
111
+ const offenders = [];
112
+ for (const token of text.split(/\s+/u)) for (const { prefix, group } of variantGroups(token)) {
113
+ if (ATTRIBUTE_PREFIX_PATTERN.test(prefix)) continue;
114
+ const relative = group.toLowerCase().replace(QUOTED_PATTERN, "\"\"").replaceAll("_", " ");
115
+ const owner = GROUP_PREFIX_PATTERN.test(prefix) ? ".group" : ".self";
116
+ if (hasCompounds(ANCESTOR_PREFIX_PATTERN.test(prefix) ? `:is(${relative.replaceAll("&", "*")}) .self` : relative.includes("&") ? relative.replaceAll("&", owner) : `${owner}:is(${relative})`).some((compound) => {
117
+ const anchor = withoutNegations(compound);
118
+ return !NARROWING_PATTERN.test(anchor) || ROOT_COMPOUND_PATTERN.test(anchor);
119
+ })) offenders.push(`[${group}]`);
120
+ }
121
+ return offenders;
122
+ }
123
+ var no_unscoped_has_default = defineRule({
124
+ meta: {
125
+ type: "problem",
126
+ docs: { description: "Disallow Tailwind arbitrary variants with a :has() that is not anchored to a class, attribute, id, or tag." }
127
+ },
128
+ create(context) {
129
+ const message = (variant) => `Anchor the :has() in ${variant} to a class, attribute, or tag below the document root, e.g. [&+[data-x]_…] or a has-* variant. Chrome evaluates an unanchored :has() on every ancestor, so any DOM change then restyles the whole page.`;
130
+ return {
131
+ Literal(node) {
132
+ if (!isString(node.value)) return;
133
+ for (const variant of findUnscopedHasVariants(node.value)) context.report({
134
+ node,
135
+ message: message(variant)
136
+ });
137
+ },
138
+ TemplateElement(node) {
139
+ for (const variant of findUnscopedHasVariants(node.value.cooked ?? node.value.raw)) context.report({
140
+ node,
141
+ message: message(variant)
142
+ });
143
+ }
144
+ };
145
+ }
146
+ });
147
+ export { no_unscoped_has_default as default };
@@ -0,0 +1,21 @@
1
+ import * as Schema from "effect/Schema";
2
+ import * as Option from "effect/Option";
3
+ // src/lint/t3code/utils.ts
4
+ const isString = Schema.is(Schema.String);
5
+ const isExpressionWrapper = (node) => node.type === "ChainExpression" || node.type === "ParenthesizedExpression" || node.type === "TSNonNullExpression" || node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
6
+ function unwrapExpression(node) {
7
+ let current = Option.fromNullishOr(node);
8
+ while (Option.isSome(current) && isExpressionWrapper(current.value)) current = Option.some(current.value.expression);
9
+ return current;
10
+ }
11
+ function getPropertyName(node) {
12
+ if (node.type === "Identifier" || node.type === "PrivateIdentifier") return Option.some(node.name);
13
+ if (node.type === "Literal" && isString(node.value)) return Option.some(node.value);
14
+ return Option.none();
15
+ }
16
+ function isIdentifier(node, name) {
17
+ if (Option.isNone(node)) return false;
18
+ const expression = node.value;
19
+ return expression.type === "Identifier" && (name === void 0 || expression.name === name);
20
+ }
21
+ export { getPropertyName, isIdentifier, isString, unwrapExpression };
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@ref0/workspace",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "The lint and workspace checks every ref-0 repo shares",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/ref-0/home.git",
9
+ "directory": "packages/workspace"
10
+ },
11
+ "bin": {
12
+ "ref0-workspace": "./dist/bin.mjs"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "!dist/**/*.test.*",
17
+ "!dist/**/fixtures",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "type": "module",
22
+ "sideEffects": false,
23
+ "exports": {
24
+ "./lint/config": {
25
+ "types": "./dist/lint/config.d.mts",
26
+ "import": "./dist/lint/config.mjs"
27
+ },
28
+ "./lint/plugins": {
29
+ "types": "./dist/lint/plugins.d.mts",
30
+ "import": "./dist/lint/plugins.mjs"
31
+ }
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "dependencies": {
37
+ "effect": "4.1.2"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "24.19.2",
41
+ "typescript": "7.0.2",
42
+ "vite-plus": "1.5.0"
43
+ },
44
+ "peerDependencies": {
45
+ "vite-plus": "1.5.0"
46
+ },
47
+ "engines": {
48
+ "node": ">=24"
49
+ },
50
+ "scripts": {
51
+ "build": "vp pack",
52
+ "test": "vp test run src",
53
+ "test:pack": "vp test run test/consumer.test.ts"
54
+ }
6
55
  }