@autotelic/plumb 0.3.1 → 0.4.0

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 (268) hide show
  1. package/dist/effect/index.d.ts +3 -0
  2. package/dist/effect/index.js +56 -0
  3. package/dist/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
  4. package/dist/effect/rules/guarded-op-must-return-effect.js +235 -0
  5. package/dist/effect/rules/guarded-op-must-return-option.d.ts +2 -0
  6. package/dist/effect/rules/guarded-op-must-return-option.js +88 -0
  7. package/dist/effect/rules/no-cascading-layer-provide.d.ts +6 -0
  8. package/dist/effect/rules/no-cascading-layer-provide.js +73 -0
  9. package/dist/effect/rules/no-decode-unknown-option.d.ts +7 -0
  10. package/dist/effect/rules/no-decode-unknown-option.js +34 -0
  11. package/dist/effect/rules/no-direct-browser-storage.d.ts +2 -0
  12. package/dist/effect/rules/no-direct-browser-storage.js +88 -0
  13. package/dist/effect/rules/no-direct-fetch.d.ts +2 -0
  14. package/dist/effect/rules/no-direct-fetch.js +37 -0
  15. package/dist/effect/rules/no-manual-field-guards.d.ts +6 -0
  16. package/dist/effect/rules/no-manual-field-guards.js +129 -0
  17. package/dist/effect/rules/no-nested-layer-provide.d.ts +2 -0
  18. package/dist/effect/rules/no-nested-layer-provide.js +50 -0
  19. package/dist/effect/rules/no-schema-class-modeling.d.ts +2 -0
  20. package/dist/effect/rules/no-schema-class-modeling.js +52 -0
  21. package/dist/effect/rules/no-service-constructor-imports.d.ts +2 -0
  22. package/dist/effect/rules/no-service-constructor-imports.js +42 -0
  23. package/dist/effect/rules/no-silent-error-swallow.d.ts +2 -0
  24. package/dist/effect/rules/no-silent-error-swallow.js +95 -0
  25. package/dist/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
  26. package/dist/effect/rules/no-static-effect-service-forwarders.js +222 -0
  27. package/dist/effect/rules/no-try-catch.d.ts +2 -0
  28. package/dist/effect/rules/no-try-catch.js +30 -0
  29. package/dist/effect/rules/no-unguarded-json-parse.d.ts +5 -0
  30. package/dist/effect/rules/no-unguarded-json-parse.js +200 -0
  31. package/dist/effect/rules/option-core-needs-effect-public.d.ts +5 -0
  32. package/dist/effect/rules/option-core-needs-effect-public.js +76 -0
  33. package/dist/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
  34. package/dist/effect/rules/prefer-die-for-precondition-defects.js +112 -0
  35. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
  36. package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
  37. package/dist/effect/rules/prefer-effect-match.d.ts +2 -0
  38. package/dist/effect/rules/prefer-effect-match.js +74 -0
  39. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
  40. package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
  41. package/dist/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
  42. package/dist/effect/rules/prefer-named-guard-predicate.js +93 -0
  43. package/dist/effect/rules/prefer-option-pipeline.d.ts +2 -0
  44. package/dist/effect/rules/prefer-option-pipeline.js +87 -0
  45. package/dist/effect/rules/prefer-ordering-match.d.ts +2 -0
  46. package/dist/effect/rules/prefer-ordering-match.js +135 -0
  47. package/dist/effect/rules/prefer-tagged-enum.d.ts +2 -0
  48. package/dist/effect/rules/prefer-tagged-enum.js +66 -0
  49. package/dist/effect/rules/require-schema-type-derivation.d.ts +7 -0
  50. package/dist/effect/rules/require-schema-type-derivation.js +80 -0
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.js +104 -0
  53. package/dist/meta/index.d.ts +7 -0
  54. package/{src/meta/index.ts → dist/meta/index.js} +13 -16
  55. package/dist/meta/rules/no-disable-directives.d.ts +6 -0
  56. package/dist/meta/rules/no-disable-directives.js +35 -0
  57. package/dist/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
  58. package/dist/meta/rules/no-manual-ancestor-walks.js +26 -0
  59. package/dist/meta/rules/prefer-before-file-scope.d.ts +2 -0
  60. package/dist/meta/rules/prefer-before-file-scope.js +57 -0
  61. package/dist/meta/rules/require-create-once.d.ts +2 -0
  62. package/dist/meta/rules/require-create-once.js +51 -0
  63. package/dist/meta/rules/require-rule-tester.d.ts +2 -0
  64. package/dist/meta/rules/require-rule-tester.js +50 -0
  65. package/dist/rules/no-anonymous-wide-tuples.d.ts +7 -0
  66. package/dist/rules/no-anonymous-wide-tuples.js +34 -0
  67. package/dist/rules/no-barrel-export-star.d.ts +2 -0
  68. package/dist/rules/no-barrel-export-star.js +26 -0
  69. package/dist/rules/no-boolean-field-signals.d.ts +2 -0
  70. package/dist/rules/no-boolean-field-signals.js +279 -0
  71. package/dist/rules/no-builtin-throws.d.ts +6 -0
  72. package/dist/rules/no-builtin-throws.js +74 -0
  73. package/dist/rules/no-chained-type-assertions.d.ts +2 -0
  74. package/dist/rules/no-chained-type-assertions.js +54 -0
  75. package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
  76. package/dist/rules/no-conditional-empty-object-spread.js +36 -0
  77. package/dist/rules/no-duplicated-literal-union.d.ts +6 -0
  78. package/dist/rules/no-duplicated-literal-union.js +62 -0
  79. package/dist/rules/no-exported-mutable-state.d.ts +7 -0
  80. package/dist/rules/no-exported-mutable-state.js +104 -0
  81. package/dist/rules/no-generic-export-names.d.ts +2 -0
  82. package/dist/rules/no-generic-export-names.js +141 -0
  83. package/dist/rules/no-impossible-branch-throw.d.ts +2 -0
  84. package/dist/rules/no-impossible-branch-throw.js +51 -0
  85. package/dist/rules/no-known-value-widening.d.ts +2 -0
  86. package/dist/rules/no-known-value-widening.js +176 -0
  87. package/dist/rules/no-module-mocking.d.ts +2 -0
  88. package/dist/rules/no-module-mocking.js +90 -0
  89. package/dist/rules/no-multiple-function-params.d.ts +2 -0
  90. package/dist/rules/no-multiple-function-params.js +155 -0
  91. package/dist/rules/no-mutable-environment-capture.d.ts +7 -0
  92. package/dist/rules/no-mutable-environment-capture.js +134 -0
  93. package/dist/rules/no-nondeterministic-core.d.ts +6 -0
  94. package/dist/rules/no-nondeterministic-core.js +63 -0
  95. package/dist/rules/no-object-parameters.d.ts +2 -0
  96. package/dist/rules/no-object-parameters.js +95 -0
  97. package/dist/rules/no-optional-function-parameters.d.ts +7 -0
  98. package/dist/rules/no-optional-function-parameters.js +44 -0
  99. package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
  100. package/dist/rules/no-product-of-state-booleans.js +79 -0
  101. package/dist/rules/no-redundant-derived-field.d.ts +6 -0
  102. package/dist/rules/no-redundant-derived-field.js +194 -0
  103. package/dist/rules/no-reflect-apply.d.ts +2 -0
  104. package/dist/rules/no-reflect-apply.js +29 -0
  105. package/dist/rules/no-reflect-get.d.ts +2 -0
  106. package/dist/rules/no-reflect-get.js +29 -0
  107. package/dist/rules/no-reinterpret-cast.d.ts +2 -0
  108. package/dist/rules/no-reinterpret-cast.js +68 -0
  109. package/dist/rules/no-runtime-typeof.d.ts +2 -0
  110. package/dist/rules/no-runtime-typeof.js +54 -0
  111. package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
  112. package/dist/rules/no-sentinel-comparison-union.js +139 -0
  113. package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
  114. package/dist/rules/no-shape-in-symbol-names.js +39 -0
  115. package/dist/rules/no-single-use-private-functions.d.ts +17 -0
  116. package/dist/rules/no-single-use-private-functions.js +419 -0
  117. package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
  118. package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
  119. package/dist/rules/no-stray-inline-comments.d.ts +2 -0
  120. package/dist/rules/no-stray-inline-comments.js +74 -0
  121. package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
  122. package/dist/rules/no-swappable-primitive-params.js +96 -0
  123. package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
  124. package/dist/rules/no-tag-ladder-assertions.js +63 -0
  125. package/dist/rules/no-transposed-field-reads.d.ts +8 -0
  126. package/dist/rules/no-transposed-field-reads.js +101 -0
  127. package/dist/rules/no-unit-return-validators.d.ts +2 -0
  128. package/dist/rules/no-unit-return-validators.js +64 -0
  129. package/dist/rules/no-unknown-parameters.d.ts +2 -0
  130. package/dist/rules/no-unknown-parameters.js +82 -0
  131. package/dist/rules/no-unknown-returns.d.ts +2 -0
  132. package/dist/rules/no-unknown-returns.js +86 -0
  133. package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
  134. package/dist/rules/no-unknown-type-aliases.js +64 -0
  135. package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
  136. package/dist/rules/no-unsafe-dictionary-type.js +116 -0
  137. package/dist/rules/no-vague-test-filenames.d.ts +2 -0
  138. package/dist/rules/no-vague-test-filenames.js +61 -0
  139. package/dist/rules/no-widen-then-assert.d.ts +2 -0
  140. package/dist/rules/no-widen-then-assert.js +268 -0
  141. package/dist/rules/prefer-payload-brand.d.ts +2 -0
  142. package/dist/rules/prefer-payload-brand.js +57 -0
  143. package/dist/rules/prefer-property-tests.d.ts +5 -0
  144. package/dist/rules/prefer-property-tests.js +39 -0
  145. package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
  146. package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
  147. package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
  148. package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
  149. package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
  150. package/dist/rules/require-exhaustive-tag-switch.js +34 -0
  151. package/dist/rules/require-fc-block-predicate.d.ts +2 -0
  152. package/dist/rules/require-fc-block-predicate.js +37 -0
  153. package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
  154. package/dist/rules/require-jsdoc-on-exported.js +66 -0
  155. package/dist/rules/require-published-order.d.ts +2 -0
  156. package/dist/rules/require-published-order.js +102 -0
  157. package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
  158. package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
  159. package/dist/rules/require-sort-comparator.d.ts +7 -0
  160. package/dist/rules/require-sort-comparator.js +34 -0
  161. package/dist/rules/test-utils.d.ts +35 -0
  162. package/dist/rules/test-utils.js +53 -0
  163. package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
  164. package/dist/shared/ancestors.js +19 -0
  165. package/dist/shared/child-nodes.d.ts +12 -0
  166. package/dist/shared/child-nodes.js +26 -0
  167. package/dist/shared/dictionary-types.d.ts +55 -0
  168. package/dist/shared/dictionary-types.js +413 -0
  169. package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
  170. package/dist/shared/is-node.js +10 -0
  171. package/dist/shared/lexical-type-parameters.d.ts +12 -0
  172. package/dist/shared/lexical-type-parameters.js +50 -0
  173. package/dist/shared/reflect-method.d.ts +15 -0
  174. package/dist/shared/reflect-method.js +32 -0
  175. package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
  176. package/dist/shared/rule-options.js +12 -0
  177. package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
  178. package/dist/shared/structural.js +40 -0
  179. package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
  180. package/dist/testing/index.js +1 -0
  181. package/dist/testing/testable-rule.d.ts +38 -0
  182. package/dist/testing/testable-rule.js +70 -0
  183. package/package.json +7 -6
  184. package/src/effect/index.ts +0 -59
  185. package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
  186. package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
  187. package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
  188. package/src/effect/rules/no-decode-unknown-option.ts +0 -41
  189. package/src/effect/rules/no-direct-browser-storage.ts +0 -91
  190. package/src/effect/rules/no-direct-fetch.ts +0 -44
  191. package/src/effect/rules/no-manual-field-guards.ts +0 -144
  192. package/src/effect/rules/no-nested-layer-provide.ts +0 -51
  193. package/src/effect/rules/no-schema-class-modeling.ts +0 -59
  194. package/src/effect/rules/no-service-constructor-imports.ts +0 -50
  195. package/src/effect/rules/no-silent-error-swallow.ts +0 -99
  196. package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
  197. package/src/effect/rules/no-try-catch.ts +0 -32
  198. package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
  199. package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
  200. package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
  201. package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
  202. package/src/effect/rules/prefer-effect-match.ts +0 -78
  203. package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
  204. package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
  205. package/src/effect/rules/prefer-option-pipeline.ts +0 -95
  206. package/src/effect/rules/prefer-ordering-match.ts +0 -152
  207. package/src/effect/rules/prefer-tagged-enum.ts +0 -68
  208. package/src/effect/rules/require-schema-type-derivation.ts +0 -83
  209. package/src/index.ts +0 -106
  210. package/src/meta/rules/no-disable-directives.ts +0 -38
  211. package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
  212. package/src/meta/rules/prefer-before-file-scope.ts +0 -57
  213. package/src/meta/rules/require-create-once.ts +0 -51
  214. package/src/meta/rules/require-rule-tester.ts +0 -57
  215. package/src/rules/no-anonymous-wide-tuples.ts +0 -38
  216. package/src/rules/no-barrel-export-star.ts +0 -30
  217. package/src/rules/no-boolean-field-signals.ts +0 -305
  218. package/src/rules/no-builtin-throws.ts +0 -83
  219. package/src/rules/no-chained-type-assertions.ts +0 -65
  220. package/src/rules/no-conditional-empty-object-spread.ts +0 -42
  221. package/src/rules/no-duplicated-literal-union.ts +0 -66
  222. package/src/rules/no-exported-mutable-state.ts +0 -111
  223. package/src/rules/no-generic-export-names.ts +0 -149
  224. package/src/rules/no-impossible-branch-throw.ts +0 -55
  225. package/src/rules/no-known-value-widening.ts +0 -225
  226. package/src/rules/no-module-mocking.ts +0 -95
  227. package/src/rules/no-multiple-function-params.ts +0 -192
  228. package/src/rules/no-nondeterministic-core.ts +0 -73
  229. package/src/rules/no-object-parameters.ts +0 -127
  230. package/src/rules/no-optional-function-parameters.ts +0 -49
  231. package/src/rules/no-product-of-state-booleans.ts +0 -80
  232. package/src/rules/no-redundant-derived-field.ts +0 -192
  233. package/src/rules/no-reflect-apply.ts +0 -32
  234. package/src/rules/no-reflect-get.ts +0 -32
  235. package/src/rules/no-reinterpret-cast.ts +0 -78
  236. package/src/rules/no-runtime-typeof.ts +0 -59
  237. package/src/rules/no-sentinel-comparison-union.ts +0 -148
  238. package/src/rules/no-shape-in-symbol-names.ts +0 -45
  239. package/src/rules/no-single-use-private-functions.ts +0 -329
  240. package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
  241. package/src/rules/no-stray-inline-comments.ts +0 -79
  242. package/src/rules/no-swappable-primitive-params.ts +0 -109
  243. package/src/rules/no-tag-ladder-assertions.ts +0 -71
  244. package/src/rules/no-transposed-field-reads.ts +0 -135
  245. package/src/rules/no-unit-return-validators.ts +0 -65
  246. package/src/rules/no-unknown-parameters.ts +0 -97
  247. package/src/rules/no-unknown-returns.ts +0 -120
  248. package/src/rules/no-unknown-type-aliases.ts +0 -70
  249. package/src/rules/no-unsafe-dictionary-type.ts +0 -132
  250. package/src/rules/no-vague-test-filenames.ts +0 -67
  251. package/src/rules/no-widen-then-assert.ts +0 -345
  252. package/src/rules/prefer-payload-brand.ts +0 -67
  253. package/src/rules/prefer-property-tests.ts +0 -43
  254. package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
  255. package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
  256. package/src/rules/require-exhaustive-tag-switch.ts +0 -42
  257. package/src/rules/require-fc-block-predicate.ts +0 -42
  258. package/src/rules/require-jsdoc-on-exported.ts +0 -74
  259. package/src/rules/require-published-order.ts +0 -109
  260. package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
  261. package/src/rules/require-sort-comparator.ts +0 -41
  262. package/src/rules/test-utils.ts +0 -68
  263. package/src/shared/child-nodes.ts +0 -27
  264. package/src/shared/dictionary-types.ts +0 -524
  265. package/src/shared/lexical-type-parameters.ts +0 -62
  266. package/src/shared/reflect-method.ts +0 -41
  267. package/src/testing/testable-rule.test.ts +0 -68
  268. package/src/testing/testable-rule.ts +0 -86
@@ -0,0 +1,95 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { ancestorsOf } from "../shared/ancestors.js";
3
+ import { lexicalTypeParameterNames } from "../shared/lexical-type-parameters.js";
4
+ function parameterAnnotation(parameter) {
5
+ if (parameter.type === "TSParameterProperty") {
6
+ return parameterAnnotation(parameter.parameter);
7
+ }
8
+ if (parameter.type === "RestElement") {
9
+ return parameter.typeAnnotation ?? parameterAnnotation(parameter.argument);
10
+ }
11
+ if (parameter.type === "AssignmentPattern") {
12
+ return parameter.typeAnnotation ?? parameter.left.typeAnnotation;
13
+ }
14
+ return parameter.typeAnnotation;
15
+ }
16
+ /** Ban the broad object type on function inputs, including local aliases to object. */
17
+ export const noObjectParametersRule = defineRule({
18
+ meta: {
19
+ type: "problem",
20
+ docs: {
21
+ description: "Disallow object function parameters; inputs must use an owner-provided type and be parsed at their boundary.",
22
+ },
23
+ messages: {
24
+ objectParameter: "Parameter `{{parameter}}` uses the broad `object` type. Accept a named owner type; parse external input at its boundary before calling this function.",
25
+ },
26
+ },
27
+ createOnce(context) {
28
+ const aliases = new Map();
29
+ const resolvesToObject = (type, shadowedAliases, visited = new Set()) => {
30
+ if (type.type === "TSObjectKeyword")
31
+ return true;
32
+ if (type.type === "TSParenthesizedType")
33
+ return resolvesToObject(type.typeAnnotation, shadowedAliases, visited);
34
+ if (type.type === "TSUnionType") {
35
+ return type.types.some((member) => resolvesToObject(member, shadowedAliases, visited));
36
+ }
37
+ if (type.type !== "TSTypeReference" ||
38
+ type.typeName.type !== "Identifier" ||
39
+ (type.typeArguments !== null &&
40
+ type.typeArguments !== undefined &&
41
+ type.typeArguments.params.length > 0) ||
42
+ visited.has(type.typeName.name) ||
43
+ shadowedAliases.has(type.typeName.name)) {
44
+ return false;
45
+ }
46
+ const alias = aliases.get(type.typeName.name);
47
+ if (alias === undefined)
48
+ return false;
49
+ const nextVisited = new Set(visited);
50
+ nextVisited.add(type.typeName.name);
51
+ return resolvesToObject(alias, shadowedAliases, nextVisited);
52
+ };
53
+ const checkParameters = (node) => {
54
+ const shadowedAliases = lexicalTypeParameterNames(node, ancestorsOf(context.sourceCode, node), context.sourceCode.visitorKeys);
55
+ for (const parameter of node.params) {
56
+ const annotation = parameterAnnotation(parameter);
57
+ if (annotation === null || annotation === undefined)
58
+ continue;
59
+ if (!resolvesToObject(annotation.typeAnnotation, shadowedAliases))
60
+ continue;
61
+ context.report({
62
+ node: annotation.typeAnnotation,
63
+ messageId: "objectParameter",
64
+ data: {
65
+ parameter: parameter.type === "Identifier"
66
+ ? parameter.name
67
+ : context.sourceCode.getText(parameter).replace(/\s*:\s*object\s*$/u, ""),
68
+ },
69
+ });
70
+ }
71
+ };
72
+ return {
73
+ Program(node) {
74
+ aliases.clear();
75
+ for (const statement of node.body) {
76
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
77
+ if (declaration?.type === "TSTypeAliasDeclaration" &&
78
+ (declaration.typeParameters === null || declaration.typeParameters === undefined)) {
79
+ aliases.set(declaration.id.name, declaration.typeAnnotation);
80
+ }
81
+ }
82
+ },
83
+ ArrowFunctionExpression: checkParameters,
84
+ FunctionDeclaration: checkParameters,
85
+ FunctionExpression: checkParameters,
86
+ TSCallSignatureDeclaration: checkParameters,
87
+ TSConstructSignatureDeclaration: checkParameters,
88
+ TSConstructorType: checkParameters,
89
+ TSDeclareFunction: checkParameters,
90
+ TSEmptyBodyFunctionExpression: checkParameters,
91
+ TSFunctionType: checkParameters,
92
+ TSMethodSignature: checkParameters,
93
+ };
94
+ },
95
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Optional parameters hide undefined from the signature; require the union spelled out.
3
+ *
4
+ * Optionality is a grammar-level flag present on every concrete ParamPattern
5
+ * shape, read after unwrapping TypeScript parameter-property wrappers.
6
+ */
7
+ export declare const noOptionalFunctionParametersRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,44 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ const TEST_FILE = /.(?:test|spec).[cm]?[jt]sx?$/u;
3
+ /**
4
+ * Optional parameters hide undefined from the signature; require the union spelled out.
5
+ *
6
+ * Optionality is a grammar-level flag present on every concrete ParamPattern
7
+ * shape, read after unwrapping TypeScript parameter-property wrappers.
8
+ */
9
+ export const noOptionalFunctionParametersRule = defineRule({
10
+ meta: {
11
+ type: "problem",
12
+ docs: {
13
+ description: "Disallow optional function parameters (`param?:`); require an explicit union with undefined so callers see the possibility in the type.",
14
+ },
15
+ messages: {
16
+ optionalParameter: "Optional parameters hide `undefined` from callers. Annotate the parameter as `T | undefined` so the possibility is spelled out in the type.",
17
+ },
18
+ },
19
+ createOnce(context) {
20
+ const check = (node) => {
21
+ if (node.type !== "FunctionDeclaration" &&
22
+ node.type !== "FunctionExpression" &&
23
+ node.type !== "ArrowFunctionExpression")
24
+ return;
25
+ for (const parameter of node.params) {
26
+ let pattern = parameter;
27
+ if (pattern.type === "TSParameterProperty")
28
+ pattern = pattern.parameter;
29
+ if (pattern.optional !== true)
30
+ continue;
31
+ context.report({ node: parameter, messageId: "optionalParameter" });
32
+ }
33
+ };
34
+ return {
35
+ before() {
36
+ if (TEST_FILE.test(context.filename.replaceAll("\\", "/")))
37
+ return false;
38
+ },
39
+ FunctionDeclaration: check,
40
+ FunctionExpression: check,
41
+ ArrowFunctionExpression: check,
42
+ };
43
+ },
44
+ });
@@ -0,0 +1,2 @@
1
+ /** A product of booleans inside a variant tends to admit an illegal combination. */
2
+ export declare const noProductOfStateBooleansRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,79 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { readField } from "../shared/structural.js";
3
+ import { ancestorsOf } from "../shared/ancestors.js";
4
+ function lastTypeNameSegment(typeName) {
5
+ if (typeName.type === "Identifier")
6
+ return typeName.name;
7
+ if (typeName.type === "TSQualifiedName")
8
+ return lastTypeNameSegment(typeName.right);
9
+ return null;
10
+ }
11
+ /**
12
+ * Returns the enclosing TSPropertySignature when the literal is a variant
13
+ * payload of a Data.TaggedEnum (i.e. `{ Variant: Payload }` inside the enum's
14
+ * type argument), otherwise null.
15
+ *
16
+ * @param {ESTree.TSTypeLiteral} node - The visited type literal (candidate payload).
17
+ * @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
18
+ * @returns {ESTree.TSPropertySignature | null} The variant property signature, or null.
19
+ */
20
+ function variantPayloadSignature(node, ancestors) {
21
+ const at = (depth) => ancestors[ancestors.length - 1 - depth];
22
+ const annotation = at(0);
23
+ if (annotation?.type !== "TSTypeAnnotation")
24
+ return null;
25
+ const signature = at(1);
26
+ if (signature?.type !== "TSPropertySignature")
27
+ return null;
28
+ const outer = at(2);
29
+ if (outer?.type !== "TSTypeLiteral")
30
+ return null;
31
+ const args = at(3);
32
+ if (args === undefined)
33
+ return null;
34
+ const reference = at(4);
35
+ if (reference?.type !== "TSTypeReference")
36
+ return null;
37
+ const name = lastTypeNameSegment(reference.typeName);
38
+ return name !== null && /TaggedEnum$/u.test(name) ? signature : null;
39
+ }
40
+ /** A product of booleans inside a variant tends to admit an illegal combination. */
41
+ export const noProductOfStateBooleansRule = defineRule({
42
+ meta: {
43
+ type: "problem",
44
+ docs: {
45
+ description: "Disallow tagged-enum variant payloads with two or more boolean state flags; replace them with a nested tag union so impossible combinations can't be represented.",
46
+ },
47
+ messages: {
48
+ productOfStateBooleans: "Variant payload `{{name}}` carries {{count}} boolean state flags. Replace them with a nested tag union (e.g. Sign) so combinations like {zero, negative} can't be represented.",
49
+ },
50
+ },
51
+ createOnce(context) {
52
+ return {
53
+ TSTypeLiteral(node) {
54
+ const signature = variantPayloadSignature(node, ancestorsOf(context.sourceCode, node));
55
+ if (signature === null)
56
+ return;
57
+ let count = 0;
58
+ for (const member of node.members) {
59
+ if (member.type !== "TSPropertySignature")
60
+ continue;
61
+ const annotation = member.typeAnnotation;
62
+ if (annotation === null || annotation === undefined)
63
+ continue;
64
+ if (annotation.typeAnnotation.type === "TSBooleanKeyword")
65
+ count += 1;
66
+ }
67
+ if (count < 2)
68
+ return;
69
+ const key = signature.key;
70
+ const name = key.type === "Identifier" ? key.name : "variant";
71
+ context.report({
72
+ node,
73
+ messageId: "productOfStateBooleans",
74
+ data: { name, count: String(count) },
75
+ });
76
+ },
77
+ };
78
+ },
79
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * One fact, one place: a type that stores data *and* a field derivable from
3
+ * that data keeps two sources of truth that drift apart independently. Counts
4
+ * belong to read sites; ordering belongs in the structure itself.
5
+ */
6
+ export declare const noRedundantDerivedFieldRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,194 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isRecordObject, isString } from "../shared/structural.js";
3
+ const COUNT_SUFFIX = /(?:Count|Length|Size)$/u;
4
+ const COUNT_PREFIX = /^(?:count|num|numberOf|total)(?=[A-Z])/u;
5
+ const KEYED_COLLECTION_NAMES = new Set(["Array", "Map", "Record", "ReadonlyArray", "ReadonlyMap", "ReadonlySet", "Set"]);
6
+ function lastTypeNameSegment(typeName) {
7
+ if (typeName.type === "Identifier")
8
+ return typeName.name;
9
+ if (typeName.type === "TSQualifiedName")
10
+ return lastTypeNameSegment(typeName.right);
11
+ return null;
12
+ }
13
+ function propertyName(member) {
14
+ if (member.type !== "TSPropertySignature")
15
+ return null;
16
+ const key = member.key;
17
+ return key.type === "Identifier" ? key.name : null;
18
+ }
19
+ function propertyAnnotation(member) {
20
+ if (member.type !== "TSPropertySignature")
21
+ return null;
22
+ return member.typeAnnotation?.typeAnnotation ?? null;
23
+ }
24
+ /** Lowercase, strip separators, and naive-singularise so `seatOrder`/`seats`, `entryIndex`/`entries` stems can be compared.
25
+ *
26
+ * @param {string} name - The field or property name to fold.
27
+ * @returns {string} The comparison stem.
28
+ */
29
+ function normaliseName(name) {
30
+ const folded = name.replaceAll(/[^a-zA-Z0-9]/gu, "").toLowerCase();
31
+ if (folded.endsWith("ies") && folded.length > 4)
32
+ return `${folded.slice(0, -3)}y`;
33
+ return folded.endsWith("s") && folded.length > 3 ? folded.slice(0, -1) : folded;
34
+ }
35
+ /** Extract the `x` from `xCount`, `countX`, `numberOfX`, … otherwise null.
36
+ *
37
+ * @param {string} name - The candidate count-field name.
38
+ * @returns {string | null} The counted stem, or null when the name isn't a count pattern.
39
+ */
40
+ function countStem(name) {
41
+ const suffixMatch = name.match(COUNT_SUFFIX);
42
+ if (suffixMatch !== null && suffixMatch.index !== null)
43
+ return name.slice(0, suffixMatch.index);
44
+ const prefixMatch = name.match(COUNT_PREFIX);
45
+ if (prefixMatch !== null) {
46
+ const stem = name.slice(prefixMatch[0].length);
47
+ return stem.charAt(0).toLowerCase() + stem.slice(1);
48
+ }
49
+ return null;
50
+ }
51
+ /** Whether the annotation is any array/map/set/record shape.
52
+ *
53
+ * @param {ESTree.TSType | null | undefined} annotation - The annotation to inspect.
54
+ * @returns {boolean} True when the annotation denotes a keyed collection.
55
+ */
56
+ function isCollectionLike(annotation) {
57
+ if (annotation === null || annotation === undefined)
58
+ return false;
59
+ if (annotation.type === "TSTypeReference") {
60
+ const name = lastTypeNameSegment(annotation.typeName);
61
+ return name !== null && KEYED_COLLECTION_NAMES.has(name);
62
+ }
63
+ return annotation.type === "TSTypeOperator" && annotation.operator === "readonly"
64
+ ? isCollectionLike(annotation.typeAnnotation)
65
+ : annotation.type === "TSArrayType";
66
+ }
67
+ /** Whether the annotation is an array (or readonly array reference) whose element is a primitive keyword.
68
+ *
69
+ * @param {ESTree.TSType | null | undefined} annotation - The annotation to inspect.
70
+ * @returns {"string" | "number" | null} The primitive keyword of the element type, or null.
71
+ */
72
+ function arrayOfPrimitiveKeys(annotation) {
73
+ if (annotation === null || annotation === undefined)
74
+ return null;
75
+ let elementType;
76
+ if (annotation.type === "TSArrayType") {
77
+ elementType = annotation.elementType;
78
+ }
79
+ else if (annotation.type === "TSTypeOperator" &&
80
+ annotation.operator === "readonly" &&
81
+ annotation.typeAnnotation.type === "TSArrayType") {
82
+ elementType = annotation.typeAnnotation.elementType;
83
+ }
84
+ else if (annotation.type === "TSTypeReference" &&
85
+ annotation.typeArguments != null &&
86
+ annotation.typeArguments.params.length === 1) {
87
+ const name = lastTypeNameSegment(annotation.typeName);
88
+ if (name === "Array" || name === "ReadonlyArray")
89
+ elementType = annotation.typeArguments.params[0];
90
+ }
91
+ if (elementType === undefined)
92
+ return null;
93
+ if (elementType.type === "TSStringKeyword")
94
+ return "string";
95
+ if (elementType.type === "TSNumberKeyword")
96
+ return "number";
97
+ return null;
98
+ }
99
+ /** First type argument's primitive keyword for a keyed collection like `Record<string, T>` / `Map<string, T>`.
100
+ *
101
+ * @param {ESTree.TSType | null | undefined} annotation - The annotation to inspect.
102
+ * @returns {"string" | "number" | null} The key keyword, or null when not a keyed reference.
103
+ */
104
+ function keyKeywordOf(annotation) {
105
+ if (annotation?.type !== "TSTypeReference")
106
+ return null;
107
+ const first = annotation.typeArguments?.params[0] ?? null;
108
+ if (first === null || first === undefined)
109
+ return null;
110
+ if (first.type === "TSStringKeyword")
111
+ return "string";
112
+ if (first.type === "TSNumberKeyword")
113
+ return "number";
114
+ return null;
115
+ }
116
+ /**
117
+ * One fact, one place: a type that stores data *and* a field derivable from
118
+ * that data keeps two sources of truth that drift apart independently. Counts
119
+ * belong to read sites; ordering belongs in the structure itself.
120
+ */
121
+ export const noRedundantDerivedFieldRule = defineRule({
122
+ meta: {
123
+ type: "suggestion",
124
+ docs: {
125
+ description: "Disallow fields that duplicate information derivable from a sibling field on the same type (derived counts, parallel key/order arrays); compute or encode them instead.",
126
+ },
127
+ messages: {
128
+ redundantCount: "`{{name}}` restates what is derivable from `{{sibling}}`, giving the type two sources of truth that can drift. Drop it and compute the count at read time.",
129
+ parallelKeyArray: "`{{name}}` mirrors the keys of `{{sibling}}` as a second source of truth that can drift. Encode the canonical form (e.g. ordering) in the collection itself instead of a parallel array.",
130
+ },
131
+ },
132
+ createOnce(context) {
133
+ function checkMembers(members) {
134
+ for (const member of members) {
135
+ const name = propertyName(member);
136
+ if (name === null)
137
+ continue;
138
+ const annotation = propertyAnnotation(member);
139
+ const stem = countStem(name);
140
+ if (stem !== null && annotation?.type === "TSNumberKeyword") {
141
+ const stemNorm = normaliseName(stem);
142
+ const sibling = members.find((other) => {
143
+ if (other === member)
144
+ return false;
145
+ const otherName = propertyName(other);
146
+ return otherName !== null && normaliseName(otherName) === stemNorm && isCollectionLike(propertyAnnotation(other));
147
+ });
148
+ if (sibling !== undefined) {
149
+ context.report({
150
+ node: member,
151
+ messageId: "redundantCount",
152
+ data: { name, sibling: propertyName(sibling) ?? "" },
153
+ });
154
+ continue;
155
+ }
156
+ }
157
+ const elementKey = arrayOfPrimitiveKeys(annotation);
158
+ if (elementKey === null)
159
+ continue;
160
+ const nameNorm = normaliseName(name);
161
+ const sibling = members.find((other) => {
162
+ if (other === member)
163
+ return false;
164
+ const otherName = propertyName(other);
165
+ if (otherName === null)
166
+ return false;
167
+ if (keyKeywordOf(propertyAnnotation(other)) !== elementKey)
168
+ return false;
169
+ const otherNorm = normaliseName(otherName);
170
+ return otherNorm.includes(nameNorm) || nameNorm.includes(otherNorm);
171
+ });
172
+ if (sibling !== undefined) {
173
+ context.report({
174
+ node: member,
175
+ messageId: "parallelKeyArray",
176
+ data: { name, sibling: propertyName(sibling) ?? "" },
177
+ });
178
+ }
179
+ }
180
+ }
181
+ function memberList(bodyNode) {
182
+ return [...bodyNode.body];
183
+ }
184
+ return {
185
+ TSInterfaceDeclaration(node) {
186
+ checkMembers(memberList(node.body));
187
+ },
188
+ TSTypeAliasDeclaration(node) {
189
+ if (node.typeAnnotation.type === "TSTypeLiteral")
190
+ checkMembers(node.typeAnnotation.members);
191
+ },
192
+ };
193
+ },
194
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban Reflect.apply, which bypasses ordinary typed function calls. */
2
+ export declare const noReflectApplyRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,29 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isGlobalReflectMethodCall } from "../shared/reflect-method.js";
3
+ /** Ban Reflect.apply, which bypasses ordinary typed function calls. */
4
+ export const noReflectApplyRule = defineRule({
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallow Reflect.apply; call typed functions directly or model dynamic dispatch behind an interface.",
9
+ },
10
+ messages: {
11
+ reflectApply: "Replace `Reflect.apply` with a typed function call. Model dynamic dispatch behind a named interface.",
12
+ },
13
+ },
14
+ createOnce(context) {
15
+ return {
16
+ CallExpression(node) {
17
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
18
+ return;
19
+ if (isGlobalReflectMethodCall({
20
+ sourceCode: context.sourceCode,
21
+ callee: node.callee,
22
+ methodName: "apply",
23
+ })) {
24
+ context.report({ node, messageId: "reflectApply" });
25
+ }
26
+ },
27
+ };
28
+ },
29
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban Reflect.get, which bypasses ordinary property access and useful type evidence. */
2
+ export declare const noReflectGetRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,29 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { isGlobalReflectMethodCall } from "../shared/reflect-method.js";
3
+ /** Ban Reflect.get, which bypasses ordinary property access and useful type evidence. */
4
+ export const noReflectGetRule = defineRule({
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallow Reflect.get; use typed property access or parse dynamic input into a domain type.",
9
+ },
10
+ messages: {
11
+ reflectGet: "Replace `Reflect.get` with typed property access. Parse dynamic input into a named domain type before reading it.",
12
+ },
13
+ },
14
+ createOnce(context) {
15
+ return {
16
+ CallExpression(node) {
17
+ if (node.callee.type === "Super" || node.callee.type === "V8IntrinsicExpression")
18
+ return;
19
+ if (isGlobalReflectMethodCall({
20
+ sourceCode: context.sourceCode,
21
+ callee: node.callee,
22
+ methodName: "get",
23
+ })) {
24
+ context.report({ node, messageId: "reflectGet" });
25
+ }
26
+ },
27
+ };
28
+ },
29
+ });
@@ -0,0 +1,2 @@
1
+ /** Type assertions erase evidence; `as const` is exempt and `// SAFETY:` documents rare verified invariants. */
2
+ export declare const noReinterpretCastRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,68 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ /** Whether a function-like body consists solely of returning an as-cast.
3
+ *
4
+ * @param {ESTree.Node | null | undefined} body - The function body to inspect.
5
+ * @returns {boolean} True when the body only returns an as-cast expression.
6
+ */
7
+ function isSoleReturnOfAssertion(body) {
8
+ if (body === null || body === undefined)
9
+ return false;
10
+ if (body.type === "BlockStatement") {
11
+ if (body.body.length !== 1)
12
+ return false;
13
+ const only = body.body[0];
14
+ return only?.type === "ReturnStatement" && only.argument?.type === "TSAsExpression";
15
+ }
16
+ return body.type === "TSAsExpression";
17
+ }
18
+ /** Whether the assertion node has an adjacent `// SAFETY:` justification.
19
+ *
20
+ * @param {{ getCommentsBefore(n: ESTree.Node): Array<CommentLike> }} sourceCode - The rule's source-code accessor.
21
+ * @param {ESTree.Node} node - The assertion node.
22
+ * @returns {boolean} True when a SAFETY comment precedes the assertion.
23
+ */
24
+ function hasAdjacentSafetyComment(sourceCode, node) {
25
+ return sourceCode.getCommentsBefore(node).some((comment) => /\bSAFETY\s*:/u.test(comment.value));
26
+ }
27
+ /** Type assertions erase evidence; `as const` is exempt and `// SAFETY:` documents rare verified invariants. */
28
+ export const noReinterpretCastRule = defineRule({
29
+ meta: {
30
+ type: "problem",
31
+ docs: {
32
+ description: "Disallow type reinterpretation via `as`; absence must be modeled by the type system, with SAFETY-commented exceptions.",
33
+ },
34
+ messages: {
35
+ noReinterpret: "Type assertion discards type evidence. Narrow with discriminants/`in` checks or a type predicate instead.",
36
+ noLaundering: "`{{name}}` exists only to perform a type assertion: a laundering wrapper that hides the cast from review and tooling.",
37
+ },
38
+ },
39
+ createOnce(context) {
40
+ return {
41
+ TSAsExpression(node) {
42
+ const annotation = node.typeAnnotation;
43
+ if (annotation.type === "TSTypeReference" &&
44
+ annotation.typeName.type === "Identifier" &&
45
+ annotation.typeName.name === "const")
46
+ return;
47
+ if (hasAdjacentSafetyComment(context.sourceCode, node))
48
+ return;
49
+ context.report({ node, messageId: "noReinterpret" });
50
+ },
51
+ TSTypeAssertion(node) {
52
+ if (hasAdjacentSafetyComment(context.sourceCode, node))
53
+ return;
54
+ context.report({ node, messageId: "noReinterpret" });
55
+ },
56
+ FunctionDeclaration(node) {
57
+ if (node.body !== null && isSoleReturnOfAssertion(node.body)) {
58
+ context.report({ node, messageId: "noLaundering", data: { name: node.id?.name ?? "<anonymous>" } });
59
+ }
60
+ },
61
+ ArrowFunctionExpression(node) {
62
+ if (node.body.type === "TSAsExpression") {
63
+ context.report({ node, messageId: "noLaundering", data: { name: "<arrow>" } });
64
+ }
65
+ },
66
+ };
67
+ },
68
+ });
@@ -0,0 +1,2 @@
1
+ /** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
2
+ export declare const noRuntimeTypeofRule: import("@oxlint/plugins").Rule;
@@ -0,0 +1,54 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { readField } from "../shared/structural.js";
3
+ import { ancestorsOf } from "../shared/ancestors.js";
4
+ import { firstOptionRecord } from "../shared/rule-options.js";
5
+ /** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
6
+ export const noRuntimeTypeofRule = defineRule({
7
+ meta: {
8
+ type: "problem",
9
+ docs: {
10
+ description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary.",
11
+ },
12
+ messages: {
13
+ runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
14
+ },
15
+ schema: [
16
+ {
17
+ type: "object",
18
+ properties: {
19
+ allowInTypeGuards: { type: "boolean" },
20
+ },
21
+ additionalProperties: false,
22
+ },
23
+ ],
24
+ defaultOptions: [{ allowInTypeGuards: false }],
25
+ },
26
+ createOnce(context) {
27
+ return {
28
+ UnaryExpression(node) {
29
+ if (node.operator !== "typeof")
30
+ return;
31
+ const option = firstOptionRecord(context.options);
32
+ const allowInTypeGuards = option.allowInTypeGuards === true;
33
+ let insideTypeGuard = false;
34
+ if (allowInTypeGuards) {
35
+ const ancestors = ancestorsOf(context.sourceCode, node);
36
+ for (let index = ancestors.length - 1; index >= 0; index--) {
37
+ const current = ancestors[index];
38
+ if (current.type === "Program")
39
+ break;
40
+ if (current.type === "ArrowFunctionExpression" ||
41
+ current.type === "FunctionDeclaration" ||
42
+ current.type === "FunctionExpression") {
43
+ insideTypeGuard =
44
+ current.returnType?.typeAnnotation.type === "TSTypePredicate";
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ if (!insideTypeGuard)
50
+ context.report({ node, messageId: "runtimeTypeof" });
51
+ },
52
+ };
53
+ },
54
+ });
@@ -0,0 +1,2 @@
1
+ /** Ban hand-built -1/0/1 comparison results; ordering must go through a named order. */
2
+ export declare const noSentinelComparisonUnionRule: import("@oxlint/plugins").Rule;