@autotelic/plumb 0.3.1

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 (94) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +64 -0
  3. package/package.json +41 -0
  4. package/src/effect/index.ts +59 -0
  5. package/src/effect/rules/guarded-op-must-return-effect.ts +236 -0
  6. package/src/effect/rules/guarded-op-must-return-option.ts +97 -0
  7. package/src/effect/rules/no-cascading-layer-provide.ts +80 -0
  8. package/src/effect/rules/no-decode-unknown-option.ts +41 -0
  9. package/src/effect/rules/no-direct-browser-storage.ts +91 -0
  10. package/src/effect/rules/no-direct-fetch.ts +44 -0
  11. package/src/effect/rules/no-manual-field-guards.ts +144 -0
  12. package/src/effect/rules/no-nested-layer-provide.ts +51 -0
  13. package/src/effect/rules/no-schema-class-modeling.ts +59 -0
  14. package/src/effect/rules/no-service-constructor-imports.ts +50 -0
  15. package/src/effect/rules/no-silent-error-swallow.ts +99 -0
  16. package/src/effect/rules/no-static-effect-service-forwarders.ts +227 -0
  17. package/src/effect/rules/no-try-catch.ts +32 -0
  18. package/src/effect/rules/no-unguarded-json-parse.ts +211 -0
  19. package/src/effect/rules/option-core-needs-effect-public.ts +81 -0
  20. package/src/effect/rules/prefer-die-for-precondition-defects.ts +118 -0
  21. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +76 -0
  22. package/src/effect/rules/prefer-effect-match.ts +78 -0
  23. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +79 -0
  24. package/src/effect/rules/prefer-named-guard-predicate.ts +105 -0
  25. package/src/effect/rules/prefer-option-pipeline.ts +95 -0
  26. package/src/effect/rules/prefer-ordering-match.ts +152 -0
  27. package/src/effect/rules/prefer-tagged-enum.ts +68 -0
  28. package/src/effect/rules/require-schema-type-derivation.ts +83 -0
  29. package/src/index.ts +106 -0
  30. package/src/meta/index.ts +25 -0
  31. package/src/meta/rules/no-disable-directives.ts +38 -0
  32. package/src/meta/rules/no-manual-ancestor-walks.ts +27 -0
  33. package/src/meta/rules/prefer-before-file-scope.ts +57 -0
  34. package/src/meta/rules/require-create-once.ts +51 -0
  35. package/src/meta/rules/require-rule-tester.ts +57 -0
  36. package/src/rules/no-anonymous-wide-tuples.ts +38 -0
  37. package/src/rules/no-barrel-export-star.ts +30 -0
  38. package/src/rules/no-boolean-field-signals.ts +305 -0
  39. package/src/rules/no-builtin-throws.ts +83 -0
  40. package/src/rules/no-chained-type-assertions.ts +65 -0
  41. package/src/rules/no-conditional-empty-object-spread.ts +42 -0
  42. package/src/rules/no-duplicated-literal-union.ts +66 -0
  43. package/src/rules/no-exported-mutable-state.ts +111 -0
  44. package/src/rules/no-generic-export-names.ts +149 -0
  45. package/src/rules/no-impossible-branch-throw.ts +55 -0
  46. package/src/rules/no-known-value-widening.ts +225 -0
  47. package/src/rules/no-module-mocking.ts +95 -0
  48. package/src/rules/no-multiple-function-params.ts +192 -0
  49. package/src/rules/no-nondeterministic-core.ts +73 -0
  50. package/src/rules/no-object-parameters.ts +127 -0
  51. package/src/rules/no-optional-function-parameters.ts +49 -0
  52. package/src/rules/no-product-of-state-booleans.ts +80 -0
  53. package/src/rules/no-redundant-derived-field.ts +192 -0
  54. package/src/rules/no-reflect-apply.ts +32 -0
  55. package/src/rules/no-reflect-get.ts +32 -0
  56. package/src/rules/no-reinterpret-cast.ts +78 -0
  57. package/src/rules/no-runtime-typeof.ts +59 -0
  58. package/src/rules/no-sentinel-comparison-union.ts +148 -0
  59. package/src/rules/no-shape-in-symbol-names.ts +45 -0
  60. package/src/rules/no-single-use-private-functions.ts +329 -0
  61. package/src/rules/no-stacked-jsdoc-blocks.ts +65 -0
  62. package/src/rules/no-stray-inline-comments.ts +79 -0
  63. package/src/rules/no-swappable-primitive-params.ts +109 -0
  64. package/src/rules/no-tag-ladder-assertions.ts +71 -0
  65. package/src/rules/no-transposed-field-reads.ts +135 -0
  66. package/src/rules/no-unit-return-validators.ts +65 -0
  67. package/src/rules/no-unknown-parameters.ts +97 -0
  68. package/src/rules/no-unknown-returns.ts +120 -0
  69. package/src/rules/no-unknown-type-aliases.ts +70 -0
  70. package/src/rules/no-unsafe-dictionary-type.ts +132 -0
  71. package/src/rules/no-vague-test-filenames.ts +67 -0
  72. package/src/rules/no-widen-then-assert.ts +345 -0
  73. package/src/rules/prefer-payload-brand.ts +67 -0
  74. package/src/rules/prefer-property-tests.ts +43 -0
  75. package/src/rules/require-canonical-stringify-for-identity.ts +80 -0
  76. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +45 -0
  77. package/src/rules/require-exhaustive-tag-switch.ts +42 -0
  78. package/src/rules/require-fc-block-predicate.ts +42 -0
  79. package/src/rules/require-jsdoc-on-exported.ts +74 -0
  80. package/src/rules/require-published-order.ts +109 -0
  81. package/src/rules/require-safety-comment-for-type-assertion.ts +61 -0
  82. package/src/rules/require-sort-comparator.ts +41 -0
  83. package/src/rules/test-utils.ts +68 -0
  84. package/src/shared/ancestors.ts +21 -0
  85. package/src/shared/child-nodes.ts +27 -0
  86. package/src/shared/dictionary-types.ts +524 -0
  87. package/src/shared/is-node.ts +13 -0
  88. package/src/shared/lexical-type-parameters.ts +62 -0
  89. package/src/shared/reflect-method.ts +41 -0
  90. package/src/shared/rule-options.ts +23 -0
  91. package/src/shared/structural.ts +81 -0
  92. package/src/testing/index.ts +3 -0
  93. package/src/testing/testable-rule.test.ts +68 -0
  94. package/src/testing/testable-rule.ts +86 -0
@@ -0,0 +1,83 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+
5
+ const STRUCT_PROPERTIES = new Set(["Struct", "TaggedStruct"]);
6
+
7
+ /**
8
+ * Whether an expression calls `Schema.struct`/`Schema.fields` on a schema-ish object.
9
+ *
10
+ * @param {ESTree.Expression | ESTree.SpreadElement | null} expression - The candidate call expression.
11
+ * @returns {boolean} True when the expression is a schema struct-style call.
12
+ */
13
+ function isSchemaStructCall(expression: ESTree.Expression | ESTree.SpreadElement | null): boolean {
14
+ if (expression === null || expression.type !== "CallExpression") return false;
15
+ const callee = expression.callee;
16
+ if (callee.type !== "MemberExpression" || callee.computed) return false;
17
+ if (callee.property.type !== "Identifier" || !STRUCT_PROPERTIES.has(callee.property.name)) return false;
18
+ const object = callee.object;
19
+ return (
20
+ object.type === "Identifier" && /schema$/iu.test(object.name)
21
+ );
22
+ }
23
+
24
+ /** Fold a declared name to its stem so `RationalSchema`/`rational` and `rationalSchema` collide.
25
+ *
26
+ * @param {string} name - The declared name to fold.
27
+ * @returns {string} The case-insensitive comparison stem.
28
+ */
29
+ function normaliseName(name: string): string {
30
+ const folded = name.replaceAll(/[^a-zA-Z0-9]/gu, "").toLowerCase();
31
+ return folded.endsWith("schema") ? folded.slice(0, -6) : folded;
32
+ }
33
+
34
+ /**
35
+ * Single source of truth: once a Schema exists, it is the canonical shape.
36
+ * A hand-written twin type drifts from it silently: derive the static side
37
+ * with `Schema.Type<typeof x>` so identical data can only have one declared
38
+ * form.
39
+ */
40
+ export const requireSchemaTypeDerivationRule = defineRule({
41
+ meta: {
42
+ type: "problem",
43
+ docs: {
44
+ description:
45
+ "Require static types paired with an Effect Schema to be derived via Schema.Type<typeof schema> instead of re-declaring the shape by hand.",
46
+ },
47
+ messages: {
48
+ handWrittenTwin:
49
+ "`{{name}}` re-declares the shape of `{{schema}}` by hand, giving the data two sources of truth that drift. Derive it as `Schema.Type<typeof {{schema}}>` (or rename if unrelated).",
50
+ },
51
+ },
52
+ createOnce(context) {
53
+ const schemas = new Map<string, string>();
54
+ const typeAliases = new Map<string, { node: ESTree.Node; name: string }>();
55
+
56
+ return {
57
+ VariableDeclarator(node) {
58
+ if (node.id.type !== "Identifier" || node.init === null || node.init === undefined) return;
59
+ if (!isSchemaStructCall(node.init)) return;
60
+ schemas.set(normaliseName(node.id.name), node.id.name);
61
+ },
62
+ TSTypeAliasDeclaration(node) {
63
+ if (node.typeAnnotation.type !== "TSTypeLiteral") return;
64
+ typeAliases.set(normaliseName(node.id.name), { node, name: node.id.name });
65
+ },
66
+ TSInterfaceDeclaration(node) {
67
+ if (node.id.type !== "Identifier") return;
68
+ typeAliases.set(normaliseName(node.id.name), { node, name: node.id.name });
69
+ },
70
+ "Program:exit"() {
71
+ for (const [stem, alias] of typeAliases) {
72
+ const schema = schemas.get(stem);
73
+ if (schema === undefined) continue;
74
+ context.report({
75
+ node: alias.node,
76
+ messageId: "handWrittenTwin",
77
+ data: { name: alias.name, schema },
78
+ });
79
+ }
80
+ },
81
+ };
82
+ },
83
+ });
package/src/index.ts ADDED
@@ -0,0 +1,106 @@
1
+ import { eslintCompatPlugin } from "@oxlint/plugins";
2
+
3
+ import { preferPropertyTestsRule } from "./rules/prefer-property-tests.ts";
4
+
5
+ import { noChainedTypeAssertionsRule } from "./rules/no-chained-type-assertions.ts";
6
+ import { noConditionalEmptyObjectSpreadRule } from "./rules/no-conditional-empty-object-spread.ts";
7
+ import { noBooleanFieldSignalsRule } from "./rules/no-boolean-field-signals.ts";
8
+ import { noImpossibleBranchThrowRule } from "./rules/no-impossible-branch-throw.ts";
9
+ import { noKnownValueWideningRule } from "./rules/no-known-value-widening.ts";
10
+ import { noModuleMockingRule } from "./rules/no-module-mocking.ts";
11
+ import { noObjectParametersRule } from "./rules/no-object-parameters.ts";
12
+ import { noReinterpretCastRule } from "./rules/no-reinterpret-cast.ts";
13
+ import { preferPayloadBrandRule } from "./rules/prefer-payload-brand.ts";
14
+ import { noProductOfStateBooleansRule } from "./rules/no-product-of-state-booleans.ts";
15
+ import { noReflectApplyRule } from "./rules/no-reflect-apply.ts";
16
+ import { requireFcBlockPredicateRule } from "./rules/require-fc-block-predicate.ts";
17
+ import { requireJsdocOnExportedRule } from "./rules/require-jsdoc-on-exported.ts";
18
+ import { requirePublishedOrderRule } from "./rules/require-published-order.ts";
19
+ import { noReflectGetRule } from "./rules/no-reflect-get.ts";
20
+ import { noRuntimeTypeofRule } from "./rules/no-runtime-typeof.ts";
21
+ import { noSentinelComparisonUnionRule } from "./rules/no-sentinel-comparison-union.ts";
22
+ import { noStackedJsdocBlocksRule } from "./rules/no-stacked-jsdoc-blocks.ts";
23
+ import { noForbiddenTermInSymbolNamesRule } from "./rules/no-shape-in-symbol-names.ts";
24
+ import { noUnitReturnValidatorsRule } from "./rules/no-unit-return-validators.ts";
25
+ import { noUnknownParametersRule } from "./rules/no-unknown-parameters.ts";
26
+ import { noUnknownReturnsRule } from "./rules/no-unknown-returns.ts";
27
+ import { noUnknownTypeAliasesRule } from "./rules/no-unknown-type-aliases.ts";
28
+ import { noUnsafeDictionaryTypeRule } from "./rules/no-unsafe-dictionary-type.ts";
29
+ import { noStrayInlineCommentsRule } from "./rules/no-stray-inline-comments.ts";
30
+ import { noWidenThenAssertRule } from "./rules/no-widen-then-assert.ts";
31
+ import { requireSafetyCommentForTypeAssertionRule } from "./rules/require-safety-comment-for-type-assertion.ts";
32
+ import { requireSortComparatorRule } from "./rules/require-sort-comparator.ts";
33
+ import { noGenericExportNamesRule } from "./rules/no-generic-export-names.ts";
34
+ import { noBarrelExportStarRule } from "./rules/no-barrel-export-star.ts";
35
+ import { requireDeprecatedTagForLegacyCommentsRule } from "./rules/require-deprecated-tag-for-legacy-comments.ts";
36
+ import { noVagueTestFilenamesRule } from "./rules/no-vague-test-filenames.ts";
37
+ import { noSwappablePrimitiveParamsRule } from "./rules/no-swappable-primitive-params.ts";
38
+ import { noTransposedFieldReadsRule } from "./rules/no-transposed-field-reads.ts";
39
+ import { noBuiltinThrowsRule } from "./rules/no-builtin-throws.ts";
40
+ import { noNondeterministicCoreRule } from "./rules/no-nondeterministic-core.ts";
41
+ import { noExportedMutableStateRule } from "./rules/no-exported-mutable-state.ts";
42
+ import { noDuplicatedLiteralUnionRule } from "./rules/no-duplicated-literal-union.ts";
43
+ import { requireCanonicalStringifyForIdentityRule } from "./rules/require-canonical-stringify-for-identity.ts";
44
+ import { noAnonymousWideTuplesRule } from "./rules/no-anonymous-wide-tuples.ts";
45
+ import { noTagLadderAssertionsRule } from "./rules/no-tag-ladder-assertions.ts";
46
+ import { noRedundantDerivedFieldRule } from "./rules/no-redundant-derived-field.ts";
47
+ import { requireExhaustiveTagSwitchRule } from "./rules/require-exhaustive-tag-switch.ts";
48
+ import { noMultipleFunctionParamsRule } from "./rules/no-multiple-function-params.ts";
49
+ import { noOptionalFunctionParametersRule } from "./rules/no-optional-function-parameters.ts";
50
+ import { noSingleUsePrivateFunctionsRule } from "./rules/no-single-use-private-functions.ts";
51
+
52
+ /** Generic Oxlint rules that reject low-evidence and low-signal implementation patterns. */
53
+ const plumbPlugin = eslintCompatPlugin({
54
+ meta: { name: "plumb" },
55
+ rules: {
56
+ "no-chained-type-assertions": noChainedTypeAssertionsRule,
57
+ "no-boolean-field-signals": noBooleanFieldSignalsRule,
58
+ "no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
59
+ "no-impossible-branch-throw": noImpossibleBranchThrowRule,
60
+ "no-known-value-widening": noKnownValueWideningRule,
61
+ "no-module-mocking": noModuleMockingRule,
62
+ "no-object-parameters": noObjectParametersRule,
63
+ "no-reinterpret-cast": noReinterpretCastRule,
64
+ "prefer-payload-brand": preferPayloadBrandRule,
65
+ "no-product-of-state-booleans": noProductOfStateBooleansRule,
66
+ "no-reflect-apply": noReflectApplyRule,
67
+ "require-published-order": requirePublishedOrderRule,
68
+ "no-reflect-get": noReflectGetRule,
69
+ "no-runtime-typeof": noRuntimeTypeofRule,
70
+ "no-sentinel-comparison-union": noSentinelComparisonUnionRule,
71
+ "no-stacked-jsdoc-blocks": noStackedJsdocBlocksRule,
72
+ "no-stray-inline-comments": noStrayInlineCommentsRule,
73
+ "no-unit-return-validators": noUnitReturnValidatorsRule,
74
+ "no-unsafe-dictionary-type": noUnsafeDictionaryTypeRule,
75
+ "no-shape-in-symbol-names": noForbiddenTermInSymbolNamesRule,
76
+ "no-unknown-parameters": noUnknownParametersRule,
77
+ "no-unknown-returns": noUnknownReturnsRule,
78
+ "no-unknown-type-aliases": noUnknownTypeAliasesRule,
79
+ "no-widen-then-assert": noWidenThenAssertRule,
80
+ "require-fc-block-predicate": requireFcBlockPredicateRule,
81
+ "require-jsdoc-on-exported": requireJsdocOnExportedRule,
82
+ "require-safety-comment-for-type-assertion": requireSafetyCommentForTypeAssertionRule,
83
+ "require-sort-comparator": requireSortComparatorRule,
84
+ "no-generic-export-names": noGenericExportNamesRule,
85
+ "no-barrel-export-star": noBarrelExportStarRule,
86
+ "require-deprecated-tag-for-legacy-comments": requireDeprecatedTagForLegacyCommentsRule,
87
+ "no-vague-test-filenames": noVagueTestFilenamesRule,
88
+ "no-swappable-primitive-params": noSwappablePrimitiveParamsRule,
89
+ "no-transposed-field-reads": noTransposedFieldReadsRule,
90
+ "no-builtin-throws": noBuiltinThrowsRule,
91
+ "no-nondeterministic-core": noNondeterministicCoreRule,
92
+ "no-exported-mutable-state": noExportedMutableStateRule,
93
+ "no-tag-ladder-assertions": noTagLadderAssertionsRule,
94
+ "no-anonymous-wide-tuples": noAnonymousWideTuplesRule,
95
+ "no-duplicated-literal-union": noDuplicatedLiteralUnionRule,
96
+ "require-canonical-stringify-for-identity": requireCanonicalStringifyForIdentityRule,
97
+ "no-redundant-derived-field": noRedundantDerivedFieldRule,
98
+ "require-exhaustive-tag-switch": requireExhaustiveTagSwitchRule,
99
+ "prefer-property-tests": preferPropertyTestsRule,
100
+ "no-multiple-function-params": noMultipleFunctionParamsRule,
101
+ "no-optional-function-parameters": noOptionalFunctionParametersRule,
102
+ "no-single-use-private-functions": noSingleUsePrivateFunctionsRule,
103
+ },
104
+ });
105
+
106
+ export default plumbPlugin;
@@ -0,0 +1,25 @@
1
+ import { eslintCompatPlugin } from "@oxlint/plugins";
2
+
3
+ import { noDisableDirectivesRule } from "./rules/no-disable-directives.ts";
4
+ import { noManualAncestorWalksRule } from "./rules/no-manual-ancestor-walks.ts";
5
+ import { preferBeforeFileScopeRule } from "./rules/prefer-before-file-scope.ts";
6
+ import { requireCreateOnceRule } from "./rules/require-create-once.ts";
7
+ import { requireRuleTesterRule } from "./rules/require-rule-tester.ts";
8
+
9
+ /**
10
+ * Meta-rules that keep rule authorship itself idiomatic (createOnce API, engine-native
11
+ * traversal, RuleTester suites, property-based coverage). Opt-in: only meaningful in
12
+ * lint-plugin codebases, so consumers enable `plumb-meta` deliberately.
13
+ */
14
+ const plumbMetaPlugin = eslintCompatPlugin({
15
+ meta: { name: "plumb-meta" },
16
+ rules: {
17
+ "no-disable-directives": noDisableDirectivesRule,
18
+ "no-manual-ancestor-walks": noManualAncestorWalksRule,
19
+ "prefer-before-file-scope": preferBeforeFileScopeRule,
20
+ "require-create-once": requireCreateOnceRule,
21
+ "require-rule-tester": requireRuleTesterRule,
22
+ },
23
+ });
24
+
25
+ export default plumbMetaPlugin;
@@ -0,0 +1,38 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+
5
+ /**
6
+ * Inline suppression comments hide lint failures from the exact files where
7
+ * enforcement matters most. Fix the code or scope a justified override in the
8
+ * config; do not silence rules line-by-line.
9
+ */
10
+ export const noDisableDirectivesRule = defineRule({
11
+ meta: {
12
+ type: "problem",
13
+ docs: {
14
+ description:
15
+ "Disallow `// oxlint-disable` suppression comments; fix the finding or add a justified file-scoped config override instead.",
16
+ },
17
+ messages: {
18
+ suppressionDirective:
19
+ "Inline suppression comments make findings invisible without making them gone. Prefer fixing the code; if an exception is truly warranted, use a scoped override entry in oxlint.config.ts with a written reason.",
20
+ },
21
+ },
22
+ createOnce(context) {
23
+ let program: ESTree.Program | null = null;
24
+ return {
25
+ Program(node) {
26
+ program = node;
27
+ },
28
+ "Program:exit"() {
29
+ if (program === null) return;
30
+ for (const comment of context.sourceCode.getAllComments()) {
31
+ if (!/^\s*oxlint-disable\b/u.test(comment.value)) continue;
32
+ context.report({ node: program, messageId: "suppressionDirective" });
33
+ return;
34
+ }
35
+ },
36
+ };
37
+ },
38
+ });
@@ -0,0 +1,27 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+
5
+ /** Hand-rolled `.parent` loops duplicate sourceCode.getAncestors and hide traversal intent. */
6
+ export const noManualAncestorWalksRule = defineRule({
7
+ meta: {
8
+ type: "suggestion",
9
+ docs: {
10
+ description: "Disallow manual `.parent` walks; use `context.sourceCode.getAncestors(node)`.",
11
+ },
12
+ messages: {
13
+ useGetAncestors:
14
+ "Hand-rolled ancestor walking via `.parent` obscures traversal intent. Use `context.sourceCode.getAncestors(node)` (root-first array) and express the search declaratively.",
15
+ },
16
+ },
17
+ createOnce(context) {
18
+ return {
19
+ MemberExpression(node) {
20
+ if (node.computed) return;
21
+ if (node.property.type !== "Identifier") return;
22
+ if (node.property.name !== "parent") return;
23
+ context.report({ node, messageId: "useGetAncestors" });
24
+ },
25
+ };
26
+ },
27
+ });
@@ -0,0 +1,57 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+
5
+ import { isString, readField } from "../../shared/structural.ts";
6
+
7
+ /**
8
+ * Property-name reader for visitor properties. The `Property` selector receives
9
+ * Object/Binding/AssignmentTarget properties; all share this structural shape.
10
+ *
11
+ * @param {{ readonly computed: boolean; readonly key: ESTree.Expression | ESTree.PrivateIdentifier }} node - A visited property node.
12
+ * @returns {string | null} The non-computed property's identifier or literal string name.
13
+ */
14
+ function propertyName(node: {
15
+ readonly computed: boolean;
16
+ readonly key: ESTree.Expression | ESTree.PrivateIdentifier;
17
+ }): string | null {
18
+ if (node.computed) return null;
19
+ const key = node.key;
20
+ const name = readField(key, "name");
21
+ if (readField(key, "type") === "Identifier" && isString(name)) return name;
22
+ const value = readField(key, "value");
23
+ if (readField(key, "type") === "Literal" && isString(value)) return value;
24
+ return null;
25
+ }
26
+
27
+ /** File-scoping logic belongs in the `before` hook, not scattered through visitors or `create`. */
28
+ export const preferBeforeFileScopeRule = defineRule({
29
+ meta: {
30
+ type: "suggestion",
31
+ docs: {
32
+ description: "Read `context.filename` only inside a `before` hook; skip the file by returning `false` there.",
33
+ },
34
+ messages: {
35
+ moveToBefore:
36
+ "File-scoping read of `context.filename` outside `before()`. Do file selection in `before()` and return `false` to skip the file, keeping visitors free of filename checks.",
37
+ },
38
+ },
39
+ createOnce(context) {
40
+ let insideBeforeHook = false;
41
+ return {
42
+ Property(node) {
43
+ if (!insideBeforeHook && propertyName(node) === "before") insideBeforeHook = true;
44
+ },
45
+ "Property:exit"(node) {
46
+ if (insideBeforeHook && propertyName(node) === "before") insideBeforeHook = false;
47
+ },
48
+ MemberExpression(node) {
49
+ if (insideBeforeHook) return;
50
+ if (node.computed) return;
51
+ if (node.object.type !== "Identifier" || node.object.name !== "context") return;
52
+ if (node.property.type !== "Identifier" || node.property.name !== "filename") return;
53
+ context.report({ node, messageId: "moveToBefore" });
54
+ },
55
+ };
56
+ },
57
+ });
@@ -0,0 +1,51 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { isString } from "../../shared/structural.ts";
4
+
5
+ import type { ESTree } from "@oxlint/plugins";
6
+
7
+ /**
8
+ * Static property name of an object property node.
9
+ *
10
+ * @param {ESTree.ObjectProperty} key - The property node to inspect.
11
+ * @returns {string | null} The identifier or literal string name, or null when computed.
12
+ */
13
+ function propertyName(key: ESTree.ObjectProperty): string | null {
14
+ if (key.computed) return null;
15
+ if (key.key.type === "Identifier") return key.key.name;
16
+ if (key.key.type === "Literal" && isString(key.key.value)) return key.key.value;
17
+ return null;
18
+ }
19
+
20
+ /** Rule objects should opt into Oxlint's performant createOnce API, not ESLint's per-file create. */
21
+ export const requireCreateOnceRule = defineRule({
22
+ meta: {
23
+ type: "suggestion",
24
+ docs: {
25
+ description: "Require `createOnce` instead of `create` when authoring Oxlint rules.",
26
+ },
27
+ messages: {
28
+ useCreateOnce:
29
+ "`create` re-runs per file and blocks Oxlint's Rust-side traversal optimizations. Use `createOnce` (per-file setup belongs in the `before` hook).",
30
+ },
31
+ },
32
+ createOnce(context) {
33
+ const visitObject = (node: ESTree.ObjectExpression): void => {
34
+ const keys = new Set<string>();
35
+ let createProperty: ESTree.ObjectProperty | null = null;
36
+ for (const property of node.properties) {
37
+ if (property.type !== "Property") continue;
38
+ const name = propertyName(property);
39
+ if (name === null) continue;
40
+ keys.add(name);
41
+ if (name === "create") createProperty = property;
42
+ }
43
+ if (createProperty !== null && keys.has("meta")) {
44
+ context.report({ node: createProperty, messageId: "useCreateOnce" });
45
+ }
46
+ };
47
+ return {
48
+ ObjectExpression: visitObject,
49
+ };
50
+ },
51
+ });
@@ -0,0 +1,57 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+
5
+ const RULE_TEST_FILE = /[/\\](?:rules|effect[/\\]rules|meta[/\\]rules)[/\\][^/\\]+\.test\.[cm]?[jt]sx?$/u;
6
+
7
+ /** Tests for lint rules belong in Oxlint's RuleTester: valid/invalid cases with message and span assertions. */
8
+ export const requireRuleTesterRule = defineRule({
9
+ meta: {
10
+ type: "suggestion",
11
+ docs: {
12
+ description:
13
+ "Require test files co-located with lint rules to drive the rule through `RuleTester` (oxlint/plugins-dev).",
14
+ },
15
+ messages: {
16
+ useRuleTester:
17
+ "This test file sits next to a lint rule but does not import `RuleTester` from `oxlint/plugins-dev`. Rule behavior should be pinned through valid/invalid cases with message and span assertions.",
18
+ neverRuns:
19
+ "`RuleTester` is imported but `run()` is never called. Every rule suite must execute `ruleTester.run(...)`.",
20
+ },
21
+ },
22
+ createOnce(context) {
23
+ let program: ESTree.Program | null = null;
24
+ let importsRuleTester = false;
25
+ let callsRun = false;
26
+ return {
27
+ before() {
28
+ if (!RULE_TEST_FILE.test(context.filename.replaceAll("\\", "/"))) return false;
29
+ },
30
+ Program(node) {
31
+ program = node;
32
+ },
33
+ ImportDeclaration(node) {
34
+ const usesRuleTester = node.specifiers.some(
35
+ (specifier) =>
36
+ specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "RuleTester",
37
+ );
38
+ if (usesRuleTester) importsRuleTester = true;
39
+ },
40
+ CallExpression(node) {
41
+ if (
42
+ node.callee.type === "MemberExpression" &&
43
+ !node.callee.computed &&
44
+ node.callee.property.type === "Identifier" &&
45
+ node.callee.property.name === "run"
46
+ ) {
47
+ callsRun = true;
48
+ }
49
+ },
50
+ "Program:exit"() {
51
+ if (program === null) return;
52
+ if (!importsRuleTester) context.report({ node: program, messageId: "useRuleTester" });
53
+ else if (!callsRun) context.report({ node: program, messageId: "neverRuns" });
54
+ },
55
+ };
56
+ },
57
+ });
@@ -0,0 +1,38 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+ import { readField } from "../shared/structural.ts";
5
+
6
+ /**
7
+ * Dense representations are sliceable on any axis because their parts are
8
+ * named. Past two elements, positional tuples hide which position carries
9
+ * which fact: swap-prone, unreadable at call sites, and impossible to
10
+ * slice meaningfully. Give wide tuples a named shape.
11
+ */
12
+ export const noAnonymousWideTuplesRule = defineRule({
13
+ meta: {
14
+ type: "suggestion",
15
+ docs: {
16
+ description:
17
+ "Disallow anonymous tuple types of three or more elements; use a named object so every field's role is explicit.",
18
+ },
19
+ messages: {
20
+ wideTuple:
21
+ "This {{count}}-element tuple leaves {{count}} unnamed positions whose meaning lives only in the reader's head. Declare a named object (or tagged union) instead so fields are self-describing.",
22
+ },
23
+ },
24
+ createOnce(context) {
25
+ return {
26
+ TSTupleType(node) {
27
+ const elements = readField<ESTree.TSType[]>(node, "elementTypes") ?? [];
28
+ const count = elements.length;
29
+ if (count < 3) return;
30
+ context.report({
31
+ node,
32
+ messageId: "wideTuple",
33
+ data: { count: String(count) },
34
+ });
35
+ },
36
+ };
37
+ },
38
+ });
@@ -0,0 +1,30 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import type { ESTree } from "@oxlint/plugins";
4
+
5
+ /** Barrel `export *` erases the names it forwards, forcing search-driven readers back inside the package. */
6
+ export const noBarrelExportStarRule = defineRule({
7
+ meta: {
8
+ type: "problem",
9
+ docs: {
10
+ description:
11
+ "Disallow `export * from ...` re-exports because the star erases forwarded names; an agent navigating by text search cannot resolve which module owns a symbol and must re-grep inside the package.",
12
+ },
13
+ messages: {
14
+ erasesForwardedNames:
15
+ "`export * from '{{source}}'` erases the names it forwards; readers resolving a symbol through this barrel must grep inside the package instead. Re-export the explicit names.",
16
+ },
17
+ },
18
+ createOnce(context) {
19
+ return {
20
+ ExportAllDeclaration(node) {
21
+ if (node.exported !== null && node.exported !== undefined) return;
22
+ context.report({
23
+ node,
24
+ messageId: "erasesForwardedNames",
25
+ data: { source: String(node.source.value) },
26
+ });
27
+ },
28
+ };
29
+ },
30
+ });