@venizia/dev-configs 0.5.0-7 → 0.5.0-9

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 (166) hide show
  1. package/README.md +15 -11
  2. package/dist/checks/purity/manifest.js +11 -3
  3. package/dist/checks/purity/manifest.js.map +1 -1
  4. package/dist/checks/purity/probe.js +19 -2
  5. package/dist/checks/purity/probe.js.map +1 -1
  6. package/dist/checks/split-report.js +2 -1
  7. package/dist/checks/split-report.js.map +1 -1
  8. package/dist/checks/test-controls.d.ts +9 -1
  9. package/dist/checks/test-controls.js +9 -3
  10. package/dist/checks/test-controls.js.map +1 -1
  11. package/dist/checks/test-dead-code.d.ts +9 -1
  12. package/dist/checks/test-dead-code.js +13 -2
  13. package/dist/checks/test-dead-code.js.map +1 -1
  14. package/dist/checks/test-mutate.d.ts +9 -1
  15. package/dist/checks/test-mutate.js +12 -6
  16. package/dist/checks/test-mutate.js.map +1 -1
  17. package/dist/cli/check.d.ts +0 -1
  18. package/dist/cli/check.js +42 -68
  19. package/dist/cli/check.js.map +1 -1
  20. package/dist/cli/clean.js +3 -2
  21. package/dist/cli/clean.js.map +1 -1
  22. package/dist/cli/codemod/any-aliases.js +13 -12
  23. package/dist/cli/codemod/any-aliases.js.map +1 -1
  24. package/dist/cli/codemod/async-style.d.ts +1 -1
  25. package/dist/cli/codemod/async-style.js +17 -16
  26. package/dist/cli/codemod/async-style.js.map +1 -1
  27. package/dist/cli/codemod/binding-keys.js +14 -13
  28. package/dist/cli/codemod/binding-keys.js.map +1 -1
  29. package/dist/cli/codemod/class-renames.d.ts +1 -1
  30. package/dist/cli/codemod/class-renames.js +30 -11
  31. package/dist/cli/codemod/class-renames.js.map +1 -1
  32. package/dist/cli/codemod/connector-imports.js +12 -11
  33. package/dist/cli/codemod/connector-imports.js.map +1 -1
  34. package/dist/cli/codemod/const-classes.d.ts +1 -1
  35. package/dist/cli/codemod/const-classes.js +21 -20
  36. package/dist/cli/codemod/const-classes.js.map +1 -1
  37. package/dist/cli/codemod/drop-redundant-casts.d.ts +6 -1
  38. package/dist/cli/codemod/drop-redundant-casts.js +27 -19
  39. package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
  40. package/dist/cli/codemod/env-get.d.ts +3 -3
  41. package/dist/cli/codemod/env-get.js +18 -17
  42. package/dist/cli/codemod/env-get.js.map +1 -1
  43. package/dist/cli/codemod/files.js +2 -2
  44. package/dist/cli/codemod/files.js.map +1 -1
  45. package/dist/cli/codemod/function-to-arrow.d.ts +76 -0
  46. package/dist/cli/codemod/function-to-arrow.js +357 -0
  47. package/dist/cli/codemod/function-to-arrow.js.map +1 -0
  48. package/dist/cli/codemod/index.js +19 -4
  49. package/dist/cli/codemod/index.js.map +1 -1
  50. package/dist/cli/codemod/namespace-functions/index.js +13 -12
  51. package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
  52. package/dist/cli/codemod/typed-route-context.d.ts +27 -0
  53. package/dist/cli/codemod/typed-route-context.js +570 -0
  54. package/dist/cli/codemod/typed-route-context.js.map +1 -0
  55. package/dist/cli/index.js +5 -5
  56. package/dist/cli/index.js.map +1 -1
  57. package/dist/common/cli-output.d.ts +16 -0
  58. package/dist/common/cli-output.js +49 -0
  59. package/dist/common/cli-output.js.map +1 -0
  60. package/dist/compilers/bun.js +1 -1
  61. package/dist/compilers/bun.js.map +1 -1
  62. package/dist/linters/eslint.js +1 -1
  63. package/dist/linters/eslint.js.map +1 -1
  64. package/dist/linters/house/browser-api-patterns.d.ts +1 -3
  65. package/dist/linters/house/browser-api-patterns.js +1 -3
  66. package/dist/linters/house/browser-api-patterns.js.map +1 -1
  67. package/dist/linters/house/common.d.ts +8 -2
  68. package/dist/linters/house/common.js +8 -2
  69. package/dist/linters/house/common.js.map +1 -1
  70. package/dist/linters/house/configs.js +8 -6
  71. package/dist/linters/house/configs.js.map +1 -1
  72. package/dist/linters/house/const-class-values.rule.d.ts +2 -2
  73. package/dist/linters/house/const-class-values.rule.js +14 -5
  74. package/dist/linters/house/const-class-values.rule.js.map +1 -1
  75. package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +2 -2
  76. package/dist/linters/house/effect-cleanup-consistency.rule.js +1 -1
  77. package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -1
  78. package/dist/linters/house/framework-api-patterns.d.ts +54 -0
  79. package/dist/linters/house/framework-api-patterns.js +62 -0
  80. package/dist/linters/house/framework-api-patterns.js.map +1 -0
  81. package/dist/linters/house/framework-exports.d.ts +1 -1
  82. package/dist/linters/house/framework-exports.js +13 -13
  83. package/dist/linters/house/framework-exports.js.map +1 -1
  84. package/dist/linters/house/index.d.ts +3 -4
  85. package/dist/linters/house/index.js +4 -6
  86. package/dist/linters/house/index.js.map +1 -1
  87. package/dist/linters/house/max-params-own.rule.d.ts +2 -2
  88. package/dist/linters/house/max-params-own.rule.js +1 -1
  89. package/dist/linters/house/max-params-own.rule.js.map +1 -1
  90. package/dist/linters/house/no-async-hook-callback.rule.d.ts +2 -2
  91. package/dist/linters/house/no-async-hook-callback.rule.js +1 -1
  92. package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -1
  93. package/dist/linters/house/no-await-new-chain.rule.d.ts +2 -2
  94. package/dist/linters/house/no-await-new-chain.rule.js +1 -1
  95. package/dist/linters/house/no-await-new-chain.rule.js.map +1 -1
  96. package/dist/linters/house/no-await-promise-chain.rule.d.ts +2 -2
  97. package/dist/linters/house/no-await-promise-chain.rule.js +5 -5
  98. package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -1
  99. package/dist/linters/house/no-inline-await.rule.d.ts +2 -2
  100. package/dist/linters/house/no-inline-await.rule.js +1 -1
  101. package/dist/linters/house/no-inline-await.rule.js.map +1 -1
  102. package/dist/linters/house/no-leaked-render.rule.d.ts +2 -2
  103. package/dist/linters/house/no-leaked-render.rule.js +1 -1
  104. package/dist/linters/house/no-leaked-render.rule.js.map +1 -1
  105. package/dist/linters/house/no-new-error.rule.d.ts +2 -2
  106. package/dist/linters/house/no-new-error.rule.js +2 -2
  107. package/dist/linters/house/no-new-error.rule.js.map +1 -1
  108. package/dist/linters/house/no-parent-import.rule.d.ts +5 -2
  109. package/dist/linters/house/no-parent-import.rule.js +5 -2
  110. package/dist/linters/house/no-parent-import.rule.js.map +1 -1
  111. package/dist/linters/house/no-return-await.rule.d.ts +2 -2
  112. package/dist/linters/house/no-return-await.rule.js +1 -1
  113. package/dist/linters/house/no-return-await.rule.js.map +1 -1
  114. package/dist/linters/house/no-shadow-framework-type.rule.d.ts +2 -2
  115. package/dist/linters/house/no-shadow-framework-type.rule.js +2 -2
  116. package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -1
  117. package/dist/linters/house/no-silent-catch.rule.d.ts +2 -2
  118. package/dist/linters/house/no-silent-catch.rule.js +3 -3
  119. package/dist/linters/house/no-silent-catch.rule.js.map +1 -1
  120. package/dist/linters/house/no-unbraced-case.rule.d.ts +2 -2
  121. package/dist/linters/house/no-unbraced-case.rule.js +1 -1
  122. package/dist/linters/house/no-unbraced-case.rule.js.map +1 -1
  123. package/dist/linters/house/plugin.d.ts +1 -1
  124. package/dist/linters/house/plugin.js +6 -5
  125. package/dist/linters/house/plugin.js.map +1 -1
  126. package/dist/linters/house/prefer-framework-api.rule.d.ts +39 -7
  127. package/dist/linters/house/prefer-framework-api.rule.js +285 -12
  128. package/dist/linters/house/prefer-framework-api.rule.js.map +1 -1
  129. package/dist/linters/house/prefer-promise-sleep.rule.d.ts +2 -2
  130. package/dist/linters/house/prefer-promise-sleep.rule.js +3 -2
  131. package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -1
  132. package/dist/linters/house/prefer-tnullable.rule.d.ts +2 -2
  133. package/dist/linters/house/prefer-tnullable.rule.js +2 -2
  134. package/dist/linters/house/prefer-tnullable.rule.js.map +1 -1
  135. package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
  136. package/dist/linters/house/typed-route-context.rule.js +322 -0
  137. package/dist/linters/house/typed-route-context.rule.js.map +1 -0
  138. package/dist/linters/house/zod-schema-convention.rule.d.ts +82 -0
  139. package/dist/linters/house/zod-schema-convention.rule.js +477 -0
  140. package/dist/linters/house/zod-schema-convention.rule.js.map +1 -0
  141. package/dist/linters/oxlint.js +11 -1
  142. package/dist/linters/oxlint.js.map +1 -1
  143. package/dist/linters/react-eslint.js.map +1 -1
  144. package/dist/linters/rules/naming-convention.rule.d.ts +4 -1
  145. package/dist/linters/rules/naming-convention.rule.js +30 -1
  146. package/dist/linters/rules/naming-convention.rule.js.map +1 -1
  147. package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
  148. package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
  149. package/dist/testing/spawn.utility.js +1 -1
  150. package/dist/testing/spawn.utility.js.map +1 -1
  151. package/package.json +5 -5
  152. package/dist/checks/use-when-baseline.d.ts +0 -25
  153. package/dist/checks/use-when-baseline.js +0 -38
  154. package/dist/checks/use-when-baseline.js.map +0 -1
  155. package/dist/linters/house/framework-rule-apis.d.ts +0 -24
  156. package/dist/linters/house/framework-rule-apis.js +0 -48
  157. package/dist/linters/house/framework-rule-apis.js.map +0 -1
  158. package/dist/linters/house/public-surface.d.ts +0 -57
  159. package/dist/linters/house/public-surface.js +0 -174
  160. package/dist/linters/house/public-surface.js.map +0 -1
  161. package/dist/linters/house/published-package-configs.d.ts +0 -23
  162. package/dist/linters/house/published-package-configs.js +0 -42
  163. package/dist/linters/house/published-package-configs.js.map +0 -1
  164. package/dist/linters/house/require-use-when.rule.d.ts +0 -42
  165. package/dist/linters/house/require-use-when.rule.js +0 -175
  166. package/dist/linters/house/require-use-when.rule.js.map +0 -1
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypedRouteContextRule = void 0;
4
+ const common_1 = require("./common");
5
+ /** The members of a route's AST this rule reads. */
6
+ class RouteNodes {
7
+ static { this.CONTEXT_TYPE = 'TContextOf'; }
8
+ static { this.CONFIG_TYPE = 'IAuthRouteConfig'; }
9
+ static { this.DECORATORS = new Set([
10
+ 'api',
11
+ 'get',
12
+ 'post',
13
+ 'put',
14
+ 'patch',
15
+ 'del',
16
+ ]); }
17
+ static field(node, key) {
18
+ return common_1.AstNode.readField({ node, key });
19
+ }
20
+ static type(node) {
21
+ return common_1.AstNode.getType({ node });
22
+ }
23
+ static list(node, key) {
24
+ const value = RouteNodes.field(node, key);
25
+ return Array.isArray(value) ? value : [];
26
+ }
27
+ static nameOf(node) {
28
+ const value = RouteNodes.field(node, 'name');
29
+ return typeof value === 'string' ? value : undefined;
30
+ }
31
+ /** The type arguments written on a type reference or a call. */
32
+ static typeArguments(node) {
33
+ return RouteNodes.list(RouteNodes.field(node, 'typeArguments') ?? RouteNodes.field(node, 'typeParameters'), 'params');
34
+ }
35
+ /** `a.b.c` of an expression, a qualified type name or an indexed access type; `undefined` for anything computed. */
36
+ static chain(node) {
37
+ const type = RouteNodes.type(node);
38
+ if (type === common_1.AstNodeTypes.IDENTIFIER) {
39
+ return RouteNodes.nameOf(node);
40
+ }
41
+ if (type === common_1.AstNodeTypes.THIS_EXPRESSION) {
42
+ return 'this';
43
+ }
44
+ const join = (left, right) => {
45
+ const head = RouteNodes.chain(left);
46
+ return head === undefined || right === undefined ? undefined : `${head}.${right}`;
47
+ };
48
+ const literal = (value) => (typeof value === 'string' ? value : undefined);
49
+ if (type === common_1.AstNodeTypes.MEMBER_EXPRESSION) {
50
+ const property = RouteNodes.field(node, 'property');
51
+ const isComputed = RouteNodes.field(node, 'computed') === true;
52
+ return join(RouteNodes.field(node, 'object'), isComputed ? literal(RouteNodes.field(property, 'value')) : RouteNodes.nameOf(property));
53
+ }
54
+ if (type === 'TSQualifiedName') {
55
+ return join(RouteNodes.field(node, 'left'), RouteNodes.nameOf(RouteNodes.field(node, 'right')));
56
+ }
57
+ if (type === common_1.AstNodeTypes.TYPE_QUERY) {
58
+ return RouteNodes.chain(RouteNodes.field(node, 'exprName'));
59
+ }
60
+ if (type === 'TSIndexedAccessType') {
61
+ const index = RouteNodes.field(RouteNodes.field(node, 'indexType'), 'literal');
62
+ return join(RouteNodes.field(node, 'objectType'), literal(RouteNodes.field(index, 'value')));
63
+ }
64
+ return undefined;
65
+ }
66
+ /** The value of the property `key` of an object expression. */
67
+ static property(node, key) {
68
+ const found = RouteNodes.list(node, 'properties').find((item) => RouteNodes.nameOf(RouteNodes.field(item, 'key')) === key);
69
+ return RouteNodes.field(found, 'value');
70
+ }
71
+ /** The type a pattern is annotated with. */
72
+ static annotation(pattern) {
73
+ return RouteNodes.field(RouteNodes.field(pattern, 'typeAnnotation'), 'typeAnnotation');
74
+ }
75
+ static referenceName(node) {
76
+ return RouteNodes.type(node) === common_1.AstNodeTypes.TYPE_REFERENCE
77
+ ? RouteNodes.nameOf(RouteNodes.field(node, 'typeName'))
78
+ : undefined;
79
+ }
80
+ /** The `TContextOf<...>` a parameter carries, directly or as the `context` of its options, and the path it binds. */
81
+ static contextOf(param) {
82
+ const annotation = RouteNodes.annotation(param);
83
+ const read = (type, path) => {
84
+ if (path === undefined || RouteNodes.referenceName(type) !== RouteNodes.CONTEXT_TYPE) {
85
+ return undefined;
86
+ }
87
+ return { path, config: RouteNodes.chain(RouteNodes.typeArguments(type)[0]) };
88
+ };
89
+ if (RouteNodes.type(annotation) !== 'TSTypeLiteral') {
90
+ return read(annotation, RouteNodes.nameOf(param));
91
+ }
92
+ const member = RouteNodes.list(annotation, 'members').find((item) => RouteNodes.nameOf(RouteNodes.field(item, 'key')) === 'context');
93
+ const bound = RouteNodes.property(param, 'context');
94
+ const holder = RouteNodes.nameOf(param);
95
+ return read(RouteNodes.annotation(member), holder === undefined ? RouteNodes.nameOf(bound) : `${holder}.context`);
96
+ }
97
+ /** The route config of a `defineRoute`, `defineJSXRoute` or `bindRoute().to` call whose options hold the handler. */
98
+ static routeOf(call) {
99
+ const callee = RouteNodes.field(call, 'callee');
100
+ const method = RouteNodes.nameOf(RouteNodes.field(callee, 'property'));
101
+ const [first] = RouteNodes.list(call, 'arguments');
102
+ if (method === 'defineRoute' || method === 'defineJSXRoute') {
103
+ return { config: RouteNodes.chain(RouteNodes.property(first, 'configs')) };
104
+ }
105
+ const bound = RouteNodes.field(callee, 'object');
106
+ const binder = RouteNodes.nameOf(RouteNodes.field(RouteNodes.field(bound, 'callee'), 'property'));
107
+ if (method !== 'to' || binder !== 'bindRoute') {
108
+ return undefined;
109
+ }
110
+ const [options] = RouteNodes.list(bound, 'arguments');
111
+ return { config: RouteNodes.chain(RouteNodes.property(options, 'configs')) };
112
+ }
113
+ /** The `this.<method>` a handler body passes its context straight to. */
114
+ static forwardOf(handler, context) {
115
+ let body = RouteNodes.field(handler, 'body');
116
+ if (RouteNodes.type(body) === common_1.AstNodeTypes.BLOCK_STATEMENT) {
117
+ const statements = RouteNodes.list(body, 'body');
118
+ body = statements.length === 1 ? RouteNodes.field(statements[0], 'argument') : undefined;
119
+ }
120
+ if (RouteNodes.type(body) === common_1.AstNodeTypes.AWAIT_EXPRESSION) {
121
+ body = RouteNodes.field(body, 'argument');
122
+ }
123
+ const callee = RouteNodes.field(body, 'callee');
124
+ if (RouteNodes.type(RouteNodes.field(callee, 'object')) !== common_1.AstNodeTypes.THIS_EXPRESSION) {
125
+ return undefined;
126
+ }
127
+ const passes = RouteNodes.list(body, 'arguments').some((argument) => RouteNodes.nameOf(argument) === context ||
128
+ RouteNodes.nameOf(RouteNodes.property(argument, 'context')) === context);
129
+ return passes ? RouteNodes.nameOf(RouteNodes.field(callee, 'property')) : undefined;
130
+ }
131
+ /** Whether a declared type is `IAuthRouteConfig`, alone, in an `Omit` or as the value of a `Record`. */
132
+ static isWideConfig(type) {
133
+ const name = RouteNodes.referenceName(type);
134
+ const [first, second] = RouteNodes.typeArguments(type);
135
+ if (name === 'Record') {
136
+ return RouteNodes.isWideConfig(second);
137
+ }
138
+ return name === 'Omit' ? RouteNodes.isWideConfig(first) : name === RouteNodes.CONFIG_TYPE;
139
+ }
140
+ }
141
+ /**
142
+ * `@venizia/typed-route-context`: reports what compiles and still leaves a route handler unchecked. It reads syntax
143
+ * only, so a context passed on to another file, stored, or passed further than one method is not followed.
144
+ *
145
+ * - a route config object declared as `IAuthRouteConfig` (or in a `Record` of it) instead of `satisfies`;
146
+ * - `valid<T>()` with a type argument on a context typed from its route;
147
+ * - a decorated method whose `TContextOf` names another route than its decorator;
148
+ * - a handler that passes its context straight to a method of the same class typed for another route.
149
+ */
150
+ class TypedRouteContextRule {
151
+ static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/typed-route-context`; }
152
+ static { this.RULE = {
153
+ meta: {
154
+ type: 'problem',
155
+ schema: [],
156
+ messages: {
157
+ wideConfig: 'Declared as `IAuthRouteConfig`, this config loses its schemas: write `{ ... } satisfies IAuthRouteConfig`.',
158
+ typedValid: 'This context is typed from its route: remove the type argument of `valid()`, which replaces the schema type.',
159
+ otherRoute: 'This route is `{{expected}}`, and the context is typed from `{{actual}}`.',
160
+ forwarded: 'The route `{{expected}}` passes its context to `{{method}}`, which is typed from `{{actual}}`.',
161
+ },
162
+ },
163
+ create: (context) => {
164
+ const frames = [];
165
+ const classes = [];
166
+ const isTyped = (path) => {
167
+ const [root] = path.split('.');
168
+ const owner = frames.findLast((frame) => frame.declared.has(root ?? ''));
169
+ return owner?.typed.has(path) === true;
170
+ };
171
+ const enterFunction = (node) => {
172
+ const frame = { declared: new Set(), typed: new Set() };
173
+ const params = RouteNodes.list(node, 'params');
174
+ for (const param of params) {
175
+ const own = RouteNodes.nameOf(param);
176
+ if (own !== undefined) {
177
+ frame.declared.add(own);
178
+ }
179
+ for (const property of RouteNodes.list(param, 'properties')) {
180
+ const bound = RouteNodes.nameOf(RouteNodes.field(property, 'value'));
181
+ if (bound !== undefined) {
182
+ frame.declared.add(bound);
183
+ }
184
+ }
185
+ const typed = RouteNodes.contextOf(param);
186
+ if (typed !== undefined) {
187
+ frame.typed.add(typed.path);
188
+ }
189
+ }
190
+ frames.push(frame);
191
+ const property = RouteNodes.field(node, 'parent');
192
+ const call = RouteNodes.field(RouteNodes.field(property, 'parent'), 'parent');
193
+ const isHandler = RouteNodes.nameOf(RouteNodes.field(property, 'key')) === 'handler';
194
+ const route = isHandler ? RouteNodes.routeOf(call) : undefined;
195
+ const [first] = params;
196
+ const name = RouteNodes.nameOf(first);
197
+ if (route === undefined || name === undefined || RouteNodes.annotation(first)) {
198
+ return;
199
+ }
200
+ frame.typed.add(name);
201
+ const method = RouteNodes.forwardOf(node, name);
202
+ if (method !== undefined && route.config !== undefined) {
203
+ classes.at(-1)?.forwards.push({ config: route.config, method, node });
204
+ }
205
+ };
206
+ const leaveFunction = () => {
207
+ frames.pop();
208
+ };
209
+ const checkDeclared = (opts) => {
210
+ // `{ ... } as const` under a wide annotation loses the schemas the same way.
211
+ const value = RouteNodes.type(opts.value) === common_1.AstNodeTypes.AS_EXPRESSION
212
+ ? RouteNodes.field(opts.value, 'expression')
213
+ : opts.value;
214
+ // An empty object is a collection filled later, with no literal schema to keep.
215
+ const isObject = RouteNodes.type(value) === common_1.AstNodeTypes.OBJECT_EXPRESSION &&
216
+ RouteNodes.list(value, 'properties').length > 0;
217
+ if (isObject && RouteNodes.isWideConfig(RouteNodes.annotation(opts.pattern))) {
218
+ context.report({ node: opts.node, messageId: 'wideConfig' });
219
+ }
220
+ };
221
+ return {
222
+ [common_1.AstNodeTypes.FUNCTION_DECLARATION]: enterFunction,
223
+ [common_1.AstNodeTypes.FUNCTION_EXPRESSION]: enterFunction,
224
+ [common_1.AstNodeTypes.ARROW_FUNCTION_EXPRESSION]: enterFunction,
225
+ [`${common_1.AstNodeTypes.FUNCTION_DECLARATION}:exit`]: leaveFunction,
226
+ [`${common_1.AstNodeTypes.FUNCTION_EXPRESSION}:exit`]: leaveFunction,
227
+ [`${common_1.AstNodeTypes.ARROW_FUNCTION_EXPRESSION}:exit`]: leaveFunction,
228
+ [common_1.AstNodeTypes.CLASS_BODY]: () => {
229
+ classes.push({ typed: new Map(), forwards: [] });
230
+ },
231
+ [`${common_1.AstNodeTypes.CLASS_BODY}:exit`]: () => {
232
+ const facts = classes.pop();
233
+ for (const { config, method, node } of facts?.forwards ?? []) {
234
+ const actual = facts?.typed.get(method);
235
+ if (actual !== undefined && actual !== config) {
236
+ context.report({
237
+ node,
238
+ messageId: 'forwarded',
239
+ data: { expected: config, method, actual },
240
+ });
241
+ }
242
+ }
243
+ },
244
+ [common_1.AstNodeTypes.METHOD_DEFINITION]: (node) => {
245
+ const method = RouteNodes.nameOf(RouteNodes.field(node, 'key'));
246
+ const typed = RouteNodes.list(RouteNodes.field(node, 'value'), 'params')
247
+ .map((param) => RouteNodes.contextOf(param))
248
+ .find((found) => found !== undefined);
249
+ const actual = typed?.config;
250
+ if (method === undefined || actual === undefined) {
251
+ return;
252
+ }
253
+ classes.at(-1)?.typed.set(method, actual);
254
+ for (const decorator of RouteNodes.list(node, 'decorators')) {
255
+ const call = RouteNodes.field(decorator, 'expression');
256
+ const name = RouteNodes.nameOf(RouteNodes.field(call, 'callee'));
257
+ const [options] = RouteNodes.list(call, 'arguments');
258
+ const expected = RouteNodes.chain(RouteNodes.property(options, 'configs'));
259
+ if (name !== undefined &&
260
+ RouteNodes.DECORATORS.has(name) &&
261
+ expected !== undefined &&
262
+ expected !== actual) {
263
+ context.report({ node, messageId: 'otherRoute', data: { expected, actual } });
264
+ }
265
+ }
266
+ },
267
+ [common_1.AstNodeTypes.VARIABLE_DECLARATOR]: (node) => {
268
+ const pattern = RouteNodes.field(node, 'id');
269
+ const value = RouteNodes.field(node, 'init');
270
+ checkDeclared({ node, pattern, value });
271
+ const frame = frames.at(-1);
272
+ if (!frame) {
273
+ return;
274
+ }
275
+ const own = RouteNodes.nameOf(pattern);
276
+ if (own !== undefined) {
277
+ frame.declared.add(own);
278
+ }
279
+ const source = RouteNodes.chain(value);
280
+ for (const property of RouteNodes.list(pattern, 'properties')) {
281
+ const key = RouteNodes.nameOf(RouteNodes.field(property, 'key'));
282
+ const bound = RouteNodes.nameOf(RouteNodes.field(property, 'value'));
283
+ if (bound === undefined) {
284
+ continue;
285
+ }
286
+ const holdsContext = source !== undefined && isTyped(`${source}.${key}`);
287
+ frame.declared.add(bound);
288
+ if (holdsContext) {
289
+ frame.typed.add(bound);
290
+ }
291
+ }
292
+ },
293
+ [common_1.AstNodeTypes.PROPERTY_DEFINITION]: (node) => {
294
+ checkDeclared({
295
+ node,
296
+ pattern: node,
297
+ value: RouteNodes.field(node, 'value'),
298
+ });
299
+ },
300
+ [common_1.AstNodeTypes.CALL_EXPRESSION]: (node) => {
301
+ const callee = RouteNodes.field(node, 'callee');
302
+ const request = RouteNodes.field(callee, 'object');
303
+ if (RouteNodes.nameOf(RouteNodes.field(callee, 'property')) !== 'valid' ||
304
+ RouteNodes.nameOf(RouteNodes.field(request, 'property')) !== 'req' ||
305
+ RouteNodes.typeArguments(node).length === 0) {
306
+ return;
307
+ }
308
+ const holder = RouteNodes.chain(RouteNodes.field(request, 'object'));
309
+ if (holder !== undefined && isTyped(holder)) {
310
+ context.report({ node, messageId: 'typedValid' });
311
+ }
312
+ },
313
+ };
314
+ },
315
+ }; }
316
+ static build(opts = {}) {
317
+ const { severity = 'error' } = opts;
318
+ return [severity];
319
+ }
320
+ }
321
+ exports.TypedRouteContextRule = TypedRouteContextRule;
322
+ //# sourceMappingURL=typed-route-context.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-route-context.rule.js","sourceRoot":"","sources":["../../../src/linters/house/typed-route-context.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAqBzE,oDAAoD;AACpD,MAAM,UAAU;aACE,iBAAY,GAAG,YAAY,CAAC;aAC5B,gBAAW,GAAG,kBAAkB,CAAC;aACjC,eAAU,GAAwB,IAAI,GAAG,CAAC;QACxD,KAAK;QACL,KAAK;QACL,MAAM;QACN,KAAK;QACL,OAAO;QACP,KAAK;KACN,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,IAAa,EAAE,GAAW;QACrC,OAAO,gBAAO,CAAC,S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UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;oBAEnD,IACE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,KAAK,OAAO;wBACnE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,KAAK,KAAK;wBAClE,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAC3C,CAAC;wBACD,OAAO;oBACT,CAAC;oBAED,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;oBAErE,IAAI,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;wBAC5C,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;oBACpD,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;QAEpC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;;AAzNH,sDA0NC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** A route a handler is written for, and the private method it hands its context to. */\ninterface IForward {\n config: string;\n method: string;\n node: Rule.Node;\n}\n\n/** What one class declares: the route each method's context is typed from, and the handlers that forward to a method. */\ninterface IClassFacts {\n typed: Map<string, string>;\n forwards: IForward[];\n}\n\n/** The bindings of one function: the root names it declares, and the paths among them that hold a typed context. */\ninterface IFrame {\n declared: Set<string>;\n typed: Set<string>;\n}\n\n/** The members of a route's AST this rule reads. */\nclass RouteNodes {\n static readonly CONTEXT_TYPE = 'TContextOf';\n static readonly CONFIG_TYPE = 'IAuthRouteConfig';\n static readonly DECORATORS: ReadonlySet<string> = new Set([\n 'api',\n 'get',\n 'post',\n 'put',\n 'patch',\n 'del',\n ]);\n\n static field(node: unknown, key: string): unknown {\n return AstNode.readField({ node, key });\n }\n\n static type(node: unknown): string | undefined {\n return AstNode.getType({ node });\n }\n\n static list(node: unknown, key: string): unknown[] {\n const value = RouteNodes.field(node, key);\n\n return Array.isArray(value) ? value : [];\n }\n\n static nameOf(node: unknown): string | undefined {\n const value = RouteNodes.field(node, 'name');\n\n return typeof value === 'string' ? value : undefined;\n }\n\n /** The type arguments written on a type reference or a call. */\n static typeArguments(node: unknown): unknown[] {\n return RouteNodes.list(\n RouteNodes.field(node, 'typeArguments') ?? RouteNodes.field(node, 'typeParameters'),\n 'params',\n );\n }\n\n /** `a.b.c` of an expression, a qualified type name or an indexed access type; `undefined` for anything computed. */\n static chain(node: unknown): string | undefined {\n const type = RouteNodes.type(node);\n\n if (type === AstNodeTypes.IDENTIFIER) {\n return RouteNodes.nameOf(node);\n }\n\n if (type === AstNodeTypes.THIS_EXPRESSION) {\n return 'this';\n }\n\n const join = (left: unknown, right: string | undefined) => {\n const head = RouteNodes.chain(left);\n\n return head === undefined || right === undefined ? undefined : `${head}.${right}`;\n };\n\n const literal = (value: unknown) => (typeof value === 'string' ? value : undefined);\n\n if (type === AstNodeTypes.MEMBER_EXPRESSION) {\n const property = RouteNodes.field(node, 'property');\n const isComputed = RouteNodes.field(node, 'computed') === true;\n\n return join(\n RouteNodes.field(node, 'object'),\n isComputed ? literal(RouteNodes.field(property, 'value')) : RouteNodes.nameOf(property),\n );\n }\n\n if (type === 'TSQualifiedName') {\n return join(\n RouteNodes.field(node, 'left'),\n RouteNodes.nameOf(RouteNodes.field(node, 'right')),\n );\n }\n\n if (type === AstNodeTypes.TYPE_QUERY) {\n return RouteNodes.chain(RouteNodes.field(node, 'exprName'));\n }\n\n if (type === 'TSIndexedAccessType') {\n const index = RouteNodes.field(RouteNodes.field(node, 'indexType'), 'literal');\n\n return join(RouteNodes.field(node, 'objectType'), literal(RouteNodes.field(index, 'value')));\n }\n\n return undefined;\n }\n\n /** The value of the property `key` of an object expression. */\n static property(node: unknown, key: string): unknown {\n const found = RouteNodes.list(node, 'properties').find(\n (item) => RouteNodes.nameOf(RouteNodes.field(item, 'key')) === key,\n );\n\n return RouteNodes.field(found, 'value');\n }\n\n /** The type a pattern is annotated with. */\n static annotation(pattern: unknown): unknown {\n return RouteNodes.field(RouteNodes.field(pattern, 'typeAnnotation'), 'typeAnnotation');\n }\n\n static referenceName(node: unknown): string | undefined {\n return RouteNodes.type(node) === AstNodeTypes.TYPE_REFERENCE\n ? RouteNodes.nameOf(RouteNodes.field(node, 'typeName'))\n : undefined;\n }\n\n /** The `TContextOf<...>` a parameter carries, directly or as the `context` of its options, and the path it binds. */\n static contextOf(param: unknown): { path: string; config: string | undefined } | undefined {\n const annotation = RouteNodes.annotation(param);\n\n const read = (type: unknown, path: string | undefined) => {\n if (path === undefined || RouteNodes.referenceName(type) !== RouteNodes.CONTEXT_TYPE) {\n return undefined;\n }\n\n return { path, config: RouteNodes.chain(RouteNodes.typeArguments(type)[0]) };\n };\n\n if (RouteNodes.type(annotation) !== 'TSTypeLiteral') {\n return read(annotation, RouteNodes.nameOf(param));\n }\n\n const member = RouteNodes.list(annotation, 'members').find(\n (item) => RouteNodes.nameOf(RouteNodes.field(item, 'key')) === 'context',\n );\n const bound = RouteNodes.property(param, 'context');\n const holder = RouteNodes.nameOf(param);\n\n return read(\n RouteNodes.annotation(member),\n holder === undefined ? RouteNodes.nameOf(bound) : `${holder}.context`,\n );\n }\n\n /** The route config of a `defineRoute`, `defineJSXRoute` or `bindRoute().to` call whose options hold the handler. */\n static routeOf(call: unknown): { config: string | undefined } | undefined {\n const callee = RouteNodes.field(call, 'callee');\n const method = RouteNodes.nameOf(RouteNodes.field(callee, 'property'));\n const [first] = RouteNodes.list(call, 'arguments');\n\n if (method === 'defineRoute' || method === 'defineJSXRoute') {\n return { config: RouteNodes.chain(RouteNodes.property(first, 'configs')) };\n }\n\n const bound = RouteNodes.field(callee, 'object');\n const binder = RouteNodes.nameOf(\n RouteNodes.field(RouteNodes.field(bound, 'callee'), 'property'),\n );\n\n if (method !== 'to' || binder !== 'bindRoute') {\n return undefined;\n }\n\n const [options] = RouteNodes.list(bound, 'arguments');\n\n return { config: RouteNodes.chain(RouteNodes.property(options, 'configs')) };\n }\n\n /** The `this.<method>` a handler body passes its context straight to. */\n static forwardOf(handler: unknown, context: string): string | undefined {\n let body = RouteNodes.field(handler, 'body');\n\n if (RouteNodes.type(body) === AstNodeTypes.BLOCK_STATEMENT) {\n const statements = RouteNodes.list(body, 'body');\n body = statements.length === 1 ? RouteNodes.field(statements[0], 'argument') : undefined;\n }\n\n if (RouteNodes.type(body) === AstNodeTypes.AWAIT_EXPRESSION) {\n body = RouteNodes.field(body, 'argument');\n }\n\n const callee = RouteNodes.field(body, 'callee');\n\n if (RouteNodes.type(RouteNodes.field(callee, 'object')) !== AstNodeTypes.THIS_EXPRESSION) {\n return undefined;\n }\n\n const passes = RouteNodes.list(body, 'arguments').some(\n (argument) =>\n RouteNodes.nameOf(argument) === context ||\n RouteNodes.nameOf(RouteNodes.property(argument, 'context')) === context,\n );\n\n return passes ? RouteNodes.nameOf(RouteNodes.field(callee, 'property')) : undefined;\n }\n\n /** Whether a declared type is `IAuthRouteConfig`, alone, in an `Omit` or as the value of a `Record`. */\n static isWideConfig(type: unknown): boolean {\n const name = RouteNodes.referenceName(type);\n const [first, second] = RouteNodes.typeArguments(type);\n\n if (name === 'Record') {\n return RouteNodes.isWideConfig(second);\n }\n\n return name === 'Omit' ? RouteNodes.isWideConfig(first) : name === RouteNodes.CONFIG_TYPE;\n }\n}\n\n/**\n * `@venizia/typed-route-context`: reports what compiles and still leaves a route handler unchecked. It reads syntax\n * only, so a context passed on to another file, stored, or passed further than one method is not followed.\n *\n * - a route config object declared as `IAuthRouteConfig` (or in a `Record` of it) instead of `satisfies`;\n * - `valid<T>()` with a type argument on a context typed from its route;\n * - a decorated method whose `TContextOf` names another route than its decorator;\n * - a handler that passes its context straight to a method of the same class typed for another route.\n */\nexport class TypedRouteContextRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/typed-route-context`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n wideConfig:\n 'Declared as `IAuthRouteConfig`, this config loses its schemas: write `{ ... } satisfies IAuthRouteConfig`.',\n typedValid:\n 'This context is typed from its route: remove the type argument of `valid()`, which replaces the schema type.',\n otherRoute: 'This route is `{{expected}}`, and the context is typed from `{{actual}}`.',\n forwarded:\n 'The route `{{expected}}` passes its context to `{{method}}`, which is typed from `{{actual}}`.',\n },\n },\n create: (context) => {\n const frames: IFrame[] = [];\n const classes: IClassFacts[] = [];\n\n const isTyped = (path: string): boolean => {\n const [root] = path.split('.');\n const owner = frames.findLast((frame) => frame.declared.has(root ?? ''));\n\n return owner?.typed.has(path) === true;\n };\n\n const enterFunction = (node: Rule.Node) => {\n const frame: IFrame = { declared: new Set(), typed: new Set() };\n const params = RouteNodes.list(node, 'params');\n\n for (const param of params) {\n const own = RouteNodes.nameOf(param);\n\n if (own !== undefined) {\n frame.declared.add(own);\n }\n\n for (const property of RouteNodes.list(param, 'properties')) {\n const bound = RouteNodes.nameOf(RouteNodes.field(property, 'value'));\n\n if (bound !== undefined) {\n frame.declared.add(bound);\n }\n }\n\n const typed = RouteNodes.contextOf(param);\n\n if (typed !== undefined) {\n frame.typed.add(typed.path);\n }\n }\n\n frames.push(frame);\n\n const property = RouteNodes.field(node, 'parent');\n const call = RouteNodes.field(RouteNodes.field(property, 'parent'), 'parent');\n const isHandler = RouteNodes.nameOf(RouteNodes.field(property, 'key')) === 'handler';\n const route = isHandler ? RouteNodes.routeOf(call) : undefined;\n const [first] = params;\n const name = RouteNodes.nameOf(first);\n\n if (route === undefined || name === undefined || RouteNodes.annotation(first)) {\n return;\n }\n\n frame.typed.add(name);\n const method = RouteNodes.forwardOf(node, name);\n\n if (method !== undefined && route.config !== undefined) {\n classes.at(-1)?.forwards.push({ config: route.config, method, node });\n }\n };\n\n const leaveFunction = () => {\n frames.pop();\n };\n\n const checkDeclared = (opts: { node: Rule.Node; pattern: unknown; value: unknown }) => {\n // `{ ... } as const` under a wide annotation loses the schemas the same way.\n const value =\n RouteNodes.type(opts.value) === AstNodeTypes.AS_EXPRESSION\n ? RouteNodes.field(opts.value, 'expression')\n : opts.value;\n // An empty object is a collection filled later, with no literal schema to keep.\n const isObject =\n RouteNodes.type(value) === AstNodeTypes.OBJECT_EXPRESSION &&\n RouteNodes.list(value, 'properties').length > 0;\n\n if (isObject && RouteNodes.isWideConfig(RouteNodes.annotation(opts.pattern))) {\n context.report({ node: opts.node, messageId: 'wideConfig' });\n }\n };\n\n return {\n [AstNodeTypes.FUNCTION_DECLARATION]: enterFunction,\n [AstNodeTypes.FUNCTION_EXPRESSION]: enterFunction,\n [AstNodeTypes.ARROW_FUNCTION_EXPRESSION]: enterFunction,\n [`${AstNodeTypes.FUNCTION_DECLARATION}:exit`]: leaveFunction,\n [`${AstNodeTypes.FUNCTION_EXPRESSION}:exit`]: leaveFunction,\n [`${AstNodeTypes.ARROW_FUNCTION_EXPRESSION}:exit`]: leaveFunction,\n [AstNodeTypes.CLASS_BODY]: () => {\n classes.push({ typed: new Map(), forwards: [] });\n },\n [`${AstNodeTypes.CLASS_BODY}:exit`]: () => {\n const facts = classes.pop();\n\n for (const { config, method, node } of facts?.forwards ?? []) {\n const actual = facts?.typed.get(method);\n\n if (actual !== undefined && actual !== config) {\n context.report({\n node,\n messageId: 'forwarded',\n data: { expected: config, method, actual },\n });\n }\n }\n },\n [AstNodeTypes.METHOD_DEFINITION]: (node: Rule.Node) => {\n const method = RouteNodes.nameOf(RouteNodes.field(node, 'key'));\n const typed = RouteNodes.list(RouteNodes.field(node, 'value'), 'params')\n .map((param) => RouteNodes.contextOf(param))\n .find((found) => found !== undefined);\n const actual = typed?.config;\n\n if (method === undefined || actual === undefined) {\n return;\n }\n\n classes.at(-1)?.typed.set(method, actual);\n\n for (const decorator of RouteNodes.list(node, 'decorators')) {\n const call = RouteNodes.field(decorator, 'expression');\n const name = RouteNodes.nameOf(RouteNodes.field(call, 'callee'));\n const [options] = RouteNodes.list(call, 'arguments');\n const expected = RouteNodes.chain(RouteNodes.property(options, 'configs'));\n\n if (\n name !== undefined &&\n RouteNodes.DECORATORS.has(name) &&\n expected !== undefined &&\n expected !== actual\n ) {\n context.report({ node, messageId: 'otherRoute', data: { expected, actual } });\n }\n }\n },\n [AstNodeTypes.VARIABLE_DECLARATOR]: (node: Rule.Node) => {\n const pattern = RouteNodes.field(node, 'id');\n const value = RouteNodes.field(node, 'init');\n checkDeclared({ node, pattern, value });\n\n const frame = frames.at(-1);\n\n if (!frame) {\n return;\n }\n\n const own = RouteNodes.nameOf(pattern);\n\n if (own !== undefined) {\n frame.declared.add(own);\n }\n\n const source = RouteNodes.chain(value);\n\n for (const property of RouteNodes.list(pattern, 'properties')) {\n const key = RouteNodes.nameOf(RouteNodes.field(property, 'key'));\n const bound = RouteNodes.nameOf(RouteNodes.field(property, 'value'));\n\n if (bound === undefined) {\n continue;\n }\n\n const holdsContext = source !== undefined && isTyped(`${source}.${key}`);\n frame.declared.add(bound);\n\n if (holdsContext) {\n frame.typed.add(bound);\n }\n }\n },\n [AstNodeTypes.PROPERTY_DEFINITION]: (node: Rule.Node) => {\n checkDeclared({\n node,\n pattern: node,\n value: RouteNodes.field(node, 'value'),\n });\n },\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n const callee = RouteNodes.field(node, 'callee');\n const request = RouteNodes.field(callee, 'object');\n\n if (\n RouteNodes.nameOf(RouteNodes.field(callee, 'property')) !== 'valid' ||\n RouteNodes.nameOf(RouteNodes.field(request, 'property')) !== 'req' ||\n RouteNodes.typeArguments(node).length === 0\n ) {\n return;\n }\n\n const holder = RouteNodes.chain(RouteNodes.field(request, 'object'));\n\n if (holder !== undefined && isTyped(holder)) {\n context.report({ node, messageId: 'typedValid' });\n }\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): Linter.RuleEntry {\n const { severity = 'error' } = opts;\n\n return [severity];\n }\n}\n"]}
@@ -0,0 +1,82 @@
1
+ import type { Linter, Rule } from 'eslint';
2
+ import type { TRuleSeverity } from '../rules/common';
3
+ /** The checks of `@venizia/zod-schema-convention`, as its options take them. */
4
+ export interface IZodSchemaConventionOptions {
5
+ /** A const that holds a schema is PascalCase and ends in `Schema`. @default true */
6
+ schemaName?: boolean;
7
+ /** A type inferred from a schema `XSchema` is named `TX` or `XType`. @default true */
8
+ typeName?: boolean;
9
+ /** Globs, from the working directory, of the files where an object schema is `z.strictObject`. @default [] */
10
+ strictPaths?: ReadonlyArray<string>;
11
+ /** Globs, from the working directory, of the files where `z.any()` is refused. @default [] */
12
+ noAnyPaths?: ReadonlyArray<string>;
13
+ /** `z.object({ ... }).strict()` is written `z.strictObject({ ... })`, in every file. @default true */
14
+ strictCall?: boolean;
15
+ /** Refuses `.passthrough()` on a schema. @default true */
16
+ noPassthrough?: boolean;
17
+ /** Globs, from the working directory, of the files where `z.coerce` is refused. @default [] */
18
+ noCoercePaths?: ReadonlyArray<string>;
19
+ /** Skips test files. @default true */
20
+ ignoreTests?: boolean;
21
+ /** Names of consts and types the two name checks leave alone. @default [] */
22
+ ignore?: ReadonlyArray<string>;
23
+ }
24
+ /**
25
+ * `@venizia/zod-schema-convention`. How a zod schema is named, how its inferred types are named, that a strict object
26
+ * is written `z.strictObject` and `.passthrough()` is not used and, in the files a project lists, that objects are
27
+ * strict and `any` and `z.coerce` are not used.
28
+ *
29
+ * A schema is recognised file by file, without types: a call chain that starts at an import of `zod` (or `z` of
30
+ * `@hono/zod-openapi`), at another schema const of the file, or at an import named `...Schema` / `..._SCHEMA` through a
31
+ * method that builds a schema (`extend`, `pick`, ...). An imported schema under another name, a member
32
+ * (`this.schema.extend`), a factory's result and a schema held in an object are not followed.
33
+ */
34
+ export declare class ZodSchemaConventionRule {
35
+ static readonly NAME = "@venizia/zod-schema-convention";
36
+ private static readonly ZOD_SOURCE;
37
+ /** Re-exports `z` next to its own functions (`createRoute`), so only its `z` is zod. */
38
+ private static readonly HONO_SOURCE;
39
+ private static readonly SCHEMA_NAME;
40
+ private static readonly SUFFIX;
41
+ /** An import that names a schema: something before the suffix, so a bare `Schema` of another library is not one. */
42
+ private static readonly IMPORTED_SCHEMA;
43
+ /** zod's classes: `ZodError.create([])` answers a value, not a schema. */
44
+ private static readonly ZOD_CLASS;
45
+ private static readonly TEST_FILE;
46
+ /** The methods that make a schema of an imported one; any other call on it may answer a value. */
47
+ private static readonly DERIVATIONS;
48
+ /** A chain through one of these answers a value, an error report or a part of a schema, not a schema. */
49
+ private static readonly NOT_A_SCHEMA;
50
+ /** The wrappers a type adds around an expression. */
51
+ private static readonly WRAPPERS;
52
+ private static readonly INFERENCES;
53
+ private static readString;
54
+ /** Whether the member access `node` leaves the schema: its value is not one. */
55
+ private static isOutside;
56
+ /**
57
+ * The identifier a call chain starts from, the member its first call goes through (`''` when it calls the identifier
58
+ * itself), when it has a call and stays a schema.
59
+ */
60
+ private static chainOf;
61
+ /** The declaration an identifier resolves to, from the scope it is read in. */
62
+ private static definitionOf;
63
+ /** The name zod exports what an import binds, when the import is zod's: `''` for a default or a namespace. */
64
+ private static zodImport;
65
+ /**
66
+ * Whether `expression` builds a schema; `seen` stops a declaration that refers to itself. `isNameTrusted` also takes
67
+ * an import named `...Schema` for one.
68
+ */
69
+ private static isSchema;
70
+ /** Whether a declaration is a const or a variable that holds a schema. */
71
+ private static isSchemaConst;
72
+ /** `saleOrder`, `SALE_ORDER` and `SaleOrder` are all `SaleOrder`. */
73
+ private static toPascalCase;
74
+ /** The name of the schema a type alias infers from, and by which inference; `undefined` for any other type. */
75
+ private static inferenceOf;
76
+ private static matches;
77
+ static readonly RULE: Rule.RuleModule;
78
+ static build(opts?: IZodSchemaConventionOptions & {
79
+ severity?: TRuleSeverity;
80
+ }): Linter.RuleEntry;
81
+ }
82
+ //# sourceMappingURL=zod-schema-convention.rule.d.ts.map