@autotelic/plumb 0.5.2 → 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/index.js +4 -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.d.ts +13 -0
- package/dist/effect/rules/no-nullish-default-on-partial-input.js +109 -0
- package/dist/effect/rules/no-raw-error-forwarding.d.ts +16 -0
- package/dist/effect/rules/no-raw-error-forwarding.js +108 -0
- 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 +10 -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.d.ts +7 -0
- package/dist/rules/no-sql-string-interpolation.js +62 -0
- 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,117 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
import { isString } from "../shared/structural.js";
|
|
3
|
+
import { inValuesPath } from "../shared/values-path.js";
|
|
4
|
+
/** The constructors that make a value claim the world is uncertain about it. */
|
|
5
|
+
const ABSENCE = new Set(["NullOr", "UndefinedOr", "optionalKey"]);
|
|
6
|
+
/** Every member name in a schema constructor chain, outermost first.
|
|
7
|
+
*
|
|
8
|
+
* `Schema.NullOr(Schema.String)` has the names `NullOr` and `String`, and
|
|
9
|
+
* `Schema.optionalKey(...)` adds `optionalKey`. The first argument is followed
|
|
10
|
+
* because a wrapper's payload is the next link, not the receiver.
|
|
11
|
+
*
|
|
12
|
+
* @param {ESTree.Node} node - The field's value expression.
|
|
13
|
+
* @returns {ReadonlyArray<string>} The constructor names the chain mentions.
|
|
14
|
+
*/
|
|
15
|
+
function constructorNames(node) {
|
|
16
|
+
const names = [];
|
|
17
|
+
const walk = (current) => {
|
|
18
|
+
if (current.type === "CallExpression") {
|
|
19
|
+
const callee = current.callee;
|
|
20
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier") {
|
|
21
|
+
names.push(callee.property.name);
|
|
22
|
+
}
|
|
23
|
+
const first = current.arguments[0];
|
|
24
|
+
if (first !== undefined)
|
|
25
|
+
walk(first);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (current.type === "MemberExpression" && !current.computed && current.property.type === "Identifier") {
|
|
29
|
+
names.push(current.property.name);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (current.type === "TSNonNullExpression")
|
|
33
|
+
walk(current.expression);
|
|
34
|
+
};
|
|
35
|
+
walk(node);
|
|
36
|
+
return names;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Whether a constructor chain admits an absent value.
|
|
40
|
+
*
|
|
41
|
+
* @param {ReadonlyArray<string>} names - The names in the field's chain.
|
|
42
|
+
* @returns {boolean} True when one of them makes the field absent.
|
|
43
|
+
*/
|
|
44
|
+
export function hasAbsence(names) {
|
|
45
|
+
return names.some((entry) => ABSENCE.has(entry));
|
|
46
|
+
}
|
|
47
|
+
/** The key of an object property, when it is a plain name.
|
|
48
|
+
*
|
|
49
|
+
* @param {ESTree.ObjectProperty} property - The property to read.
|
|
50
|
+
* @returns {string | null} The key, or null for a computed or spread entry.
|
|
51
|
+
*/
|
|
52
|
+
function propertyKey(property) {
|
|
53
|
+
if (property.key.type === "Identifier")
|
|
54
|
+
return property.key.name;
|
|
55
|
+
if (property.key.type === "Literal" && isString(property.key.value))
|
|
56
|
+
return property.key.value;
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A value is certain, or it is not a value.
|
|
61
|
+
*
|
|
62
|
+
* Nullability from a `left join` is a retrieval artifact. When it becomes a
|
|
63
|
+
* field of the concept, the concept starts saying the business is unsure about
|
|
64
|
+
* something it knows. The partiality belongs in the derivation that read the
|
|
65
|
+
* row, and the exception ("this field is absent by nature") needs a comment.
|
|
66
|
+
*/
|
|
67
|
+
export const noNullableValueFieldRule = defineRule({
|
|
68
|
+
meta: {
|
|
69
|
+
type: "suggestion",
|
|
70
|
+
docs: {
|
|
71
|
+
description: "Disallow nullable or optional Schema.Struct fields inside a declared values path; project the partiality into the derivation instead.",
|
|
72
|
+
},
|
|
73
|
+
messages: {
|
|
74
|
+
nullableValueField: "`{{name}}` can be absent inside a value, so the value now claims the business is uncertain. Absence is a property of a projection: project it here, or document why this concept is genuinely partial.",
|
|
75
|
+
},
|
|
76
|
+
schema: [
|
|
77
|
+
{
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: {
|
|
80
|
+
paths: { type: "array", items: { type: "string" } },
|
|
81
|
+
},
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
defaultOptions: [{}],
|
|
86
|
+
},
|
|
87
|
+
createOnce(context) {
|
|
88
|
+
function checkStruct(node) {
|
|
89
|
+
const callee = node.callee;
|
|
90
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
91
|
+
return;
|
|
92
|
+
if (callee.property.name !== "Struct")
|
|
93
|
+
return;
|
|
94
|
+
const first = node.arguments[0];
|
|
95
|
+
if (first === undefined || first.type !== "ObjectExpression")
|
|
96
|
+
return;
|
|
97
|
+
for (const property of first.properties) {
|
|
98
|
+
if (property.type !== "Property")
|
|
99
|
+
continue;
|
|
100
|
+
const name = propertyKey(property);
|
|
101
|
+
if (name === null)
|
|
102
|
+
continue;
|
|
103
|
+
const names = constructorNames(property.value);
|
|
104
|
+
if (!hasAbsence(names))
|
|
105
|
+
continue;
|
|
106
|
+
context.report({ node: property, messageId: "nullableValueField", data: { name } });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
before() {
|
|
111
|
+
if (!inValuesPath(context.filename, context.options))
|
|
112
|
+
return false;
|
|
113
|
+
},
|
|
114
|
+
CallExpression: checkStruct,
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a member expression's root names transport input rather than a row.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} name - The root identifier.
|
|
5
|
+
* @returns {boolean} True when the root is a request, a query or a body.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isTransportRoot(name: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* A number read out of a row is text from the driver until something decodes
|
|
10
|
+
* it. `Number(row.amount)` is a second implementation of the domain's schema,
|
|
11
|
+
* with its own failure: `NaN` instead of a decode error.
|
|
12
|
+
*/
|
|
13
|
+
export declare const noRowCoercionRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
/** Packages whose rows arrive with the driver's own static types. */
|
|
3
|
+
const DATA_PACKAGES = new Set([
|
|
4
|
+
"@prisma/client",
|
|
5
|
+
"better-sqlite3",
|
|
6
|
+
"drizzle-orm",
|
|
7
|
+
"knex",
|
|
8
|
+
"kysely",
|
|
9
|
+
"mongodb",
|
|
10
|
+
"mysql",
|
|
11
|
+
"mysql2",
|
|
12
|
+
"pg",
|
|
13
|
+
"postgres",
|
|
14
|
+
"prisma",
|
|
15
|
+
"sequelize",
|
|
16
|
+
"slonik",
|
|
17
|
+
"sqlite3",
|
|
18
|
+
"typeorm",
|
|
19
|
+
]);
|
|
20
|
+
/** Names that are a coercion of a row value, not a conversion of a request field. */
|
|
21
|
+
const COERCIONS = new Set(["Number", "parseFloat", "parseInt"]);
|
|
22
|
+
/**
|
|
23
|
+
* Roots that name transport input rather than a row.
|
|
24
|
+
*
|
|
25
|
+
* `Number(query.year)` converts a search parameter, which is the boundary doing
|
|
26
|
+
* its job. The candidate filter drops it here so the expected ignore is not
|
|
27
|
+
* needed; anything else with a member expression is a row until proven
|
|
28
|
+
* otherwise.
|
|
29
|
+
*/
|
|
30
|
+
const TRANSPORT_ROOTS = new Set(["body", "form", "options", "params", "query", "req", "request", "searchParams"]);
|
|
31
|
+
/** Whether an imported specifier means this module reads rows.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} specifier - The import specifier.
|
|
34
|
+
* @returns {boolean} True for a query builder, a driver or an internal query path.
|
|
35
|
+
*/
|
|
36
|
+
function readsRows(specifier) {
|
|
37
|
+
const parts = specifier.split("/");
|
|
38
|
+
const [first, second] = parts;
|
|
39
|
+
const packageName = first?.startsWith("@") === true && second !== undefined ? `${first}/${second}` : first;
|
|
40
|
+
if (packageName !== undefined && DATA_PACKAGES.has(packageName))
|
|
41
|
+
return true;
|
|
42
|
+
if (!specifier.startsWith(".") && !specifier.startsWith("/"))
|
|
43
|
+
return false;
|
|
44
|
+
return specifier
|
|
45
|
+
.replaceAll("\\", "/")
|
|
46
|
+
.split("/")
|
|
47
|
+
.some((segment) => segment === "db" || segment === "database" || segment === "queries" || segment === "query");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether a member expression's root names transport input rather than a row.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} name - The root identifier.
|
|
53
|
+
* @returns {boolean} True when the root is a request, a query or a body.
|
|
54
|
+
*/
|
|
55
|
+
export function isTransportRoot(name) {
|
|
56
|
+
return TRANSPORT_ROOTS.has(name);
|
|
57
|
+
}
|
|
58
|
+
/** The identifier a member expression starts at.
|
|
59
|
+
*
|
|
60
|
+
* @param {ESTree.Expression} expression - The expression to walk down.
|
|
61
|
+
* @returns {string | null} The root name, or null when the root is computed.
|
|
62
|
+
*/
|
|
63
|
+
function rootName(expression) {
|
|
64
|
+
let current = expression;
|
|
65
|
+
for (let guard = 0; guard < 16; guard += 1) {
|
|
66
|
+
if (current.type === "Identifier")
|
|
67
|
+
return current.name;
|
|
68
|
+
if (current.type !== "MemberExpression")
|
|
69
|
+
return null;
|
|
70
|
+
current = current.object;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A number read out of a row is text from the driver until something decodes
|
|
76
|
+
* it. `Number(row.amount)` is a second implementation of the domain's schema,
|
|
77
|
+
* with its own failure: `NaN` instead of a decode error.
|
|
78
|
+
*/
|
|
79
|
+
export const noRowCoercionRule = defineRule({
|
|
80
|
+
meta: {
|
|
81
|
+
type: "problem",
|
|
82
|
+
docs: {
|
|
83
|
+
description: "Disallow Number/parseInt/parseFloat coercion of a row member expression in a module that reads the database; decode through the domain schema instead.",
|
|
84
|
+
},
|
|
85
|
+
messages: {
|
|
86
|
+
rowCoercion: "`{{callee}}({{member}})` trusts the driver's text to be a number. Decode it through the domain schema, so the conversion has one implementation and one failure.",
|
|
87
|
+
},
|
|
88
|
+
schema: [
|
|
89
|
+
{
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
paths: { type: "array", items: { type: "string" } },
|
|
93
|
+
},
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
defaultOptions: [{}],
|
|
98
|
+
},
|
|
99
|
+
createOnce(context) {
|
|
100
|
+
let readsDatabase = false;
|
|
101
|
+
function checkImport(node) {
|
|
102
|
+
if (readsRows(node.source.value))
|
|
103
|
+
readsDatabase = true;
|
|
104
|
+
}
|
|
105
|
+
function checkCall(node) {
|
|
106
|
+
if (node.callee.type === "Identifier" && node.callee.name === "knex")
|
|
107
|
+
readsDatabase = true;
|
|
108
|
+
if (!readsDatabase)
|
|
109
|
+
return;
|
|
110
|
+
if (node.callee.type !== "Identifier" || !COERCIONS.has(node.callee.name))
|
|
111
|
+
return;
|
|
112
|
+
const first = node.arguments[0];
|
|
113
|
+
if (first === undefined || first.type !== "MemberExpression")
|
|
114
|
+
return;
|
|
115
|
+
const root = rootName(first);
|
|
116
|
+
if (root === null || isTransportRoot(root))
|
|
117
|
+
return;
|
|
118
|
+
context.report({
|
|
119
|
+
node,
|
|
120
|
+
messageId: "rowCoercion",
|
|
121
|
+
data: {
|
|
122
|
+
callee: node.callee.name,
|
|
123
|
+
member: context.sourceCode.text.slice(first.start, first.end),
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
before() {
|
|
129
|
+
readsDatabase = false;
|
|
130
|
+
},
|
|
131
|
+
ImportDeclaration: checkImport,
|
|
132
|
+
CallExpression: checkCall,
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import { ancestorsOf } from "../shared/ancestors.js";
|
|
3
3
|
import { isString } from "../shared/structural.js";
|
|
4
|
-
const TEST_FILE =
|
|
4
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
5
5
|
const MESSAGE_BY_KIND = {
|
|
6
6
|
"effect-function": "singleUseEffectFunction",
|
|
7
7
|
"effect-program": "singleUseEffectProgram",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disallow SQL queries built from template literal interpolation. String
|
|
3
|
+
* interpolation in SQL is an injection vector: attacker-controlled values
|
|
4
|
+
* become query structure. Use parameterized queries or a query builder
|
|
5
|
+
* instead so values never become syntax.
|
|
6
|
+
*/
|
|
7
|
+
export declare const noSqlStringInterpolationRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
3
|
+
/**
|
|
4
|
+
* SQL keywords that suggest a string is a query. Case-insensitive match
|
|
5
|
+
* against the raw template string portions.
|
|
6
|
+
*/
|
|
7
|
+
const SQL_KEYWORDS = [
|
|
8
|
+
"SELECT",
|
|
9
|
+
"INSERT",
|
|
10
|
+
"UPDATE",
|
|
11
|
+
"DELETE",
|
|
12
|
+
"FROM",
|
|
13
|
+
"WHERE",
|
|
14
|
+
"JOIN",
|
|
15
|
+
"CREATE\\s+TABLE",
|
|
16
|
+
"DROP\\s+TABLE",
|
|
17
|
+
"ALTER\\s+TABLE",
|
|
18
|
+
];
|
|
19
|
+
const SQL_PATTERN = new RegExp("\\b(?:" + SQL_KEYWORDS.join("|") + ")\\b", "iu");
|
|
20
|
+
/**
|
|
21
|
+
* Whether a template literal's raw text contains a SQL keyword.
|
|
22
|
+
* @param {ESTree.TemplateElement} quasi - The template element to test.
|
|
23
|
+
* @returns {boolean} True when the raw text contains a SQL keyword.
|
|
24
|
+
*/
|
|
25
|
+
function hasSqlKeyword(quasi) {
|
|
26
|
+
return SQL_PATTERN.test(quasi.value.raw);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Disallow SQL queries built from template literal interpolation. String
|
|
30
|
+
* interpolation in SQL is an injection vector: attacker-controlled values
|
|
31
|
+
* become query structure. Use parameterized queries or a query builder
|
|
32
|
+
* instead so values never become syntax.
|
|
33
|
+
*/
|
|
34
|
+
export const noSqlStringInterpolationRule = defineRule({
|
|
35
|
+
meta: {
|
|
36
|
+
type: "problem",
|
|
37
|
+
docs: {
|
|
38
|
+
description: "Disallow SQL queries built via template literal interpolation; use parameterized queries or a query builder to prevent SQL injection.",
|
|
39
|
+
},
|
|
40
|
+
messages: {
|
|
41
|
+
sqlInterpolation: "SQL via template literal interpolation is an injection vector. Use parameterized queries or a query builder so values never become syntax.",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
createOnce(context) {
|
|
45
|
+
return {
|
|
46
|
+
before() {
|
|
47
|
+
if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
|
|
48
|
+
return false;
|
|
49
|
+
},
|
|
50
|
+
TemplateLiteral(node) {
|
|
51
|
+
if (node.expressions.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
for (const quasi of node.quasis) {
|
|
54
|
+
if (hasSqlKeyword(quasi)) {
|
|
55
|
+
context.report({ node, messageId: "sqlInterpolation" });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
@@ -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
|
/** Directive and safety comments are tooling contracts, not prose. */
|
|
5
5
|
const EXEMPT = /^(?:SAFETY:|eslint|oxlint|@ts-|ts-check|jscpd)/iu;
|
|
6
6
|
/** Stray inline notes inside a function body belong in its JSDoc, not the code. */
|
|
@@ -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
|
+
}
|