@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,15 @@
|
|
|
1
|
+
/** Whether a field name claims to be an instant.
|
|
2
|
+
*
|
|
3
|
+
* @param {string} name - The field's name.
|
|
4
|
+
* @returns {boolean} True when the name is a date or a time.
|
|
5
|
+
*/
|
|
6
|
+
export declare function namesAnInstant(name: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* An instant is a value with an identity, not the text of one.
|
|
9
|
+
*
|
|
10
|
+
* `"2026-10-22T00:00:00Z"` and `"2026-10-22 00:00:00+00"` agree until one of
|
|
11
|
+
* them crosses a timezone. A string field in the values stratum lets every
|
|
12
|
+
* reader parse it differently, so the format becomes folklore instead of a
|
|
13
|
+
* type. The wire type may be text; the value must not.
|
|
14
|
+
*/
|
|
15
|
+
export declare const noStringInstantRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isString } from "../shared/structural.js";
|
|
3
|
+
import { inValuesPath } from "../shared/values-path.js";
|
|
4
|
+
/** The suffixes that name an instant rather than a piece of text. */
|
|
5
|
+
const INSTANT_SUFFIXES = ["At", "Date", "Timestamp", "_at", "_date"];
|
|
6
|
+
/** Whether a field name claims to be an instant.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} name - The field's name.
|
|
9
|
+
* @returns {boolean} True when the name is a date or a time.
|
|
10
|
+
*/
|
|
11
|
+
export function namesAnInstant(name) {
|
|
12
|
+
if (name.toLowerCase() === "timestamp")
|
|
13
|
+
return true;
|
|
14
|
+
return INSTANT_SUFFIXES.some((suffix) => name.endsWith(suffix));
|
|
15
|
+
}
|
|
16
|
+
/** Whether a schema chain bottoms out at `Schema.String`.
|
|
17
|
+
*
|
|
18
|
+
* @param {ESTree.Node} node - The field's value expression.
|
|
19
|
+
* @returns {boolean} True when the chain constructs a string.
|
|
20
|
+
*/
|
|
21
|
+
function isSchemaString(node) {
|
|
22
|
+
if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") {
|
|
23
|
+
return node.property.name === "String";
|
|
24
|
+
}
|
|
25
|
+
if (node.type === "CallExpression") {
|
|
26
|
+
const first = node.arguments[0];
|
|
27
|
+
return first !== undefined && isSchemaString(first);
|
|
28
|
+
}
|
|
29
|
+
return node.type === "TSNonNullExpression" ? isSchemaString(node.expression) : false;
|
|
30
|
+
}
|
|
31
|
+
/** The key of an object property, when it is a plain name.
|
|
32
|
+
*
|
|
33
|
+
* @param {ESTree.ObjectProperty} property - The property to read.
|
|
34
|
+
* @returns {string | null} The key, or null for a computed or spread entry.
|
|
35
|
+
*/
|
|
36
|
+
function propertyKey(property) {
|
|
37
|
+
if (property.key.type === "Identifier")
|
|
38
|
+
return property.key.name;
|
|
39
|
+
if (property.key.type === "Literal" && isString(property.key.value))
|
|
40
|
+
return property.key.value;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An instant is a value with an identity, not the text of one.
|
|
45
|
+
*
|
|
46
|
+
* `"2026-10-22T00:00:00Z"` and `"2026-10-22 00:00:00+00"` agree until one of
|
|
47
|
+
* them crosses a timezone. A string field in the values stratum lets every
|
|
48
|
+
* reader parse it differently, so the format becomes folklore instead of a
|
|
49
|
+
* type. The wire type may be text; the value must not.
|
|
50
|
+
*/
|
|
51
|
+
export const noStringInstantRule = defineRule({
|
|
52
|
+
meta: {
|
|
53
|
+
type: "suggestion",
|
|
54
|
+
docs: {
|
|
55
|
+
description: "Disallow string-typed instant fields inside a declared values path; use a date type so the format has one implementation.",
|
|
56
|
+
},
|
|
57
|
+
messages: {
|
|
58
|
+
stringInstant: "`{{name}}` holds an instant as text. Text is transport: two formats that agree today disagree after a timezone. Parse it at the boundary and carry a date type here.",
|
|
59
|
+
},
|
|
60
|
+
schema: [
|
|
61
|
+
{
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
paths: { type: "array", items: { type: "string" } },
|
|
65
|
+
},
|
|
66
|
+
additionalProperties: false,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
defaultOptions: [{}],
|
|
70
|
+
},
|
|
71
|
+
createOnce(context) {
|
|
72
|
+
function checkProperty(node) {
|
|
73
|
+
if (node.key.type !== "Identifier" || !namesAnInstant(node.key.name))
|
|
74
|
+
return;
|
|
75
|
+
if (node.typeAnnotation?.typeAnnotation.type !== "TSStringKeyword")
|
|
76
|
+
return;
|
|
77
|
+
context.report({ node, messageId: "stringInstant", data: { name: node.key.name } });
|
|
78
|
+
}
|
|
79
|
+
function checkStruct(node) {
|
|
80
|
+
const callee = node.callee;
|
|
81
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
82
|
+
return;
|
|
83
|
+
if (callee.property.name !== "Struct")
|
|
84
|
+
return;
|
|
85
|
+
const first = node.arguments[0];
|
|
86
|
+
if (first === undefined || first.type !== "ObjectExpression")
|
|
87
|
+
return;
|
|
88
|
+
for (const property of first.properties) {
|
|
89
|
+
if (property.type !== "Property")
|
|
90
|
+
continue;
|
|
91
|
+
const name = propertyKey(property);
|
|
92
|
+
if (name === null || !namesAnInstant(name))
|
|
93
|
+
continue;
|
|
94
|
+
if (!isSchemaString(property.value))
|
|
95
|
+
continue;
|
|
96
|
+
context.report({ node: property, messageId: "stringInstant", data: { name } });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
before() {
|
|
101
|
+
if (!inValuesPath(context.filename, context.options))
|
|
102
|
+
return false;
|
|
103
|
+
},
|
|
104
|
+
TSPropertySignature: checkProperty,
|
|
105
|
+
CallExpression: checkStruct,
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
const TEST_FILE =
|
|
2
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
3
3
|
/** Keyword node type -> spelled-out primitive for messages. */
|
|
4
4
|
const PRIMITIVE_KEYWORDS = new Map([
|
|
5
5
|
["TSStringKeyword", "string"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import { isRecordObject, isString } from "../shared/structural.js";
|
|
3
|
-
const TEST_FILE =
|
|
3
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
|
|
4
4
|
/** Whether the if-consequent (or alternate) is a bare `throw new Error(...)` assertion.
|
|
5
5
|
*
|
|
6
6
|
* @param {ESTree.Statement | null | undefined} statement - The branch body to inspect.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
const TEST_FILE =
|
|
2
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
3
3
|
/** Stems that name nothing; a test file must point back at the module it covers. */
|
|
4
4
|
const VAGUE_STEMS = new Set([
|
|
5
5
|
"index",
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* We default to property-based testing: a test suite without fast-check only
|
|
3
3
|
* pins examples. Escape hatch is an explicit inline disable with a reason.
|
|
4
|
+
*
|
|
5
|
+
* The visitor resets its state in `before()`: `createOnce` state spans the whole
|
|
6
|
+
* run, so without the reset a file that imports fast-check marks every later file
|
|
7
|
+
* as having one, and the same tree reports a suite or does not depending on the
|
|
8
|
+
* order files are visited.
|
|
4
9
|
*/
|
|
5
10
|
export declare const preferPropertyTestsRule: import("@oxlint/plugins").Rule;
|
|
@@ -3,6 +3,11 @@ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
|
3
3
|
/**
|
|
4
4
|
* We default to property-based testing: a test suite without fast-check only
|
|
5
5
|
* pins examples. Escape hatch is an explicit inline disable with a reason.
|
|
6
|
+
*
|
|
7
|
+
* The visitor resets its state in `before()`: `createOnce` state spans the whole
|
|
8
|
+
* run, so without the reset a file that imports fast-check marks every later file
|
|
9
|
+
* as having one, and the same tree reports a suite or does not depending on the
|
|
10
|
+
* order files are visited.
|
|
6
11
|
*/
|
|
7
12
|
export const preferPropertyTestsRule = defineRule({
|
|
8
13
|
meta: {
|
|
@@ -19,6 +24,8 @@ export const preferPropertyTestsRule = defineRule({
|
|
|
19
24
|
let sawFastCheck = false;
|
|
20
25
|
return {
|
|
21
26
|
before() {
|
|
27
|
+
program = null;
|
|
28
|
+
sawFastCheck = false;
|
|
22
29
|
if (!TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
23
30
|
return false;
|
|
24
31
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import { getAllComments } from "../shared/structural.js";
|
|
3
|
-
const TEST_FILE =
|
|
3
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
4
4
|
/** Every exported function carries a complete JSDoc contract. */
|
|
5
5
|
export const requireJsdocOnExportedRule = defineRule({
|
|
6
6
|
meta: {
|
|
@@ -13,6 +13,6 @@ import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
|
13
13
|
*
|
|
14
14
|
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
15
15
|
* @param {ESTree.Node} node - The node whose ancestor chain is requested.
|
|
16
|
-
* @returns {ReadonlyArray<ESTree.Node>}
|
|
16
|
+
* @returns {ReadonlyArray<ESTree.Node>} Outermost-first ancestor chain (Program at index 0, the immediate parent last; use `.at(-1)` for the parent).
|
|
17
17
|
*/
|
|
18
18
|
export declare function ancestorsOf(sourceCode: SourceCode, node: ESTree.Node): ReadonlyArray<ESTree.Node>;
|
package/dist/shared/ancestors.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
14
14
|
* @param {ESTree.Node} node - The node whose ancestor chain is requested.
|
|
15
|
-
* @returns {ReadonlyArray<ESTree.Node>}
|
|
15
|
+
* @returns {ReadonlyArray<ESTree.Node>} Outermost-first ancestor chain (Program at index 0, the immediate parent last; use `.at(-1)` for the parent).
|
|
16
16
|
*/
|
|
17
17
|
export function ancestorsOf(sourceCode, node) {
|
|
18
18
|
return sourceCode.getAncestors(node);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a file belongs to the declared values path.
|
|
3
|
+
*
|
|
4
|
+
* A declared prefix matches the file itself or anything below it. With no
|
|
5
|
+
* option, a directory SEGMENT carries the name, so `src/domain/money.ts` and
|
|
6
|
+
* `packages/domain/src/hours.ts` are both values.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} filename - The file being linted.
|
|
9
|
+
* @param {readonly unknown[] | undefined} options - The rule's raw options.
|
|
10
|
+
* @returns {boolean} True when the file is inside the values stratum.
|
|
11
|
+
*/
|
|
12
|
+
export declare function inValuesPath(filename: string, options: readonly unknown[] | undefined): boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { firstOptionRecord } from "./rule-options.js";
|
|
2
|
+
import { isString } from "./structural.js";
|
|
3
|
+
/**
|
|
4
|
+
* The directories a repository declares as its values stratum.
|
|
5
|
+
*
|
|
6
|
+
* The default is a CONVENTION, not a fact: `domain`, `values` and `model` are
|
|
7
|
+
* the names repositories give the folder that holds `Money` and `Hours`. A
|
|
8
|
+
* repository whose values live somewhere else names the path in the rule's
|
|
9
|
+
* options (`{ "paths": ["src/domain"] }`), because a lint rule cannot infer
|
|
10
|
+
* where the pure layer is from one file.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_SEGMENTS = new Set(["domain", "model", "value-objects", "values"]);
|
|
13
|
+
/**
|
|
14
|
+
* The declared path prefixes, or an empty list when the option is absent or malformed.
|
|
15
|
+
*
|
|
16
|
+
* @param {readonly unknown[] | undefined} options - The rule's raw options.
|
|
17
|
+
* @returns {ReadonlyArray<string>} The non-empty path prefixes, if any.
|
|
18
|
+
*/
|
|
19
|
+
function declaredPaths(options) {
|
|
20
|
+
const record = firstOptionRecord(options);
|
|
21
|
+
const declared = record["paths"];
|
|
22
|
+
if (!Array.isArray(declared))
|
|
23
|
+
return [];
|
|
24
|
+
return declared.filter((entry) => isString(entry) && entry.length > 0);
|
|
25
|
+
}
|
|
26
|
+
/** Normalise a path prefix so `./src/domain/` and `src/domain` compare equally.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} path - The path or prefix to normalise.
|
|
29
|
+
* @returns {string} A slash-only path with no leading `./` or trailing slash.
|
|
30
|
+
*/
|
|
31
|
+
function normalise(path) {
|
|
32
|
+
return path.replaceAll("\\", "/").replace(/^\.\//u, "").replace(/\/+$/u, "");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether a file belongs to the declared values path.
|
|
36
|
+
*
|
|
37
|
+
* A declared prefix matches the file itself or anything below it. With no
|
|
38
|
+
* option, a directory SEGMENT carries the name, so `src/domain/money.ts` and
|
|
39
|
+
* `packages/domain/src/hours.ts` are both values.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} filename - The file being linted.
|
|
42
|
+
* @param {readonly unknown[] | undefined} options - The rule's raw options.
|
|
43
|
+
* @returns {boolean} True when the file is inside the values stratum.
|
|
44
|
+
*/
|
|
45
|
+
export function inValuesPath(filename, options) {
|
|
46
|
+
const file = normalise(filename);
|
|
47
|
+
const paths = declaredPaths(options);
|
|
48
|
+
if (paths.length > 0) {
|
|
49
|
+
return paths.some((prefix) => {
|
|
50
|
+
const normalised = normalise(prefix);
|
|
51
|
+
return file === normalised || file.startsWith(`${normalised}/`) || file.includes(`/${normalised}/`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const directories = file.split("/").slice(0, -1);
|
|
55
|
+
return directories.some((segment) => DEFAULT_SEGMENTS.has(segment));
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin } from "@oxlint/plugins";
|
|
2
|
+
/** The parts of a plugin a shared rule set is derived from. */
|
|
3
|
+
type RuleSetSource = Pick<Plugin, "meta" | "rules">;
|
|
4
|
+
/** Every rule a plugin ships, enabled at `error` under the plugin's own name.
|
|
5
|
+
*
|
|
6
|
+
* The keys assume the plugin is registered under `meta.name` (`plumb`,
|
|
7
|
+
* `plumb-effect`, `plumb-react`), in `jsPlugins` for Oxlint or `plugins` for
|
|
8
|
+
* ESLint. The result drops straight into either linter's `rules` object.
|
|
9
|
+
*
|
|
10
|
+
* @param {RuleSetSource} plugin - The plugin whose rules to enable.
|
|
11
|
+
* @returns {Readonly<Record<string, "error">>} Namespaced rule ids mapped to `error`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function recommendedRulesFor(plugin: RuleSetSource): Readonly<Record<string, "error">>;
|
|
14
|
+
/** Every `plumb` rule at `error`. */
|
|
15
|
+
export declare const plumbRecommendedRules: Readonly<Record<string, "error">>;
|
|
16
|
+
/** Every `plumb-effect` rule at `error`; enable only in repos that depend on `effect`. */
|
|
17
|
+
export declare const plumbEffectRecommendedRules: Readonly<Record<string, "error">>;
|
|
18
|
+
/** Every `plumb-react` rule at `error`; enable only in React repos. */
|
|
19
|
+
export declare const plumbReactRecommendedRules: Readonly<Record<string, "error">>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import plumbPlugin from "../index.js";
|
|
2
|
+
import plumbEffectPlugin from "../effect/index.js";
|
|
3
|
+
import plumbReactPlugin from "../react/index.js";
|
|
4
|
+
/** Every rule a plugin ships, enabled at `error` under the plugin's own name.
|
|
5
|
+
*
|
|
6
|
+
* The keys assume the plugin is registered under `meta.name` (`plumb`,
|
|
7
|
+
* `plumb-effect`, `plumb-react`), in `jsPlugins` for Oxlint or `plugins` for
|
|
8
|
+
* ESLint. The result drops straight into either linter's `rules` object.
|
|
9
|
+
*
|
|
10
|
+
* @param {RuleSetSource} plugin - The plugin whose rules to enable.
|
|
11
|
+
* @returns {Readonly<Record<string, "error">>} Namespaced rule ids mapped to `error`.
|
|
12
|
+
*/
|
|
13
|
+
export function recommendedRulesFor(plugin) {
|
|
14
|
+
const name = plugin.meta?.name ?? "";
|
|
15
|
+
return Object.fromEntries(Object.keys(plugin.rules).map((rule) => [`${name}/${rule}`, "error"]));
|
|
16
|
+
}
|
|
17
|
+
/** Every `plumb` rule at `error`. */
|
|
18
|
+
export const plumbRecommendedRules = recommendedRulesFor(plumbPlugin);
|
|
19
|
+
/** Every `plumb-effect` rule at `error`; enable only in repos that depend on `effect`. */
|
|
20
|
+
export const plumbEffectRecommendedRules = recommendedRulesFor(plumbEffectPlugin);
|
|
21
|
+
/** Every `plumb-react` rule at `error`; enable only in React repos. */
|
|
22
|
+
export const plumbReactRecommendedRules = recommendedRulesFor(plumbReactPlugin);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from "@oxlint/plugins";
|
|
2
|
+
import { guardedOpMustReturnEffectRule } from "./rules/guarded-op-must-return-effect.js";
|
|
3
|
+
import { guardedOpMustReturnOptionRule } from "./rules/guarded-op-must-return-option.js";
|
|
4
|
+
import { noDecodeUnknownOptionRule } from "./rules/no-decode-unknown-option.js";
|
|
5
|
+
import { noManualFieldGuardsRule } from "./rules/no-manual-field-guards.js";
|
|
6
|
+
import { noUnguardedJsonParseRule } from "./rules/no-unguarded-json-parse.js";
|
|
7
|
+
import { noSchemaClassModelingRule } from "./rules/no-schema-class-modeling.js";
|
|
8
|
+
import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.js";
|
|
9
|
+
import { optionCoreNeedsEffectPublicRule } from "./rules/option-core-needs-effect-public.js";
|
|
10
|
+
import { preferDieForPreconditionDefectsRule } from "./rules/prefer-die-for-precondition-defects.js";
|
|
11
|
+
import { preferEffectGenForGuardLaddersRule } from "./rules/prefer-effect-gen-for-guard-ladders.js";
|
|
12
|
+
import { preferEffectPredicateOverBooleanFunctionRule } from "./rules/prefer-effect-predicate-over-boolean-function.js";
|
|
13
|
+
import { preferNamedGuardPredicateRule } from "./rules/prefer-named-guard-predicate.js";
|
|
14
|
+
import { preferOrderingMatchRule } from "./rules/prefer-ordering-match.js";
|
|
15
|
+
import { preferOptionPipelineRule } from "./rules/prefer-option-pipeline.js";
|
|
16
|
+
import { preferTaggedEnumRule } from "./rules/prefer-tagged-enum.js";
|
|
17
|
+
import { requireSchemaTypeDerivationRule } from "./rules/require-schema-type-derivation.js";
|
|
18
|
+
import { noDirectFetchRule } from "./rules/no-direct-fetch.js";
|
|
19
|
+
import { noDirectBrowserStorageRule } from "./rules/no-direct-browser-storage.js";
|
|
20
|
+
import { noTryCatchRule } from "./rules/no-try-catch.js";
|
|
21
|
+
import { noSilentErrorSwallowRule } from "./rules/no-silent-error-swallow.js";
|
|
22
|
+
import { preferEffectMatchRule } from "./rules/prefer-effect-match.js";
|
|
23
|
+
import { noNestedLayerProvideRule } from "./rules/no-nested-layer-provide.js";
|
|
24
|
+
import { noCascadingLayerProvideRule } from "./rules/no-cascading-layer-provide.js";
|
|
25
|
+
import { noStaticEffectServiceForwardersRule } from "./rules/no-static-effect-service-forwarders.js";
|
|
26
|
+
import { noRawErrorForwardingRule } from "./rules/no-raw-error-forwarding.js";
|
|
27
|
+
import { noNullishDefaultOnPartialInputRule } from "./rules/no-nullish-default-on-partial-input.js";
|
|
28
|
+
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
29
|
+
const plumbEffectPlugin = eslintCompatPlugin({
|
|
30
|
+
meta: { name: "plumb-effect" },
|
|
31
|
+
rules: {
|
|
32
|
+
"guarded-op-must-return-effect": guardedOpMustReturnEffectRule,
|
|
33
|
+
"guarded-op-must-return-option": guardedOpMustReturnOptionRule,
|
|
34
|
+
"no-decode-unknown-option": noDecodeUnknownOptionRule,
|
|
35
|
+
"no-manual-field-guards": noManualFieldGuardsRule,
|
|
36
|
+
"no-unguarded-json-parse": noUnguardedJsonParseRule,
|
|
37
|
+
"option-core-needs-effect-public": optionCoreNeedsEffectPublicRule,
|
|
38
|
+
"no-schema-class-modeling": noSchemaClassModelingRule,
|
|
39
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
40
|
+
"prefer-die-for-precondition-defects": preferDieForPreconditionDefectsRule,
|
|
41
|
+
"prefer-effect-gen-for-guard-ladders": preferEffectGenForGuardLaddersRule,
|
|
42
|
+
"prefer-effect-predicate-over-boolean-function": preferEffectPredicateOverBooleanFunctionRule,
|
|
43
|
+
"prefer-named-guard-predicate": preferNamedGuardPredicateRule,
|
|
44
|
+
"prefer-option-pipeline": preferOptionPipelineRule,
|
|
45
|
+
"prefer-ordering-match": preferOrderingMatchRule,
|
|
46
|
+
"prefer-tagged-enum": preferTaggedEnumRule,
|
|
47
|
+
"require-schema-type-derivation": requireSchemaTypeDerivationRule,
|
|
48
|
+
"no-direct-fetch": noDirectFetchRule,
|
|
49
|
+
"no-direct-browser-storage": noDirectBrowserStorageRule,
|
|
50
|
+
"no-try-catch": noTryCatchRule,
|
|
51
|
+
"no-silent-error-swallow": noSilentErrorSwallowRule,
|
|
52
|
+
"prefer-effect-match": preferEffectMatchRule,
|
|
53
|
+
"no-nested-layer-provide": noNestedLayerProvideRule,
|
|
54
|
+
"no-cascading-layer-provide": noCascadingLayerProvideRule,
|
|
55
|
+
"no-static-effect-service-forwarders": noStaticEffectServiceForwardersRule,
|
|
56
|
+
"no-raw-error-forwarding": noRawErrorForwardingRule,
|
|
57
|
+
"no-nullish-default-on-partial-input": noNullishDefaultOnPartialInputRule,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
export default plumbEffectPlugin;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarded operations must surface failure reasons as tagged MoneyError values
|
|
3
|
+
* through the Effect error channel, not as bare Option.None which conflates
|
|
4
|
+
* every possible why into one silent absence.
|
|
5
|
+
*/
|
|
6
|
+
export declare const guardedOpMustReturnEffectRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,235 @@
|
|
|
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
|
+
/** Whether the member chain ends in the Option namespace, e.g. `Option` or `O`.
|
|
5
|
+
*
|
|
6
|
+
* @param {ESTree.Expression | ESTree.Super} node - The callee object to inspect.
|
|
7
|
+
* @returns {boolean} True when the object resolves to the Option namespace.
|
|
8
|
+
*/
|
|
9
|
+
function isOptionObject(node) {
|
|
10
|
+
if (node.type === "Identifier")
|
|
11
|
+
return node.name === "Option";
|
|
12
|
+
if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") {
|
|
13
|
+
return node.property.name === "Option";
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
/** The name of the function whose body contains this node, if determinable.
|
|
18
|
+
*
|
|
19
|
+
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
20
|
+
* @param {ESTree.Node} node - The node whose enclosing function is sought.
|
|
21
|
+
* @returns {string | null} The enclosing function's name, or null.
|
|
22
|
+
*/
|
|
23
|
+
function enclosingFunctionName(sourceCode, node) {
|
|
24
|
+
const chain = ancestorsOf(sourceCode, node);
|
|
25
|
+
for (let index = chain.length - 1; index >= 0; index--) {
|
|
26
|
+
const current = chain[index];
|
|
27
|
+
if (current.type === "FunctionDeclaration" && current.id !== null)
|
|
28
|
+
return current.id.name;
|
|
29
|
+
if ((current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") &&
|
|
30
|
+
node !== current) {
|
|
31
|
+
const name = current.type === "FunctionExpression" && current.id !== null
|
|
32
|
+
? current.id.name
|
|
33
|
+
: variableDeclaratorName(sourceCode, current);
|
|
34
|
+
if (name !== null)
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
/** The declared name of the variable a function expression initialises, if any.
|
|
41
|
+
*
|
|
42
|
+
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
43
|
+
* @param {ESTree.Node} node - The function expression node.
|
|
44
|
+
* @returns {string | null} The initialising declarator's name, or null.
|
|
45
|
+
*/
|
|
46
|
+
function variableDeclaratorName(sourceCode, node) {
|
|
47
|
+
const chain = ancestorsOf(sourceCode, node);
|
|
48
|
+
for (let index = chain.length - 1; index >= 0; index--) {
|
|
49
|
+
const current = chain[index];
|
|
50
|
+
if (current.type === "Program")
|
|
51
|
+
break;
|
|
52
|
+
if (current.type === "VariableDeclarator" && current.id.type === "Identifier")
|
|
53
|
+
return current.id.name;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/** The doctrine binds public APIs: walk up to see if this node is exported.
|
|
58
|
+
*
|
|
59
|
+
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
60
|
+
* @param {ESTree.Node} node - The node to test for export ancestry.
|
|
61
|
+
* @returns {boolean} True when an export declaration encloses the node.
|
|
62
|
+
*/
|
|
63
|
+
function hasExportAncestor(sourceCode, node) {
|
|
64
|
+
const chain = ancestorsOf(sourceCode, node);
|
|
65
|
+
for (let index = chain.length - 1; index >= 0; index--) {
|
|
66
|
+
const current = chain[index];
|
|
67
|
+
if (current.type === "ExportNamedDeclaration" || current.type === "ExportDefaultDeclaration")
|
|
68
|
+
return true;
|
|
69
|
+
if (current.type === "Program")
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
/** A return-type annotation naming Option<T>, e.g. `Option.Option<Account>`.
|
|
75
|
+
*
|
|
76
|
+
* @param {ESTree.TSType} type - The type node to inspect.
|
|
77
|
+
* @returns {string | null} The Option spelling used, or null when not an Option reference.
|
|
78
|
+
*/
|
|
79
|
+
function optionTypeReference(type) {
|
|
80
|
+
if (type.type !== "TSTypeReference")
|
|
81
|
+
return null;
|
|
82
|
+
const name = type.typeName;
|
|
83
|
+
if (name.type === "Identifier" && name.name === "Option")
|
|
84
|
+
return "Option";
|
|
85
|
+
if (name.type === "TSQualifiedName" &&
|
|
86
|
+
name.right.type === "Identifier" &&
|
|
87
|
+
name.right.name === "Option") {
|
|
88
|
+
return "Option.Option";
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Guarded operations must surface failure reasons as tagged MoneyError values
|
|
94
|
+
* through the Effect error channel, not as bare Option.None which conflates
|
|
95
|
+
* every possible why into one silent absence.
|
|
96
|
+
*/
|
|
97
|
+
export const guardedOpMustReturnEffectRule = defineRule({
|
|
98
|
+
meta: {
|
|
99
|
+
type: "problem",
|
|
100
|
+
docs: {
|
|
101
|
+
description: "Require guarded operations to fail with typed MoneyError reasons via Effect/Either instead of returning bare Option values.",
|
|
102
|
+
},
|
|
103
|
+
messages: {
|
|
104
|
+
optionReturn: "`{{found}}` hides why the operation failed. Return `Effect.Effect<T, MoneyError>` (or `Either<T, MoneyError>` in sync cores) with Schema.TaggedError reasons so callers can match Overflow vs InvalidInput vs ZeroDivisor. Options buried in tuples, records or arrays hide it just as well.",
|
|
105
|
+
bareNone: "`Option.none()` here discards the reason for failure. Fail with a tagged MoneyError reason instead, or keep the Option strictly internal while a converted public API owns the error channel.",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
createOnce(context) {
|
|
109
|
+
return {
|
|
110
|
+
before() {
|
|
111
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
112
|
+
return false;
|
|
113
|
+
},
|
|
114
|
+
ReturnStatement(node) {
|
|
115
|
+
if (!hasExportAncestor(context.sourceCode, node))
|
|
116
|
+
return;
|
|
117
|
+
if (enclosingFunctionName(context.sourceCode, node)?.endsWith("Option"))
|
|
118
|
+
return;
|
|
119
|
+
const argument = node.argument;
|
|
120
|
+
if (argument === null || argument === undefined)
|
|
121
|
+
return;
|
|
122
|
+
let call = argument;
|
|
123
|
+
while (call.type === "ParenthesizedExpression")
|
|
124
|
+
call = call.expression;
|
|
125
|
+
if (call.type !== "CallExpression")
|
|
126
|
+
return;
|
|
127
|
+
if (call.callee.type === "MemberExpression" &&
|
|
128
|
+
call.callee.property.type === "Identifier" &&
|
|
129
|
+
call.callee.property.name === "none" &&
|
|
130
|
+
isOptionObject(call.callee.object)) {
|
|
131
|
+
context.report({ node, messageId: "bareNone" });
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
ArrowFunctionExpression(node) {
|
|
135
|
+
if (!hasExportAncestor(context.sourceCode, node))
|
|
136
|
+
return;
|
|
137
|
+
const parentId = variableDeclaratorName(context.sourceCode, node);
|
|
138
|
+
if (parentId !== null && parentId.endsWith("Option"))
|
|
139
|
+
return;
|
|
140
|
+
const annotation = node.returnType?.typeAnnotation;
|
|
141
|
+
if (annotation === undefined)
|
|
142
|
+
return;
|
|
143
|
+
const found = optionInReturnType(annotation);
|
|
144
|
+
if (found !== null) {
|
|
145
|
+
context.report({ node: node.returnType ?? node, messageId: "optionReturn", data: { found } });
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
FunctionDeclaration(node) {
|
|
149
|
+
if (!hasExportAncestor(context.sourceCode, node))
|
|
150
|
+
return;
|
|
151
|
+
checkFunctionReturn(context, node, node.id?.name ?? null);
|
|
152
|
+
},
|
|
153
|
+
FunctionExpression(node) {
|
|
154
|
+
if (!hasExportAncestor(context.sourceCode, node))
|
|
155
|
+
return;
|
|
156
|
+
checkFunctionReturn(context, node, node.id?.name ?? variableDeclaratorName(context.sourceCode, node));
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
function checkFunctionReturn(context, node, idName) {
|
|
162
|
+
if (idName !== null && idName.endsWith("Option"))
|
|
163
|
+
return;
|
|
164
|
+
const annotation = node.returnType?.typeAnnotation;
|
|
165
|
+
if (annotation === undefined)
|
|
166
|
+
return;
|
|
167
|
+
const found = optionInReturnType(annotation);
|
|
168
|
+
if (found !== null) {
|
|
169
|
+
context.report({ node: node.returnType ?? node, messageId: "optionReturn", data: { found } });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Search a type node for an embedded Option reference (tuples, arrays, members).
|
|
173
|
+
*
|
|
174
|
+
* @param {ESTree.TSType} type - The type node to search.
|
|
175
|
+
* @returns {string | null} The first embedded Option spelling, or null when none.
|
|
176
|
+
*/
|
|
177
|
+
function findOptionType(type) {
|
|
178
|
+
const direct = optionTypeReference(type);
|
|
179
|
+
if (direct !== null)
|
|
180
|
+
return direct;
|
|
181
|
+
switch (type.type) {
|
|
182
|
+
case "TSTupleType": {
|
|
183
|
+
const render = (element) => {
|
|
184
|
+
if ("elementType" in element)
|
|
185
|
+
return render(element.elementType);
|
|
186
|
+
if (element.type === "TSOptionalType" || element.type === "TSRestType") {
|
|
187
|
+
return findOptionType(element.typeAnnotation);
|
|
188
|
+
}
|
|
189
|
+
return findOptionType(element);
|
|
190
|
+
};
|
|
191
|
+
for (const element of type.elementTypes) {
|
|
192
|
+
const found = render(element);
|
|
193
|
+
if (found !== null)
|
|
194
|
+
return found;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
case "TSTypeOperator":
|
|
199
|
+
return findOptionType(type.typeAnnotation);
|
|
200
|
+
case "TSArrayType":
|
|
201
|
+
return findOptionType(type.elementType);
|
|
202
|
+
case "TSTypeLiteral":
|
|
203
|
+
for (const member of type.members) {
|
|
204
|
+
if (member.type !== "TSPropertySignature")
|
|
205
|
+
continue;
|
|
206
|
+
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
207
|
+
if (annotation === undefined || annotation === null)
|
|
208
|
+
continue;
|
|
209
|
+
const found = findOptionType(annotation);
|
|
210
|
+
if (found !== null)
|
|
211
|
+
return found;
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
default:
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** A return-type annotation hiding an Option anywhere: unions, tuples, arrays, members.
|
|
219
|
+
*
|
|
220
|
+
* @param {ESTree.TSType} annotation - The return-type annotation to search.
|
|
221
|
+
* @returns {string | null} The Option spelling found, or null when none.
|
|
222
|
+
*/
|
|
223
|
+
function optionInReturnType(annotation) {
|
|
224
|
+
let current = annotation;
|
|
225
|
+
while (current.type === "TSParenthesizedType")
|
|
226
|
+
current = current.typeAnnotation;
|
|
227
|
+
if (current.type === "TSUnionType") {
|
|
228
|
+
for (const member of current.types) {
|
|
229
|
+
const found = optionTypeReference(member);
|
|
230
|
+
if (found !== null)
|
|
231
|
+
return found;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return findOptionType(current);
|
|
235
|
+
}
|