@autotelic/plumb 0.6.0 → 0.6.2

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.
Files changed (71) hide show
  1. package/README.md +81 -8
  2. package/dist/configs/recommended-rules.d.ts +36 -0
  3. package/dist/configs/recommended-rules.js +57 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +1 -1
  5. package/dist/effect/rules/no-cascading-layer-provide.js +1 -1
  6. package/dist/effect/rules/no-decode-unknown-option.js +1 -1
  7. package/dist/effect/rules/no-direct-browser-storage.js +3 -3
  8. package/dist/effect/rules/no-direct-fetch.js +1 -1
  9. package/dist/effect/rules/no-manual-field-guards.js +1 -1
  10. package/dist/effect/rules/no-nested-layer-provide.js +1 -1
  11. package/dist/effect/rules/no-nullish-default-on-partial-input.js +2 -2
  12. package/dist/effect/rules/no-raw-error-forwarding.d.ts +4 -0
  13. package/dist/effect/rules/no-raw-error-forwarding.js +7 -2
  14. package/dist/effect/rules/no-silent-error-swallow.js +1 -1
  15. package/dist/effect/rules/no-static-effect-service-forwarders.js +5 -4
  16. package/dist/effect/rules/no-try-catch.js +1 -1
  17. package/dist/effect/rules/no-unguarded-json-parse.js +1 -1
  18. package/dist/effect/rules/option-core-needs-effect-public.js +1 -1
  19. package/dist/effect/rules/prefer-die-for-precondition-defects.js +1 -1
  20. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +1 -1
  21. package/dist/effect/rules/prefer-effect-match.js +2 -2
  22. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +1 -1
  23. package/dist/effect/rules/prefer-named-guard-predicate.js +1 -1
  24. package/dist/effect/rules/prefer-option-pipeline.js +13 -12
  25. package/dist/effect/rules/prefer-ordering-match.js +1 -1
  26. package/dist/effect/rules/prefer-tagged-enum.js +1 -1
  27. package/dist/effect/rules/require-schema-type-derivation.d.ts +8 -2
  28. package/dist/effect/rules/require-schema-type-derivation.js +14 -4
  29. package/dist/index.js +8 -0
  30. package/dist/react/rules/require-dot-notation-exports.js +1 -1
  31. package/dist/react/rules/require-guarded-context-hook.js +1 -1
  32. package/dist/react/rules/require-tripartite-context.js +1 -1
  33. package/dist/react/rules/use-encapsulation.js +1 -1
  34. package/dist/rules/no-adapter-in-values.d.ts +12 -0
  35. package/dist/rules/no-adapter-in-values.js +110 -0
  36. package/dist/rules/no-builtin-throws.js +1 -1
  37. package/dist/rules/no-duplicated-literal-union.d.ts +7 -0
  38. package/dist/rules/no-duplicated-literal-union.js +5 -1
  39. package/dist/rules/no-generic-export-names.js +1 -1
  40. package/dist/rules/no-multiple-function-params.js +26 -12
  41. package/dist/rules/no-mutable-environment-capture.js +2 -2
  42. package/dist/rules/no-nondeterministic-core.js +1 -1
  43. package/dist/rules/no-nullable-value-field.d.ts +16 -0
  44. package/dist/rules/no-nullable-value-field.js +117 -0
  45. package/dist/rules/no-optional-function-parameters.js +1 -1
  46. package/dist/rules/no-row-coercion.d.ts +13 -0
  47. package/dist/rules/no-row-coercion.js +135 -0
  48. package/dist/rules/no-single-use-private-functions.js +1 -1
  49. package/dist/rules/no-sql-string-interpolation.js +2 -2
  50. package/dist/rules/no-stray-inline-comments.js +1 -1
  51. package/dist/rules/no-string-instant.d.ts +15 -0
  52. package/dist/rules/no-string-instant.js +108 -0
  53. package/dist/rules/no-swappable-primitive-params.js +1 -1
  54. package/dist/rules/no-tag-ladder-assertions.js +1 -1
  55. package/dist/rules/no-vague-test-filenames.js +1 -1
  56. package/dist/rules/prefer-property-tests.d.ts +5 -0
  57. package/dist/rules/prefer-property-tests.js +7 -0
  58. package/dist/rules/require-jsdoc-on-exported.js +1 -1
  59. package/dist/shared/ancestors.d.ts +1 -1
  60. package/dist/shared/ancestors.js +1 -1
  61. package/dist/shared/values-path.d.ts +12 -0
  62. package/dist/shared/values-path.js +56 -0
  63. package/dist/testing/testable-rule.d.ts +6 -5
  64. package/dist/testing/testable-rule.js +20 -6
  65. package/dist/ui/index.d.ts +12 -0
  66. package/dist/ui/index.js +18 -0
  67. package/dist/ui/manifest.d.ts +49 -0
  68. package/dist/ui/manifest.js +90 -0
  69. package/dist/ui/rules/no-deprecated-parts.d.ts +3 -0
  70. package/dist/ui/rules/no-deprecated-parts.js +172 -0
  71. package/package.json +28 -19
@@ -1,7 +1,7 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { ancestorsOf } from "../../shared/ancestors.js";
3
3
  import { isHookName } from "../role.js";
4
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
5
5
  /**
6
6
  * Whether a custom context hook that reads context must be reported for
7
7
  * lacking a guard against a missing Provider.
@@ -1,6 +1,6 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { isString } from "../../shared/structural.js";
3
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
4
  /** The three required keys of a context value type. */
5
5
  const REQUIRED_KEYS = ["state", "actions", "meta"];
6
6
  /**
@@ -2,7 +2,7 @@ import { defineRule } from "@oxlint/plugins";
2
2
  import { ancestorsOf } from "../../shared/ancestors.js";
3
3
  import { readField } from "../../shared/structural.js";
4
4
  import { isProviderName } from "../role.js";
5
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
5
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
6
6
  /** Pattern identifying custom hooks (names starting with `use`). */
7
7
  const HOOK_PATTERN = /^use/u;
8
8
  /** React's built-in hooks that must not be used directly inside components. */
@@ -0,0 +1,12 @@
1
+ /** Whether an import is a cost-driven dependency the values stratum may not hold.
2
+ *
3
+ * @param {string} specifier - The import specifier.
4
+ * @returns {boolean} True when it is a query builder, a driver or an adapter path.
5
+ */
6
+ export declare function isAdapter(specifier: string): boolean;
7
+ /**
8
+ * The values stratum depends on nothing internal. A `Money` that can import the
9
+ * query builder is not a value: it is a row with a reassuring name, and the
10
+ * next author will put a `where` clause in it.
11
+ */
12
+ export declare const noAdapterInValuesRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,110 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { inValuesPath } from "../shared/values-path.js";
3
+ /**
4
+ * Packages that put a value on a database, a socket or a request.
5
+ *
6
+ * A DECLARED vocabulary, like the `node:` builtins in `dependency-fit`: which
7
+ * driver a repository chose is a fact about the adapter, and the packages that
8
+ * can be one are a closed list. A repository with an in-house client adds its
9
+ * path to the rule's `paths` option rather than teaching the rule a new name.
10
+ */
11
+ const ADAPTER_PACKAGES = new Set([
12
+ "@hapi/hapi",
13
+ "@nestjs/common",
14
+ "@prisma/client",
15
+ "better-sqlite3",
16
+ "drizzle-orm",
17
+ "express",
18
+ "fastify",
19
+ "hono",
20
+ "knex",
21
+ "koa",
22
+ "kysely",
23
+ "mongodb",
24
+ "mysql",
25
+ "mysql2",
26
+ "pg",
27
+ "postgres",
28
+ "prisma",
29
+ "sequelize",
30
+ "slonik",
31
+ "sqlite3",
32
+ "typeorm",
33
+ ]);
34
+ /** Path fragments that name an adapter or a query module inside the repository. */
35
+ const ADAPTER_PATH_SEGMENTS = new Set(["adapter", "adapters", "db", "database", "queries", "query", "repository", "repositories"]);
36
+ /** The package a specifier names, so `knex/lib/query` is still `knex`.
37
+ *
38
+ * @param {string} specifier - An import specifier.
39
+ * @returns {string} The package name, or the specifier when it is relative.
40
+ */
41
+ function packageOf(specifier) {
42
+ const parts = specifier.split("/");
43
+ const [first, second] = parts;
44
+ if (first === undefined)
45
+ return specifier;
46
+ return first.startsWith("@") && second !== undefined ? `${first}/${second}` : first;
47
+ }
48
+ /** Whether an import is a cost-driven dependency the values stratum may not hold.
49
+ *
50
+ * @param {string} specifier - The import specifier.
51
+ * @returns {boolean} True when it is a query builder, a driver or an adapter path.
52
+ */
53
+ export function isAdapter(specifier) {
54
+ if (ADAPTER_PACKAGES.has(packageOf(specifier)))
55
+ return true;
56
+ if (!specifier.startsWith(".") && !specifier.startsWith("/"))
57
+ return false;
58
+ const segments = specifier.replaceAll("\\", "/").split("/");
59
+ return segments.some((segment) => ADAPTER_PATH_SEGMENTS.has(segment));
60
+ }
61
+ /**
62
+ * The values stratum depends on nothing internal. A `Money` that can import the
63
+ * query builder is not a value: it is a row with a reassuring name, and the
64
+ * next author will put a `where` clause in it.
65
+ */
66
+ export const noAdapterInValuesRule = defineRule({
67
+ meta: {
68
+ type: "problem",
69
+ docs: {
70
+ description: "Disallow imports of query builders, database drivers, HTTP frameworks and query modules from a declared values path.",
71
+ },
72
+ messages: {
73
+ adapterInValues: "`{{specifier}}` belongs to the adapter, not to a value. The domain depends on nothing internal: move this import to the derivation or edge that reads it.",
74
+ },
75
+ schema: [
76
+ {
77
+ type: "object",
78
+ properties: {
79
+ paths: { type: "array", items: { type: "string" } },
80
+ },
81
+ additionalProperties: false,
82
+ },
83
+ ],
84
+ defaultOptions: [{}],
85
+ },
86
+ createOnce(context) {
87
+ function check(specifier, node) {
88
+ if (specifier === null || specifier === undefined)
89
+ return;
90
+ if (!isAdapter(specifier))
91
+ return;
92
+ context.report({ node, messageId: "adapterInValues", data: { specifier } });
93
+ }
94
+ return {
95
+ before() {
96
+ if (!inValuesPath(context.filename, context.options))
97
+ return false;
98
+ },
99
+ ImportDeclaration(node) {
100
+ check(node.source.value, node);
101
+ },
102
+ ExportAllDeclaration(node) {
103
+ check(node.source.value, node);
104
+ },
105
+ ExportNamedDeclaration(node) {
106
+ check(node.source?.value, node);
107
+ },
108
+ };
109
+ },
110
+ });
@@ -1,7 +1,7 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { firstOptionRecord } from "../shared/rule-options.js";
3
3
  import { isRecordObject, isString } from "../shared/structural.js";
4
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
5
5
  /** Generic built-in errors: untyped, prose-only, and invisible to tag-based handling. */
6
6
  const BUILTIN_ERRORS = new Set([
7
7
  "Error",
@@ -1,3 +1,10 @@
1
+ import type { ESTree } from "@oxlint/plugins";
2
+ /** Sorted string-literal members of a union annotation, or null if it isn't one.
3
+ *
4
+ * @param {ESTree.TSType} annotation - The annotation to inspect.
5
+ * @returns {string[] | null} Sorted literal members, or null when not a literal union.
6
+ */
7
+ export declare function literalUnionKey(annotation: ESTree.TSType): string[] | null;
1
8
  /**
2
9
  * One fact, one place: a set of variants declared twice drifts the moment
3
10
  * someone adds a member to one copy. Declare each variant set once and
@@ -5,7 +5,7 @@ import { isRecordObject, isString } from "../shared/structural.js";
5
5
  * @param {ESTree.TSType} annotation - The annotation to inspect.
6
6
  * @returns {string[] | null} Sorted literal members, or null when not a literal union.
7
7
  */
8
- function literalUnionKey(annotation) {
8
+ export function literalUnionKey(annotation) {
9
9
  const types = annotation.type === "TSUnionType" ? annotation.types : [annotation];
10
10
  const literals = [];
11
11
  for (const member of types) {
@@ -36,6 +36,10 @@ export const noDuplicatedLiteralUnionRule = defineRule({
36
36
  const seen = new Map();
37
37
  const duplicates = new Map();
38
38
  return {
39
+ before() {
40
+ seen.clear();
41
+ duplicates.clear();
42
+ },
39
43
  TSTypeAliasDeclaration(node) {
40
44
  const key = literalUnionKey(node.typeAnnotation);
41
45
  if (key === null)
@@ -38,7 +38,7 @@ const GENERIC_TERMS = new Set([
38
38
  "temp",
39
39
  "tmp",
40
40
  ]);
41
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
41
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
42
42
  /** Split an identifier into its words across camelCase and separators.
43
43
  *
44
44
  * @param {string} name - Identifier or filename stem to split.
@@ -1,7 +1,7 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { readField } from "../shared/structural.js";
3
3
  import { ancestorsOf } from "../shared/ancestors.js";
4
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
4
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
5
5
  const DEFAULT_MAX_PARAMS = 1;
6
6
  /** Conventional HTTP method handler names, exempt inside framework route files. */
7
7
  const HTTP_METHOD_NAMES = new Set([
@@ -15,19 +15,28 @@ const HTTP_METHOD_NAMES = new Set([
15
15
  ]);
16
16
  const DEFAULT_ROUTE_BASENAMES = new Set(["route.ts", "route.tsx"]);
17
17
  function parentOf(sourceCode, node) {
18
- return ancestorsOf(sourceCode, node)[0] ?? null;
18
+ return ancestorsOf(sourceCode, node).at(-1) ?? null;
19
19
  }
20
20
  /**
21
21
  * Functions the module owns: declarations and named bindings, not callbacks.
22
22
  *
23
+ * A function nested inside another function is a closure — its arity is local, not part of
24
+ * the module's surface, so the rule does not apply. (`ancestorsOf` is outermost-first.)
25
+ *
23
26
  * @param {SourceCode} sourceCode - The rule's source-code accessor.
24
27
  * @param {ESTree.Node} node - The visited function-like node.
25
28
  * @returns {boolean} True when the module owns the function's arity.
26
29
  */
27
30
  function isOwnedFunction(sourceCode, node) {
31
+ const chain = ancestorsOf(sourceCode, node);
32
+ const nested = chain.some((ancestor) => ancestor.type === "FunctionDeclaration" ||
33
+ ancestor.type === "FunctionExpression" ||
34
+ ancestor.type === "ArrowFunctionExpression");
35
+ if (nested)
36
+ return false;
28
37
  if (node.type === "FunctionDeclaration")
29
38
  return true;
30
- const parent = parentOf(sourceCode, node);
39
+ const parent = chain.at(-1) ?? null;
31
40
  if (parent === null)
32
41
  return false;
33
42
  const parentType = parent.type;
@@ -57,11 +66,15 @@ function isExemptRouteHandler(payload) {
57
66
  const parent = parentOf(payload.sourceCode, payload.node);
58
67
  return parent !== null && parent.type === "ExportNamedDeclaration";
59
68
  }
60
- /** Primitive annotations transpose silently; structural ones fail the compiler. */
61
- const PRIMITIVE_TYPE_TEXT = /^(?:string|number|bigint|boolean|unknown|any|null|undefined|void)$/u;
62
69
  /**
63
- * Whether every positional parameter carries a distinct non-primitive type:
64
- * transposing such arguments is a compile error, so ordering needs no guard.
70
+ * Whether every positional parameter carries a distinct annotated type: transposing such
71
+ * arguments is a compile error, so ordering needs no guard. Distinctness is the test, not
72
+ * primitive-versus-structural: `(name: string, count: number)` is as safe as
73
+ * `(left: Node, right: Node)` is unsafe, and only a repeated type transposes silently.
74
+ *
75
+ * A default value wraps the identifier in an `AssignmentPattern`; the annotation lives on
76
+ * the left. Treating a defaulted parameter as unannotated made every function with a default
77
+ * look unsafe.
65
78
  *
66
79
  * @param {SourceCode} sourceCode - The rule's source-code accessor.
67
80
  * @param {ReadonlyArray<ESTree.ParamPattern>} params - The parameter list to inspect.
@@ -70,13 +83,14 @@ const PRIMITIVE_TYPE_TEXT = /^(?:string|number|bigint|boolean|unknown|any|null|u
70
83
  function transpositionSafe(sourceCode, params) {
71
84
  const texts = [];
72
85
  for (const param of params) {
73
- if (param.type !== "Identifier")
86
+ const identifier = param.type === "AssignmentPattern" ? param.left : param;
87
+ if (identifier.type !== "Identifier")
74
88
  return false;
75
- const annotation = param.typeAnnotation;
89
+ const annotation = identifier.typeAnnotation;
76
90
  if (annotation === null || annotation === undefined)
77
91
  return false;
78
92
  const text = sourceCode.getText(annotation.typeAnnotation).replaceAll(" ", "");
79
- if (text === "" || PRIMITIVE_TYPE_TEXT.test(text))
93
+ if (text === "")
80
94
  return false;
81
95
  texts.push(text);
82
96
  }
@@ -87,10 +101,10 @@ export const noMultipleFunctionParamsRule = defineRule({
87
101
  meta: {
88
102
  type: "problem",
89
103
  docs: {
90
- description: "Disallow owned functions with more than one positional parameter; collapse multiple inputs into a single named payload object so transposed arguments fail the compiler.",
104
+ description: "Disallow owned functions with more than one positional parameter unless every parameter has a distinct annotated type; collapse multiple inputs into a single named payload object so a transposed argument fails the compiler.",
91
105
  },
92
106
  messages: {
93
- multipleParams: "`{{name}}` takes {{count}} positional parameters. Accept a single named payload object instead; transposed primitive arguments compile silently.",
107
+ multipleParams: "`{{name}}` takes {{count}} positional parameters without distinct types. Accept a single named payload object instead; two parameters of the same type transpose silently.",
94
108
  },
95
109
  },
96
110
  createOnce(context) {
@@ -1,6 +1,6 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { ancestorsOf } from "../shared/ancestors.js";
3
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
4
4
  /**
5
5
  * Whether the identifier sits inside a type annotation rather than a value position.
6
6
  *
@@ -25,7 +25,7 @@ function isTypePosition(sourceCode, identifier) {
25
25
  function functionName(node, sourceCode) {
26
26
  if (node.type === "FunctionDeclaration" && node.id !== null)
27
27
  return node.id.name;
28
- const parent = ancestorsOf(sourceCode, node)[0];
28
+ const parent = ancestorsOf(sourceCode, node).at(-1);
29
29
  if (parent !== undefined) {
30
30
  if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier")
31
31
  return parent.id.name;
@@ -1,6 +1,6 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  const NONDETERMINISTIC_MEMBERS = new Set(["getRandomValues", "random", "randomUUID", "now"]);
3
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$|\/test\//u;
3
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$|\/test\//u;
4
4
  function memberChain(node) {
5
5
  if (node.type === "MemberExpression" && !node.computed) {
6
6
  return [...memberChain(node.object), node.property.type === "Identifier" ? node.property.name : ""];
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Whether a constructor chain admits an absent value.
3
+ *
4
+ * @param {ReadonlyArray<string>} names - The names in the field's chain.
5
+ * @returns {boolean} True when one of them makes the field absent.
6
+ */
7
+ export declare function hasAbsence(names: ReadonlyArray<string>): boolean;
8
+ /**
9
+ * A value is certain, or it is not a value.
10
+ *
11
+ * Nullability from a `left join` is a retrieval artifact. When it becomes a
12
+ * field of the concept, the concept starts saying the business is unsure about
13
+ * something it knows. The partiality belongs in the derivation that read the
14
+ * row, and the exception ("this field is absent by nature") needs a comment.
15
+ */
16
+ export declare const noNullableValueFieldRule: import("@oxlint/plugins").Rule;
@@ -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
+ });
@@ -1,5 +1,5 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
3
  /**
4
4
  * Optional parameters hide undefined from the signature; require the union spelled out.
5
5
  *
@@ -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 = /.(?:test|spec).[cm]?[jt]sx?$/u;
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",
@@ -1,5 +1,5 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
2
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
3
  /**
4
4
  * SQL keywords that suggest a string is a query. Case-insensitive match
5
5
  * against the raw template string portions.
@@ -44,7 +44,7 @@ export const noSqlStringInterpolationRule = defineRule({
44
44
  createOnce(context) {
45
45
  return {
46
46
  before() {
47
- if (TEST_FILE.test(context.filename.replaceAll("\\\\", "/")))
47
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
48
48
  return false;
49
49
  },
50
50
  TemplateLiteral(node) {
@@ -1,6 +1,6 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import { getAllComments } from "../shared/structural.js";
3
- const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
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. */