@venizia/dev-configs 0.4.6 → 0.4.7-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/LICENSE.md +1 -3
  2. package/README.md +1 -1
  3. package/dist/checks/catalog.d.ts +4 -2
  4. package/dist/checks/catalog.d.ts.map +1 -1
  5. package/dist/checks/catalog.js +72 -68
  6. package/dist/checks/catalog.js.map +1 -1
  7. package/dist/checks/module-cycles.d.ts +11 -9
  8. package/dist/checks/module-cycles.d.ts.map +1 -1
  9. package/dist/checks/module-cycles.js +32 -30
  10. package/dist/checks/module-cycles.js.map +1 -1
  11. package/dist/checks/purity/manifest.d.ts +44 -38
  12. package/dist/checks/purity/manifest.d.ts.map +1 -1
  13. package/dist/checks/purity/manifest.js +121 -115
  14. package/dist/checks/purity/manifest.js.map +1 -1
  15. package/dist/checks/purity/probe.d.ts +22 -18
  16. package/dist/checks/purity/probe.d.ts.map +1 -1
  17. package/dist/checks/purity/probe.js +101 -99
  18. package/dist/checks/purity/probe.js.map +1 -1
  19. package/dist/checks/purity/run.d.ts +18 -16
  20. package/dist/checks/purity/run.d.ts.map +1 -1
  21. package/dist/checks/purity/run.js +90 -86
  22. package/dist/checks/purity/run.js.map +1 -1
  23. package/dist/checks/test-controls.d.ts +17 -15
  24. package/dist/checks/test-controls.d.ts.map +1 -1
  25. package/dist/checks/test-controls.js +71 -69
  26. package/dist/checks/test-controls.js.map +1 -1
  27. package/dist/checks/test-dead-code.d.ts +5 -3
  28. package/dist/checks/test-dead-code.d.ts.map +1 -1
  29. package/dist/checks/test-dead-code.js +23 -21
  30. package/dist/checks/test-dead-code.js.map +1 -1
  31. package/dist/checks/test-mutate.d.ts +12 -7
  32. package/dist/checks/test-mutate.d.ts.map +1 -1
  33. package/dist/checks/test-mutate.js +59 -56
  34. package/dist/checks/test-mutate.js.map +1 -1
  35. package/dist/checks/test-weight.d.ts +11 -8
  36. package/dist/checks/test-weight.d.ts.map +1 -1
  37. package/dist/checks/test-weight.js +98 -94
  38. package/dist/checks/test-weight.js.map +1 -1
  39. package/dist/cli/check.d.ts.map +1 -1
  40. package/dist/cli/check.js +11 -8
  41. package/dist/cli/check.js.map +1 -1
  42. package/dist/cli/codemod/async-style.d.ts +62 -0
  43. package/dist/cli/codemod/async-style.d.ts.map +1 -0
  44. package/dist/cli/codemod/async-style.js +248 -0
  45. package/dist/cli/codemod/async-style.js.map +1 -0
  46. package/dist/cli/codemod/const-classes.d.ts.map +1 -1
  47. package/dist/cli/codemod/const-classes.js +2 -1
  48. package/dist/cli/codemod/const-classes.js.map +1 -1
  49. package/dist/cli/codemod/drop-redundant-casts.d.ts.map +1 -1
  50. package/dist/cli/codemod/drop-redundant-casts.js +2 -1
  51. package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
  52. package/dist/cli/codemod/files.d.ts +7 -0
  53. package/dist/cli/codemod/files.d.ts.map +1 -1
  54. package/dist/cli/codemod/files.js +33 -0
  55. package/dist/cli/codemod/files.js.map +1 -1
  56. package/dist/cli/codemod/index.d.ts.map +1 -1
  57. package/dist/cli/codemod/index.js +12 -3
  58. package/dist/cli/codemod/index.js.map +1 -1
  59. package/dist/cli/codemod/model-settings.d.ts +7 -5
  60. package/dist/cli/codemod/model-settings.d.ts.map +1 -1
  61. package/dist/cli/codemod/model-settings.js +293 -291
  62. package/dist/cli/codemod/model-settings.js.map +1 -1
  63. package/dist/cli/codemod/namespace-functions/index.d.ts +20 -0
  64. package/dist/cli/codemod/namespace-functions/index.d.ts.map +1 -0
  65. package/dist/cli/codemod/namespace-functions/index.js +182 -0
  66. package/dist/cli/codemod/namespace-functions/index.js.map +1 -0
  67. package/dist/cli/codemod/namespace-functions/logger-scope.d.ts +32 -0
  68. package/dist/cli/codemod/namespace-functions/logger-scope.d.ts.map +1 -0
  69. package/dist/cli/codemod/namespace-functions/logger-scope.js +128 -0
  70. package/dist/cli/codemod/namespace-functions/logger-scope.js.map +1 -0
  71. package/dist/cli/codemod/namespace-functions/mapping.d.ts +66 -0
  72. package/dist/cli/codemod/namespace-functions/mapping.d.ts.map +1 -0
  73. package/dist/cli/codemod/namespace-functions/mapping.js +99 -0
  74. package/dist/cli/codemod/namespace-functions/mapping.js.map +1 -0
  75. package/dist/cli/codemod/namespace-functions/mappings/boot.d.ts +7 -0
  76. package/dist/cli/codemod/namespace-functions/mappings/boot.d.ts.map +1 -0
  77. package/dist/cli/codemod/namespace-functions/mappings/boot.js +28 -0
  78. package/dist/cli/codemod/namespace-functions/mappings/boot.js.map +1 -0
  79. package/dist/cli/codemod/namespace-functions/mappings/connectors.d.ts +4 -0
  80. package/dist/cli/codemod/namespace-functions/mappings/connectors.d.ts.map +1 -0
  81. package/dist/cli/codemod/namespace-functions/mappings/connectors.js +218 -0
  82. package/dist/cli/codemod/namespace-functions/mappings/connectors.js.map +1 -0
  83. package/dist/cli/codemod/namespace-functions/mappings/core-server.d.ts +7 -0
  84. package/dist/cli/codemod/namespace-functions/mappings/core-server.d.ts.map +1 -0
  85. package/dist/cli/codemod/namespace-functions/mappings/core-server.js +162 -0
  86. package/dist/cli/codemod/namespace-functions/mappings/core-server.js.map +1 -0
  87. package/dist/cli/codemod/namespace-functions/mappings/core-worker.d.ts +7 -0
  88. package/dist/cli/codemod/namespace-functions/mappings/core-worker.d.ts.map +1 -0
  89. package/dist/cli/codemod/namespace-functions/mappings/core-worker.js +18 -0
  90. package/dist/cli/codemod/namespace-functions/mappings/core-worker.js.map +1 -0
  91. package/dist/cli/codemod/namespace-functions/mappings/dev-configs.d.ts +7 -0
  92. package/dist/cli/codemod/namespace-functions/mappings/dev-configs.d.ts.map +1 -0
  93. package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js +192 -0
  94. package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js.map +1 -0
  95. package/dist/cli/codemod/namespace-functions/mappings/filter.d.ts +7 -0
  96. package/dist/cli/codemod/namespace-functions/mappings/filter.d.ts.map +1 -0
  97. package/dist/cli/codemod/namespace-functions/mappings/filter.js +30 -0
  98. package/dist/cli/codemod/namespace-functions/mappings/filter.js.map +1 -0
  99. package/dist/cli/codemod/namespace-functions/mappings/helpers.d.ts +16 -0
  100. package/dist/cli/codemod/namespace-functions/mappings/helpers.d.ts.map +1 -0
  101. package/dist/cli/codemod/namespace-functions/mappings/helpers.js +535 -0
  102. package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -0
  103. package/dist/cli/codemod/namespace-functions/mappings/index.d.ts +4 -0
  104. package/dist/cli/codemod/namespace-functions/mappings/index.d.ts.map +1 -0
  105. package/dist/cli/codemod/namespace-functions/mappings/index.js +25 -0
  106. package/dist/cli/codemod/namespace-functions/mappings/index.js.map +1 -0
  107. package/dist/cli/codemod/namespace-functions/mappings/inversion.d.ts +10 -0
  108. package/dist/cli/codemod/namespace-functions/mappings/inversion.d.ts.map +1 -0
  109. package/dist/cli/codemod/namespace-functions/mappings/inversion.js +81 -0
  110. package/dist/cli/codemod/namespace-functions/mappings/inversion.js.map +1 -0
  111. package/dist/cli/codemod/namespace-functions/mappings/kernel.d.ts +17 -0
  112. package/dist/cli/codemod/namespace-functions/mappings/kernel.d.ts.map +1 -0
  113. package/dist/cli/codemod/namespace-functions/mappings/kernel.js +229 -0
  114. package/dist/cli/codemod/namespace-functions/mappings/kernel.js.map +1 -0
  115. package/dist/cli/codemod/namespace-functions/rewriter.d.ts +61 -0
  116. package/dist/cli/codemod/namespace-functions/rewriter.d.ts.map +1 -0
  117. package/dist/cli/codemod/namespace-functions/rewriter.js +564 -0
  118. package/dist/cli/codemod/namespace-functions/rewriter.js.map +1 -0
  119. package/dist/cli/index.js +2 -0
  120. package/dist/cli/index.js.map +1 -1
  121. package/dist/compilers/bun.d.ts +1 -1
  122. package/dist/compilers/bun.js +1 -1
  123. package/dist/compilers/bun.js.map +1 -1
  124. package/dist/linters/house/await-support.d.ts +74 -0
  125. package/dist/linters/house/await-support.d.ts.map +1 -0
  126. package/dist/linters/house/await-support.js +238 -0
  127. package/dist/linters/house/await-support.js.map +1 -0
  128. package/dist/linters/house/common.d.ts +15 -9
  129. package/dist/linters/house/common.d.ts.map +1 -1
  130. package/dist/linters/house/common.js +20 -15
  131. package/dist/linters/house/common.js.map +1 -1
  132. package/dist/linters/house/configs.d.ts +26 -0
  133. package/dist/linters/house/configs.d.ts.map +1 -1
  134. package/dist/linters/house/configs.js +55 -1
  135. package/dist/linters/house/configs.js.map +1 -1
  136. package/dist/linters/house/const-class-values.rule.d.ts.map +1 -1
  137. package/dist/linters/house/const-class-values.rule.js +27 -19
  138. package/dist/linters/house/const-class-values.rule.js.map +1 -1
  139. package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +17 -0
  140. package/dist/linters/house/effect-cleanup-consistency.rule.d.ts.map +1 -0
  141. package/dist/linters/house/effect-cleanup-consistency.rule.js +87 -0
  142. package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -0
  143. package/dist/linters/house/hook-support.d.ts +29 -0
  144. package/dist/linters/house/hook-support.d.ts.map +1 -0
  145. package/dist/linters/house/hook-support.js +72 -0
  146. package/dist/linters/house/hook-support.js.map +1 -0
  147. package/dist/linters/house/index.d.ts +9 -0
  148. package/dist/linters/house/index.d.ts.map +1 -1
  149. package/dist/linters/house/index.js +9 -0
  150. package/dist/linters/house/index.js.map +1 -1
  151. package/dist/linters/house/max-params-own.rule.d.ts.map +1 -1
  152. package/dist/linters/house/max-params-own.rule.js +33 -24
  153. package/dist/linters/house/max-params-own.rule.js.map +1 -1
  154. package/dist/linters/house/no-async-hook-callback.rule.d.ts +18 -0
  155. package/dist/linters/house/no-async-hook-callback.rule.d.ts.map +1 -0
  156. package/dist/linters/house/no-async-hook-callback.rule.js +50 -0
  157. package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -0
  158. package/dist/linters/house/no-await-promise-chain.rule.d.ts +24 -0
  159. package/dist/linters/house/no-await-promise-chain.rule.d.ts.map +1 -0
  160. package/dist/linters/house/no-await-promise-chain.rule.js +298 -0
  161. package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -0
  162. package/dist/linters/house/no-inline-await.rule.d.ts +20 -0
  163. package/dist/linters/house/no-inline-await.rule.d.ts.map +1 -0
  164. package/dist/linters/house/no-inline-await.rule.js +70 -0
  165. package/dist/linters/house/no-inline-await.rule.js.map +1 -0
  166. package/dist/linters/house/no-new-error.rule.js +4 -4
  167. package/dist/linters/house/no-new-error.rule.js.map +1 -1
  168. package/dist/linters/house/no-return-await.rule.d.ts +15 -0
  169. package/dist/linters/house/no-return-await.rule.d.ts.map +1 -0
  170. package/dist/linters/house/no-return-await.rule.js +92 -0
  171. package/dist/linters/house/no-return-await.rule.js.map +1 -0
  172. package/dist/linters/house/no-silent-catch.rule.d.ts +22 -0
  173. package/dist/linters/house/no-silent-catch.rule.d.ts.map +1 -0
  174. package/dist/linters/house/no-silent-catch.rule.js +88 -0
  175. package/dist/linters/house/no-silent-catch.rule.js.map +1 -0
  176. package/dist/linters/house/plugin.d.ts.map +1 -1
  177. package/dist/linters/house/plugin.js +12 -0
  178. package/dist/linters/house/plugin.js.map +1 -1
  179. package/dist/linters/house/promise-chain-support.d.ts +49 -0
  180. package/dist/linters/house/promise-chain-support.d.ts.map +1 -0
  181. package/dist/linters/house/promise-chain-support.js +188 -0
  182. package/dist/linters/house/promise-chain-support.js.map +1 -0
  183. package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
  184. package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
  185. package/dist/testing/rejection.helper.d.ts +25 -20
  186. package/dist/testing/rejection.helper.d.ts.map +1 -1
  187. package/dist/testing/rejection.helper.js +33 -31
  188. package/dist/testing/rejection.helper.js.map +1 -1
  189. package/dist/testing/repo-tmp.d.ts +19 -9
  190. package/dist/testing/repo-tmp.d.ts.map +1 -1
  191. package/dist/testing/repo-tmp.js +50 -48
  192. package/dist/testing/repo-tmp.js.map +1 -1
  193. package/dist/testing/spawn.helper.d.ts +12 -10
  194. package/dist/testing/spawn.helper.d.ts.map +1 -1
  195. package/dist/testing/spawn.helper.js +22 -16
  196. package/dist/testing/spawn.helper.js.map +1 -1
  197. package/dist/testing/tmpdir-preload.js +1 -1
  198. package/dist/testing/tmpdir-preload.js.map +1 -1
  199. package/package.json +2 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-support.js","sourceRoot":"","sources":["../../../src/linters/house/hook-support.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAEnC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,CAAC,CAAC,CAAC;AACrF,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,yBAAyB,EAAE,oBAAoB,CAAC,CAAC,CAAC;AAElF,sGAAsG;AACtG,MAAa,WAAW;IACtB,wHAAwH;IACxH,MAAM,CAAC,UAAU,CAAC,IAAuB;QACvC,MAAM,MAAM,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrE,MAAM,IAAI,GAAG,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAE/C,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;YAC9D,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACrD,CAAC;QAED,IACE,IAAI,KAAK,kBAAkB;YAC3B,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,KAAK,KAAK,EAC9D,CAAC;YACD,MAAM,QAAQ,GAA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AAC;CACF;AAjFD,kCAiFC","sourcesContent":["import { AstNode } from './common';\n\nconst HOOK_NAME = /^use[A-Z]/;\nconst EFFECT_HOOKS = new Set(['useEffect', 'useLayoutEffect', 'useInsertionEffect']);\nconst CALLBACK_TYPES = new Set(['ArrowFunctionExpression', 'FunctionExpression']);\n\n/** The shared parts of the two hook rules: which call is a hook, and which argument is a function. */\nexport class HookSupport {\n /** `useX(...)` and `React.useX(...)`: the name the call is made through, or `undefined` when it is not a plain name. */\n static calleeName(opts: { call: unknown }): string | undefined {\n const callee = AstNode.readField({ node: opts.call, key: 'callee' });\n const type = AstNode.getType({ node: callee });\n\n if (type === 'Identifier') {\n const name = AstNode.readField({ node: callee, key: 'name' });\n return typeof name === 'string' ? name : undefined;\n }\n\n if (\n type === 'MemberExpression' &&\n AstNode.readField({ node: callee, key: 'computed' }) === false\n ) {\n const property = AstNode.readField({ node: callee, key: 'property' });\n const name = AstNode.readField({ node: property, key: 'name' });\n return AstNode.getType({ node: property }) === 'Identifier' && typeof name === 'string'\n ? name\n : undefined;\n }\n\n return undefined;\n }\n\n static isHook(opts: { name: string | undefined }): boolean {\n return opts.name !== undefined && HOOK_NAME.test(opts.name);\n }\n\n static isEffectHook(opts: { name: string | undefined }): boolean {\n return opts.name !== undefined && EFFECT_HOOKS.has(opts.name);\n }\n\n /** An arrow or a function expression: the two forms a hook callback is written in. */\n static isCallback(opts: { node: unknown }): boolean {\n return CALLBACK_TYPES.has(AstNode.getType({ node: opts.node }) ?? '');\n }\n\n static isAsync(opts: { node: unknown }): boolean {\n return (\n HookSupport.isCallback(opts) && AstNode.readField({ node: opts.node, key: 'async' }) === true\n );\n }\n\n /**\n * The async functions an argument hands over: the argument itself, a property value of an object literal\n * (`useMutation({ mutationFn: async () => {} })`, an async method too) and an element of an array literal, at any\n * depth of literals. It does not look inside a function: what a sync callback builds is not an argument.\n */\n static asyncFunctionsIn(opts: { node: unknown }): unknown[] {\n const { node } = opts;\n const type = AstNode.getType({ node });\n\n if (HookSupport.isAsync({ node })) {\n return [node];\n }\n\n if (type === 'ObjectExpression') {\n const properties = AstNode.readField({ node, key: 'properties' });\n\n return Array.isArray(properties)\n ? properties.flatMap((property) =>\n AstNode.getType({ node: property }) === 'Property'\n ? HookSupport.asyncFunctionsIn({\n node: AstNode.readField({ node: property, key: 'value' }),\n })\n : [],\n )\n : [];\n }\n\n if (type === 'ArrayExpression') {\n const elements = AstNode.readField({ node, key: 'elements' });\n\n return Array.isArray(elements)\n ? elements.flatMap((element) => HookSupport.asyncFunctionsIn({ node: element }))\n : [];\n }\n\n return [];\n }\n}\n"]}
@@ -1,8 +1,17 @@
1
+ export * from './await-support';
1
2
  export * from './common';
2
3
  export * from './const-class-values.rule';
4
+ export * from './effect-cleanup-consistency.rule';
5
+ export * from './hook-support';
3
6
  export * from './max-params-own.rule';
7
+ export * from './no-async-hook-callback.rule';
8
+ export * from './no-await-promise-chain.rule';
9
+ export * from './no-inline-await.rule';
4
10
  export * from './no-leaked-render.rule';
5
11
  export * from './no-new-error.rule';
12
+ export * from './no-return-await.rule';
13
+ export * from './no-silent-catch.rule';
6
14
  export * from './plugin';
15
+ export * from './promise-chain-support';
7
16
  export * from './configs';
8
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linters/house/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linters/house/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC"}
@@ -14,11 +14,20 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./await-support"), exports);
17
18
  __exportStar(require("./common"), exports);
18
19
  __exportStar(require("./const-class-values.rule"), exports);
20
+ __exportStar(require("./effect-cleanup-consistency.rule"), exports);
21
+ __exportStar(require("./hook-support"), exports);
19
22
  __exportStar(require("./max-params-own.rule"), exports);
23
+ __exportStar(require("./no-async-hook-callback.rule"), exports);
24
+ __exportStar(require("./no-await-promise-chain.rule"), exports);
25
+ __exportStar(require("./no-inline-await.rule"), exports);
20
26
  __exportStar(require("./no-leaked-render.rule"), exports);
21
27
  __exportStar(require("./no-new-error.rule"), exports);
28
+ __exportStar(require("./no-return-await.rule"), exports);
29
+ __exportStar(require("./no-silent-catch.rule"), exports);
22
30
  __exportStar(require("./plugin"), exports);
31
+ __exportStar(require("./promise-chain-support"), exports);
23
32
  __exportStar(require("./configs"), exports);
24
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/linters/house/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4DAA0C;AAC1C,wDAAsC;AACtC,0DAAwC;AACxC,sDAAoC;AACpC,2CAAyB;AACzB,4CAA0B","sourcesContent":["export * from './common';\nexport * from './const-class-values.rule';\nexport * from './max-params-own.rule';\nexport * from './no-leaked-render.rule';\nexport * from './no-new-error.rule';\nexport * from './plugin';\nexport * from './configs';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/linters/house/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,2CAAyB;AACzB,4DAA0C;AAC1C,oEAAkD;AAClD,iDAA+B;AAC/B,wDAAsC;AACtC,gEAA8C;AAC9C,gEAA8C;AAC9C,yDAAuC;AACvC,0DAAwC;AACxC,sDAAoC;AACpC,yDAAuC;AACvC,yDAAuC;AACvC,2CAAyB;AACzB,0DAAwC;AACxC,4CAA0B","sourcesContent":["export * from './await-support';\nexport * from './common';\nexport * from './const-class-values.rule';\nexport * from './effect-cleanup-consistency.rule';\nexport * from './hook-support';\nexport * from './max-params-own.rule';\nexport * from './no-async-hook-callback.rule';\nexport * from './no-await-promise-chain.rule';\nexport * from './no-inline-await.rule';\nexport * from './no-leaked-render.rule';\nexport * from './no-new-error.rule';\nexport * from './no-return-await.rule';\nexport * from './no-silent-catch.rule';\nexport * from './plugin';\nexport * from './promise-chain-support';\nexport * from './configs';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"max-params-own.rule.d.ts","sourceRoot":"","sources":["../../../src/linters/house/max-params-own.rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAyDrD;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,QAAQ,CAAC,IAAI,4BAA8C;IAElE,MAAM,CAAC,QAAQ,CAAC,WAAW,KAAK;IAEhC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAmFnC;IAEF,MAAM,CAAC,KAAK,CAAC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,aAAa,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,MAAM,CAAC,SAAS;CAItF"}
1
+ {"version":3,"file":"max-params-own.rule.d.ts","sourceRoot":"","sources":["../../../src/linters/house/max-params-own.rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAgErD;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,QAAQ,CAAC,IAAI,4BAA8C;IAElE,MAAM,CAAC,QAAQ,CAAC,WAAW,KAAK;IAEhC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAuFnC;IAEF,MAAM,CAAC,KAAK,CAAC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,aAAa,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,MAAM,CAAC,SAAS;CAItF"}
@@ -7,14 +7,16 @@ const CALL_TYPES = new Set(['CallExpression', 'NewExpression']);
7
7
  const isArrayContaining = (opts) => Array.isArray(opts.list) && opts.list.includes(opts.item);
8
8
  /** `useX(...)`: a hook's callback is ours, so it counts. */
9
9
  const isHookCall = (call) => {
10
- const callee = (0, common_1.readField)({ node: call, key: 'callee' });
11
- const name = (0, common_1.readField)({ node: callee, key: 'name' });
12
- return ((0, common_1.nodeType)({ node: callee }) === 'Identifier' && typeof name === 'string' && HOOK_NAME.test(name));
10
+ const callee = common_1.AstNode.readField({ node: call, key: 'callee' });
11
+ const name = common_1.AstNode.readField({ node: callee, key: 'name' });
12
+ return (common_1.AstNode.getType({ node: callee }) === 'Identifier' &&
13
+ typeof name === 'string' &&
14
+ HOOK_NAME.test(name));
13
15
  };
14
16
  /** `node` is an argument of a call or `new` that is not a hook. */
15
- const isLibraryArgument = (opts) => CALL_TYPES.has((0, common_1.nodeType)({ node: opts.parent }) ?? '') &&
17
+ const isLibraryArgument = (opts) => CALL_TYPES.has(common_1.AstNode.getType({ node: opts.parent }) ?? '') &&
16
18
  isArrayContaining({
17
- list: (0, common_1.readField)({ node: opts.parent, key: 'arguments' }),
19
+ list: common_1.AstNode.readField({ node: opts.parent, key: 'arguments' }),
18
20
  item: opts.node,
19
21
  }) &&
20
22
  !isHookCall(opts.parent);
@@ -25,17 +27,20 @@ const isLibraryArgument = (opts) => CALL_TYPES.has((0, common_1.nodeType)({ node
25
27
  const hasDeclaredShape = (object) => {
26
28
  let current = object;
27
29
  while (current) {
28
- const parent = (0, common_1.readField)({ node: current, key: 'parent' });
29
- const parentType = (0, common_1.nodeType)({ node: parent });
30
+ const parent = common_1.AstNode.readField({ node: current, key: 'parent' });
31
+ const parentType = common_1.AstNode.getType({ node: parent });
30
32
  const isTypedVariable = parentType === 'VariableDeclarator' &&
31
- Boolean((0, common_1.readField)({ node: (0, common_1.readField)({ node: parent, key: 'id' }), key: 'typeAnnotation' }));
33
+ Boolean(common_1.AstNode.readField({
34
+ node: common_1.AstNode.readField({ node: parent, key: 'id' }),
35
+ key: 'typeAnnotation',
36
+ }));
32
37
  if (isTypedVariable ||
33
38
  parentType === 'TSSatisfiesExpression' ||
34
39
  isLibraryArgument({ node: current, parent })) {
35
40
  return true;
36
41
  }
37
- const isNestedValue = parentType === 'Property' && (0, common_1.readField)({ node: parent, key: 'value' }) === current;
38
- current = isNestedValue ? (0, common_1.readField)({ node: parent, key: 'parent' }) : undefined;
42
+ const isNestedValue = parentType === 'Property' && common_1.AstNode.readField({ node: parent, key: 'value' }) === current;
43
+ current = isNestedValue ? common_1.AstNode.readField({ node: parent, key: 'parent' }) : undefined;
39
44
  }
40
45
  return false;
41
46
  };
@@ -61,39 +66,43 @@ class MaxParamsOwnRule {
61
66
  const max = typeof context.options[0] === 'number' ? context.options[0] : MaxParamsOwnRule.DEFAULT_MAX;
62
67
  const isCallback = (node) => {
63
68
  const parent = node.parent;
64
- const isJsxProp = (0, common_1.nodeType)({ node: parent }) === 'JSXExpressionContainer' &&
65
- (0, common_1.nodeType)({ node: (0, common_1.readField)({ node: parent, key: 'parent' }) }) === 'JSXAttribute';
69
+ const isJsxProp = common_1.AstNode.getType({ node: parent }) === 'JSXExpressionContainer' &&
70
+ common_1.AstNode.getType({ node: common_1.AstNode.readField({ node: parent, key: 'parent' }) }) ===
71
+ 'JSXAttribute';
66
72
  return isJsxProp || isLibraryArgument({ node, parent });
67
73
  };
68
74
  const isInjectedConstructor = (opts) => {
69
75
  const parent = opts.node.parent;
70
76
  const isDecorated = (param) => {
71
- const own = (0, common_1.readField)({ node: param, key: 'decorators' });
72
- const property = (0, common_1.readField)({
73
- node: (0, common_1.readField)({ node: param, key: 'parameter' }),
77
+ const own = common_1.AstNode.readField({ node: param, key: 'decorators' });
78
+ const property = common_1.AstNode.readField({
79
+ node: common_1.AstNode.readField({ node: param, key: 'parameter' }),
74
80
  key: 'decorators',
75
81
  });
76
82
  return ((Array.isArray(own) && own.length > 0) ||
77
83
  (Array.isArray(property) && property.length > 0));
78
84
  };
79
- return ((0, common_1.nodeType)({ node: parent }) === 'MethodDefinition' &&
80
- (0, common_1.readField)({ node: parent, key: 'kind' }) === 'constructor' &&
85
+ return (common_1.AstNode.getType({ node: parent }) === 'MethodDefinition' &&
86
+ common_1.AstNode.readField({ node: parent, key: 'kind' }) === 'constructor' &&
81
87
  opts.params.every(isDecorated));
82
88
  };
83
89
  const isTypedByContext = (node) => {
84
90
  const parent = node.parent;
85
- const parentType = (0, common_1.nodeType)({ node: parent });
91
+ const parentType = common_1.AstNode.getType({ node: parent });
86
92
  const isTypedInit = parentType === 'VariableDeclarator' &&
87
- (0, common_1.readField)({ node: parent, key: 'init' }) === node &&
88
- Boolean((0, common_1.readField)({ node: (0, common_1.readField)({ node: parent, key: 'id' }), key: 'typeAnnotation' }));
89
- const grandParent = (0, common_1.readField)({ node: parent, key: 'parent' });
93
+ common_1.AstNode.readField({ node: parent, key: 'init' }) === node &&
94
+ Boolean(common_1.AstNode.readField({
95
+ node: common_1.AstNode.readField({ node: parent, key: 'id' }),
96
+ key: 'typeAnnotation',
97
+ }));
98
+ const grandParent = common_1.AstNode.readField({ node: parent, key: 'parent' });
90
99
  const isMember = parentType === 'Property' &&
91
- (0, common_1.readField)({ node: parent, key: 'value' }) === node &&
92
- (0, common_1.nodeType)({ node: grandParent }) === 'ObjectExpression';
100
+ common_1.AstNode.readField({ node: parent, key: 'value' }) === node &&
101
+ common_1.AstNode.getType({ node: grandParent }) === 'ObjectExpression';
93
102
  return isTypedInit || (isMember && hasDeclaredShape(grandParent));
94
103
  };
95
104
  const check = (node) => {
96
- const params = (0, common_1.readField)({ node, key: 'params' });
105
+ const params = common_1.AstNode.readField({ node, key: 'params' });
97
106
  if (!Array.isArray(params) || params.length <= max) {
98
107
  return;
99
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"max-params-own.rule.js","sourceRoot":"","sources":["../../../src/linters/house/max-params-own.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAqF;AAErF,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC;AAEhE,MAAM,iBAAiB,GAAG,CAAC,IAAsC,EAAE,EAAE,CACnE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE5D,4DAA4D;AAC5D,MAAM,UAAU,GAAG,CAAC,IAAa,EAAE,EAAE;IACnC,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,IAAA,kBAAS,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,M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qBAAqB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC1F,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,SAAS;oBACpB,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE;iBACzD,CAAC,CAAC;YACL,CAAC,CAAC;YAEF,OAAO;gBACL,CAAC,qBAAY,CAAC,oBAAoB,CAAC,EAAE,KAAK;gBAC1C,CAAC,qBAAY,CAAC,mBAAmB,CAAC,EAAE,KAAK;gBACzC,CAAC,qBAAY,CAAC,yBAAyB,CAAC,EAAE,KAAK;aAChD,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAmD,EAAE;QAChE,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,GAAG,gBAAgB,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC;QACxE,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACzB,CAAC;;AA7FH,4CA8FC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNodeTypes, HOUSE_PLUGIN_NAMESPACE, nodeType, readField } from './common';\n\nconst HOOK_NAME = /^use[A-Z]/;\nconst CALL_TYPES = new Set(['CallExpression', 'NewExpression']);\n\nconst isArrayContaining = (opts: { list: unknown; item: unknown }) =>\n Array.isArray(opts.list) && opts.list.includes(opts.item);\n\n/** `useX(...)`: a hook's callback is ours, so it counts. */\nconst isHookCall = (call: unknown) => {\n const callee = readField({ node: call, key: 'callee' });\n const name = readField({ node: callee, key: 'name' });\n return (\n nodeType({ node: callee }) === 'Identifier' && typeof name === 'string' && HOOK_NAME.test(name)\n );\n};\n\n/** `node` is an argument of a call or `new` that is not a hook. */\nconst isLibraryArgument = (opts: { node: unknown; parent: unknown }) =>\n CALL_TYPES.has(nodeType({ node: opts.parent }) ?? '') &&\n isArrayContaining({\n list: readField({ node: opts.parent, key: 'arguments' }),\n item: opts.node,\n }) &&\n !isHookCall(opts.parent);\n\n/**\n * An object literal whose shape something else declares: a typed variable, `satisfies`, or an argument\n * of a non-hook call (a library option bag). A nested literal inherits it.\n */\nconst hasDeclaredShape = (object: unknown): boolean => {\n let current = object;\n\n while (current) {\n const parent = readField({ node: current, key: 'parent' });\n const parentType = nodeType({ node: parent });\n const isTypedVariable =\n parentType === 'VariableDeclarator' &&\n Boolean(readField({ node: readField({ node: parent, key: 'id' }), key: 'typeAnnotation' }));\n\n if (\n isTypedVariable ||\n parentType === 'TSSatisfiesExpression' ||\n isLibraryArgument({ node: current, parent })\n ) {\n return true;\n }\n\n const isNestedValue =\n parentType === 'Property' && readField({ node: parent, key: 'value' }) === current;\n current = isNestedValue ? readField({ node: parent, key: 'parent' }) : undefined;\n }\n\n return false;\n};\n\n/**\n * `venizia/max-params-own`. A function we write takes at most `max` (default 5) positional parameters;\n * beyond that it takes one options object. A signature that belongs to someone else is not counted: an\n * inline callback handed to a call (map, reduce, sort, a library handler) or to a JSX prop, a function a\n * declared type fixes (`const x: TFn = (...)`, a member of a typed or `satisfies` object), and a\n * constructor whose every parameter is injected (`@inject`). A hook's callback (`useCallback(...)`) is ours.\n */\nexport class MaxParamsOwnRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/max-params-own`;\n\n static readonly DEFAULT_MAX = 5;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [{ type: 'integer', minimum: 0 }],\n messages: {\n tooMany:\n 'A function we write takes up to {{max}} positional parameters, not {{count}}: take one options object.',\n },\n },\n create: (context) => {\n const max =\n typeof context.options[0] === 'number' ? context.options[0] : MaxParamsOwnRule.DEFAULT_MAX;\n\n const isCallback = (node: Rule.Node) => {\n const parent = node.parent;\n const isJsxProp =\n nodeType({ node: parent }) === 'JSXExpressionContainer' &&\n nodeType({ node: readField({ node: parent, key: 'parent' }) }) === 'JSXAttribute';\n return isJsxProp || isLibraryArgument({ node, parent });\n };\n\n const isInjectedConstructor = (opts: { node: Rule.Node; params: unknown[] }) => {\n const parent = opts.node.parent;\n const isDecorated = (param: unknown) => {\n const own = readField({ node: param, key: 'decorators' });\n const property = readField({\n node: readField({ node: param, key: 'parameter' }),\n key: 'decorators',\n });\n return (\n (Array.isArray(own) && own.length > 0) ||\n (Array.isArray(property) && property.length > 0)\n );\n };\n\n return (\n nodeType({ node: parent }) === 'MethodDefinition' &&\n readField({ node: parent, key: 'kind' }) === 'constructor' &&\n opts.params.every(isDecorated)\n );\n };\n\n const isTypedByContext = (node: Rule.Node) => {\n const parent = node.parent;\n const parentType = nodeType({ node: parent });\n const isTypedInit =\n parentType === 'VariableDeclarator' &&\n readField({ node: parent, key: 'init' }) === node &&\n Boolean(\n readField({ node: readField({ node: parent, key: 'id' }), key: 'typeAnnotation' }),\n );\n const grandParent = readField({ node: parent, key: 'parent' });\n const isMember =\n parentType === 'Property' &&\n readField({ node: parent, key: 'value' }) === node &&\n nodeType({ node: grandParent }) === 'ObjectExpression';\n\n return isTypedInit || (isMember && hasDeclaredShape(grandParent));\n };\n\n const check = (node: Rule.Node) => {\n const params = readField({ node, key: 'params' });\n if (!Array.isArray(params) || params.length <= max) {\n return;\n }\n\n if (isCallback(node) || isInjectedConstructor({ node, params }) || isTypedByContext(node)) {\n return;\n }\n\n context.report({\n node,\n messageId: 'tooMany',\n data: { count: String(params.length), max: String(max) },\n });\n };\n\n return {\n [AstNodeTypes.FUNCTION_DECLARATION]: check,\n [AstNodeTypes.FUNCTION_EXPRESSION]: check,\n [AstNodeTypes.ARROW_FUNCTION_EXPRESSION]: check,\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity; max?: number } = {}): Linter.RuleEntry {\n const { severity = 'error', max = MaxParamsOwnRule.DEFAULT_MAX } = opts;\n return [severity, max];\n }\n}\n"]}
1
+ {"version":3,"file":"max-params-own.rule.js","sourceRoot":"","sources":["../../../src/linters/house/max-params-own.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC;AAEhE,MAAM,iBAAiB,GAAG,CAAC,IAAsC,EAAE,EAAE,CACnE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE5D,4DAA4D;AAC5D,MAAM,UAAU,GAAG,CAAC,IAAa,EAAE,EAAE;IACnC,MAAM,MAAM,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,OAAO,CACL,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,YAAY;QAClD,OAAO,IAAI,KAAK,QAAQ;QACxB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CACrB,CAAC;AACJ,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,iBAAiB,GAAG,CAAC,IAAwC,EAAE,EAAE,CACrE,UAAU,CAAC,GAAG,CAAC,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;IAC5D,iBAAiB,CAAC;QAChB,IAAI,EAAE,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,GA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AC,qBAAY,CAAC,oBAAoB,CAAC,EAAE,KAAK;gBAC1C,CAAC,qBAAY,CAAC,mBAAmB,CAAC,EAAE,KAAK;gBACzC,CAAC,qBAAY,CAAC,yBAAyB,CAAC,EAAE,KAAK;aAChD,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAmD,EAAE;QAChE,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,GAAG,gBAAgB,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC;QACxE,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACzB,CAAC;;AAjGH,4CAkGC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\nconst HOOK_NAME = /^use[A-Z]/;\nconst CALL_TYPES = new Set(['CallExpression', 'NewExpression']);\n\nconst isArrayContaining = (opts: { list: unknown; item: unknown }) =>\n Array.isArray(opts.list) && opts.list.includes(opts.item);\n\n/** `useX(...)`: a hook's callback is ours, so it counts. */\nconst isHookCall = (call: unknown) => {\n const callee = AstNode.readField({ node: call, key: 'callee' });\n const name = AstNode.readField({ node: callee, key: 'name' });\n return (\n AstNode.getType({ node: callee }) === 'Identifier' &&\n typeof name === 'string' &&\n HOOK_NAME.test(name)\n );\n};\n\n/** `node` is an argument of a call or `new` that is not a hook. */\nconst isLibraryArgument = (opts: { node: unknown; parent: unknown }) =>\n CALL_TYPES.has(AstNode.getType({ node: opts.parent }) ?? '') &&\n isArrayContaining({\n list: AstNode.readField({ node: opts.parent, key: 'arguments' }),\n item: opts.node,\n }) &&\n !isHookCall(opts.parent);\n\n/**\n * An object literal whose shape something else declares: a typed variable, `satisfies`, or an argument\n * of a non-hook call (a library option bag). A nested literal inherits it.\n */\nconst hasDeclaredShape = (object: unknown): boolean => {\n let current = object;\n\n while (current) {\n const parent = AstNode.readField({ node: current, key: 'parent' });\n const parentType = AstNode.getType({ node: parent });\n const isTypedVariable =\n parentType === 'VariableDeclarator' &&\n Boolean(\n AstNode.readField({\n node: AstNode.readField({ node: parent, key: 'id' }),\n key: 'typeAnnotation',\n }),\n );\n\n if (\n isTypedVariable ||\n parentType === 'TSSatisfiesExpression' ||\n isLibraryArgument({ node: current, parent })\n ) {\n return true;\n }\n\n const isNestedValue =\n parentType === 'Property' && AstNode.readField({ node: parent, key: 'value' }) === current;\n current = isNestedValue ? AstNode.readField({ node: parent, key: 'parent' }) : undefined;\n }\n\n return false;\n};\n\n/**\n * `venizia/max-params-own`. A function we write takes at most `max` (default 5) positional parameters;\n * beyond that it takes one options object. A signature that belongs to someone else is not counted: an\n * inline callback handed to a call (map, reduce, sort, a library handler) or to a JSX prop, a function a\n * declared type fixes (`const x: TFn = (...)`, a member of a typed or `satisfies` object), and a\n * constructor whose every parameter is injected (`@inject`). A hook's callback (`useCallback(...)`) is ours.\n */\nexport class MaxParamsOwnRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/max-params-own`;\n\n static readonly DEFAULT_MAX = 5;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [{ type: 'integer', minimum: 0 }],\n messages: {\n tooMany:\n 'A function we write takes up to {{max}} positional parameters, not {{count}}: take one options object.',\n },\n },\n create: (context) => {\n const max =\n typeof context.options[0] === 'number' ? context.options[0] : MaxParamsOwnRule.DEFAULT_MAX;\n\n const isCallback = (node: Rule.Node) => {\n const parent = node.parent;\n const isJsxProp =\n AstNode.getType({ node: parent }) === 'JSXExpressionContainer' &&\n AstNode.getType({ node: AstNode.readField({ node: parent, key: 'parent' }) }) ===\n 'JSXAttribute';\n return isJsxProp || isLibraryArgument({ node, parent });\n };\n\n const isInjectedConstructor = (opts: { node: Rule.Node; params: unknown[] }) => {\n const parent = opts.node.parent;\n const isDecorated = (param: unknown) => {\n const own = AstNode.readField({ node: param, key: 'decorators' });\n const property = AstNode.readField({\n node: AstNode.readField({ node: param, key: 'parameter' }),\n key: 'decorators',\n });\n return (\n (Array.isArray(own) && own.length > 0) ||\n (Array.isArray(property) && property.length > 0)\n );\n };\n\n return (\n AstNode.getType({ node: parent }) === 'MethodDefinition' &&\n AstNode.readField({ node: parent, key: 'kind' }) === 'constructor' &&\n opts.params.every(isDecorated)\n );\n };\n\n const isTypedByContext = (node: Rule.Node) => {\n const parent = node.parent;\n const parentType = AstNode.getType({ node: parent });\n const isTypedInit =\n parentType === 'VariableDeclarator' &&\n AstNode.readField({ node: parent, key: 'init' }) === node &&\n Boolean(\n AstNode.readField({\n node: AstNode.readField({ node: parent, key: 'id' }),\n key: 'typeAnnotation',\n }),\n );\n const grandParent = AstNode.readField({ node: parent, key: 'parent' });\n const isMember =\n parentType === 'Property' &&\n AstNode.readField({ node: parent, key: 'value' }) === node &&\n AstNode.getType({ node: grandParent }) === 'ObjectExpression';\n\n return isTypedInit || (isMember && hasDeclaredShape(grandParent));\n };\n\n const check = (node: Rule.Node) => {\n const params = AstNode.readField({ node, key: 'params' });\n if (!Array.isArray(params) || params.length <= max) {\n return;\n }\n\n if (isCallback(node) || isInjectedConstructor({ node, params }) || isTypedByContext(node)) {\n return;\n }\n\n context.report({\n node,\n messageId: 'tooMany',\n data: { count: String(params.length), max: String(max) },\n });\n };\n\n return {\n [AstNodeTypes.FUNCTION_DECLARATION]: check,\n [AstNodeTypes.FUNCTION_EXPRESSION]: check,\n [AstNodeTypes.ARROW_FUNCTION_EXPRESSION]: check,\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity; max?: number } = {}): Linter.RuleEntry {\n const { severity = 'error', max = MaxParamsOwnRule.DEFAULT_MAX } = opts;\n return [severity, max];\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { TRuleSeverity } from '../rules/common';
3
+ /**
4
+ * `venizia/no-async-hook-callback`. A hook never gets an async function: `useEffect(async () => {})` makes the
5
+ * callback return a promise where React expects a cleanup function or nothing. Pass a sync callback and handle
6
+ * the promise inside it with `.then`, `.catch` and `.finally`. Every argument of a `use[A-Z]...` call is checked,
7
+ * `React.useX` too: an async function as the argument, as the value of a property of an object literal
8
+ * (`useMutation({ mutationFn: async () => {} })`) and as an element of an array literal. A sync callback that
9
+ * builds an async function inside is not an argument and is left alone.
10
+ */
11
+ export declare class NoAsyncHookCallbackRule {
12
+ static readonly NAME = "venizia/no-async-hook-callback";
13
+ static readonly RULE: Rule.RuleModule;
14
+ static build(opts?: {
15
+ severity?: TRuleSeverity;
16
+ }): TRuleSeverity;
17
+ }
18
+ //# sourceMappingURL=no-async-hook-callback.rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-async-hook-callback.rule.d.ts","sourceRoot":"","sources":["../../../src/linters/house/no-async-hook-callback.rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKrD;;;;;;;GAOG;AACH,qBAAa,uBAAuB;IAClC,MAAM,CAAC,QAAQ,CAAC,IAAI,oCAAsD;IAE1E,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CA8BnC;IAEF,MAAM,CAAC,KAAK,CAAC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,aAAa,CAAA;KAAO,GAAG,aAAa;CAGrE"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoAsyncHookCallbackRule = void 0;
4
+ const await_support_1 = require("./await-support");
5
+ const common_1 = require("./common");
6
+ const hook_support_1 = require("./hook-support");
7
+ /**
8
+ * `venizia/no-async-hook-callback`. A hook never gets an async function: `useEffect(async () => {})` makes the
9
+ * callback return a promise where React expects a cleanup function or nothing. Pass a sync callback and handle
10
+ * the promise inside it with `.then`, `.catch` and `.finally`. Every argument of a `use[A-Z]...` call is checked,
11
+ * `React.useX` too: an async function as the argument, as the value of a property of an object literal
12
+ * (`useMutation({ mutationFn: async () => {} })`) and as an element of an array literal. A sync callback that
13
+ * builds an async function inside is not an argument and is left alone.
14
+ */
15
+ class NoAsyncHookCallbackRule {
16
+ static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/no-async-hook-callback`; }
17
+ static { this.RULE = {
18
+ meta: {
19
+ type: 'problem',
20
+ schema: [],
21
+ messages: {
22
+ asyncCallback: 'Do not pass an async function to `{{hook}}`; pass a sync callback and handle the promise inside it with .then/.catch/.finally.',
23
+ },
24
+ },
25
+ create: (context) => ({
26
+ [common_1.AstNodeTypes.CALL_EXPRESSION]: (node) => {
27
+ const hook = hook_support_1.HookSupport.calleeName({ call: node });
28
+ if (hook === undefined || !hook_support_1.HookSupport.isHook({ name: hook })) {
29
+ return;
30
+ }
31
+ const args = common_1.AstNode.readField({ node, key: 'arguments' });
32
+ if (!Array.isArray(args)) {
33
+ return;
34
+ }
35
+ for (const argument of args) {
36
+ for (const found of hook_support_1.HookSupport.asyncFunctionsIn({ node: argument })) {
37
+ if (await_support_1.AwaitSupport.isNode(found)) {
38
+ context.report({ node: found, messageId: 'asyncCallback', data: { hook } });
39
+ }
40
+ }
41
+ }
42
+ },
43
+ }),
44
+ }; }
45
+ static build(opts = {}) {
46
+ return opts.severity ?? 'error';
47
+ }
48
+ }
49
+ exports.NoAsyncHookCallbackRule = NoAsyncHookCallbackRule;
50
+ //# sourceMappingURL=no-async-hook-callback.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-async-hook-callback.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-async-hook-callback.rule.ts"],"names":[],"mappings":";;;AAEA,mDAA+C;AAC/C,qCAAyE;AACzE,iDAA6C;AAE7C;;;;;;;GAOG;AACH,MAAa,uBAAuB;aAClB,SAAI,GAAG,GAAG,+BAAsB,yBAAyB,CAAC;aAE1D,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ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TRuleSeverity } from '../rules/common';\nimport { AwaitSupport } from './await-support';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { HookSupport } from './hook-support';\n\n/**\n * `venizia/no-async-hook-callback`. A hook never gets an async function: `useEffect(async () => {})` makes the\n * callback return a promise where React expects a cleanup function or nothing. Pass a sync callback and handle\n * the promise inside it with `.then`, `.catch` and `.finally`. Every argument of a `use[A-Z]...` call is checked,\n * `React.useX` too: an async function as the argument, as the value of a property of an object literal\n * (`useMutation({ mutationFn: async () => {} })`) and as an element of an array literal. A sync callback that\n * builds an async function inside is not an argument and is left alone.\n */\nexport class NoAsyncHookCallbackRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-async-hook-callback`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n asyncCallback:\n 'Do not pass an async function to `{{hook}}`; pass a sync callback and handle the promise inside it with .then/.catch/.finally.',\n },\n },\n create: (context) => ({\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n const hook = HookSupport.calleeName({ call: node });\n if (hook === undefined || !HookSupport.isHook({ name: hook })) {\n return;\n }\n\n const args = AstNode.readField({ node, key: 'arguments' });\n if (!Array.isArray(args)) {\n return;\n }\n\n for (const argument of args) {\n for (const found of HookSupport.asyncFunctionsIn({ node: argument })) {\n if (AwaitSupport.isNode(found)) {\n context.report({ node: found, messageId: 'asyncCallback', data: { hook } });\n }\n }\n }\n },\n }),\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { TRuleSeverity } from '../rules/common';
3
+ /**
4
+ * `venizia/no-await-promise-chain`. One expression uses one async style: `await` (in a try/catch when it can
5
+ * fail), or a promise chain that is not awaited. An `await` whose operand - after parentheses, `!`, `as`,
6
+ * `satisfies` and an optional chain - is a call of `.then`, `.catch` or `.finally` (`?.then(`, `['then'](`, a
7
+ * thenable such as a query builder) is reported once, however long the chain. A chain that is returned or stands
8
+ * as a statement is not awaited and is not reported, nor is `await Promise.all(xs.map(f))`, `await new Promise(...)`,
9
+ * `await x.then` (no call), or an `await` inside a callback of a chain.
10
+ *
11
+ * The fix is made for one shape only, `const|let x = await f().catch(() => <value>)` (see `planFix` for every
12
+ * condition), and writes `let x; try { x = await f(); } catch (error) { x = <value>; }` (`catch { ... }` when the value does not read the error): the `const` becomes a
13
+ * `let`, a type annotation stays, the catch variable takes the handler's parameter name (`error` without one,
14
+ * renamed when the name is taken), and is typed `any` when the value reads it, as the handler's parameter was.
15
+ * The try also catches a synchronous throw of `f()`, which the chain let through. Everything else is reported.
16
+ */
17
+ export declare class NoAwaitPromiseChainRule {
18
+ static readonly NAME = "venizia/no-await-promise-chain";
19
+ static readonly RULE: Rule.RuleModule;
20
+ static build(opts?: {
21
+ severity?: TRuleSeverity;
22
+ }): TRuleSeverity;
23
+ }
24
+ //# sourceMappingURL=no-await-promise-chain.rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-await-promise-chain.rule.d.ts","sourceRoot":"","sources":["../../../src/linters/house/no-await-promise-chain.rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAqB,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAiTrD;;;;;;;;;;;;;GAaG;AACH,qBAAa,uBAAuB;IAClC,MAAM,CAAC,QAAQ,CAAC,IAAI,oCAAsD;IAE1E,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAsDnC;IAEF,MAAM,CAAC,KAAK,CAAC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,aAAa,CAAA;KAAO,GAAG,aAAa;CAGrE"}