@autotelic/plumb 0.6.1 → 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 (209) hide show
  1. package/package.json +18 -18
  2. package/dist/src/configs/recommended-rules.d.ts +0 -20
  3. package/dist/src/configs/recommended-rules.js +0 -22
  4. package/dist/src/effect/index.d.ts +0 -3
  5. package/dist/src/effect/index.js +0 -60
  6. package/dist/src/effect/rules/guarded-op-must-return-effect.d.ts +0 -6
  7. package/dist/src/effect/rules/guarded-op-must-return-effect.js +0 -235
  8. package/dist/src/effect/rules/guarded-op-must-return-option.d.ts +0 -2
  9. package/dist/src/effect/rules/guarded-op-must-return-option.js +0 -88
  10. package/dist/src/effect/rules/no-cascading-layer-provide.d.ts +0 -6
  11. package/dist/src/effect/rules/no-cascading-layer-provide.js +0 -73
  12. package/dist/src/effect/rules/no-decode-unknown-option.d.ts +0 -7
  13. package/dist/src/effect/rules/no-decode-unknown-option.js +0 -34
  14. package/dist/src/effect/rules/no-direct-browser-storage.d.ts +0 -2
  15. package/dist/src/effect/rules/no-direct-browser-storage.js +0 -88
  16. package/dist/src/effect/rules/no-direct-fetch.d.ts +0 -2
  17. package/dist/src/effect/rules/no-direct-fetch.js +0 -37
  18. package/dist/src/effect/rules/no-manual-field-guards.d.ts +0 -6
  19. package/dist/src/effect/rules/no-manual-field-guards.js +0 -129
  20. package/dist/src/effect/rules/no-nested-layer-provide.d.ts +0 -2
  21. package/dist/src/effect/rules/no-nested-layer-provide.js +0 -50
  22. package/dist/src/effect/rules/no-nullish-default-on-partial-input.d.ts +0 -13
  23. package/dist/src/effect/rules/no-nullish-default-on-partial-input.js +0 -109
  24. package/dist/src/effect/rules/no-raw-error-forwarding.d.ts +0 -12
  25. package/dist/src/effect/rules/no-raw-error-forwarding.js +0 -103
  26. package/dist/src/effect/rules/no-schema-class-modeling.d.ts +0 -2
  27. package/dist/src/effect/rules/no-schema-class-modeling.js +0 -52
  28. package/dist/src/effect/rules/no-service-constructor-imports.d.ts +0 -2
  29. package/dist/src/effect/rules/no-service-constructor-imports.js +0 -42
  30. package/dist/src/effect/rules/no-silent-error-swallow.d.ts +0 -2
  31. package/dist/src/effect/rules/no-silent-error-swallow.js +0 -95
  32. package/dist/src/effect/rules/no-static-effect-service-forwarders.d.ts +0 -6
  33. package/dist/src/effect/rules/no-static-effect-service-forwarders.js +0 -222
  34. package/dist/src/effect/rules/no-try-catch.d.ts +0 -2
  35. package/dist/src/effect/rules/no-try-catch.js +0 -30
  36. package/dist/src/effect/rules/no-unguarded-json-parse.d.ts +0 -5
  37. package/dist/src/effect/rules/no-unguarded-json-parse.js +0 -200
  38. package/dist/src/effect/rules/option-core-needs-effect-public.d.ts +0 -5
  39. package/dist/src/effect/rules/option-core-needs-effect-public.js +0 -76
  40. package/dist/src/effect/rules/prefer-die-for-precondition-defects.d.ts +0 -5
  41. package/dist/src/effect/rules/prefer-die-for-precondition-defects.js +0 -112
  42. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +0 -5
  43. package/dist/src/effect/rules/prefer-effect-gen-for-guard-ladders.js +0 -72
  44. package/dist/src/effect/rules/prefer-effect-match.d.ts +0 -2
  45. package/dist/src/effect/rules/prefer-effect-match.js +0 -74
  46. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +0 -2
  47. package/dist/src/effect/rules/prefer-effect-predicate-over-boolean-function.js +0 -75
  48. package/dist/src/effect/rules/prefer-named-guard-predicate.d.ts +0 -2
  49. package/dist/src/effect/rules/prefer-named-guard-predicate.js +0 -93
  50. package/dist/src/effect/rules/prefer-option-pipeline.d.ts +0 -2
  51. package/dist/src/effect/rules/prefer-option-pipeline.js +0 -87
  52. package/dist/src/effect/rules/prefer-ordering-match.d.ts +0 -2
  53. package/dist/src/effect/rules/prefer-ordering-match.js +0 -135
  54. package/dist/src/effect/rules/prefer-tagged-enum.d.ts +0 -2
  55. package/dist/src/effect/rules/prefer-tagged-enum.js +0 -66
  56. package/dist/src/effect/rules/require-schema-type-derivation.d.ts +0 -7
  57. package/dist/src/effect/rules/require-schema-type-derivation.js +0 -80
  58. package/dist/src/index.d.ts +0 -3
  59. package/dist/src/index.js +0 -106
  60. package/dist/src/meta/index.d.ts +0 -7
  61. package/dist/src/meta/index.js +0 -22
  62. package/dist/src/meta/rules/no-disable-directives.d.ts +0 -6
  63. package/dist/src/meta/rules/no-disable-directives.js +0 -35
  64. package/dist/src/meta/rules/no-manual-ancestor-walks.d.ts +0 -2
  65. package/dist/src/meta/rules/no-manual-ancestor-walks.js +0 -26
  66. package/dist/src/meta/rules/prefer-before-file-scope.d.ts +0 -2
  67. package/dist/src/meta/rules/prefer-before-file-scope.js +0 -57
  68. package/dist/src/meta/rules/require-create-once.d.ts +0 -2
  69. package/dist/src/meta/rules/require-create-once.js +0 -51
  70. package/dist/src/meta/rules/require-rule-tester.d.ts +0 -2
  71. package/dist/src/meta/rules/require-rule-tester.js +0 -50
  72. package/dist/src/react/index.d.ts +0 -3
  73. package/dist/src/react/index.js +0 -16
  74. package/dist/src/react/role.d.ts +0 -23
  75. package/dist/src/react/role.js +0 -30
  76. package/dist/src/react/rules/require-dot-notation-exports.d.ts +0 -27
  77. package/dist/src/react/rules/require-dot-notation-exports.js +0 -144
  78. package/dist/src/react/rules/require-guarded-context-hook.d.ts +0 -19
  79. package/dist/src/react/rules/require-guarded-context-hook.js +0 -167
  80. package/dist/src/react/rules/require-tripartite-context.d.ts +0 -17
  81. package/dist/src/react/rules/require-tripartite-context.js +0 -160
  82. package/dist/src/react/rules/use-encapsulation.d.ts +0 -22
  83. package/dist/src/react/rules/use-encapsulation.js +0 -97
  84. package/dist/src/rules/no-anonymous-wide-tuples.d.ts +0 -7
  85. package/dist/src/rules/no-anonymous-wide-tuples.js +0 -34
  86. package/dist/src/rules/no-barrel-export-star.d.ts +0 -2
  87. package/dist/src/rules/no-barrel-export-star.js +0 -26
  88. package/dist/src/rules/no-boolean-field-signals.d.ts +0 -2
  89. package/dist/src/rules/no-boolean-field-signals.js +0 -279
  90. package/dist/src/rules/no-builtin-throws.d.ts +0 -6
  91. package/dist/src/rules/no-builtin-throws.js +0 -74
  92. package/dist/src/rules/no-chained-type-assertions.d.ts +0 -2
  93. package/dist/src/rules/no-chained-type-assertions.js +0 -54
  94. package/dist/src/rules/no-conditional-empty-object-spread.d.ts +0 -2
  95. package/dist/src/rules/no-conditional-empty-object-spread.js +0 -36
  96. package/dist/src/rules/no-duplicated-literal-union.d.ts +0 -6
  97. package/dist/src/rules/no-duplicated-literal-union.js +0 -66
  98. package/dist/src/rules/no-exported-mutable-state.d.ts +0 -7
  99. package/dist/src/rules/no-exported-mutable-state.js +0 -104
  100. package/dist/src/rules/no-generic-export-names.d.ts +0 -2
  101. package/dist/src/rules/no-generic-export-names.js +0 -141
  102. package/dist/src/rules/no-impossible-branch-throw.d.ts +0 -2
  103. package/dist/src/rules/no-impossible-branch-throw.js +0 -51
  104. package/dist/src/rules/no-known-value-widening.d.ts +0 -2
  105. package/dist/src/rules/no-known-value-widening.js +0 -176
  106. package/dist/src/rules/no-module-mocking.d.ts +0 -2
  107. package/dist/src/rules/no-module-mocking.js +0 -90
  108. package/dist/src/rules/no-multiple-function-params.d.ts +0 -2
  109. package/dist/src/rules/no-multiple-function-params.js +0 -155
  110. package/dist/src/rules/no-mutable-environment-capture.d.ts +0 -7
  111. package/dist/src/rules/no-mutable-environment-capture.js +0 -134
  112. package/dist/src/rules/no-nondeterministic-core.d.ts +0 -6
  113. package/dist/src/rules/no-nondeterministic-core.js +0 -63
  114. package/dist/src/rules/no-object-parameters.d.ts +0 -2
  115. package/dist/src/rules/no-object-parameters.js +0 -95
  116. package/dist/src/rules/no-optional-function-parameters.d.ts +0 -7
  117. package/dist/src/rules/no-optional-function-parameters.js +0 -44
  118. package/dist/src/rules/no-product-of-state-booleans.d.ts +0 -2
  119. package/dist/src/rules/no-product-of-state-booleans.js +0 -79
  120. package/dist/src/rules/no-redundant-derived-field.d.ts +0 -6
  121. package/dist/src/rules/no-redundant-derived-field.js +0 -194
  122. package/dist/src/rules/no-reflect-apply.d.ts +0 -2
  123. package/dist/src/rules/no-reflect-apply.js +0 -29
  124. package/dist/src/rules/no-reflect-get.d.ts +0 -2
  125. package/dist/src/rules/no-reflect-get.js +0 -29
  126. package/dist/src/rules/no-reinterpret-cast.d.ts +0 -2
  127. package/dist/src/rules/no-reinterpret-cast.js +0 -68
  128. package/dist/src/rules/no-runtime-typeof.d.ts +0 -2
  129. package/dist/src/rules/no-runtime-typeof.js +0 -54
  130. package/dist/src/rules/no-sentinel-comparison-union.d.ts +0 -2
  131. package/dist/src/rules/no-sentinel-comparison-union.js +0 -139
  132. package/dist/src/rules/no-shape-in-symbol-names.d.ts +0 -2
  133. package/dist/src/rules/no-shape-in-symbol-names.js +0 -39
  134. package/dist/src/rules/no-single-use-private-functions.d.ts +0 -17
  135. package/dist/src/rules/no-single-use-private-functions.js +0 -419
  136. package/dist/src/rules/no-sql-string-interpolation.d.ts +0 -7
  137. package/dist/src/rules/no-sql-string-interpolation.js +0 -62
  138. package/dist/src/rules/no-stacked-jsdoc-blocks.d.ts +0 -2
  139. package/dist/src/rules/no-stacked-jsdoc-blocks.js +0 -50
  140. package/dist/src/rules/no-stray-inline-comments.d.ts +0 -2
  141. package/dist/src/rules/no-stray-inline-comments.js +0 -74
  142. package/dist/src/rules/no-swappable-primitive-params.d.ts +0 -2
  143. package/dist/src/rules/no-swappable-primitive-params.js +0 -96
  144. package/dist/src/rules/no-tag-ladder-assertions.d.ts +0 -6
  145. package/dist/src/rules/no-tag-ladder-assertions.js +0 -63
  146. package/dist/src/rules/no-transposed-field-reads.d.ts +0 -8
  147. package/dist/src/rules/no-transposed-field-reads.js +0 -101
  148. package/dist/src/rules/no-unit-return-validators.d.ts +0 -2
  149. package/dist/src/rules/no-unit-return-validators.js +0 -64
  150. package/dist/src/rules/no-unknown-parameters.d.ts +0 -2
  151. package/dist/src/rules/no-unknown-parameters.js +0 -82
  152. package/dist/src/rules/no-unknown-returns.d.ts +0 -2
  153. package/dist/src/rules/no-unknown-returns.js +0 -86
  154. package/dist/src/rules/no-unknown-type-aliases.d.ts +0 -2
  155. package/dist/src/rules/no-unknown-type-aliases.js +0 -64
  156. package/dist/src/rules/no-unsafe-dictionary-type.d.ts +0 -2
  157. package/dist/src/rules/no-unsafe-dictionary-type.js +0 -116
  158. package/dist/src/rules/no-vague-test-filenames.d.ts +0 -2
  159. package/dist/src/rules/no-vague-test-filenames.js +0 -61
  160. package/dist/src/rules/no-widen-then-assert.d.ts +0 -2
  161. package/dist/src/rules/no-widen-then-assert.js +0 -268
  162. package/dist/src/rules/prefer-payload-brand.d.ts +0 -2
  163. package/dist/src/rules/prefer-payload-brand.js +0 -57
  164. package/dist/src/rules/prefer-property-tests.d.ts +0 -5
  165. package/dist/src/rules/prefer-property-tests.js +0 -39
  166. package/dist/src/rules/require-canonical-stringify-for-identity.d.ts +0 -8
  167. package/dist/src/rules/require-canonical-stringify-for-identity.js +0 -72
  168. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.d.ts +0 -2
  169. package/dist/src/rules/require-deprecated-tag-for-legacy-comments.js +0 -34
  170. package/dist/src/rules/require-exhaustive-tag-switch.d.ts +0 -7
  171. package/dist/src/rules/require-exhaustive-tag-switch.js +0 -34
  172. package/dist/src/rules/require-fc-block-predicate.d.ts +0 -2
  173. package/dist/src/rules/require-fc-block-predicate.js +0 -37
  174. package/dist/src/rules/require-jsdoc-on-exported.d.ts +0 -2
  175. package/dist/src/rules/require-jsdoc-on-exported.js +0 -66
  176. package/dist/src/rules/require-published-order.d.ts +0 -2
  177. package/dist/src/rules/require-published-order.js +0 -102
  178. package/dist/src/rules/require-safety-comment-for-type-assertion.d.ts +0 -2
  179. package/dist/src/rules/require-safety-comment-for-type-assertion.js +0 -53
  180. package/dist/src/rules/require-sort-comparator.d.ts +0 -7
  181. package/dist/src/rules/require-sort-comparator.js +0 -34
  182. package/dist/src/rules/test-utils.d.ts +0 -35
  183. package/dist/src/rules/test-utils.js +0 -53
  184. package/dist/src/shared/ancestors.d.ts +0 -18
  185. package/dist/src/shared/ancestors.js +0 -19
  186. package/dist/src/shared/child-nodes.d.ts +0 -12
  187. package/dist/src/shared/child-nodes.js +0 -26
  188. package/dist/src/shared/dictionary-types.d.ts +0 -55
  189. package/dist/src/shared/dictionary-types.js +0 -413
  190. package/dist/src/shared/is-node.d.ts +0 -9
  191. package/dist/src/shared/is-node.js +0 -10
  192. package/dist/src/shared/lexical-type-parameters.d.ts +0 -12
  193. package/dist/src/shared/lexical-type-parameters.js +0 -50
  194. package/dist/src/shared/reflect-method.d.ts +0 -15
  195. package/dist/src/shared/reflect-method.js +0 -32
  196. package/dist/src/shared/rule-options.d.ts +0 -18
  197. package/dist/src/shared/rule-options.js +0 -12
  198. package/dist/src/shared/structural.d.ts +0 -54
  199. package/dist/src/shared/structural.js +0 -40
  200. package/dist/src/testing/index.d.ts +0 -2
  201. package/dist/src/testing/index.js +0 -1
  202. package/dist/src/testing/testable-rule.d.ts +0 -39
  203. package/dist/src/testing/testable-rule.js +0 -84
  204. package/dist/src/ui/index.d.ts +0 -12
  205. package/dist/src/ui/index.js +0 -18
  206. package/dist/src/ui/manifest.d.ts +0 -34
  207. package/dist/src/ui/manifest.js +0 -75
  208. package/dist/src/ui/rules/no-deprecated-parts.d.ts +0 -3
  209. package/dist/src/ui/rules/no-deprecated-parts.js +0 -131
@@ -1,116 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { classifyUnsafeDictionary, classifyUnsafeDictionaryValue, createTypeEnvironment, } from "../shared/dictionary-types.js";
3
- import { ancestorsOf } from "../shared/ancestors.js";
4
- const typeNodeKinds = new Set([
5
- "JSDocNonNullableType",
6
- "JSDocNullableType",
7
- "JSDocUnknownType",
8
- "TSAnyKeyword",
9
- "TSArrayType",
10
- "TSBigIntKeyword",
11
- "TSBooleanKeyword",
12
- "TSConditionalType",
13
- "TSConstructorType",
14
- "TSFunctionType",
15
- "TSImportType",
16
- "TSIndexedAccessType",
17
- "TSInferType",
18
- "TSIntersectionType",
19
- "TSIntrinsicKeyword",
20
- "TSLiteralType",
21
- "TSMappedType",
22
- "TSNamedTupleMember",
23
- "TSNeverKeyword",
24
- "TSNullKeyword",
25
- "TSNumberKeyword",
26
- "TSObjectKeyword",
27
- "TSParenthesizedType",
28
- "TSStringKeyword",
29
- "TSSymbolKeyword",
30
- "TSTemplateLiteralType",
31
- "TSThisType",
32
- "TSTupleType",
33
- "TSTypeLiteral",
34
- "TSTypeOperator",
35
- "TSTypePredicate",
36
- "TSTypeQuery",
37
- "TSTypeReference",
38
- "TSUndefinedKeyword",
39
- "TSUnionType",
40
- "TSUnknownKeyword",
41
- "TSVoidKeyword",
42
- ]);
43
- /**
44
- * Whether a node is one of the grammar's type-node kinds.
45
- *
46
- * @param {ESTree.Node} node - The ancestor node to test.
47
- * @returns {boolean} True when the node is a type node.
48
- */
49
- function isTypeNode(node) {
50
- return typeNodeKinds.has(node.type);
51
- }
52
- /** Disallow object-dictionary contracts whose direct value type is an unsafe escape hatch. */
53
- export const noUnsafeDictionaryTypeRule = defineRule({
54
- meta: {
55
- type: "problem",
56
- docs: {
57
- description: "Disallow object-dictionary contracts whose direct value type is unknown, any, object, {}, or a union/alias containing one of those escape hatches.",
58
- },
59
- messages: {
60
- unsafeDictionary: "This dictionary's {{value}} value type gives callers no concrete value contract. Use an owner/schema-derived value type; parse external payloads before insertion.",
61
- },
62
- },
63
- createOnce(context) {
64
- let environment = null;
65
- const report = (node, value) => {
66
- context.report({ node, messageId: "unsafeDictionary", data: { value } });
67
- };
68
- const reportIfUnsafe = (node) => {
69
- if (environment === null)
70
- return;
71
- if (node.type === "TSTypeReference" && !node.typeArguments?.params.length) {
72
- const aliasName = node.typeName.type === "Identifier" ? node.typeName.name : null;
73
- if (aliasName !== null && environment.aliases.has(aliasName)) {
74
- let insideAliasDeclaration = false;
75
- for (const current of ancestorsOf(context.sourceCode, node)) {
76
- if (current.type === "Program")
77
- break;
78
- if (current.type === "TSTypeAliasDeclaration") {
79
- insideAliasDeclaration = true;
80
- break;
81
- }
82
- }
83
- if (!insideAliasDeclaration)
84
- return;
85
- }
86
- }
87
- const unsafe = classifyUnsafeDictionary(node, environment);
88
- if (unsafe === null)
89
- return;
90
- for (const current of ancestorsOf(context.sourceCode, node)) {
91
- if (current.type === "Program")
92
- break;
93
- if (isTypeNode(current) && classifyUnsafeDictionary(current, environment) !== null)
94
- return;
95
- }
96
- report(node, unsafe.unsafeValue);
97
- };
98
- return {
99
- Program(node) {
100
- environment = createTypeEnvironment(node);
101
- },
102
- TSTypeReference: reportIfUnsafe,
103
- TSTypeLiteral: reportIfUnsafe,
104
- TSMappedType: reportIfUnsafe,
105
- TSIndexSignature(node) {
106
- if (environment === null ||
107
- node.typeAnnotation === null ||
108
- ancestorsOf(context.sourceCode, node).at(-1)?.type === "TSTypeLiteral")
109
- return;
110
- const unsafe = classifyUnsafeDictionaryValue(node.typeAnnotation.typeAnnotation, environment);
111
- if (unsafe !== null)
112
- report(node, unsafe.unsafeValue);
113
- },
114
- };
115
- },
116
- });
@@ -1,2 +0,0 @@
1
- /** Name test files after the source they cover so agents can navigate both directions. */
2
- export declare const noVagueTestFilenamesRule: import("@oxlint/plugins").Rule;
@@ -1,61 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
- /** Stems that name nothing; a test file must point back at the module it covers. */
4
- const VAGUE_STEMS = new Set([
5
- "index",
6
- "test",
7
- "tests",
8
- "spec",
9
- "util",
10
- "utils",
11
- "helper",
12
- "helpers",
13
- "misc",
14
- "common",
15
- "shared",
16
- "core",
17
- "base",
18
- "main",
19
- "lib",
20
- ]);
21
- /** Strip the directory and extension from a test filename.
22
- *
23
- * @param {string} filename - The raw filename to process.
24
- * @returns {string} The bare stem without path or extension. */
25
- function testFileStem(filename) {
26
- const segments = filename.replaceAll("\\", "/").split("/");
27
- const base = segments[segments.length - 1] ?? "";
28
- return base.replace(/\.[cm]?[jt]sx?$/u, "").replace(/\.(?:test|spec)$/u, "");
29
- }
30
- /** Name test files after the source they cover so agents can navigate both directions. */
31
- export const noVagueTestFilenamesRule = defineRule({
32
- meta: {
33
- type: "problem",
34
- docs: {
35
- description: "Disallow vague test file names (index.test.ts, utils.test.ts, ...) because tests are found by searching for the source module's name; a test file that does not name the code it covers costs extra agent turns to locate.",
36
- },
37
- messages: {
38
- vagueTestFilename: "Test file `{{stem}}.test.ts` does not name the source it covers. Rename it after the module under test (e.g. `stripe.ts` -> `stripe.test.ts`) so searches for the source name land on its tests too.",
39
- },
40
- },
41
- createOnce(context) {
42
- let filePath = "";
43
- return {
44
- before() {
45
- filePath = context.filename.replaceAll("\\", "/");
46
- },
47
- Program(node) {
48
- if (!TEST_FILE.test(filePath))
49
- return;
50
- const stem = testFileStem(filePath);
51
- if (!VAGUE_STEMS.has(stem.toLowerCase()))
52
- return;
53
- context.report({
54
- node,
55
- messageId: "vagueTestFilename",
56
- data: { stem },
57
- });
58
- },
59
- };
60
- },
61
- });
@@ -1,2 +0,0 @@
1
- /** Detect immutable local bindings that erase a known type and are later asserted back to a narrower type. */
2
- export declare const noWidenThenAssertRule: import("@oxlint/plugins").Rule;
@@ -1,268 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { ancestorsOf } from "../shared/ancestors.js";
3
- const functionBoundaryTypes = new Set([
4
- "ArrowFunctionExpression",
5
- "FunctionDeclaration",
6
- "FunctionExpression",
7
- "TSDeclareFunction",
8
- "TSEmptyBodyFunctionExpression",
9
- ]);
10
- function unwrapExpressionParentheses(expression) {
11
- let current = expression;
12
- while (current.type === "ParenthesizedExpression")
13
- current = current.expression;
14
- return current;
15
- }
16
- function unwrapTypeParentheses(type) {
17
- let current = type;
18
- while (current.type === "TSParenthesizedType")
19
- current = current.typeAnnotation;
20
- return current;
21
- }
22
- function typeReferenceName(type) {
23
- return type.typeName.type === "Identifier" ? type.typeName.name : null;
24
- }
25
- function isUnknownOrAnyType(type) {
26
- const unwrapped = unwrapTypeParentheses(type);
27
- return unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword";
28
- }
29
- function isBroadRecordKeyType(type) {
30
- const unwrapped = unwrapTypeParentheses(type);
31
- if (unwrapped.type === "TSStringKeyword" ||
32
- unwrapped.type === "TSNumberKeyword" ||
33
- unwrapped.type === "TSSymbolKeyword") {
34
- return true;
35
- }
36
- if (unwrapped.type === "TSUnionType")
37
- return unwrapped.types.every(isBroadRecordKeyType);
38
- return unwrapped.type === "TSTypeReference" && typeReferenceName(unwrapped) === "PropertyKey";
39
- }
40
- function isBroadRecordType(type) {
41
- const unwrapped = unwrapTypeParentheses(type);
42
- if (unwrapped.type === "TSTypeReference") {
43
- if (typeReferenceName(unwrapped) === "Readonly") {
44
- const [inner] = unwrapped.typeArguments?.params ?? [];
45
- return inner !== undefined && isBroadRecordType(inner);
46
- }
47
- if (typeReferenceName(unwrapped) !== "Record")
48
- return false;
49
- const parameters = unwrapped.typeArguments?.params ?? [];
50
- return (parameters.length === 2 &&
51
- parameters[0] !== undefined &&
52
- parameters[1] !== undefined &&
53
- isBroadRecordKeyType(parameters[0]) &&
54
- isUnknownOrAnyType(parameters[1]));
55
- }
56
- if (unwrapped.type !== "TSTypeLiteral" || unwrapped.members.length !== 1)
57
- return false;
58
- const [member] = unwrapped.members;
59
- const [parameter] = member?.type === "TSIndexSignature" ? member.parameters : [];
60
- return (member?.type === "TSIndexSignature" &&
61
- member.parameters.length === 1 &&
62
- parameter !== undefined &&
63
- isBroadRecordKeyType(parameter.typeAnnotation.typeAnnotation) &&
64
- isUnknownOrAnyType(member.typeAnnotation.typeAnnotation));
65
- }
66
- function broadTypeKind(type) {
67
- const unwrapped = unwrapTypeParentheses(type);
68
- if (unwrapped.type === "TSUnknownKeyword" || unwrapped.type === "TSAnyKeyword")
69
- return "top";
70
- if (unwrapped.type === "TSObjectKeyword")
71
- return "object";
72
- return isBroadRecordType(unwrapped) ? "record" : null;
73
- }
74
- function assertedExpression(node) {
75
- return unwrapExpressionParentheses(node.expression);
76
- }
77
- function isDefinitelyObjectType(type) {
78
- const unwrapped = unwrapTypeParentheses(type);
79
- switch (unwrapped.type) {
80
- case "TSArrayType":
81
- case "TSConstructorType":
82
- case "TSFunctionType":
83
- case "TSMappedType":
84
- case "TSObjectKeyword":
85
- case "TSTupleType":
86
- return true;
87
- case "TSTypeLiteral":
88
- return unwrapped.members.length > 0;
89
- case "TSIntersectionType":
90
- return unwrapped.types.every(isDefinitelyObjectType);
91
- case "TSTypeOperator":
92
- return unwrapped.operator === "readonly" && isDefinitelyObjectType(unwrapped.typeAnnotation);
93
- default:
94
- return false;
95
- }
96
- }
97
- function isDefinitelyNarrowerRecordType(type) {
98
- const unwrapped = unwrapTypeParentheses(type);
99
- if (unwrapped.type === "TSTypeLiteral") {
100
- return unwrapped.members.some((member) => member.type !== "TSIndexSignature");
101
- }
102
- if (unwrapped.type !== "TSTypeReference")
103
- return false;
104
- if (typeReferenceName(unwrapped) === "Readonly") {
105
- const [inner] = unwrapped.typeArguments?.params ?? [];
106
- return inner !== undefined && isDefinitelyNarrowerRecordType(inner);
107
- }
108
- if (typeReferenceName(unwrapped) !== "Record")
109
- return false;
110
- const parameters = unwrapped.typeArguments?.params ?? [];
111
- return (parameters.length === 2 && parameters[1] !== undefined && !isUnknownOrAnyType(parameters[1]));
112
- }
113
- function functionBoundary(sourceCode, node) {
114
- const ancestors = ancestorsOf(sourceCode, node);
115
- for (let index = ancestors.length - 1; index >= 0; index--) {
116
- const current = ancestors[index];
117
- if (current.type === "Program")
118
- break;
119
- if (functionBoundaryTypes.has(current.type))
120
- return current;
121
- }
122
- return null;
123
- }
124
- function resolvedVariableForIdentifier(scopes, identifier) {
125
- for (const scope of scopes) {
126
- const reference = scope.references.find((candidate) => candidate.identifier.start === identifier.start &&
127
- candidate.identifier.end === identifier.end);
128
- if (reference !== undefined)
129
- return reference.resolved;
130
- }
131
- return null;
132
- }
133
- function variableDeclarator(variable) {
134
- for (const definition of variable.defs) {
135
- if (definition.type === "Variable" && definition.node.type === "VariableDeclarator") {
136
- return definition.node;
137
- }
138
- }
139
- return null;
140
- }
141
- function knownValueEvidence(sourceCode, expression, scopes, boundary, visitedVariables) {
142
- const unwrapped = unwrapExpressionParentheses(expression);
143
- if (unwrapped.type === "TSAsExpression" || unwrapped.type === "TSTypeAssertion") {
144
- if (broadTypeKind(unwrapped.typeAnnotation) !== null)
145
- return null;
146
- return { type: unwrapped.typeAnnotation };
147
- }
148
- if (unwrapped.type === "Literal" || unwrapped.type === "TemplateLiteral") {
149
- return { type: null };
150
- }
151
- if (unwrapped.type === "ArrayExpression" ||
152
- unwrapped.type === "ArrowFunctionExpression" ||
153
- unwrapped.type === "ClassExpression" ||
154
- unwrapped.type === "FunctionExpression" ||
155
- unwrapped.type === "NewExpression" ||
156
- unwrapped.type === "ObjectExpression") {
157
- return { type: null };
158
- }
159
- if (unwrapped.type !== "Identifier")
160
- return null;
161
- const variable = resolvedVariableForIdentifier(scopes, unwrapped);
162
- if (variable === null || visitedVariables.has(variable))
163
- return null;
164
- const annotatedIdentifier = variable.identifiers.find((identifier) => identifier.typeAnnotation !== null && identifier.typeAnnotation !== undefined);
165
- const annotation = annotatedIdentifier?.typeAnnotation?.typeAnnotation;
166
- if (annotation !== undefined && annotatedIdentifier !== undefined) {
167
- if (functionBoundary(sourceCode, annotatedIdentifier) !== boundary || broadTypeKind(annotation) !== null) {
168
- return null;
169
- }
170
- return { type: annotation };
171
- }
172
- const declarator = variableDeclarator(variable);
173
- const declaration = declarator === null ? null : ancestorsOf(sourceCode, declarator).at(-1);
174
- if (declarator === null ||
175
- declaration === null ||
176
- declaration?.type !== "VariableDeclaration" ||
177
- declaration?.kind !== "const" ||
178
- declarator.init === null ||
179
- variable.references.some((reference) => reference.isWrite() && !reference.init) ||
180
- functionBoundary(sourceCode, declarator) !== boundary) {
181
- return null;
182
- }
183
- return knownValueEvidence(sourceCode, declarator.init, scopes, boundary, new Set([...visitedVariables, variable]));
184
- }
185
- /** Detect immutable local bindings that erase a known type and are later asserted back to a narrower type. */
186
- export const noWidenThenAssertRule = defineRule({
187
- meta: {
188
- type: "problem",
189
- docs: {
190
- description: "Disallow local const flows that explicitly widen a known value before asserting the widened binding to a narrower type.",
191
- },
192
- messages: {
193
- widenThenAssert: 'Binding "{{name}}" discards type evidence and later recreates it with an assertion. Keep the precise type from initialization through use; parse boundary input once.',
194
- },
195
- },
196
- createOnce(context) {
197
- let scopes = [];
198
- const checkAssertion = (node) => {
199
- const expression = assertedExpression(node);
200
- if (expression.type !== "Identifier")
201
- return;
202
- const variable = resolvedVariableForIdentifier(scopes, expression);
203
- if (variable === null)
204
- return;
205
- const declarator = variableDeclarator(variable);
206
- const declaration = declarator === null ? null : ancestorsOf(context.sourceCode, declarator).at(-1);
207
- if (declarator === null ||
208
- declaration === null ||
209
- declaration?.type !== "VariableDeclaration" ||
210
- declaration?.kind !== "const" ||
211
- declarator.id.type !== "Identifier" ||
212
- declarator.init === null ||
213
- variable.references.some((reference) => reference.isWrite() && !reference.init)) {
214
- return;
215
- }
216
- const boundary = functionBoundary(context.sourceCode, declarator);
217
- const declaredType = declarator.id.typeAnnotation?.typeAnnotation;
218
- const initializerUnwrapped = unwrapExpressionParentheses(declarator.init);
219
- const initializerAssertion = initializerUnwrapped.type === "TSAsExpression" || initializerUnwrapped.type === "TSTypeAssertion"
220
- ? initializerUnwrapped
221
- : null;
222
- const initializerBroadKind = initializerAssertion === null ? null : broadTypeKind(initializerAssertion.typeAnnotation);
223
- const declaredBroadKind = declaredType === undefined ? null : broadTypeKind(declaredType);
224
- const broadKind = declaredBroadKind ?? initializerBroadKind;
225
- if (broadKind === null)
226
- return;
227
- const originalExpression = initializerAssertion !== null && initializerBroadKind !== null
228
- ? assertedExpression(initializerAssertion)
229
- : declarator.init;
230
- const evidence = knownValueEvidence(context.sourceCode, originalExpression, scopes, boundary, new Set([variable]));
231
- if (evidence === null)
232
- return;
233
- if (node.start <= declarator.end || functionBoundary(context.sourceCode, node) !== boundary) {
234
- return;
235
- }
236
- const assertedType = node.typeAnnotation;
237
- if (broadTypeKind(assertedType) !== null)
238
- return;
239
- if (broadKind !== "top") {
240
- const normalized = (type) => context.sourceCode.text.slice(type.start, type.end).replaceAll(/\s+/gu, "");
241
- const sameSyntax = evidence.type !== null &&
242
- normalized(unwrapTypeParentheses(evidence.type)) ===
243
- normalized(unwrapTypeParentheses(assertedType));
244
- if (!sameSyntax) {
245
- if (broadKind === "object") {
246
- if (!isDefinitelyObjectType(assertedType))
247
- return;
248
- }
249
- else if (!isDefinitelyNarrowerRecordType(assertedType)) {
250
- return;
251
- }
252
- }
253
- }
254
- context.report({
255
- node,
256
- messageId: "widenThenAssert",
257
- data: { name: expression.name },
258
- });
259
- };
260
- return {
261
- Program() {
262
- scopes = context.sourceCode.scopeManager.scopes;
263
- },
264
- TSAsExpression: checkAssertion,
265
- TSTypeAssertion: checkAssertion,
266
- };
267
- },
268
- });
@@ -1,2 +0,0 @@
1
- /** Opaque brand interfaces hide their payload behind casts; carry the payload in the brand. */
2
- export declare const preferPayloadBrandRule: import("@oxlint/plugins").Rule;
@@ -1,57 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- /** True for a heritage clause referencing Brand.Brand (any ESTree spelling).
3
- *
4
- * @param {ESTree.TSTypeName | ESTree.Expression | ESTree.PrivateIdentifier} expression - Heritage clause expression.
5
- * @returns {boolean} True when the expression is the Brand.Brand reference.
6
- */
7
- function isBrandBrandReference(expression) {
8
- if (expression.type === "TSQualifiedName") {
9
- return (expression.left.type === "Identifier" &&
10
- expression.left.name === "Brand" &&
11
- expression.right.type === "Identifier" &&
12
- expression.right.name === "Brand");
13
- }
14
- if (expression.type === "MemberExpression") {
15
- return (expression.object.type === "Identifier" &&
16
- expression.object.name === "Brand" &&
17
- expression.property.type === "Identifier" &&
18
- expression.property.name === "Brand");
19
- }
20
- return false;
21
- }
22
- /** Opaque brand interfaces hide their payload behind casts; carry the payload in the brand. */
23
- export const preferPayloadBrandRule = defineRule({
24
- meta: {
25
- type: "problem",
26
- docs: {
27
- description: "Prefer payload-carrying brands (type X = Base & Brand.Brand<\"X\">) over opaque brand interfaces so the payload stays recoverable without type assertions.",
28
- },
29
- messages: {
30
- opaqueBrand: "Opaque brand interface `{{name}}` hides its payload behind casts. Carry the payload in the brand instead: `type {{name}} = Base & Brand.Brand<\"{{name}}\">` with a cast-free `un{{name}}` accessor.",
31
- },
32
- },
33
- createOnce(context) {
34
- return {
35
- Program(node) {
36
- for (const statement of node.body) {
37
- const declaration = statement.type === "ExportNamedDeclaration" ||
38
- statement.type === "ExportDefaultDeclaration"
39
- ? (statement.declaration ?? null)
40
- : statement;
41
- if (declaration?.type !== "TSInterfaceDeclaration")
42
- continue;
43
- const heritages = declaration.extends ?? [];
44
- if (heritages.length !== 1)
45
- continue;
46
- if (!isBrandBrandReference(heritages[0].expression))
47
- continue;
48
- context.report({
49
- node: declaration.id,
50
- messageId: "opaqueBrand",
51
- data: { name: declaration.id.name },
52
- });
53
- }
54
- },
55
- };
56
- },
57
- });
@@ -1,5 +0,0 @@
1
- /**
2
- * We default to property-based testing: a test suite without fast-check only
3
- * pins examples. Escape hatch is an explicit inline disable with a reason.
4
- */
5
- export declare const preferPropertyTestsRule: import("@oxlint/plugins").Rule;
@@ -1,39 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
3
- /**
4
- * We default to property-based testing: a test suite without fast-check only
5
- * pins examples. Escape hatch is an explicit inline disable with a reason.
6
- */
7
- export const preferPropertyTestsRule = defineRule({
8
- meta: {
9
- type: "suggestion",
10
- docs: {
11
- description: "Require `fast-check` in every test file; suites that genuinely cannot use properties must disable this rule inline with a justification.",
12
- },
13
- messages: {
14
- useFastCheck: "No `fast-check` import: this suite only exercises hand-picked examples. Add property-based coverage (generate inputs, assert invariants), or disable this rule inline with a reason if the behavior is truly non-property-testable.",
15
- },
16
- },
17
- createOnce(context) {
18
- let program = null;
19
- let sawFastCheck = false;
20
- return {
21
- before() {
22
- if (!TEST_FILE.test(context.filename.replaceAll("\\", "/")))
23
- return false;
24
- },
25
- Program(node) {
26
- program = node;
27
- },
28
- ImportDeclaration(node) {
29
- if (node.source.value === "fast-check")
30
- sawFastCheck = true;
31
- },
32
- "Program:exit"() {
33
- if (!sawFastCheck && program !== null) {
34
- context.report({ node: program, messageId: "useFastCheck" });
35
- }
36
- },
37
- };
38
- },
39
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Canonical form: JSON.stringify walks insertion order, so structurally
3
- * equal data can serialise to different strings depending on construction
4
- * history. As an identity function (comparison, Map/Set key, hash input),
5
- * that is a false-negative machine. Only a canonical (key-sorted)
6
- * serializer may stand in for structural equality there.
7
- */
8
- export declare const requireCanonicalStringifyForIdentityRule: import("@oxlint/plugins").Rule;
@@ -1,72 +0,0 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import { ancestorsOf } from "../shared/ancestors.js";
3
- const COMPARISON_OPERATORS = new Set(["===", "!==", "==", "!="]);
4
- const MAP_KEY_METHODS = new Set(["get", "has", "delete"]);
5
- const SET_KEY_METHODS = new Set(["add", "has", "delete"]);
6
- /**
7
- * Canonical form: JSON.stringify walks insertion order, so structurally
8
- * equal data can serialise to different strings depending on construction
9
- * history. As an identity function (comparison, Map/Set key, hash input),
10
- * that is a false-negative machine. Only a canonical (key-sorted)
11
- * serializer may stand in for structural equality there.
12
- */
13
- export const requireCanonicalStringifyForIdentityRule = defineRule({
14
- meta: {
15
- type: "problem",
16
- docs: {
17
- description: "Disallow JSON.stringify as an identity function (equality comparison, Map/Set key, hash input); use a canonical key-sorted serializer instead.",
18
- },
19
- messages: {
20
- nonCanonicalIdentity: "`JSON.stringify` here follows property insertion order, so equal data can produce different strings and identical-looking data can hide inequality. Use a canonical serializer (recursively key-sorted) before using the result for {{use}}.",
21
- },
22
- },
23
- createOnce(context) {
24
- function report(payload) {
25
- context.report({
26
- node: payload.node,
27
- messageId: "nonCanonicalIdentity",
28
- data: { use: payload.use },
29
- });
30
- }
31
- return {
32
- CallExpression(node) {
33
- const callee = node.callee;
34
- if (node.type !== "CallExpression" ||
35
- callee.type !== "MemberExpression" ||
36
- callee.computed ||
37
- callee.object.type !== "Identifier" ||
38
- callee.object.name !== "JSON" ||
39
- callee.property.type !== "Identifier" ||
40
- callee.property.name !== "stringify")
41
- return;
42
- const parent = (ancestorsOf(context.sourceCode, node)).at(-1);
43
- if (parent === null || parent === undefined)
44
- return;
45
- if (parent.type === "BinaryExpression" && COMPARISON_OPERATORS.has(parent.operator)) {
46
- report({ node, use: "equality comparison" });
47
- return;
48
- }
49
- if (parent.type === "MemberExpression" && parent.computed) {
50
- report({ node, use: "property lookup" });
51
- return;
52
- }
53
- if (parent.type === "CallExpression" && parent.callee.type === "MemberExpression" && !parent.callee.computed) {
54
- const method = parent.callee.property;
55
- if (method.type !== "Identifier")
56
- return;
57
- if (MAP_KEY_METHODS.has(method.name) && parent.arguments[0] === node) {
58
- report({ node, use: `${method.name}() on a map` });
59
- return;
60
- }
61
- if (SET_KEY_METHODS.has(method.name) && parent.arguments[0] === node) {
62
- report({ node, use: `${method.name}() on a set` });
63
- return;
64
- }
65
- if (method.name === "set" && parent.arguments[0] === node) {
66
- report({ node, use: "a map key" });
67
- }
68
- }
69
- },
70
- };
71
- },
72
- });
@@ -1,2 +0,0 @@
1
- /** Prose-only retirement notes are invisible to tooling; require the machine-readable tag. */
2
- export declare const requireDeprecatedTagForLegacyCommentsRule: import("@oxlint/plugins").Rule;