@autotelic/plumb 0.6.0 → 0.6.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.
- package/README.md +81 -8
- package/dist/configs/recommended-rules.d.ts +36 -0
- package/dist/configs/recommended-rules.js +57 -0
- package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
- package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
- package/dist/effect/rules/no-decode-unknown-option.js +1 -1
- package/dist/effect/rules/no-direct-browser-storage.js +3 -3
- package/dist/effect/rules/no-direct-fetch.js +1 -1
- package/dist/effect/rules/no-manual-field-guards.js +1 -1
- package/dist/effect/rules/no-nested-layer-provide.js +1 -1
- package/dist/effect/rules/no-nullish-default-on-partial-input.js +2 -2
- package/dist/effect/rules/no-raw-error-forwarding.d.ts +4 -0
- package/dist/effect/rules/no-raw-error-forwarding.js +7 -2
- package/dist/effect/rules/no-silent-error-swallow.js +1 -1
- package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
- package/dist/effect/rules/no-try-catch.js +1 -1
- package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
- package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
- package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
- package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
- package/dist/effect/rules/prefer-effect-match.js +2 -2
- package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
- package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
- package/dist/effect/rules/prefer-option-pipeline.js +13 -12
- package/dist/effect/rules/prefer-ordering-match.js +1 -1
- package/dist/effect/rules/prefer-tagged-enum.js +1 -1
- package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
- package/dist/effect/rules/require-schema-type-derivation.js +14 -4
- package/dist/index.js +8 -0
- package/dist/react/rules/require-dot-notation-exports.js +1 -1
- package/dist/react/rules/require-guarded-context-hook.js +1 -1
- package/dist/react/rules/require-tripartite-context.js +1 -1
- package/dist/react/rules/use-encapsulation.js +1 -1
- package/dist/rules/no-adapter-in-values.d.ts +12 -0
- package/dist/rules/no-adapter-in-values.js +110 -0
- package/dist/rules/no-builtin-throws.js +1 -1
- package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
- package/dist/rules/no-duplicated-literal-union.js +5 -1
- package/dist/rules/no-generic-export-names.js +1 -1
- package/dist/rules/no-multiple-function-params.js +26 -12
- package/dist/rules/no-mutable-environment-capture.js +2 -2
- package/dist/rules/no-nondeterministic-core.js +1 -1
- package/dist/rules/no-nullable-value-field.d.ts +16 -0
- package/dist/rules/no-nullable-value-field.js +117 -0
- package/dist/rules/no-optional-function-parameters.js +1 -1
- package/dist/rules/no-row-coercion.d.ts +13 -0
- package/dist/rules/no-row-coercion.js +135 -0
- package/dist/rules/no-single-use-private-functions.js +1 -1
- package/dist/rules/no-sql-string-interpolation.js +2 -2
- package/dist/rules/no-stray-inline-comments.js +1 -1
- package/dist/rules/no-string-instant.d.ts +15 -0
- package/dist/rules/no-string-instant.js +108 -0
- package/dist/rules/no-swappable-primitive-params.js +1 -1
- package/dist/rules/no-tag-ladder-assertions.js +1 -1
- package/dist/rules/no-vague-test-filenames.js +1 -1
- package/dist/rules/prefer-property-tests.d.ts +5 -0
- package/dist/rules/prefer-property-tests.js +7 -0
- package/dist/rules/require-jsdoc-on-exported.js +1 -1
- package/dist/shared/ancestors.d.ts +1 -1
- package/dist/shared/ancestors.js +1 -1
- package/dist/shared/values-path.d.ts +12 -0
- package/dist/shared/values-path.js +56 -0
- package/dist/src/configs/recommended-rules.d.ts +20 -0
- package/dist/src/configs/recommended-rules.js +22 -0
- package/dist/src/effect/index.d.ts +3 -0
- package/dist/src/effect/index.js +60 -0
- package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
- package/dist/src/effect/rules/guarded-op-must-return-effect.js +235 -0
- package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +2 -0
- package/dist/src/effect/rules/guarded-op-must-return-option.js +88 -0
- package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +6 -0
- package/dist/src/effect/rules/no-cascading-layer-provide.js +73 -0
- package/dist/src/effect/rules/no-decode-unknown-option.d.ts +7 -0
- package/dist/src/effect/rules/no-decode-unknown-option.js +34 -0
- package/dist/src/effect/rules/no-direct-browser-storage.d.ts +2 -0
- package/dist/src/effect/rules/no-direct-browser-storage.js +88 -0
- package/dist/src/effect/rules/no-direct-fetch.d.ts +2 -0
- package/dist/src/effect/rules/no-direct-fetch.js +37 -0
- package/dist/src/effect/rules/no-manual-field-guards.d.ts +6 -0
- package/dist/src/effect/rules/no-manual-field-guards.js +129 -0
- package/dist/src/effect/rules/no-nested-layer-provide.d.ts +2 -0
- package/dist/src/effect/rules/no-nested-layer-provide.js +50 -0
- package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +13 -0
- package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +109 -0
- package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +12 -0
- package/dist/src/effect/rules/no-raw-error-forwarding.js +103 -0
- package/dist/src/effect/rules/no-schema-class-modeling.d.ts +2 -0
- package/dist/src/effect/rules/no-schema-class-modeling.js +52 -0
- package/dist/src/effect/rules/no-service-constructor-imports.d.ts +2 -0
- package/dist/src/effect/rules/no-service-constructor-imports.js +42 -0
- package/dist/src/effect/rules/no-silent-error-swallow.d.ts +2 -0
- package/dist/src/effect/rules/no-silent-error-swallow.js +95 -0
- package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
- package/dist/src/effect/rules/no-static-effect-service-forwarders.js +222 -0
- package/dist/src/effect/rules/no-try-catch.d.ts +2 -0
- package/dist/src/effect/rules/no-try-catch.js +30 -0
- package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +5 -0
- package/dist/src/effect/rules/no-unguarded-json-parse.js +200 -0
- package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +5 -0
- package/dist/src/effect/rules/option-core-needs-effect-public.js +76 -0
- package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
- package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +112 -0
- package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
- package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
- package/dist/src/effect/rules/prefer-effect-match.d.ts +2 -0
- package/dist/src/effect/rules/prefer-effect-match.js +74 -0
- package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
- package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
- package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
- package/dist/src/effect/rules/prefer-named-guard-predicate.js +93 -0
- package/dist/src/effect/rules/prefer-option-pipeline.d.ts +2 -0
- package/dist/src/effect/rules/prefer-option-pipeline.js +87 -0
- package/dist/src/effect/rules/prefer-ordering-match.d.ts +2 -0
- package/dist/src/effect/rules/prefer-ordering-match.js +135 -0
- package/dist/src/effect/rules/prefer-tagged-enum.d.ts +2 -0
- package/dist/src/effect/rules/prefer-tagged-enum.js +66 -0
- package/dist/src/effect/rules/require-schema-type-derivation.d.ts +7 -0
- package/dist/src/effect/rules/require-schema-type-derivation.js +80 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +106 -0
- package/dist/src/meta/index.d.ts +7 -0
- package/dist/src/meta/index.js +22 -0
- package/dist/src/meta/rules/no-disable-directives.d.ts +6 -0
- package/dist/src/meta/rules/no-disable-directives.js +35 -0
- package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
- package/dist/src/meta/rules/no-manual-ancestor-walks.js +26 -0
- package/dist/src/meta/rules/prefer-before-file-scope.d.ts +2 -0
- package/dist/src/meta/rules/prefer-before-file-scope.js +57 -0
- package/dist/src/meta/rules/require-create-once.d.ts +2 -0
- package/dist/src/meta/rules/require-create-once.js +51 -0
- package/dist/src/meta/rules/require-rule-tester.d.ts +2 -0
- package/dist/src/meta/rules/require-rule-tester.js +50 -0
- package/dist/src/react/index.d.ts +3 -0
- package/dist/src/react/index.js +16 -0
- package/dist/src/react/role.d.ts +23 -0
- package/dist/src/react/role.js +30 -0
- package/dist/src/react/rules/require-dot-notation-exports.d.ts +27 -0
- package/dist/src/react/rules/require-dot-notation-exports.js +144 -0
- package/dist/src/react/rules/require-guarded-context-hook.d.ts +19 -0
- package/dist/src/react/rules/require-guarded-context-hook.js +167 -0
- package/dist/src/react/rules/require-tripartite-context.d.ts +17 -0
- package/dist/src/react/rules/require-tripartite-context.js +160 -0
- package/dist/src/react/rules/use-encapsulation.d.ts +22 -0
- package/dist/src/react/rules/use-encapsulation.js +97 -0
- package/dist/src/rules/no-anonymous-wide-tuples.d.ts +7 -0
- package/dist/src/rules/no-anonymous-wide-tuples.js +34 -0
- package/dist/src/rules/no-barrel-export-star.d.ts +2 -0
- package/dist/src/rules/no-barrel-export-star.js +26 -0
- package/dist/src/rules/no-boolean-field-signals.d.ts +2 -0
- package/dist/src/rules/no-boolean-field-signals.js +279 -0
- package/dist/src/rules/no-builtin-throws.d.ts +6 -0
- package/dist/src/rules/no-builtin-throws.js +74 -0
- package/dist/src/rules/no-chained-type-assertions.d.ts +2 -0
- package/dist/src/rules/no-chained-type-assertions.js +54 -0
- package/dist/src/rules/no-conditional-empty-object-spread.d.ts +2 -0
- package/dist/src/rules/no-conditional-empty-object-spread.js +36 -0
- package/dist/src/rules/no-duplicated-literal-union.d.ts +6 -0
- package/dist/src/rules/no-duplicated-literal-union.js +66 -0
- package/dist/src/rules/no-exported-mutable-state.d.ts +7 -0
- package/dist/src/rules/no-exported-mutable-state.js +104 -0
- package/dist/src/rules/no-generic-export-names.d.ts +2 -0
- package/dist/src/rules/no-generic-export-names.js +141 -0
- package/dist/src/rules/no-impossible-branch-throw.d.ts +2 -0
- package/dist/src/rules/no-impossible-branch-throw.js +51 -0
- package/dist/src/rules/no-known-value-widening.d.ts +2 -0
- package/dist/src/rules/no-known-value-widening.js +176 -0
- package/dist/src/rules/no-module-mocking.d.ts +2 -0
- package/dist/src/rules/no-module-mocking.js +90 -0
- package/dist/src/rules/no-multiple-function-params.d.ts +2 -0
- package/dist/src/rules/no-multiple-function-params.js +155 -0
- package/dist/src/rules/no-mutable-environment-capture.d.ts +7 -0
- package/dist/src/rules/no-mutable-environment-capture.js +134 -0
- package/dist/src/rules/no-nondeterministic-core.d.ts +6 -0
- package/dist/src/rules/no-nondeterministic-core.js +63 -0
- package/dist/src/rules/no-object-parameters.d.ts +2 -0
- package/dist/src/rules/no-object-parameters.js +95 -0
- package/dist/src/rules/no-optional-function-parameters.d.ts +7 -0
- package/dist/src/rules/no-optional-function-parameters.js +44 -0
- package/dist/src/rules/no-product-of-state-booleans.d.ts +2 -0
- package/dist/src/rules/no-product-of-state-booleans.js +79 -0
- package/dist/src/rules/no-redundant-derived-field.d.ts +6 -0
- package/dist/src/rules/no-redundant-derived-field.js +194 -0
- package/dist/src/rules/no-reflect-apply.d.ts +2 -0
- package/dist/src/rules/no-reflect-apply.js +29 -0
- package/dist/src/rules/no-reflect-get.d.ts +2 -0
- package/dist/src/rules/no-reflect-get.js +29 -0
- package/dist/src/rules/no-reinterpret-cast.d.ts +2 -0
- package/dist/src/rules/no-reinterpret-cast.js +68 -0
- package/dist/src/rules/no-runtime-typeof.d.ts +2 -0
- package/dist/src/rules/no-runtime-typeof.js +54 -0
- package/dist/src/rules/no-sentinel-comparison-union.d.ts +2 -0
- package/dist/src/rules/no-sentinel-comparison-union.js +139 -0
- package/dist/src/rules/no-shape-in-symbol-names.d.ts +2 -0
- package/dist/src/rules/no-shape-in-symbol-names.js +39 -0
- package/dist/src/rules/no-single-use-private-functions.d.ts +17 -0
- package/dist/src/rules/no-single-use-private-functions.js +419 -0
- package/dist/src/rules/no-sql-string-interpolation.d.ts +7 -0
- package/dist/src/rules/no-sql-string-interpolation.js +62 -0
- package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
- package/dist/src/rules/no-stacked-jsdoc-blocks.js +50 -0
- package/dist/src/rules/no-stray-inline-comments.d.ts +2 -0
- package/dist/src/rules/no-stray-inline-comments.js +74 -0
- package/dist/src/rules/no-swappable-primitive-params.d.ts +2 -0
- package/dist/src/rules/no-swappable-primitive-params.js +96 -0
- package/dist/src/rules/no-tag-ladder-assertions.d.ts +6 -0
- package/dist/src/rules/no-tag-ladder-assertions.js +63 -0
- package/dist/src/rules/no-transposed-field-reads.d.ts +8 -0
- package/dist/src/rules/no-transposed-field-reads.js +101 -0
- package/dist/src/rules/no-unit-return-validators.d.ts +2 -0
- package/dist/src/rules/no-unit-return-validators.js +64 -0
- package/dist/src/rules/no-unknown-parameters.d.ts +2 -0
- package/dist/src/rules/no-unknown-parameters.js +82 -0
- package/dist/src/rules/no-unknown-returns.d.ts +2 -0
- package/dist/src/rules/no-unknown-returns.js +86 -0
- package/dist/src/rules/no-unknown-type-aliases.d.ts +2 -0
- package/dist/src/rules/no-unknown-type-aliases.js +64 -0
- package/dist/src/rules/no-unsafe-dictionary-type.d.ts +2 -0
- package/dist/src/rules/no-unsafe-dictionary-type.js +116 -0
- package/dist/src/rules/no-vague-test-filenames.d.ts +2 -0
- package/dist/src/rules/no-vague-test-filenames.js +61 -0
- package/dist/src/rules/no-widen-then-assert.d.ts +2 -0
- package/dist/src/rules/no-widen-then-assert.js +268 -0
- package/dist/src/rules/prefer-payload-brand.d.ts +2 -0
- package/dist/src/rules/prefer-payload-brand.js +57 -0
- package/dist/src/rules/prefer-property-tests.d.ts +5 -0
- package/dist/src/rules/prefer-property-tests.js +39 -0
- package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +8 -0
- package/dist/src/rules/require-canonical-stringify-for-identity.js +72 -0
- package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
- package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
- package/dist/src/rules/require-exhaustive-tag-switch.d.ts +7 -0
- package/dist/src/rules/require-exhaustive-tag-switch.js +34 -0
- package/dist/src/rules/require-fc-block-predicate.d.ts +2 -0
- package/dist/src/rules/require-fc-block-predicate.js +37 -0
- package/dist/src/rules/require-jsdoc-on-exported.d.ts +2 -0
- package/dist/src/rules/require-jsdoc-on-exported.js +66 -0
- package/dist/src/rules/require-published-order.d.ts +2 -0
- package/dist/src/rules/require-published-order.js +102 -0
- package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
- package/dist/src/rules/require-safety-comment-for-type-assertion.js +53 -0
- package/dist/src/rules/require-sort-comparator.d.ts +7 -0
- package/dist/src/rules/require-sort-comparator.js +34 -0
- package/dist/src/rules/test-utils.d.ts +35 -0
- package/dist/src/rules/test-utils.js +53 -0
- package/dist/src/shared/ancestors.d.ts +18 -0
- package/dist/src/shared/ancestors.js +19 -0
- package/dist/src/shared/child-nodes.d.ts +12 -0
- package/dist/src/shared/child-nodes.js +26 -0
- package/dist/src/shared/dictionary-types.d.ts +55 -0
- package/dist/src/shared/dictionary-types.js +413 -0
- package/dist/src/shared/is-node.d.ts +9 -0
- package/dist/src/shared/is-node.js +10 -0
- package/dist/src/shared/lexical-type-parameters.d.ts +12 -0
- package/dist/src/shared/lexical-type-parameters.js +50 -0
- package/dist/src/shared/reflect-method.d.ts +15 -0
- package/dist/src/shared/reflect-method.js +32 -0
- package/dist/src/shared/rule-options.d.ts +18 -0
- package/dist/src/shared/rule-options.js +12 -0
- package/dist/src/shared/structural.d.ts +54 -0
- package/dist/src/shared/structural.js +40 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.js +1 -0
- package/dist/src/testing/testable-rule.d.ts +39 -0
- package/dist/src/testing/testable-rule.js +84 -0
- package/dist/src/ui/index.d.ts +12 -0
- package/dist/src/ui/index.js +18 -0
- package/dist/src/ui/manifest.d.ts +34 -0
- package/dist/src/ui/manifest.js +75 -0
- package/dist/src/ui/rules/no-deprecated-parts.d.ts +3 -0
- package/dist/src/ui/rules/no-deprecated-parts.js +131 -0
- package/dist/testing/testable-rule.d.ts +6 -5
- package/dist/testing/testable-rule.js +20 -6
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/index.js +18 -0
- package/dist/ui/manifest.d.ts +49 -0
- package/dist/ui/manifest.js +90 -0
- package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
- package/dist/ui/rules/no-deprecated-parts.js +172 -0
- package/package.json +20 -11
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
/**
|
|
3
|
+
* Inline suppression comments hide lint failures from the exact files where
|
|
4
|
+
* enforcement matters most. Fix the code or scope a justified override in the
|
|
5
|
+
* config; do not silence rules line-by-line.
|
|
6
|
+
*/
|
|
7
|
+
export const noDisableDirectivesRule = defineRule({
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "Disallow `// oxlint-disable` suppression comments; fix the finding or add a justified file-scoped config override instead.",
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
suppressionDirective: "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.",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
createOnce(context) {
|
|
18
|
+
let program = null;
|
|
19
|
+
return {
|
|
20
|
+
Program(node) {
|
|
21
|
+
program = node;
|
|
22
|
+
},
|
|
23
|
+
"Program:exit"() {
|
|
24
|
+
if (program === null)
|
|
25
|
+
return;
|
|
26
|
+
for (const comment of context.sourceCode.getAllComments()) {
|
|
27
|
+
if (!/^\s*oxlint-disable\b/u.test(comment.value))
|
|
28
|
+
continue;
|
|
29
|
+
context.report({ node: program, messageId: "suppressionDirective" });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
/** Hand-rolled `.parent` loops duplicate sourceCode.getAncestors and hide traversal intent. */
|
|
3
|
+
export const noManualAncestorWalksRule = defineRule({
|
|
4
|
+
meta: {
|
|
5
|
+
type: "suggestion",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Disallow manual `.parent` walks; use `context.sourceCode.getAncestors(node)`.",
|
|
8
|
+
},
|
|
9
|
+
messages: {
|
|
10
|
+
useGetAncestors: "Hand-rolled ancestor walking via `.parent` obscures traversal intent. Use `context.sourceCode.getAncestors(node)` (root-first array) and express the search declaratively.",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
return {
|
|
15
|
+
MemberExpression(node) {
|
|
16
|
+
if (node.computed)
|
|
17
|
+
return;
|
|
18
|
+
if (node.property.type !== "Identifier")
|
|
19
|
+
return;
|
|
20
|
+
if (node.property.name !== "parent")
|
|
21
|
+
return;
|
|
22
|
+
context.report({ node, messageId: "useGetAncestors" });
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isString, readField } from "../../shared/structural.js";
|
|
3
|
+
/**
|
|
4
|
+
* Property-name reader for visitor properties. The `Property` selector receives
|
|
5
|
+
* Object/Binding/AssignmentTarget properties; all share this structural shape.
|
|
6
|
+
*
|
|
7
|
+
* @param {{ readonly computed: boolean; readonly key: ESTree.Expression | ESTree.PrivateIdentifier }} node - A visited property node.
|
|
8
|
+
* @returns {string | null} The non-computed property's identifier or literal string name.
|
|
9
|
+
*/
|
|
10
|
+
function propertyName(node) {
|
|
11
|
+
if (node.computed)
|
|
12
|
+
return null;
|
|
13
|
+
const key = node.key;
|
|
14
|
+
const name = readField(key, "name");
|
|
15
|
+
if (readField(key, "type") === "Identifier" && isString(name))
|
|
16
|
+
return name;
|
|
17
|
+
const value = readField(key, "value");
|
|
18
|
+
if (readField(key, "type") === "Literal" && isString(value))
|
|
19
|
+
return value;
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/** File-scoping logic belongs in the `before` hook, not scattered through visitors or `create`. */
|
|
23
|
+
export const preferBeforeFileScopeRule = defineRule({
|
|
24
|
+
meta: {
|
|
25
|
+
type: "suggestion",
|
|
26
|
+
docs: {
|
|
27
|
+
description: "Read `context.filename` only inside a `before` hook; skip the file by returning `false` there.",
|
|
28
|
+
},
|
|
29
|
+
messages: {
|
|
30
|
+
moveToBefore: "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.",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
createOnce(context) {
|
|
34
|
+
let insideBeforeHook = false;
|
|
35
|
+
return {
|
|
36
|
+
Property(node) {
|
|
37
|
+
if (!insideBeforeHook && propertyName(node) === "before")
|
|
38
|
+
insideBeforeHook = true;
|
|
39
|
+
},
|
|
40
|
+
"Property:exit"(node) {
|
|
41
|
+
if (insideBeforeHook && propertyName(node) === "before")
|
|
42
|
+
insideBeforeHook = false;
|
|
43
|
+
},
|
|
44
|
+
MemberExpression(node) {
|
|
45
|
+
if (insideBeforeHook)
|
|
46
|
+
return;
|
|
47
|
+
if (node.computed)
|
|
48
|
+
return;
|
|
49
|
+
if (node.object.type !== "Identifier" || node.object.name !== "context")
|
|
50
|
+
return;
|
|
51
|
+
if (node.property.type !== "Identifier" || node.property.name !== "filename")
|
|
52
|
+
return;
|
|
53
|
+
context.report({ node, messageId: "moveToBefore" });
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isString } from "../../shared/structural.js";
|
|
3
|
+
/**
|
|
4
|
+
* Static property name of an object property node.
|
|
5
|
+
*
|
|
6
|
+
* @param {ESTree.ObjectProperty} key - The property node to inspect.
|
|
7
|
+
* @returns {string | null} The identifier or literal string name, or null when computed.
|
|
8
|
+
*/
|
|
9
|
+
function propertyName(key) {
|
|
10
|
+
if (key.computed)
|
|
11
|
+
return null;
|
|
12
|
+
if (key.key.type === "Identifier")
|
|
13
|
+
return key.key.name;
|
|
14
|
+
if (key.key.type === "Literal" && isString(key.key.value))
|
|
15
|
+
return key.key.value;
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
/** Rule objects should opt into Oxlint's performant createOnce API, not ESLint's per-file create. */
|
|
19
|
+
export const requireCreateOnceRule = defineRule({
|
|
20
|
+
meta: {
|
|
21
|
+
type: "suggestion",
|
|
22
|
+
docs: {
|
|
23
|
+
description: "Require `createOnce` instead of `create` when authoring Oxlint rules.",
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
useCreateOnce: "`create` re-runs per file and blocks Oxlint's Rust-side traversal optimizations. Use `createOnce` (per-file setup belongs in the `before` hook).",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
createOnce(context) {
|
|
30
|
+
const visitObject = (node) => {
|
|
31
|
+
const keys = new Set();
|
|
32
|
+
let createProperty = null;
|
|
33
|
+
for (const property of node.properties) {
|
|
34
|
+
if (property.type !== "Property")
|
|
35
|
+
continue;
|
|
36
|
+
const name = propertyName(property);
|
|
37
|
+
if (name === null)
|
|
38
|
+
continue;
|
|
39
|
+
keys.add(name);
|
|
40
|
+
if (name === "create")
|
|
41
|
+
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,50 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const RULE_TEST_FILE = /[/\\](?:rules|effect[/\\]rules|meta[/\\]rules)[/\\][^/\\]+\.test\.[cm]?[jt]sx?$/u;
|
|
3
|
+
/** Tests for lint rules belong in Oxlint's RuleTester: valid/invalid cases with message and span assertions. */
|
|
4
|
+
export const requireRuleTesterRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "suggestion",
|
|
7
|
+
docs: {
|
|
8
|
+
description: "Require test files co-located with lint rules to drive the rule through `RuleTester` (oxlint/plugins-dev).",
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
useRuleTester: "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.",
|
|
12
|
+
neverRuns: "`RuleTester` is imported but `run()` is never called. Every rule suite must execute `ruleTester.run(...)`.",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
createOnce(context) {
|
|
16
|
+
let program = null;
|
|
17
|
+
let importsRuleTester = false;
|
|
18
|
+
let callsRun = false;
|
|
19
|
+
return {
|
|
20
|
+
before() {
|
|
21
|
+
if (!RULE_TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
22
|
+
return false;
|
|
23
|
+
},
|
|
24
|
+
Program(node) {
|
|
25
|
+
program = node;
|
|
26
|
+
},
|
|
27
|
+
ImportDeclaration(node) {
|
|
28
|
+
const usesRuleTester = node.specifiers.some((specifier) => specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "RuleTester");
|
|
29
|
+
if (usesRuleTester)
|
|
30
|
+
importsRuleTester = true;
|
|
31
|
+
},
|
|
32
|
+
CallExpression(node) {
|
|
33
|
+
if (node.callee.type === "MemberExpression" &&
|
|
34
|
+
!node.callee.computed &&
|
|
35
|
+
node.callee.property.type === "Identifier" &&
|
|
36
|
+
node.callee.property.name === "run") {
|
|
37
|
+
callsRun = true;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"Program:exit"() {
|
|
41
|
+
if (program === null)
|
|
42
|
+
return;
|
|
43
|
+
if (!importsRuleTester)
|
|
44
|
+
context.report({ node: program, messageId: "useRuleTester" });
|
|
45
|
+
else if (!callsRun)
|
|
46
|
+
context.report({ node: program, messageId: "neverRuns" });
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
import { requireTripartiteContextRule } from "./rules/require-tripartite-context.js";
|
|
3
|
+
import { requireGuardedContextHookRule } from "./rules/require-guarded-context-hook.js";
|
|
4
|
+
import { requireDotNotationExportsRule } from "./rules/require-dot-notation-exports.js";
|
|
5
|
+
import { useEncapsulationRule } from "./rules/use-encapsulation.js";
|
|
6
|
+
/** Opt-in Oxlint rules for React composition (the "perfect component" contract). */
|
|
7
|
+
const plumbReactPlugin = eslintCompatPlugin({
|
|
8
|
+
meta: { name: "plumb-react" },
|
|
9
|
+
rules: {
|
|
10
|
+
"require-tripartite-context": requireTripartiteContextRule,
|
|
11
|
+
"require-guarded-context-hook": requireGuardedContextHookRule,
|
|
12
|
+
"require-dot-notation-exports": requireDotNotationExportsRule,
|
|
13
|
+
"use-encapsulation": useEncapsulationRule,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
export default plumbReactPlugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a binding name denotes a context Provider (the generic Provider or a
|
|
3
|
+
* family-scoped XProvider). A Provider is the stateful root of a context family
|
|
4
|
+
* and the only component legitimately allowed to use React hooks inline.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} name - The binding name.
|
|
7
|
+
* @returns {boolean} True when the name is `Provider` or ends with `Provider`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isProviderName(name: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Family name contributed by a useXxx export binding.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} name - The exported binding name.
|
|
14
|
+
* @returns {string | null} The family name, or null when not a useXxx hook.
|
|
15
|
+
*/
|
|
16
|
+
export declare function hookFamily(name: string): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a binding name denotes a custom hook (use + an uppercase letter).
|
|
19
|
+
*
|
|
20
|
+
* @param {string | null} name - The binding name, if known.
|
|
21
|
+
* @returns {name is string} True when the name starts with `use` + a capital.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isHookName(name: string | null): name is string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a binding name denotes a context Provider (the generic Provider or a
|
|
3
|
+
* family-scoped XProvider). A Provider is the stateful root of a context family
|
|
4
|
+
* and the only component legitimately allowed to use React hooks inline.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} name - The binding name.
|
|
7
|
+
* @returns {boolean} True when the name is `Provider` or ends with `Provider`.
|
|
8
|
+
*/
|
|
9
|
+
export function isProviderName(name) {
|
|
10
|
+
return name === "Provider" || name.endsWith("Provider");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Family name contributed by a useXxx export binding.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} name - The exported binding name.
|
|
16
|
+
* @returns {string | null} The family name, or null when not a useXxx hook.
|
|
17
|
+
*/
|
|
18
|
+
export function hookFamily(name) {
|
|
19
|
+
const match = /^use([A-Z]\w*)$/u.exec(name);
|
|
20
|
+
return match === null ? null : (match[1] ?? null);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether a binding name denotes a custom hook (use + an uppercase letter).
|
|
24
|
+
*
|
|
25
|
+
* @param {string | null} name - The binding name, if known.
|
|
26
|
+
* @returns {name is string} True when the name starts with `use` + a capital.
|
|
27
|
+
*/
|
|
28
|
+
export function isHookName(name) {
|
|
29
|
+
return name !== null && /^use[A-Z]/u.test(name);
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a component family (a Provider plus a useXxx hook sharing one family
|
|
3
|
+
* name) must carry a dot-notation aggregate export. The useXxx hook is the
|
|
4
|
+
* family's consumption API and is exported separately by convention, so
|
|
5
|
+
* `aggregateOk` only asks whether the aggregate (export const Family = {
|
|
6
|
+
* Provider, ... }) exists and carries its Provider.
|
|
7
|
+
*
|
|
8
|
+
* @param {{ providerFamily: string | null; hookFamily: string; singleFamily: boolean; aggregateOk: boolean }} input - The family's export facts.
|
|
9
|
+
* @returns {boolean} True when an aggregate is required but absent.
|
|
10
|
+
*/
|
|
11
|
+
export declare function familyRequiresAggregate(input: {
|
|
12
|
+
providerFamily: string | null;
|
|
13
|
+
hookFamily: string;
|
|
14
|
+
singleFamily: boolean;
|
|
15
|
+
aggregateOk: boolean;
|
|
16
|
+
}): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A component family (a Provider plus a `useXxx` consumer hook) must be exported
|
|
19
|
+
* through a single dot-notation aggregate (`export const Family = { Provider, ... }`)
|
|
20
|
+
* so consumers compose `Family.Provider` / `Family.Header` and the blocks are
|
|
21
|
+
* discoverable. Bare re-exports of `Provider`/`useXxx` without the aggregate
|
|
22
|
+
* hide the family boundary.
|
|
23
|
+
*
|
|
24
|
+
* Uses createOnce; per-file state is reset in before() (which oxlint calls per
|
|
25
|
+
* file), so a family seen in one file cannot leak into another.
|
|
26
|
+
*/
|
|
27
|
+
export declare const requireDotNotationExportsRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isString } from "../../shared/structural.js";
|
|
3
|
+
import { hookFamily, isProviderName } from "../role.js";
|
|
4
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a component family (a Provider plus a useXxx hook sharing one family
|
|
7
|
+
* name) must carry a dot-notation aggregate export. The useXxx hook is the
|
|
8
|
+
* family's consumption API and is exported separately by convention, so
|
|
9
|
+
* `aggregateOk` only asks whether the aggregate (export const Family = {
|
|
10
|
+
* Provider, ... }) exists and carries its Provider.
|
|
11
|
+
*
|
|
12
|
+
* @param {{ providerFamily: string | null; hookFamily: string; singleFamily: boolean; aggregateOk: boolean }} input - The family's export facts.
|
|
13
|
+
* @returns {boolean} True when an aggregate is required but absent.
|
|
14
|
+
*/
|
|
15
|
+
export function familyRequiresAggregate(input) {
|
|
16
|
+
const providerPresent = input.providerFamily === input.hookFamily ||
|
|
17
|
+
(input.providerFamily === "" && input.singleFamily);
|
|
18
|
+
return providerPresent && !input.aggregateOk;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Property key names of an object literal.
|
|
22
|
+
*
|
|
23
|
+
* @param {ESTree.Node} node - The object expression node.
|
|
24
|
+
* @returns {Set<string>} The property key names.
|
|
25
|
+
*/
|
|
26
|
+
function objectPropKeys(node) {
|
|
27
|
+
const keys = new Set();
|
|
28
|
+
if (node.type !== "ObjectExpression")
|
|
29
|
+
return keys;
|
|
30
|
+
for (const prop of node.properties) {
|
|
31
|
+
if (prop.type === "Property") {
|
|
32
|
+
const key = prop.key;
|
|
33
|
+
if (key.type === "Identifier")
|
|
34
|
+
keys.add(key.name);
|
|
35
|
+
else if (key.type === "Literal" && isString(key.value))
|
|
36
|
+
keys.add(key.value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return keys;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Whether an aggregate's keys include the Provider (the family's stateful root).
|
|
43
|
+
* The useXxx hook is the family's consumption API and is exported separately by
|
|
44
|
+
* convention, so it need not appear as a key of the aggregate.
|
|
45
|
+
*
|
|
46
|
+
* @param {Set<string>} keys - The aggregate object's property keys.
|
|
47
|
+
* @returns {boolean} True when both the Provider and the hook are present.
|
|
48
|
+
*/
|
|
49
|
+
function hasProviderKey(keys) {
|
|
50
|
+
for (const k of keys)
|
|
51
|
+
if (k === "Provider" || /Provider$/u.test(k))
|
|
52
|
+
return true;
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A component family (a Provider plus a `useXxx` consumer hook) must be exported
|
|
57
|
+
* through a single dot-notation aggregate (`export const Family = { Provider, ... }`)
|
|
58
|
+
* so consumers compose `Family.Provider` / `Family.Header` and the blocks are
|
|
59
|
+
* discoverable. Bare re-exports of `Provider`/`useXxx` without the aggregate
|
|
60
|
+
* hide the family boundary.
|
|
61
|
+
*
|
|
62
|
+
* Uses createOnce; per-file state is reset in before() (which oxlint calls per
|
|
63
|
+
* file), so a family seen in one file cannot leak into another.
|
|
64
|
+
*/
|
|
65
|
+
export const requireDotNotationExportsRule = defineRule({
|
|
66
|
+
meta: {
|
|
67
|
+
type: "problem",
|
|
68
|
+
docs: {
|
|
69
|
+
description: "Require a component family (Provider + useXxx hook) to be exported via a single dot-notation aggregate (export const Family = { Provider, ... }).",
|
|
70
|
+
},
|
|
71
|
+
messages: {
|
|
72
|
+
missingAggregate: "Component family `{{family}}` exports a Provider and a `use{{family}}` hook but no dot-notation aggregate `export const {{family}} = { Provider, ... }`. Export the family as one object so consumers compose `{{family}}.Provider` / `{{family}}.Header` and the blocks are discoverable.",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
createOnce(context) {
|
|
76
|
+
const providerBases = new Set();
|
|
77
|
+
const hookFamilies = new Set();
|
|
78
|
+
const aggregates = new Map();
|
|
79
|
+
let reportNode = null;
|
|
80
|
+
const recordName = (entry) => {
|
|
81
|
+
if (reportNode === null)
|
|
82
|
+
reportNode = entry.node;
|
|
83
|
+
if (isProviderName(entry.name)) {
|
|
84
|
+
providerBases.add(entry.name === "Provider" ? "" : entry.name.slice(0, -"Provider".length));
|
|
85
|
+
}
|
|
86
|
+
const hf = hookFamily(entry.name);
|
|
87
|
+
if (hf !== null)
|
|
88
|
+
hookFamilies.add(hf);
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
before() {
|
|
92
|
+
providerBases.clear();
|
|
93
|
+
hookFamilies.clear();
|
|
94
|
+
aggregates.clear();
|
|
95
|
+
reportNode = null;
|
|
96
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
97
|
+
return false;
|
|
98
|
+
},
|
|
99
|
+
ExportNamedDeclaration(node) {
|
|
100
|
+
const decl = node.declaration;
|
|
101
|
+
if (decl !== null && decl !== undefined) {
|
|
102
|
+
if (decl.type === "VariableDeclaration") {
|
|
103
|
+
for (const declarator of decl.declarations) {
|
|
104
|
+
if (declarator.id.type !== "Identifier")
|
|
105
|
+
continue;
|
|
106
|
+
recordName({ name: declarator.id.name, node });
|
|
107
|
+
if (declarator.init?.type === "ObjectExpression") {
|
|
108
|
+
aggregates.set(declarator.id.name, objectPropKeys(declarator.init));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (decl.type === "FunctionDeclaration" && decl.id !== null) {
|
|
113
|
+
recordName({ name: decl.id.name, node });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (const specifier of node.specifiers) {
|
|
117
|
+
if (specifier.type !== "ExportSpecifier")
|
|
118
|
+
continue;
|
|
119
|
+
const exported = specifier.exported;
|
|
120
|
+
const name = exported.type === "Identifier" ? exported.name : (exported.value ?? "");
|
|
121
|
+
recordName({ name, node });
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"Program:exit"() {
|
|
125
|
+
if (hookFamilies.size === 0)
|
|
126
|
+
return;
|
|
127
|
+
const node = reportNode;
|
|
128
|
+
if (node === null)
|
|
129
|
+
return;
|
|
130
|
+
const singleFamily = hookFamilies.size === 1;
|
|
131
|
+
for (const family of hookFamilies) {
|
|
132
|
+
const providerPresent = providerBases.has(family) || (providerBases.has("") && singleFamily);
|
|
133
|
+
if (!providerPresent)
|
|
134
|
+
continue;
|
|
135
|
+
const agg = aggregates.get(family);
|
|
136
|
+
const ok = agg !== undefined && hasProviderKey(agg);
|
|
137
|
+
if (ok)
|
|
138
|
+
continue;
|
|
139
|
+
context.report({ node, messageId: "missingAggregate", data: { family } });
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a custom context hook that reads context must be reported for
|
|
3
|
+
* lacking a guard against a missing Provider.
|
|
4
|
+
*
|
|
5
|
+
* @param {{ isHook: boolean; callsUseContext: boolean; guarded: boolean }} input - The hook's shape facts.
|
|
6
|
+
* @returns {boolean} True when the hook needs a guard but has none.
|
|
7
|
+
*/
|
|
8
|
+
export declare function requiresContextGuard(input: {
|
|
9
|
+
isHook: boolean;
|
|
10
|
+
callsUseContext: boolean;
|
|
11
|
+
guarded: boolean;
|
|
12
|
+
}): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* A custom hook that reads context with `useContext` must throw when the
|
|
15
|
+
* Provider is missing, rather than returning `undefined` and pushing a
|
|
16
|
+
* null-check onto every consumer. Returning a possibly-undefined context is the
|
|
17
|
+
* same hidden-nullable defect the rest of the library forbids.
|
|
18
|
+
*/
|
|
19
|
+
export declare const requireGuardedContextHookRule: import("@oxlint/plugins").Rule;
|