@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,29 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isGlobalReflectMethodCall } from "../shared/reflect-method.js";
|
|
3
|
+
/** Ban Reflect.apply, which bypasses ordinary typed function calls. */
|
|
4
|
+
export const noReflectApplyRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: {
|
|
8
|
+
description: "Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface.",
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
reflectApply: "Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
createOnce(context) {
|
|
15
|
+
return {
|
|
16
|
+
CallExpression(node) {
|
|
17
|
+
if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
|
|
18
|
+
return;
|
|
19
|
+
if (isGlobalReflectMethodCall({
|
|
20
|
+
sourceCode: context.sourceCode,
|
|
21
|
+
callee: node.callee,
|
|
22
|
+
methodName: "apply",
|
|
23
|
+
})) {
|
|
24
|
+
context.report({ node, messageId: "reflectApply" });
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isGlobalReflectMethodCall } from "../shared/reflect-method.js";
|
|
3
|
+
/** Ban Reflect.get, which bypasses ordinary property access and useful type evidence. */
|
|
4
|
+
export const noReflectGetRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: {
|
|
8
|
+
description: "Disallow Reflect.get; use typed property access or parse dynamic input into a domain type.",
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
reflectGet: "Replace `Reflect.get` with typed property access. Parse dynamic input into a named domain type before reading it.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
createOnce(context) {
|
|
15
|
+
return {
|
|
16
|
+
CallExpression(node) {
|
|
17
|
+
if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
|
|
18
|
+
return;
|
|
19
|
+
if (isGlobalReflectMethodCall({
|
|
20
|
+
sourceCode: context.sourceCode,
|
|
21
|
+
callee: node.callee,
|
|
22
|
+
methodName: "get",
|
|
23
|
+
})) {
|
|
24
|
+
context.report({ node, messageId: "reflectGet" });
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
/** Whether a function-like body consists solely of returning an as-cast.
|
|
3
|
+
*
|
|
4
|
+
* @param {ESTree.Node | null | undefined} body - The function body to inspect.
|
|
5
|
+
* @returns {boolean} True when the body only returns an as-cast expression.
|
|
6
|
+
*/
|
|
7
|
+
function isSoleReturnOfAssertion(body) {
|
|
8
|
+
if (body === null || body === undefined)
|
|
9
|
+
return false;
|
|
10
|
+
if (body.type === "BlockStatement") {
|
|
11
|
+
if (body.body.length !== 1)
|
|
12
|
+
return false;
|
|
13
|
+
const only = body.body[0];
|
|
14
|
+
return only?.type === "ReturnStatement" && only.argument?.type === "TSAsExpression";
|
|
15
|
+
}
|
|
16
|
+
return body.type === "TSAsExpression";
|
|
17
|
+
}
|
|
18
|
+
/** Whether the assertion node has an adjacent `// SAFETY:` justification.
|
|
19
|
+
*
|
|
20
|
+
* @param {{ getCommentsBefore(n: ESTree.Node): Array<CommentLike> }} sourceCode - The rule's source-code accessor.
|
|
21
|
+
* @param {ESTree.Node} node - The assertion node.
|
|
22
|
+
* @returns {boolean} True when a SAFETY comment precedes the assertion.
|
|
23
|
+
*/
|
|
24
|
+
function hasAdjacentSafetyComment(sourceCode, node) {
|
|
25
|
+
return sourceCode.getCommentsBefore(node).some((comment) => /\bSAFETY\s*:/u.test(comment.value));
|
|
26
|
+
}
|
|
27
|
+
/** Type assertions erase evidence; `as const` is exempt and `// SAFETY:` documents rare verified invariants. */
|
|
28
|
+
export const noReinterpretCastRule = defineRule({
|
|
29
|
+
meta: {
|
|
30
|
+
type: "problem",
|
|
31
|
+
docs: {
|
|
32
|
+
description: "Disallow type reinterpretation via `as`; absence must be modeled by the type system, with SAFETY-commented exceptions.",
|
|
33
|
+
},
|
|
34
|
+
messages: {
|
|
35
|
+
noReinterpret: "Type assertion discards type evidence. Narrow with discriminants/`in` checks or a type predicate instead.",
|
|
36
|
+
noLaundering: "`{{name}}` exists only to perform a type assertion: a laundering wrapper that hides the cast from review and tooling.",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
createOnce(context) {
|
|
40
|
+
return {
|
|
41
|
+
TSAsExpression(node) {
|
|
42
|
+
const annotation = node.typeAnnotation;
|
|
43
|
+
if (annotation.type === "TSTypeReference" &&
|
|
44
|
+
annotation.typeName.type === "Identifier" &&
|
|
45
|
+
annotation.typeName.name === "const")
|
|
46
|
+
return;
|
|
47
|
+
if (hasAdjacentSafetyComment(context.sourceCode, node))
|
|
48
|
+
return;
|
|
49
|
+
context.report({ node, messageId: "noReinterpret" });
|
|
50
|
+
},
|
|
51
|
+
TSTypeAssertion(node) {
|
|
52
|
+
if (hasAdjacentSafetyComment(context.sourceCode, node))
|
|
53
|
+
return;
|
|
54
|
+
context.report({ node, messageId: "noReinterpret" });
|
|
55
|
+
},
|
|
56
|
+
FunctionDeclaration(node) {
|
|
57
|
+
if (node.body !== null && isSoleReturnOfAssertion(node.body)) {
|
|
58
|
+
context.report({ node, messageId: "noLaundering", data: { name: node.id?.name ?? "<anonymous>" } });
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
ArrowFunctionExpression(node) {
|
|
62
|
+
if (node.body.type === "TSAsExpression") {
|
|
63
|
+
context.report({ node, messageId: "noLaundering", data: { name: "<arrow>" } });
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { readField } from "../shared/structural.js";
|
|
3
|
+
import { ancestorsOf } from "../shared/ancestors.js";
|
|
4
|
+
import { firstOptionRecord } from "../shared/rule-options.js";
|
|
5
|
+
/** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
|
|
6
|
+
export const noRuntimeTypeofRule = defineRule({
|
|
7
|
+
meta: {
|
|
8
|
+
type: "problem",
|
|
9
|
+
docs: {
|
|
10
|
+
description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary.",
|
|
11
|
+
},
|
|
12
|
+
messages: {
|
|
13
|
+
runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
|
|
14
|
+
},
|
|
15
|
+
schema: [
|
|
16
|
+
{
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
allowInTypeGuards: { type: "boolean" },
|
|
20
|
+
},
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
defaultOptions: [{ allowInTypeGuards: false }],
|
|
25
|
+
},
|
|
26
|
+
createOnce(context) {
|
|
27
|
+
return {
|
|
28
|
+
UnaryExpression(node) {
|
|
29
|
+
if (node.operator !== "typeof")
|
|
30
|
+
return;
|
|
31
|
+
const option = firstOptionRecord(context.options);
|
|
32
|
+
const allowInTypeGuards = option.allowInTypeGuards === true;
|
|
33
|
+
let insideTypeGuard = false;
|
|
34
|
+
if (allowInTypeGuards) {
|
|
35
|
+
const ancestors = ancestorsOf(context.sourceCode, node);
|
|
36
|
+
for (let index = ancestors.length - 1; index >= 0; index--) {
|
|
37
|
+
const current = ancestors[index];
|
|
38
|
+
if (current.type === "Program")
|
|
39
|
+
break;
|
|
40
|
+
if (current.type === "ArrowFunctionExpression" ||
|
|
41
|
+
current.type === "FunctionDeclaration" ||
|
|
42
|
+
current.type === "FunctionExpression") {
|
|
43
|
+
insideTypeGuard =
|
|
44
|
+
current.returnType?.typeAnnotation.type === "TSTypePredicate";
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!insideTypeGuard)
|
|
50
|
+
context.report({ node, messageId: "runtimeTypeof" });
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { readField } from "../shared/structural.js";
|
|
3
|
+
import { ancestorsOf } from "../shared/ancestors.js";
|
|
4
|
+
const SENTINELS = new Set([-1, 0, 1]);
|
|
5
|
+
const ORDERING_OPERATORS = new Set([">", "<", ">=", "<="]);
|
|
6
|
+
function sentinelValue(expression) {
|
|
7
|
+
if (expression.type === "Literal") {
|
|
8
|
+
const numeric = readField(expression, "value");
|
|
9
|
+
return numeric !== undefined && SENTINELS.has(numeric) ? numeric : null;
|
|
10
|
+
}
|
|
11
|
+
if (expression.type === "UnaryExpression" &&
|
|
12
|
+
expression.operator === "-" &&
|
|
13
|
+
expression.argument.type === "Literal" &&
|
|
14
|
+
expression.argument.value === -1) {
|
|
15
|
+
return -1;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
/** True when every leaf of an expression tree is one of the ordering sentinels.
|
|
20
|
+
* @param {ESTree.Expression} expression - Candidate expression to inspect.
|
|
21
|
+
* @returns {boolean} True when the expression (or both conditional branches) are sentinels. */
|
|
22
|
+
function chainIsSentinel(expression) {
|
|
23
|
+
if (sentinelValue(expression) !== null)
|
|
24
|
+
return true;
|
|
25
|
+
if (expression.type === "ConditionalExpression") {
|
|
26
|
+
return chainIsSentinel(expression.consequent) && chainIsSentinel(expression.alternate);
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function hasOrderingComparison(expression) {
|
|
31
|
+
if (expression.type === "BinaryExpression") {
|
|
32
|
+
return ORDERING_OPERATORS.has(expression.operator);
|
|
33
|
+
}
|
|
34
|
+
if (expression.type === "LogicalExpression") {
|
|
35
|
+
return hasOrderingComparison(expression.left) || hasOrderingComparison(expression.right);
|
|
36
|
+
}
|
|
37
|
+
if (expression.type === "UnaryExpression") {
|
|
38
|
+
return hasOrderingComparison(expression.argument);
|
|
39
|
+
}
|
|
40
|
+
if (expression.type === "ParenthesizedExpression") {
|
|
41
|
+
return hasOrderingComparison(expression.expression);
|
|
42
|
+
}
|
|
43
|
+
if (expression.type === "ConditionalExpression") {
|
|
44
|
+
return (hasOrderingComparison(expression.test) ||
|
|
45
|
+
hasOrderingComparison(expression.consequent) ||
|
|
46
|
+
hasOrderingComparison(expression.alternate));
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
/** True when the conditional is nested under a larger sentinel chain already reported at its root.
|
|
51
|
+
* @param {ESTree.ConditionalExpression} node - The conditional being checked.
|
|
52
|
+
* @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain from the traversal engine.
|
|
53
|
+
* @returns {boolean} True when an enclosing conditional already forms a reported sentinel chain. */
|
|
54
|
+
function coveredByOuterSentinelChain(node, ancestors) {
|
|
55
|
+
for (let index = ancestors.length - 1; index >= 0; index--) {
|
|
56
|
+
const current = ancestors[index];
|
|
57
|
+
if (current.type === "ConditionalExpression") {
|
|
58
|
+
if (chainIsSentinel(current))
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
else if (current.type === "ArrowFunctionExpression" ||
|
|
62
|
+
current.type === "FunctionDeclaration" ||
|
|
63
|
+
current.type === "FunctionExpression" ||
|
|
64
|
+
current.type === "Program") {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
function asSingleReturnSentinel(statement) {
|
|
71
|
+
const target = statement.type === "BlockStatement" && statement.body.length === 1
|
|
72
|
+
? statement.body[0] ?? statement
|
|
73
|
+
: statement;
|
|
74
|
+
return (target.type === "ReturnStatement" &&
|
|
75
|
+
target.argument !== null &&
|
|
76
|
+
sentinelValue(target.argument) !== null);
|
|
77
|
+
}
|
|
78
|
+
/** True when an if/else-if/else chain returns only ordering sentinels from every branch.
|
|
79
|
+
* @param {ESTree.IfStatement} node - The root if-statement of the chain.
|
|
80
|
+
* @returns {boolean} True when every branch returns a sentinel comparison. */
|
|
81
|
+
function ifChainIsSentinel(node) {
|
|
82
|
+
let branch = node;
|
|
83
|
+
while (branch !== null) {
|
|
84
|
+
if (!asSingleReturnSentinel(branch.consequent))
|
|
85
|
+
return false;
|
|
86
|
+
const alternate = branch.alternate;
|
|
87
|
+
if (alternate === null)
|
|
88
|
+
return false;
|
|
89
|
+
if (alternate.type === "IfStatement") {
|
|
90
|
+
branch = alternate;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
return asSingleReturnSentinel(alternate);
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
/** Ban hand-built -1/0/1 comparison results; ordering must go through a named order. */
|
|
98
|
+
export const noSentinelComparisonUnionRule = defineRule({
|
|
99
|
+
meta: {
|
|
100
|
+
type: "problem",
|
|
101
|
+
docs: {
|
|
102
|
+
description: "Disallow hand-built -1/0/1 ordering results from comparison expressions; use a named Order/Ordering or a domain comparison instead.",
|
|
103
|
+
},
|
|
104
|
+
messages: {
|
|
105
|
+
sentinelComparisonUnion: "This comparison hand-builds a -1/0/1 result. Publish a named order (Order.compare + Ordering.match) or return the compared values directly.",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
createOnce(context) {
|
|
109
|
+
return {
|
|
110
|
+
ConditionalExpression(node) {
|
|
111
|
+
if (!chainIsSentinel(node))
|
|
112
|
+
return;
|
|
113
|
+
if (coveredByOuterSentinelChain(node, ancestorsOf(context.sourceCode, node)))
|
|
114
|
+
return;
|
|
115
|
+
if (!hasOrderingComparison(node))
|
|
116
|
+
return;
|
|
117
|
+
context.report({ node, messageId: "sentinelComparisonUnion" });
|
|
118
|
+
},
|
|
119
|
+
IfStatement(node) {
|
|
120
|
+
const parent = ancestorsOf(context.sourceCode, node).at(-1);
|
|
121
|
+
if (parent?.type === "IfStatement" && parent.alternate === node)
|
|
122
|
+
return;
|
|
123
|
+
if (!ifChainIsSentinel(node))
|
|
124
|
+
return;
|
|
125
|
+
const conditions = [node.test];
|
|
126
|
+
let branch = node.alternate;
|
|
127
|
+
while (branch !== null) {
|
|
128
|
+
if (branch.type !== "IfStatement")
|
|
129
|
+
break;
|
|
130
|
+
conditions.push(branch.test);
|
|
131
|
+
branch = branch.alternate;
|
|
132
|
+
}
|
|
133
|
+
if (!conditions.some(hasOrderingComparison))
|
|
134
|
+
return;
|
|
135
|
+
context.report({ node, messageId: "sentinelComparisonUnion" });
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const FORBIDDEN_SYMBOL_NAME = "shape";
|
|
3
|
+
/**
|
|
4
|
+
* Whether a symbol name contains the forbidden substring.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} name - The symbol name to inspect.
|
|
7
|
+
* @returns {boolean} True when the name contains the forbidden term.
|
|
8
|
+
*/
|
|
9
|
+
function containsForbiddenSymbolName(name) {
|
|
10
|
+
return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
|
|
11
|
+
}
|
|
12
|
+
/** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
|
|
13
|
+
export const noForbiddenTermInSymbolNamesRule = defineRule({
|
|
14
|
+
meta: {
|
|
15
|
+
type: "problem",
|
|
16
|
+
docs: {
|
|
17
|
+
description: 'Disallow the case-insensitive substring "shape" in JavaScript, TypeScript, private, and JSX symbol names.',
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
forbiddenSymbolName: 'Rename symbol "{{name}}" for its domain role; "shape" describes structure rather than ownership.',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
createOnce(context) {
|
|
24
|
+
const reportForbiddenSymbolName = (node) => {
|
|
25
|
+
if (!containsForbiddenSymbolName(node.name))
|
|
26
|
+
return;
|
|
27
|
+
context.report({
|
|
28
|
+
node,
|
|
29
|
+
messageId: "forbiddenSymbolName",
|
|
30
|
+
data: { name: node.name },
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
Identifier: reportForbiddenSymbolName,
|
|
35
|
+
PrivateIdentifier: reportForbiddenSymbolName,
|
|
36
|
+
JSXIdentifier: reportForbiddenSymbolName,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a function is a pure alias: it returns a single call that forwards
|
|
4
|
+
* each of its parameters verbatim (a generator may delegate-yield such a call).
|
|
5
|
+
* Anything else raises the level of abstraction and earns its name.
|
|
6
|
+
*
|
|
7
|
+
* @param {ESTree.Node} fn - The function-like node to inspect.
|
|
8
|
+
* @returns {boolean} True when the function is dead indirection.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isTrivialForwarder(fn: ESTree.Node): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Top-level privates referenced exactly once are only worth inlining when they
|
|
13
|
+
* are pure aliases (they forward their inputs verbatim to another call). A
|
|
14
|
+
* single-use helper that earns its name by raising the level of abstraction is
|
|
15
|
+
* kept: the document argues for factoring proactively, even at n=1.
|
|
16
|
+
*/
|
|
17
|
+
export declare const noSingleUsePrivateFunctionsRule: import("@oxlint/plugins").Rule;
|