@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,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disallow forwarding raw error messages from caught exceptions. This pattern
|
|
3
|
+
* re-invent's Effect's typed error channel: raw strings leak internal details
|
|
4
|
+
* (stack traces, file paths, database errors) and lose structure so callers
|
|
5
|
+
* can't match on the failure kind.
|
|
6
|
+
*
|
|
7
|
+
* Use Effect's `TaggedError`: a tagged class per failure kind carrying
|
|
8
|
+
* structured evidence as fields, rendering its message from those fields. The
|
|
9
|
+
* error then flows through Effect's typed error channel instead of being
|
|
10
|
+
* stringified at every boundary.
|
|
11
|
+
*/
|
|
12
|
+
export declare const noRawErrorForwardingRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { ancestorsOf } from "../../shared/ancestors.js";
|
|
3
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
4
|
+
/** Error properties that carry internal details and must not be forwarded raw. */
|
|
5
|
+
const ERROR_PROPS = new Set(["message", "stack"]);
|
|
6
|
+
/**
|
|
7
|
+
* Whether a member expression accesses an error property on a catch parameter.
|
|
8
|
+
* @param {ESTree.MemberExpression} member - The member expression to test.
|
|
9
|
+
* @param {ReadonlySet<string>} catchParams - Names of catch parameters in scope.
|
|
10
|
+
* @returns {boolean} True when the member accesses an error property on a catch param.
|
|
11
|
+
*/
|
|
12
|
+
function isErrorPropAccess(member, catchParams) {
|
|
13
|
+
if (member.object.type !== "Identifier")
|
|
14
|
+
return false;
|
|
15
|
+
if (!catchParams.has(member.object.name))
|
|
16
|
+
return false;
|
|
17
|
+
if (member.computed)
|
|
18
|
+
return false;
|
|
19
|
+
return member.property.type === "Identifier" && ERROR_PROPS.has(member.property.name);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether the error property access is inside a console.* call (logging, not forwarding).
|
|
23
|
+
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
24
|
+
* @param {ESTree.Node} node - The node to test.
|
|
25
|
+
* @returns {boolean} True when the access is inside a console.* call.
|
|
26
|
+
*/
|
|
27
|
+
function isLoggingCall(sourceCode, node) {
|
|
28
|
+
const chain = ancestorsOf(sourceCode, node);
|
|
29
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
30
|
+
const ancestor = chain[i];
|
|
31
|
+
if (ancestor === undefined)
|
|
32
|
+
continue;
|
|
33
|
+
if (ancestor.type === "CallExpression" && ancestor.callee.type === "MemberExpression") {
|
|
34
|
+
const obj = ancestor.callee.object;
|
|
35
|
+
if (obj.type === "Identifier" && obj.name === "console")
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (ancestor.type === "Program" || ancestor.type === "BlockStatement")
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Disallow forwarding raw error messages from caught exceptions. This pattern
|
|
45
|
+
* re-invent's Effect's typed error channel: raw strings leak internal details
|
|
46
|
+
* (stack traces, file paths, database errors) and lose structure so callers
|
|
47
|
+
* can't match on the failure kind.
|
|
48
|
+
*
|
|
49
|
+
* Use Effect's `TaggedError`: a tagged class per failure kind carrying
|
|
50
|
+
* structured evidence as fields, rendering its message from those fields. The
|
|
51
|
+
* error then flows through Effect's typed error channel instead of being
|
|
52
|
+
* stringified at every boundary.
|
|
53
|
+
*/
|
|
54
|
+
export const noRawErrorForwardingRule = defineRule({
|
|
55
|
+
meta: {
|
|
56
|
+
type: "problem",
|
|
57
|
+
docs: {
|
|
58
|
+
description: "Disallow forwarding raw error messages (e.message, e.stack) from caught exceptions; this pattern re-invent's Effect's typed error channel. Use Effect's TaggedError so failures carry structured evidence and flow through the typed channel.",
|
|
59
|
+
},
|
|
60
|
+
messages: {
|
|
61
|
+
rawErrorForwarding: "Forwarding the raw error '{{prop}}' re-invent's Effect's typed error channel: it leaks internal details and loses structure so callers can't match on the failure kind. Use Effect's TaggedError (a tagged class per failure kind carrying structured evidence as fields) so the error flows through the typed channel.",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
createOnce(context) {
|
|
65
|
+
const catchParamStack = [];
|
|
66
|
+
return {
|
|
67
|
+
before() {
|
|
68
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
69
|
+
return false;
|
|
70
|
+
},
|
|
71
|
+
CatchClause(node) {
|
|
72
|
+
const param = node.param;
|
|
73
|
+
if (param !== null && param !== undefined && param.type === "Identifier") {
|
|
74
|
+
catchParamStack.push(new Set([param.name]));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
catchParamStack.push(new Set());
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"CatchClause:exit"() {
|
|
81
|
+
catchParamStack.pop();
|
|
82
|
+
},
|
|
83
|
+
MemberExpression(node) {
|
|
84
|
+
if (catchParamStack.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
const allParams = new Set();
|
|
87
|
+
for (const params of catchParamStack) {
|
|
88
|
+
for (const name of params)
|
|
89
|
+
allParams.add(name);
|
|
90
|
+
}
|
|
91
|
+
if (!isErrorPropAccess(node, allParams))
|
|
92
|
+
return;
|
|
93
|
+
if (isLoggingCall(context.sourceCode, node))
|
|
94
|
+
return;
|
|
95
|
+
context.report({
|
|
96
|
+
node,
|
|
97
|
+
messageId: "rawErrorForwarding",
|
|
98
|
+
data: { prop: node.property.type === "Identifier" ? node.property.name : "message" },
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const BANNED = new Set(["Class", "TaggedClass"]);
|
|
3
|
+
function isBannedSchemaStatic(expression) {
|
|
4
|
+
return (expression?.type === "MemberExpression" &&
|
|
5
|
+
expression.object.type === "Identifier" &&
|
|
6
|
+
expression.object.name === "Schema" &&
|
|
7
|
+
expression.property.type === "Identifier" &&
|
|
8
|
+
BANNED.has(expression.property.name));
|
|
9
|
+
}
|
|
10
|
+
/** Schema.Class/TaggedClass must not be the default data-modeling pattern. */
|
|
11
|
+
export const noSchemaClassModelingRule = defineRule({
|
|
12
|
+
meta: {
|
|
13
|
+
type: "problem",
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Disallow Schema.Class and Schema.TaggedClass as default data-modeling patterns; model records with Schema.Struct plus a same-name interface, variants with Schema.TaggedUnion/TaggedStruct, and typed errors with Schema.TaggedError.",
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
schemaClass: "Do not introduce `Schema.{{name}}` as a data-modeling pattern. Model records with `Schema.Struct(...)` plus a same-name interface, tagged variants with `Schema.TaggedStruct`/`Schema.TaggedUnion`, and typed errors with `Schema.TaggedError`.",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
createOnce(context) {
|
|
22
|
+
const checkExpression = (callee) => {
|
|
23
|
+
if (!isBannedSchemaStatic(callee))
|
|
24
|
+
return;
|
|
25
|
+
const property = callee.property;
|
|
26
|
+
if (property.type !== "Identifier")
|
|
27
|
+
return;
|
|
28
|
+
context.report({
|
|
29
|
+
node: callee,
|
|
30
|
+
messageId: "schemaClass",
|
|
31
|
+
data: { name: property.name },
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
CallExpression(node) {
|
|
36
|
+
checkExpression(node.callee);
|
|
37
|
+
},
|
|
38
|
+
ClassDeclaration(node) {
|
|
39
|
+
if (!isBannedSchemaStatic(node.superClass))
|
|
40
|
+
return;
|
|
41
|
+
const property = node.superClass.property;
|
|
42
|
+
if (property.type !== "Identifier")
|
|
43
|
+
return;
|
|
44
|
+
context.report({
|
|
45
|
+
node: node.superClass,
|
|
46
|
+
messageId: "schemaClass",
|
|
47
|
+
data: { name: property.name },
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
3
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
4
|
+
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
5
|
+
export const noServiceConstructorImportsRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: {
|
|
9
|
+
description: "Disallow project-local make<CapabilityName> imports outside test and spec files.",
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
serviceConstructorImport: 'Do not import Effect service constructor "{{name}}" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root.',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
createOnce(context) {
|
|
16
|
+
let isTestFile = false;
|
|
17
|
+
return {
|
|
18
|
+
before() {
|
|
19
|
+
isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
20
|
+
},
|
|
21
|
+
ImportDeclaration(node) {
|
|
22
|
+
const source = node.source.value;
|
|
23
|
+
if (isTestFile || !(source.startsWith("./") || source.startsWith("../")))
|
|
24
|
+
return;
|
|
25
|
+
for (const specifier of node.specifiers) {
|
|
26
|
+
if (specifier.type !== "ImportSpecifier")
|
|
27
|
+
continue;
|
|
28
|
+
const importedName = specifier.imported.type === "Identifier"
|
|
29
|
+
? specifier.imported.name
|
|
30
|
+
: specifier.imported.value;
|
|
31
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName))
|
|
32
|
+
continue;
|
|
33
|
+
context.report({
|
|
34
|
+
node: specifier,
|
|
35
|
+
messageId: "serviceConstructorImport",
|
|
36
|
+
data: { name: importedName },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
3
|
+
const CATCH_METHODS = new Set([
|
|
4
|
+
"catch",
|
|
5
|
+
"catchTag",
|
|
6
|
+
"catchTags",
|
|
7
|
+
"catchReason",
|
|
8
|
+
"catchReasons",
|
|
9
|
+
]);
|
|
10
|
+
const VOID_OR_UNIT_METHODS = new Set(["void", "unit"]);
|
|
11
|
+
/**
|
|
12
|
+
* Whether the expression is the bare `Effect.void` / `Effect.unit` member.
|
|
13
|
+
*
|
|
14
|
+
* @param {ESTree.Node | null | undefined} node - The candidate member expression.
|
|
15
|
+
* @returns {boolean} True when the expression reads Effect.void or Effect.unit.
|
|
16
|
+
*/
|
|
17
|
+
function isEffectVoidOrUnit(node) {
|
|
18
|
+
if (node === null || node === undefined || node.type !== "MemberExpression")
|
|
19
|
+
return false;
|
|
20
|
+
if (node.object.type !== "Identifier" || node.object.name !== "Effect")
|
|
21
|
+
return false;
|
|
22
|
+
return node.property.type === "Identifier" && VOID_OR_UNIT_METHODS.has(node.property.name);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A recovery callback that reduces every failure to Effect.void/unit swallows it silently.
|
|
26
|
+
*
|
|
27
|
+
* @param {ESTree.Node} handler - The catch handler argument to inspect.
|
|
28
|
+
* @returns {boolean} True when the handler can only produce Effect.void/unit.
|
|
29
|
+
*/
|
|
30
|
+
function returnsOnlyVoid(handler) {
|
|
31
|
+
if (handler.type !== "ArrowFunctionExpression" &&
|
|
32
|
+
handler.type !== "FunctionExpression") {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const body = handler.body;
|
|
36
|
+
if (body === null || body === undefined)
|
|
37
|
+
return false;
|
|
38
|
+
if (isEffectVoidOrUnit(body))
|
|
39
|
+
return true;
|
|
40
|
+
if (body.type !== "BlockStatement")
|
|
41
|
+
return false;
|
|
42
|
+
if (body.body.length !== 1)
|
|
43
|
+
return false;
|
|
44
|
+
const statement = body.body[0];
|
|
45
|
+
if (statement.type !== "ReturnStatement")
|
|
46
|
+
return false;
|
|
47
|
+
return isEffectVoidOrUnit(statement.argument);
|
|
48
|
+
}
|
|
49
|
+
/** Recovering into Effect.void/Effect.unit erases the failure; recover meaningfully or propagate. */
|
|
50
|
+
export const noSilentErrorSwallowRule = defineRule({
|
|
51
|
+
meta: {
|
|
52
|
+
type: "problem",
|
|
53
|
+
docs: {
|
|
54
|
+
description: "Disallow Effect catch handlers that reduce failures to Effect.void or Effect.unit; recover meaningfully, transform the error, or let it propagate.",
|
|
55
|
+
},
|
|
56
|
+
messages: {
|
|
57
|
+
silentSwallow: "This catch handler reduces every failure to `Effect.void`/`Effect.unit`, erasing the error. Recover meaningfully, transform it into a tagged failure, or remove the handler and let the error propagate.",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
createOnce(context) {
|
|
61
|
+
return {
|
|
62
|
+
before() {
|
|
63
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
64
|
+
return false;
|
|
65
|
+
},
|
|
66
|
+
CallExpression(node) {
|
|
67
|
+
const callee = node.callee;
|
|
68
|
+
if (callee.type !== "MemberExpression" ||
|
|
69
|
+
callee.computed ||
|
|
70
|
+
callee.object.type !== "Identifier" ||
|
|
71
|
+
callee.object.name !== "Effect" ||
|
|
72
|
+
callee.property.type !== "Identifier" ||
|
|
73
|
+
!CATCH_METHODS.has(callee.property.name)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
for (const argument of node.arguments) {
|
|
77
|
+
if (returnsOnlyVoid(argument)) {
|
|
78
|
+
context.report({ node, messageId: "silentSwallow" });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (argument.type !== "ObjectExpression")
|
|
82
|
+
continue;
|
|
83
|
+
for (const property of argument.properties) {
|
|
84
|
+
if (property.type !== "Property")
|
|
85
|
+
continue;
|
|
86
|
+
if (returnsOnlyVoid(property.value)) {
|
|
87
|
+
context.report({ node, messageId: "silentSwallow" });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Static forwarders alias a service method at module scope; acquire the service where its method is used instead.
|
|
2
|
+
*
|
|
3
|
+
* Import tracking covers local names bound by imports of "effect" and
|
|
4
|
+
* "effect/Effect"; re-exports are not tracked.
|
|
5
|
+
*/
|
|
6
|
+
export declare const noStaticEffectServiceForwardersRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { ancestorsOf } from "../../shared/ancestors.js";
|
|
3
|
+
import { isString } from "../../shared/structural.js";
|
|
4
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
5
|
+
/** Computed or plain property name on a member expression.
|
|
6
|
+
*
|
|
7
|
+
* @param {ESTree.MemberExpression} member - The member expression node.
|
|
8
|
+
* @returns {string | null} The property name, or null when unavailable.
|
|
9
|
+
*/
|
|
10
|
+
function memberName(member) {
|
|
11
|
+
if (!member.computed) {
|
|
12
|
+
return member.property.type === "Identifier" ? member.property.name : null;
|
|
13
|
+
}
|
|
14
|
+
if (member.property.type === "Literal" && isString(member.property.value)) {
|
|
15
|
+
return member.property.value;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
/** Imported name behind an import specifier, for both plain and string-literal spellings.
|
|
20
|
+
*
|
|
21
|
+
* @param {ESTree.Node} specifier - The import specifier node.
|
|
22
|
+
* @returns {string | undefined} The imported name, if any.
|
|
23
|
+
*/
|
|
24
|
+
function importedNameOf(specifier) {
|
|
25
|
+
if (specifier.type !== "ImportSpecifier")
|
|
26
|
+
return undefined;
|
|
27
|
+
return specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
28
|
+
}
|
|
29
|
+
/** Local binding name of an import specifier.
|
|
30
|
+
*
|
|
31
|
+
* @param {ESTree.Node} specifier - The import specifier node.
|
|
32
|
+
* @returns {string | undefined} The local bound name, if any.
|
|
33
|
+
*/
|
|
34
|
+
function localNameOf(specifier) {
|
|
35
|
+
return specifier.type === "ImportSpecifier" || specifier.type === "ImportNamespaceSpecifier"
|
|
36
|
+
? specifier.local.name
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Whether the call site sits inside a `static` class property initializer.
|
|
40
|
+
*
|
|
41
|
+
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
42
|
+
* @param {ESTree.Node} node - The call expression being visited.
|
|
43
|
+
* @returns {boolean} True when enclosed by a static property definition.
|
|
44
|
+
*/
|
|
45
|
+
function inStaticClassField(sourceCode, node) {
|
|
46
|
+
for (const current of ancestorsOf(sourceCode, node)) {
|
|
47
|
+
if (current.type === "PropertyDefinition")
|
|
48
|
+
return current.static === true;
|
|
49
|
+
if (current.type === "Program")
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Single-parameter handler whose body is one expression or one return statement.
|
|
56
|
+
*
|
|
57
|
+
* @param {ESTree.Node} node - The candidate callback function node.
|
|
58
|
+
* @returns {CallbackExpression | undefined} The extracted expression and parameter, if matching.
|
|
59
|
+
*/
|
|
60
|
+
function callbackExpression(node) {
|
|
61
|
+
if (node.type !== "ArrowFunctionExpression" && node.type !== "FunctionExpression")
|
|
62
|
+
return undefined;
|
|
63
|
+
if (node.params.length !== 1)
|
|
64
|
+
return undefined;
|
|
65
|
+
const parameter = node.params[0];
|
|
66
|
+
if (parameter.type !== "Identifier")
|
|
67
|
+
return undefined;
|
|
68
|
+
const parameterName = parameter.name;
|
|
69
|
+
if (node.body === null)
|
|
70
|
+
return undefined;
|
|
71
|
+
let body = node.body;
|
|
72
|
+
if (body.type === "BlockStatement") {
|
|
73
|
+
if (body.body.length !== 1)
|
|
74
|
+
return undefined;
|
|
75
|
+
const statement = body.body[0];
|
|
76
|
+
if (statement.type !== "ReturnStatement")
|
|
77
|
+
return undefined;
|
|
78
|
+
if (statement.argument === null || statement.argument === undefined)
|
|
79
|
+
return undefined;
|
|
80
|
+
body = statement.argument;
|
|
81
|
+
}
|
|
82
|
+
return { expression: body, parameterName };
|
|
83
|
+
}
|
|
84
|
+
/** `svc.member(...)` or bare `svc.member`, where `svc` is exactly the acquired service.
|
|
85
|
+
*
|
|
86
|
+
* @param {ESTree.Expression} expression - The forwarded callback expression.
|
|
87
|
+
* @param {string | undefined} parameterName - The acquired service parameter name.
|
|
88
|
+
* @returns {boolean} True when the expression only reads that service's member.
|
|
89
|
+
*/
|
|
90
|
+
function isDirectParameterMember(expression, parameterName) {
|
|
91
|
+
if (parameterName === undefined)
|
|
92
|
+
return false;
|
|
93
|
+
const member = expression.type === "CallExpression" ? expression.callee : expression;
|
|
94
|
+
if (member.type !== "MemberExpression")
|
|
95
|
+
return false;
|
|
96
|
+
return member.object.type === "Identifier" && member.object.name === parameterName;
|
|
97
|
+
}
|
|
98
|
+
/** Static forwarders alias a service method at module scope; acquire the service where its method is used instead.
|
|
99
|
+
*
|
|
100
|
+
* Import tracking covers local names bound by imports of "effect" and
|
|
101
|
+
* "effect/Effect"; re-exports are not tracked.
|
|
102
|
+
*/
|
|
103
|
+
export const noStaticEffectServiceForwardersRule = defineRule({
|
|
104
|
+
meta: {
|
|
105
|
+
type: "problem",
|
|
106
|
+
docs: {
|
|
107
|
+
description: "Disallow static class-field forwarders around Effect services; yield the service at the usage site and call the method directly so dependencies stay explicit.",
|
|
108
|
+
},
|
|
109
|
+
messages: {
|
|
110
|
+
staticForwarder: "This static field forwards an Effect service method. Acquire the service where the method is used (`Effect.flatMap(Service, (svc) => ...)`) so the dependency stays explicit and testable.",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
createOnce(context) {
|
|
114
|
+
const effectNamespaceNames = new Set();
|
|
115
|
+
const flatMapNames = new Set();
|
|
116
|
+
const serviceNames = new Set();
|
|
117
|
+
const pipeNames = new Set();
|
|
118
|
+
const isEffectCall = (node, method, directNames) => {
|
|
119
|
+
if (node.type !== "CallExpression")
|
|
120
|
+
return false;
|
|
121
|
+
const callee = node.callee;
|
|
122
|
+
if (callee.type === "Identifier") {
|
|
123
|
+
return directNames.has(callee.name);
|
|
124
|
+
}
|
|
125
|
+
if (callee.type !== "MemberExpression")
|
|
126
|
+
return false;
|
|
127
|
+
return (callee.object.type === "Identifier" &&
|
|
128
|
+
effectNamespaceNames.has(callee.object.name) &&
|
|
129
|
+
memberName(callee) === method);
|
|
130
|
+
};
|
|
131
|
+
const isServiceAcquisition = (node) => {
|
|
132
|
+
if (!isEffectCall(node, "service", serviceNames))
|
|
133
|
+
return false;
|
|
134
|
+
return node.arguments.length === 1 && node.arguments[0].type === "ThisExpression";
|
|
135
|
+
};
|
|
136
|
+
const isForwardingFlatMap = (node) => {
|
|
137
|
+
if (!isEffectCall(node, "flatMap", flatMapNames))
|
|
138
|
+
return false;
|
|
139
|
+
const last = node.arguments[node.arguments.length - 1];
|
|
140
|
+
if (last === undefined)
|
|
141
|
+
return false;
|
|
142
|
+
const callback = callbackExpression(last);
|
|
143
|
+
if (callback === undefined)
|
|
144
|
+
return false;
|
|
145
|
+
return isDirectParameterMember(callback.expression, callback.parameterName);
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
before() {
|
|
149
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
150
|
+
return false;
|
|
151
|
+
},
|
|
152
|
+
ImportDeclaration(node) {
|
|
153
|
+
if (node.source.value === "effect") {
|
|
154
|
+
for (const specifier of node.specifiers) {
|
|
155
|
+
const local = localNameOf(specifier);
|
|
156
|
+
if (local === undefined)
|
|
157
|
+
continue;
|
|
158
|
+
if (specifier.type === "ImportNamespaceSpecifier")
|
|
159
|
+
effectNamespaceNames.add(local);
|
|
160
|
+
const imported = importedNameOf(specifier);
|
|
161
|
+
if (specifier.type === "ImportSpecifier" && imported === "Effect") {
|
|
162
|
+
effectNamespaceNames.add(local);
|
|
163
|
+
}
|
|
164
|
+
if (specifier.type === "ImportSpecifier" && imported === "pipe")
|
|
165
|
+
pipeNames.add(local);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (node.source.value !== "effect/Effect")
|
|
170
|
+
return;
|
|
171
|
+
for (const specifier of node.specifiers) {
|
|
172
|
+
const local = localNameOf(specifier);
|
|
173
|
+
if (local === undefined)
|
|
174
|
+
continue;
|
|
175
|
+
if (specifier.type === "ImportNamespaceSpecifier" ||
|
|
176
|
+
specifier.type === "ImportDefaultSpecifier") {
|
|
177
|
+
effectNamespaceNames.add(local);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const imported = importedNameOf(specifier);
|
|
181
|
+
if (imported === "flatMap")
|
|
182
|
+
flatMapNames.add(local);
|
|
183
|
+
else if (imported === "service")
|
|
184
|
+
serviceNames.add(local);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
CallExpression(node) {
|
|
188
|
+
if (!inStaticClassField(context.sourceCode, node))
|
|
189
|
+
return;
|
|
190
|
+
const args = node.arguments;
|
|
191
|
+
if (isEffectCall(node, "flatMap", flatMapNames) && args.length >= 2) {
|
|
192
|
+
const first = args[0];
|
|
193
|
+
if (first !== undefined && isServiceAcquisition(first) && isForwardingFlatMap(node)) {
|
|
194
|
+
context.report({ node, messageId: "staticForwarder" });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const callee = node.callee;
|
|
199
|
+
let subject;
|
|
200
|
+
let operators;
|
|
201
|
+
if (callee.type === "Identifier") {
|
|
202
|
+
if (!pipeNames.has(callee.name))
|
|
203
|
+
return;
|
|
204
|
+
subject = args[0];
|
|
205
|
+
operators = args.slice(1);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
if (callee.type !== "MemberExpression" || memberName(callee) !== "pipe") {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
subject = callee.object;
|
|
212
|
+
operators = args;
|
|
213
|
+
}
|
|
214
|
+
if (subject !== undefined &&
|
|
215
|
+
isServiceAcquisition(subject) &&
|
|
216
|
+
operators.some((operator) => isForwardingFlatMap(operator))) {
|
|
217
|
+
context.report({ node, messageId: "staticForwarder" });
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
3
|
+
/** Raw `try`/`catch` detours failures around the typed error channel; route them through `Effect.try` instead. */
|
|
4
|
+
export const noTryCatchRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: {
|
|
8
|
+
description: "Disallow raw try/catch; move fallible work behind Effect.try (with a tagged failure reason) or let errors propagate through the typed channel. Unavoidable boundaries justify themselves with a SAFETY comment.",
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
tryCatch: "Raw `try`/`catch` detours this failure around the typed error channel. Use `Effect.try` (or `Effect.tryPromise`) failing a tagged reason, or let the error propagate. An integration boundary that must consume throwing APIs justifies itself with a `SAFETY:` comment.",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
createOnce(context) {
|
|
15
|
+
return {
|
|
16
|
+
before() {
|
|
17
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
18
|
+
return false;
|
|
19
|
+
},
|
|
20
|
+
TryStatement(node) {
|
|
21
|
+
const justified = context.sourceCode
|
|
22
|
+
.getCommentsBefore(node)
|
|
23
|
+
.some((comment) => /\bSAFETY\s*:/u.test(comment.value));
|
|
24
|
+
if (justified)
|
|
25
|
+
return;
|
|
26
|
+
context.report({ node, messageId: "tryCatch" });
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
});
|