@venizia/dev-configs 0.5.0-0 → 0.5.0-10

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 (177) hide show
  1. package/README.md +18 -13
  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.js +42 -38
  18. package/dist/cli/check.js.map +1 -1
  19. package/dist/cli/clean.js +3 -2
  20. package/dist/cli/clean.js.map +1 -1
  21. package/dist/cli/codemod/any-aliases.d.ts +1 -1
  22. package/dist/cli/codemod/any-aliases.js +14 -13
  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 +18 -17
  26. package/dist/cli/codemod/async-style.js.map +1 -1
  27. package/dist/cli/codemod/binding-keys.d.ts +32 -1
  28. package/dist/cli/codemod/binding-keys.js +251 -68
  29. package/dist/cli/codemod/binding-keys.js.map +1 -1
  30. package/dist/cli/codemod/class-renames.d.ts +39 -0
  31. package/dist/cli/codemod/class-renames.js +297 -0
  32. package/dist/cli/codemod/class-renames.js.map +1 -0
  33. package/dist/cli/codemod/connector-imports.d.ts +1 -1
  34. package/dist/cli/codemod/connector-imports.js +13 -12
  35. package/dist/cli/codemod/connector-imports.js.map +1 -1
  36. package/dist/cli/codemod/const-class-sets.d.ts +55 -0
  37. package/dist/cli/codemod/const-class-sets.js +219 -0
  38. package/dist/cli/codemod/const-class-sets.js.map +1 -0
  39. package/dist/cli/codemod/const-classes.d.ts +21 -3
  40. package/dist/cli/codemod/const-classes.js +151 -36
  41. package/dist/cli/codemod/const-classes.js.map +1 -1
  42. package/dist/cli/codemod/drop-redundant-casts.d.ts +6 -1
  43. package/dist/cli/codemod/drop-redundant-casts.js +27 -19
  44. package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
  45. package/dist/cli/codemod/env-get.d.ts +3 -3
  46. package/dist/cli/codemod/env-get.js +19 -18
  47. package/dist/cli/codemod/env-get.js.map +1 -1
  48. package/dist/cli/codemod/files.d.ts +4 -2
  49. package/dist/cli/codemod/files.js +7 -8
  50. package/dist/cli/codemod/files.js.map +1 -1
  51. package/dist/cli/codemod/function-to-arrow.d.ts +76 -0
  52. package/dist/cli/codemod/function-to-arrow.js +357 -0
  53. package/dist/cli/codemod/function-to-arrow.js.map +1 -0
  54. package/dist/cli/codemod/index.js +25 -4
  55. package/dist/cli/codemod/index.js.map +1 -1
  56. package/dist/cli/codemod/namespace-functions/index.d.ts +1 -1
  57. package/dist/cli/codemod/namespace-functions/index.js +14 -13
  58. package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
  59. package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js +3 -3
  60. package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js.map +1 -1
  61. package/dist/cli/codemod/namespace-functions/mappings/helpers.js +1 -1
  62. package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -1
  63. package/dist/cli/codemod/typed-route-context.d.ts +58 -0
  64. package/dist/cli/codemod/typed-route-context.js +918 -0
  65. package/dist/cli/codemod/typed-route-context.js.map +1 -0
  66. package/dist/cli/index.js +5 -4
  67. package/dist/cli/index.js.map +1 -1
  68. package/dist/common/cli-output.d.ts +16 -0
  69. package/dist/common/cli-output.js +49 -0
  70. package/dist/common/cli-output.js.map +1 -0
  71. package/dist/compilers/bun.js +1 -1
  72. package/dist/compilers/bun.js.map +1 -1
  73. package/dist/linters/eslint.js +1 -1
  74. package/dist/linters/eslint.js.map +1 -1
  75. package/dist/linters/house/browser-api-patterns.d.ts +43 -0
  76. package/dist/linters/house/browser-api-patterns.js +87 -0
  77. package/dist/linters/house/browser-api-patterns.js.map +1 -0
  78. package/dist/linters/house/common.d.ts +17 -2
  79. package/dist/linters/house/common.js +18 -2
  80. package/dist/linters/house/common.js.map +1 -1
  81. package/dist/linters/house/configs.js +25 -0
  82. package/dist/linters/house/configs.js.map +1 -1
  83. package/dist/linters/house/const-class-values.rule.d.ts +2 -2
  84. package/dist/linters/house/const-class-values.rule.js +14 -5
  85. package/dist/linters/house/const-class-values.rule.js.map +1 -1
  86. package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +2 -2
  87. package/dist/linters/house/effect-cleanup-consistency.rule.js +1 -1
  88. package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -1
  89. package/dist/linters/house/framework-api-patterns.d.ts +54 -0
  90. package/dist/linters/house/framework-api-patterns.js +62 -0
  91. package/dist/linters/house/framework-api-patterns.js.map +1 -0
  92. package/dist/linters/house/framework-exports.d.ts +62 -0
  93. package/dist/linters/house/framework-exports.js +325 -0
  94. package/dist/linters/house/framework-exports.js.map +1 -0
  95. package/dist/linters/house/import-support.d.ts +56 -0
  96. package/dist/linters/house/import-support.js +179 -0
  97. package/dist/linters/house/import-support.js.map +1 -0
  98. package/dist/linters/house/index.d.ts +12 -0
  99. package/dist/linters/house/index.js +15 -1
  100. package/dist/linters/house/index.js.map +1 -1
  101. package/dist/linters/house/max-params-own.rule.d.ts +2 -2
  102. package/dist/linters/house/max-params-own.rule.js +1 -1
  103. package/dist/linters/house/max-params-own.rule.js.map +1 -1
  104. package/dist/linters/house/no-async-hook-callback.rule.d.ts +2 -2
  105. package/dist/linters/house/no-async-hook-callback.rule.js +1 -1
  106. package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -1
  107. package/dist/linters/house/no-await-new-chain.rule.d.ts +2 -2
  108. package/dist/linters/house/no-await-new-chain.rule.js +1 -1
  109. package/dist/linters/house/no-await-new-chain.rule.js.map +1 -1
  110. package/dist/linters/house/no-await-promise-chain.rule.d.ts +2 -2
  111. package/dist/linters/house/no-await-promise-chain.rule.js +5 -5
  112. package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -1
  113. package/dist/linters/house/no-inline-await.rule.d.ts +2 -2
  114. package/dist/linters/house/no-inline-await.rule.js +1 -1
  115. package/dist/linters/house/no-inline-await.rule.js.map +1 -1
  116. package/dist/linters/house/no-leaked-render.rule.d.ts +2 -2
  117. package/dist/linters/house/no-leaked-render.rule.js +1 -1
  118. package/dist/linters/house/no-leaked-render.rule.js.map +1 -1
  119. package/dist/linters/house/no-new-error.rule.d.ts +2 -2
  120. package/dist/linters/house/no-new-error.rule.js +2 -2
  121. package/dist/linters/house/no-new-error.rule.js.map +1 -1
  122. package/dist/linters/house/no-parent-import.rule.d.ts +45 -0
  123. package/dist/linters/house/no-parent-import.rule.js +176 -0
  124. package/dist/linters/house/no-parent-import.rule.js.map +1 -0
  125. package/dist/linters/house/no-return-await.rule.d.ts +2 -2
  126. package/dist/linters/house/no-return-await.rule.js +1 -1
  127. package/dist/linters/house/no-return-await.rule.js.map +1 -1
  128. package/dist/linters/house/no-shadow-framework-type.rule.d.ts +24 -0
  129. package/dist/linters/house/no-shadow-framework-type.rule.js +100 -0
  130. package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -0
  131. package/dist/linters/house/no-silent-catch.rule.d.ts +2 -2
  132. package/dist/linters/house/no-silent-catch.rule.js +3 -3
  133. package/dist/linters/house/no-silent-catch.rule.js.map +1 -1
  134. package/dist/linters/house/no-unbraced-case.rule.d.ts +2 -2
  135. package/dist/linters/house/no-unbraced-case.rule.js +1 -1
  136. package/dist/linters/house/no-unbraced-case.rule.js.map +1 -1
  137. package/dist/linters/house/plugin.d.ts +1 -1
  138. package/dist/linters/house/plugin.js +18 -2
  139. package/dist/linters/house/plugin.js.map +1 -1
  140. package/dist/linters/house/prefer-framework-api.rule.d.ts +83 -0
  141. package/dist/linters/house/prefer-framework-api.rule.js +562 -0
  142. package/dist/linters/house/prefer-framework-api.rule.js.map +1 -0
  143. package/dist/linters/house/prefer-http-method.rule.d.ts +22 -0
  144. package/dist/linters/house/prefer-http-method.rule.js +182 -0
  145. package/dist/linters/house/prefer-http-method.rule.js.map +1 -0
  146. package/dist/linters/house/prefer-promise-sleep.rule.d.ts +26 -0
  147. package/dist/linters/house/prefer-promise-sleep.rule.js +155 -0
  148. package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -0
  149. package/dist/linters/house/prefer-tnullable.rule.d.ts +25 -0
  150. package/dist/linters/house/prefer-tnullable.rule.js +124 -0
  151. package/dist/linters/house/prefer-tnullable.rule.js.map +1 -0
  152. package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
  153. package/dist/linters/house/typed-route-context.rule.js +334 -0
  154. package/dist/linters/house/typed-route-context.rule.js.map +1 -0
  155. package/dist/linters/house/zod-schema-convention.rule.d.ts +82 -0
  156. package/dist/linters/house/zod-schema-convention.rule.js +477 -0
  157. package/dist/linters/house/zod-schema-convention.rule.js.map +1 -0
  158. package/dist/linters/oxlint.js +11 -1
  159. package/dist/linters/oxlint.js.map +1 -1
  160. package/dist/linters/react-eslint.js.map +1 -1
  161. package/dist/linters/rules/naming-convention.rule.d.ts +4 -1
  162. package/dist/linters/rules/naming-convention.rule.js +30 -1
  163. package/dist/linters/rules/naming-convention.rule.js.map +1 -1
  164. package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
  165. package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
  166. package/dist/testing/index.d.ts +2 -2
  167. package/dist/testing/index.js +2 -2
  168. package/dist/testing/index.js.map +1 -1
  169. package/dist/testing/{rejection.helper.d.ts → rejection.utility.d.ts} +4 -4
  170. package/dist/testing/{rejection.helper.js → rejection.utility.js} +7 -7
  171. package/dist/testing/rejection.utility.js.map +1 -0
  172. package/dist/testing/{spawn.helper.d.ts → spawn.utility.d.ts} +2 -2
  173. package/dist/testing/{spawn.helper.js → spawn.utility.js} +6 -6
  174. package/dist/testing/spawn.utility.js.map +1 -0
  175. package/package.json +7 -7
  176. package/dist/testing/rejection.helper.js.map +0 -1
  177. package/dist/testing/spawn.helper.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"no-await-promise-chain.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-await-promise-chain.rule.ts"],"names":[],"mappings":";;;AAEA,mDAAgE;AAChE,qCAAyE;AACzE,mEAA8D;AAE9D,2EAA2E;AAC3E,MAAM,UAAU,GAAG,OAAO,CAAC;AAc3B,wGAAwG;AACxG,MAAM,YAAY,GAAG,CAAC,IAIrB,EAAW,EAAE;IACZ,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC9C,MAAM,IAAI,GAAG,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;IAExF,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,qBAAY,CAAC,OAAO,CAAC,CAAC,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,qBAAY,CAAC,UAAU,CAAC,CAAC,CAAC;YAC7B,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,qBAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC;YACnC,OAAO,2CAAmB,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,KAAK,qBAAY,CAAC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AAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO;wBAC1D,IAAI,EAAE,EAAE,MAAM,EAAE;wBAChB,GAAG,EAAE,IAAI;4BACP,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;gCACR,MAAM,MAAM,GAAG,4BAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;gCAC7E,MAAM,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;gCAC5B,oGAAoG;gCACpG,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gCAE3E,OAAO,KAAK,CAAC,WAAW,CACtB,IAAI,CAAC,WAAW,EAChB;oCACE,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,GAAG;oCACrC,GAAG,MAAM,OAAO;oCAChB,GAAG,KAAK,GAAG,IAAI,CAAC,IAAI,YAAY,IAAI,CAAC,YAAY,GAAG;oCACpD,GAAG,MAAM,KAAK,IAAI,IAAI;oCACtB,GAAG,KAAK,GAAG,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,SAAS,GAAG;oCAC3C,GAAG,MAAM,GAAG;iCACb,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;4BACJ,CAAC;4BACH,CAAC,CAAC,IAAI;qBACT,CAAC,CAAC;gBACL,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AA9DH,0DA+DC","sourcesContent":["import type { Rule, Scope, SourceCode } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AwaitSupport, STATEMENT_LISTS } from './await-support';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { PromiseChainSupport } from './promise-chain-support';\n\n/** The catch variable the fix writes when the handler has no parameter. */\nconst CATCH_NAME = 'error';\n\n/** What the fix needs, read once from a `const x = await f().catch(h)` that passed every check. */\ninterface IFixPlan {\n declaration: Rule.Node;\n kind: string;\n name: string;\n annotation: string;\n receiverText: string;\n catchName: string;\n isErrorRead: boolean;\n valueText: string;\n}\n\n/** The identifiers a fallback value reads, and whether every node of it is a value the fix may move. */\nconst collectValue = (opts: {\n node: unknown;\n parameter: string | undefined;\n identifiers: unknown[];\n}): boolean => {\n const { node, parameter, identifiers } = opts;\n const type = AstNode.getType({ node }) ?? '';\n const value = (child: unknown) => collectValue({ node: child, parameter, identifiers });\n\n switch (type) {\n case AstNodeTypes.LITERAL: {\n return true;\n }\n case AstNodeTypes.IDENTIFIER: {\n identifiers.push(node);\n\n return true;\n }\n case AstNodeTypes.TEMPLATE_LITERAL: {\n return PromiseChainSupport.isConstant({ node });\n }\n case AstNodeTypes.UNARY_EXPRESSION: {\n return PromiseChainSupport.isConstant({ node });\n }\n case AstNodeTypes.CHAIN_EXPRESSION: {\n return value(AstNode.readField({ node, key: 'expression' }));\n }\n case AstNodeTypes.MEMBER_EXPRESSION: {\n // Only a read of the error itself: `error.message`, `error?.response.status`.\n const object = AstNode.readField({ node, key: 'object' });\n const isRead =\n AstNode.readField({ node, key: 'computed' }) !== true ||\n AstNode.getType({ node: AstNode.readField({ node, key: 'property' }) }) ===\n AstNodeTypes.LITERAL;\n const isRooted =\n AstNode.getType({ node: object }) === AstNodeTypes.MEMBER_EXPRESSION ||\n (AstNode.getType({ node: object }) === AstNodeTypes.IDENTIFIER &&\n AstNode.readField({ node: object, key: 'name' }) === parameter);\n\n return isRead && isRooted && parameter !== undefined && value(object);\n }\n case AstNodeTypes.ARRAY_EXPRESSION: {\n const elements = AstNode.readField({ node, key: 'elements' });\n\n return (\n Array.isArray(elements) && elements.every((element) => element === null || value(element))\n );\n }\n case AstNodeTypes.OBJECT_EXPRESSION: {\n const properties = AstNode.readField({ node, key: 'properties' });\n\n return (\n Array.isArray(properties) &&\n properties.every(\n (property) =>\n AstNode.getType({ node: property }) === AstNodeTypes.PROPERTY &&\n AstNode.readField({ node: property, key: 'computed' }) !== true &&\n AstNode.readField({ node: property, key: 'method' }) !== true &&\n AstNode.readField({ node: property, key: 'kind' }) === 'init' &&\n value(AstNode.readField({ node: property, key: 'value' })),\n )\n );\n }\n default: {\n return false;\n }\n }\n};\n\n/** Whether `name` is declared in `scope` or any scope around it: a catch variable of that name would shadow it. */\nconst isDeclaredAround = (opts: { scope: Scope.Scope | null; name: string }): boolean => {\n for (let scope = opts.scope; scope; scope = scope.upper) {\n if (scope.set.has(opts.name)) {\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * The plan of the fix for `awaitNode`, or `undefined` when the strict safe shape does not hold:\n * `const|let x[: T] = await f().catch(() => <value>)` or `.catch((error) => <value>)`, alone in its declaration,\n * in a statement list; `x` never written again and, without a type annotation, read only in its own function;\n * the handler an expression-bodied, non-async arrow with at most one plain parameter; `<value>` a literal, an\n * identifier, a read of the error (`error.message`) or an array or object literal of those; `f()` with no\n * `.then`, `.catch` or `.finally` before and no `await` inside; no comment the fix would drop.\n */\nconst planFix = (opts: { awaitNode: Rule.Node; sourceCode: SourceCode }): IFixPlan | undefined => {\n const { awaitNode, sourceCode } = opts;\n const call = AstNode.readField({ node: awaitNode, key: 'argument' });\n const callee = AstNode.readField({ node: call, key: 'callee' });\n const args = AstNode.readField({ node: call, key: 'arguments' });\n\n if (\n AstNode.getType({ node: call }) !== AstNodeTypes.CALL_EXPRESSION ||\n AstNode.readField({ node: call, key: 'optional' }) === true ||\n AstNode.getType({ node: callee }) !== AstNodeTypes.MEMBER_EXPRESSION ||\n AstNode.readField({ node: callee, key: 'computed' }) === true ||\n AstNode.readField({ node: callee, key: 'optional' }) === true ||\n PromiseChainSupport.memberName({ member: callee }) !== 'catch' ||\n !Array.isArray(args) ||\n args.length !== 1\n ) {\n return undefined;\n }\n\n const handler: unknown = args[0];\n const params = AstNode.readField({ node: handler, key: 'params' });\n const body = AstNode.readField({ node: handler, key: 'body' });\n const parameter: unknown = Array.isArray(params) ? params[0] : undefined;\n\n if (\n AstNode.getType({ node: handler }) !== AstNodeTypes.ARROW_FUNCTION_EXPRESSION ||\n AstNode.readField({ node: handler, key: 'async' }) === true ||\n AstNode.getType({ node: body }) === AstNodeTypes.BLOCK_STATEMENT ||\n AstNode.readField({ node: handler, key: 'returnType' }) ||\n AstNode.readField({ node: handler, key: 'typeParameters' }) ||\n !Array.isArray(params) ||\n params.length > 1 ||\n (parameter !== undefined &&\n (AstNode.getType({ node: parameter }) !== AstNodeTypes.IDENTIFIER ||\n AstNode.readField({ node: parameter, key: 'typeAnnotation' }) ||\n AstNode.readField({ node: parameter, key: 'optional' }) === true))\n ) {\n return undefined;\n }\n\n const receiver = AstNode.readField({ node: callee, key: 'object' });\n\n if (\n !AwaitSupport.isNode(receiver) ||\n !AwaitSupport.isNode(body) ||\n !AwaitSupport.isNode(handler) ||\n PromiseChainSupport.hasChainOnSpine({ node: receiver }) ||\n /\\b(await|yield)\\b/.test(sourceCode.getText(receiver))\n ) {\n return undefined;\n }\n\n const declarator = AwaitSupport.parentOf({ node: awaitNode });\n const declaration = AwaitSupport.parentOf({ node: declarator });\n const id = AstNode.readField({ node: declarator, key: 'id' });\n const declarations = AstNode.readField({ node: declaration, key: 'declarations' });\n const kind = String(AstNode.readField({ node: declaration, key: 'kind' }));\n\n if (\n AstNode.getType({ node: declarator }) !== AstNodeTypes.VARIABLE_DECLARATOR ||\n AstNode.readField({ node: declarator, key: 'init' }) !== awaitNode ||\n AstNode.readField({ node: declarator, key: 'definite' }) === true ||\n AstNode.getType({ node: id }) !== AstNodeTypes.IDENTIFIER ||\n !AwaitSupport.isNode(declarator) ||\n !AwaitSupport.isNode(declaration) ||\n !Array.isArray(declarations) ||\n declarations.length !== 1 ||\n !['const', 'let'].includes(kind) ||\n !STATEMENT_LISTS.has(\n AstNode.getType({ node: AwaitSupport.parentOf({ node: declaration }) }) ?? '',\n )\n ) {\n return undefined;\n }\n\n const name = String(AstNode.readField({ node: id, key: 'name' }));\n const typeAnnotation = AstNode.readField({ node: id, key: 'typeAnnotation' });\n const annotation = AwaitSupport.isNode(typeAnnotation) ? sourceCode.getText(typeAnnotation) : '';\n\n // `let x;` with no annotation takes its type from the assignments that follow, so TypeScript must see every\n // read in the same function: a read from a nested function, an export or a `typeof` makes it an implicit any.\n const variable = sourceCode.getDeclaredVariables(declarator).find((entry) => entry.name === name);\n\n if (!variable) {\n return undefined;\n }\n\n for (const reference of variable.references) {\n if (reference.identifier === id) {\n continue;\n }\n\n const parentType = AstNode.getType({\n node: AwaitSupport.parentOf({ node: reference.identifier }),\n });\n\n if (\n reference.isWrite() ||\n (annotation === '' &&\n (reference.from.variableScope !== variable.scope.variableScope ||\n parentType === AstNodeTypes.EXPORT_SPECIFIER ||\n parentType === AstNodeTypes.TYPE_QUERY))\n ) {\n return undefined;\n }\n }\n\n const parameterName =\n parameter === undefined\n ? undefined\n : String(AstNode.readField({ node: parameter, key: 'name' }));\n const identifiers: unknown[] = [];\n\n if (!collectValue({ node: body, parameter: parameterName, identifiers })) {\n return undefined;\n }\n\n // `x = []` on a `let x;` with no annotation makes an evolving `any[]`, looser than the `never[]` it was.\n const elements = AstNode.readField({ node: body, key: 'elements' });\n\n if (\n annotation === '' &&\n AstNode.getType({ node: body }) === AstNodeTypes.ARRAY_EXPRESSION &&\n Array.isArray(elements) &&\n elements.length === 0\n ) {\n return undefined;\n }\n\n const parameterVariable = sourceCode\n .getDeclaredVariables(handler)\n .find((entry) => entry.name === parameterName);\n const errorReads = new Set<unknown>(\n parameterVariable?.references.map((reference) => reference.identifier) ?? [],\n );\n const freeNames = new Set(\n identifiers\n .filter((identifier) => !errorReads.has(identifier))\n .map((identifier) => String(AstNode.readField({ node: identifier, key: 'name' }))),\n );\n\n // The fallback is evaluated after the `let`: reading the declared name there would read `undefined`.\n if (freeNames.has(name)) {\n return undefined;\n }\n\n const scope = sourceCode.getScope(declaration);\n const isTaken = (candidate: string) =>\n candidate === name ||\n freeNames.has(candidate) ||\n (candidate !== parameterName && isDeclaredAround({ scope, name: candidate }));\n const base = parameterName ?? CATCH_NAME;\n let catchName = base;\n\n for (let index = 2; isTaken(catchName); index += 1) {\n catchName = `${base}${index}`;\n }\n\n const comments = sourceCode.getCommentsInside(declaration);\n const isInside = (range: [number, number] | undefined, inner: [number, number] | undefined) =>\n range !== undefined && inner !== undefined && range[0] <= inner[0] && inner[1] <= range[1];\n\n if (\n comments.some(\n (comment) => !isInside(receiver.range, comment.range) && !isInside(body.range, comment.range),\n )\n ) {\n return undefined;\n }\n\n const bodyStart = body.range?.[0] ?? 0;\n let valueText = sourceCode.getText(body);\n\n if (catchName !== parameterName && errorReads.size > 0) {\n const edits = [...errorReads]\n .filter(AwaitSupport.isNode)\n .map((identifier) => {\n const parent = AwaitSupport.parentOf({ node: identifier });\n const isShorthand =\n AstNode.getType({ node: parent }) === AstNodeTypes.PROPERTY &&\n AstNode.readField({ node: parent, key: 'shorthand' }) === true;\n\n return {\n range: identifier.range ?? [0, 0],\n text: isShorthand ? `${parameterName}: ${catchName}` : catchName,\n };\n })\n .sort((left, right) => right.range[0] - left.range[0]);\n\n for (const edit of edits) {\n valueText =\n valueText.slice(0, edit.range[0] - bodyStart) +\n edit.text +\n valueText.slice(edit.range[1] - bodyStart);\n }\n }\n\n return {\n declaration,\n kind,\n name,\n annotation,\n receiverText: sourceCode.getText(receiver),\n catchName,\n isErrorRead: errorReads.size > 0,\n valueText,\n };\n};\n\n/**\n * `venizia/no-await-promise-chain`. One expression uses one async style: `await` (in a try/catch when it can\n * fail), or a promise chain that is not awaited. An `await` whose operand - after parentheses, `!`, `as`,\n * `satisfies` and an optional chain - is a call of `.then`, `.catch` or `.finally` (`?.then(`, `['then'](`, a\n * thenable such as a query builder) is reported once, however long the chain. A chain that is returned or stands\n * as a statement is not awaited and is not reported, nor is `await Promise.all(xs.map(f))`, `await new Promise(...)`,\n * `await x.then` (no call), or an `await` inside a callback of a chain.\n *\n * The fix is made for one shape only, `const|let x = await f().catch(() => <value>)` (see `planFix` for every\n * 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\n * `let`, a type annotation stays, the catch variable takes the handler's parameter name (`error` without one,\n * renamed when the name is taken), and is typed `any` when the value reads it, as the handler's parameter was.\n * The try also catches a synchronous throw of `f()`, which the chain let through. Everything else is reported.\n */\nexport class NoAwaitPromiseChainRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-await-promise-chain`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n fixable: 'code',\n schema: [],\n messages: {\n mixed:\n 'Do not `await` a promise chain (`.{{method}}(...)`): wrap `await f()` in try/catch, or drop the `await` and keep the chain.',\n mixedConst:\n 'Do not `await` a promise chain (`.{{method}}(...)`): wrap `await f()` in try/catch, or drop the `await` and keep the chain. The fix writes the try/catch and turns the `const` into a `let`.',\n },\n },\n create: (context) => {\n const { sourceCode } = context;\n\n return {\n [AstNodeTypes.AWAIT_EXPRESSION]: (node: Rule.Node) => {\n const method = PromiseChainSupport.chainMethodOf({\n node: AstNode.readField({ node, key: 'argument' }),\n });\n\n if (method === undefined) {\n return;\n }\n\n const plan = planFix({ awaitNode: node, sourceCode });\n\n context.report({\n node,\n messageId: plan?.kind === 'const' ? 'mixedConst' : 'mixed',\n data: { method },\n fix: plan\n ? (fixer) => {\n const indent = AwaitSupport.indentOf({ node: plan.declaration, sourceCode });\n const inner = `${indent} `;\n // The optional catch binding when nothing reads the error: a named one would be an unused variable.\n const head = plan.isErrorRead ? `catch (${plan.catchName}: any)` : 'catch';\n\n return fixer.replaceText(\n plan.declaration,\n [\n `let ${plan.name}${plan.annotation};`,\n `${indent}try {`,\n `${inner}${plan.name} = await ${plan.receiverText};`,\n `${indent}} ${head} {`,\n `${inner}${plan.name} = ${plan.valueText};`,\n `${indent}}`,\n ].join('\\n'),\n );\n }\n : null,\n });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
1
+ {"version":3,"file":"no-await-promise-chain.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-await-promise-chain.rule.ts"],"names":[],"mappings":";;;AAEA,mDAAgE;AAChE,qCAAyE;AACzE,mEAA8D;AAE9D,2EAA2E;AAC3E,MAAM,UAAU,GAAG,OAAO,CAAC;AAc3B,wGAAwG;AACxG,MAAM,YAAY,GAAG,CAAC,IAIrB,EAAW,EAAE;IACZ,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC9C,MAAM,IAAI,GAAG,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;IAExF,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,qBAAY,CAAC,OAAO,CAAC,CAAC,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,qBAAY,CAAC,UAAU,CAAC,CAAC,CAAC;YAC7B,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,qBAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC;YACnC,OAAO,2CAAmB,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,KAAK,qBAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC;YACnC,OAAO,2CAAmB,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,KAAK,qBAAY,CAA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AK,EAAE,EAAE;gCACR,MAAM,MAAM,GAAG,4BAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;gCAC7E,MAAM,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;gCAC5B,oGAAoG;gCACpG,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;gCAE3E,OAAO,KAAK,CAAC,WAAW,CACtB,IAAI,CAAC,WAAW,EAChB;oCACE,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,GAAG;oCACrC,GAAG,MAAM,OAAO;oCAChB,GAAG,KAAK,GAAG,IAAI,CAAC,IAAI,YAAY,IAAI,CAAC,YAAY,GAAG;oCACpD,GAAG,MAAM,KAAK,IAAI,IAAI;oCACtB,GAAG,KAAK,GAAG,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,SAAS,GAAG;oCAC3C,GAAG,MAAM,GAAG;iCACb,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;4BACJ,CAAC;4BACH,CAAC,CAAC,IAAI;qBACT,CAAC,CAAC;gBACL,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AA9DH,0DA+DC","sourcesContent":["import type { Rule, Scope, SourceCode } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AwaitSupport, STATEMENT_LISTS } from './await-support';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { PromiseChainSupport } from './promise-chain-support';\n\n/** The catch variable the fix writes when the handler has no parameter. */\nconst CATCH_NAME = 'error';\n\n/** What the fix needs, read once from a `const x = await f().catch(h)` that passed every check. */\ninterface IFixPlan {\n declaration: Rule.Node;\n keyword: string;\n name: string;\n annotation: string;\n receiverText: string;\n catchName: string;\n isErrorRead: boolean;\n valueText: string;\n}\n\n/** The identifiers a fallback value reads, and whether every node of it is a value the fix may move. */\nconst collectValue = (opts: {\n node: unknown;\n parameter: string | undefined;\n identifiers: unknown[];\n}): boolean => {\n const { node, parameter, identifiers } = opts;\n const type = AstNode.getType({ node }) ?? '';\n const value = (child: unknown) => collectValue({ node: child, parameter, identifiers });\n\n switch (type) {\n case AstNodeTypes.LITERAL: {\n return true;\n }\n case AstNodeTypes.IDENTIFIER: {\n identifiers.push(node);\n\n return true;\n }\n case AstNodeTypes.TEMPLATE_LITERAL: {\n return PromiseChainSupport.isConstant({ node });\n }\n case AstNodeTypes.UNARY_EXPRESSION: {\n return PromiseChainSupport.isConstant({ node });\n }\n case AstNodeTypes.CHAIN_EXPRESSION: {\n return value(AstNode.readField({ node, key: 'expression' }));\n }\n case AstNodeTypes.MEMBER_EXPRESSION: {\n // Only a read of the error itself: `error.message`, `error?.response.status`.\n const object = AstNode.readField({ node, key: 'object' });\n const isRead =\n AstNode.readField({ node, key: 'computed' }) !== true ||\n AstNode.getType({ node: AstNode.readField({ node, key: 'property' }) }) ===\n AstNodeTypes.LITERAL;\n const isRooted =\n AstNode.getType({ node: object }) === AstNodeTypes.MEMBER_EXPRESSION ||\n (AstNode.getType({ node: object }) === AstNodeTypes.IDENTIFIER &&\n AstNode.readField({ node: object, key: 'name' }) === parameter);\n\n return isRead && isRooted && parameter !== undefined && value(object);\n }\n case AstNodeTypes.ARRAY_EXPRESSION: {\n const elements = AstNode.readField({ node, key: 'elements' });\n\n return (\n Array.isArray(elements) && elements.every((element) => element === null || value(element))\n );\n }\n case AstNodeTypes.OBJECT_EXPRESSION: {\n const properties = AstNode.readField({ node, key: 'properties' });\n\n return (\n Array.isArray(properties) &&\n properties.every(\n (property) =>\n AstNode.getType({ node: property }) === AstNodeTypes.PROPERTY &&\n AstNode.readField({ node: property, key: 'computed' }) !== true &&\n AstNode.readField({ node: property, key: 'method' }) !== true &&\n AstNode.readField({ node: property, key: 'kind' }) === 'init' &&\n value(AstNode.readField({ node: property, key: 'value' })),\n )\n );\n }\n default: {\n return false;\n }\n }\n};\n\n/** Whether `name` is declared in `scope` or any scope around it: a catch variable of that name would shadow it. */\nconst isDeclaredAround = (opts: { scope: Scope.Scope | null; name: string }): boolean => {\n for (let scope = opts.scope; scope; scope = scope.upper) {\n if (scope.set.has(opts.name)) {\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * The plan of the fix for `awaitNode`, or `undefined` when the strict safe shape does not hold:\n * `const|let x[: T] = await f().catch(() => <value>)` or `.catch((error) => <value>)`, alone in its declaration,\n * in a statement list; `x` never written again and, without a type annotation, read only in its own function;\n * the handler an expression-bodied, non-async arrow with at most one plain parameter; `<value>` a literal, an\n * identifier, a read of the error (`error.message`) or an array or object literal of those; `f()` with no\n * `.then`, `.catch` or `.finally` before and no `await` inside; no comment the fix would drop.\n */\nconst planFix = (opts: { awaitNode: Rule.Node; sourceCode: SourceCode }): IFixPlan | undefined => {\n const { awaitNode, sourceCode } = opts;\n const call = AstNode.readField({ node: awaitNode, key: 'argument' });\n const callee = AstNode.readField({ node: call, key: 'callee' });\n const args = AstNode.readField({ node: call, key: 'arguments' });\n\n if (\n AstNode.getType({ node: call }) !== AstNodeTypes.CALL_EXPRESSION ||\n AstNode.readField({ node: call, key: 'optional' }) === true ||\n AstNode.getType({ node: callee }) !== AstNodeTypes.MEMBER_EXPRESSION ||\n AstNode.readField({ node: callee, key: 'computed' }) === true ||\n AstNode.readField({ node: callee, key: 'optional' }) === true ||\n PromiseChainSupport.memberName({ member: callee }) !== 'catch' ||\n !Array.isArray(args) ||\n args.length !== 1\n ) {\n return undefined;\n }\n\n const handler: unknown = args[0];\n const params = AstNode.readField({ node: handler, key: 'params' });\n const body = AstNode.readField({ node: handler, key: 'body' });\n const parameter: unknown = Array.isArray(params) ? params[0] : undefined;\n\n if (\n AstNode.getType({ node: handler }) !== AstNodeTypes.ARROW_FUNCTION_EXPRESSION ||\n AstNode.readField({ node: handler, key: 'async' }) === true ||\n AstNode.getType({ node: body }) === AstNodeTypes.BLOCK_STATEMENT ||\n AstNode.readField({ node: handler, key: 'returnType' }) ||\n AstNode.readField({ node: handler, key: 'typeParameters' }) ||\n !Array.isArray(params) ||\n params.length > 1 ||\n (parameter !== undefined &&\n (AstNode.getType({ node: parameter }) !== AstNodeTypes.IDENTIFIER ||\n AstNode.readField({ node: parameter, key: 'typeAnnotation' }) ||\n AstNode.readField({ node: parameter, key: 'optional' }) === true))\n ) {\n return undefined;\n }\n\n const receiver = AstNode.readField({ node: callee, key: 'object' });\n\n if (\n !AwaitSupport.isNode(receiver) ||\n !AwaitSupport.isNode(body) ||\n !AwaitSupport.isNode(handler) ||\n PromiseChainSupport.hasChainOnSpine({ node: receiver }) ||\n /\\b(await|yield)\\b/.test(sourceCode.getText(receiver))\n ) {\n return undefined;\n }\n\n const declarator = AwaitSupport.parentOf({ node: awaitNode });\n const declaration = AwaitSupport.parentOf({ node: declarator });\n const id = AstNode.readField({ node: declarator, key: 'id' });\n const declarations = AstNode.readField({ node: declaration, key: 'declarations' });\n const keyword = String(AstNode.readField({ node: declaration, key: 'kind' }));\n\n if (\n AstNode.getType({ node: declarator }) !== AstNodeTypes.VARIABLE_DECLARATOR ||\n AstNode.readField({ node: declarator, key: 'init' }) !== awaitNode ||\n AstNode.readField({ node: declarator, key: 'definite' }) === true ||\n AstNode.getType({ node: id }) !== AstNodeTypes.IDENTIFIER ||\n !AwaitSupport.isNode(declarator) ||\n !AwaitSupport.isNode(declaration) ||\n !Array.isArray(declarations) ||\n declarations.length !== 1 ||\n !['const', 'let'].includes(keyword) ||\n !STATEMENT_LISTS.has(\n AstNode.getType({ node: AwaitSupport.parentOf({ node: declaration }) }) ?? '',\n )\n ) {\n return undefined;\n }\n\n const name = String(AstNode.readField({ node: id, key: 'name' }));\n const typeAnnotation = AstNode.readField({ node: id, key: 'typeAnnotation' });\n const annotation = AwaitSupport.isNode(typeAnnotation) ? sourceCode.getText(typeAnnotation) : '';\n\n // `let x;` with no annotation takes its type from the assignments that follow, so TypeScript must see every\n // read in the same function: a read from a nested function, an export or a `typeof` makes it an implicit any.\n const variable = sourceCode.getDeclaredVariables(declarator).find((entry) => entry.name === name);\n\n if (!variable) {\n return undefined;\n }\n\n for (const reference of variable.references) {\n if (reference.identifier === id) {\n continue;\n }\n\n const parentType = AstNode.getType({\n node: AwaitSupport.parentOf({ node: reference.identifier }),\n });\n\n if (\n reference.isWrite() ||\n (annotation === '' &&\n (reference.from.variableScope !== variable.scope.variableScope ||\n parentType === AstNodeTypes.EXPORT_SPECIFIER ||\n parentType === AstNodeTypes.TYPE_QUERY))\n ) {\n return undefined;\n }\n }\n\n const parameterName =\n parameter === undefined\n ? undefined\n : String(AstNode.readField({ node: parameter, key: 'name' }));\n const identifiers: unknown[] = [];\n\n if (!collectValue({ node: body, parameter: parameterName, identifiers })) {\n return undefined;\n }\n\n // `x = []` on a `let x;` with no annotation makes an evolving `any[]`, looser than the `never[]` it was.\n const elements = AstNode.readField({ node: body, key: 'elements' });\n\n if (\n annotation === '' &&\n AstNode.getType({ node: body }) === AstNodeTypes.ARRAY_EXPRESSION &&\n Array.isArray(elements) &&\n elements.length === 0\n ) {\n return undefined;\n }\n\n const parameterVariable = sourceCode\n .getDeclaredVariables(handler)\n .find((entry) => entry.name === parameterName);\n const errorReads = new Set<unknown>(\n parameterVariable?.references.map((reference) => reference.identifier) ?? [],\n );\n const freeNames = new Set(\n identifiers\n .filter((identifier) => !errorReads.has(identifier))\n .map((identifier) => String(AstNode.readField({ node: identifier, key: 'name' }))),\n );\n\n // The fallback is evaluated after the `let`: reading the declared name there would read `undefined`.\n if (freeNames.has(name)) {\n return undefined;\n }\n\n const scope = sourceCode.getScope(declaration);\n const isTaken = (candidate: string) =>\n candidate === name ||\n freeNames.has(candidate) ||\n (candidate !== parameterName && isDeclaredAround({ scope, name: candidate }));\n const base = parameterName ?? CATCH_NAME;\n let catchName = base;\n\n for (let index = 2; isTaken(catchName); index += 1) {\n catchName = `${base}${index}`;\n }\n\n const comments = sourceCode.getCommentsInside(declaration);\n const isInside = (range: [number, number] | undefined, inner: [number, number] | undefined) =>\n range !== undefined && inner !== undefined && range[0] <= inner[0] && inner[1] <= range[1];\n\n if (\n comments.some(\n (comment) => !isInside(receiver.range, comment.range) && !isInside(body.range, comment.range),\n )\n ) {\n return undefined;\n }\n\n const bodyStart = body.range?.[0] ?? 0;\n let valueText = sourceCode.getText(body);\n\n if (catchName !== parameterName && errorReads.size > 0) {\n const edits = [...errorReads]\n .filter(AwaitSupport.isNode)\n .map((identifier) => {\n const parent = AwaitSupport.parentOf({ node: identifier });\n const isShorthand =\n AstNode.getType({ node: parent }) === AstNodeTypes.PROPERTY &&\n AstNode.readField({ node: parent, key: 'shorthand' }) === true;\n\n return {\n range: identifier.range ?? [0, 0],\n text: isShorthand ? `${parameterName}: ${catchName}` : catchName,\n };\n })\n .sort((left, right) => right.range[0] - left.range[0]);\n\n for (const edit of edits) {\n valueText =\n valueText.slice(0, edit.range[0] - bodyStart) +\n edit.text +\n valueText.slice(edit.range[1] - bodyStart);\n }\n }\n\n return {\n declaration,\n keyword,\n name,\n annotation,\n receiverText: sourceCode.getText(receiver),\n catchName,\n isErrorRead: errorReads.size > 0,\n valueText,\n };\n};\n\n/**\n * `@venizia/no-await-promise-chain`. One expression uses one async style: `await` (in a try/catch when it can\n * fail), or a promise chain that is not awaited. An `await` whose operand - after parentheses, `!`, `as`,\n * `satisfies` and an optional chain - is a call of `.then`, `.catch` or `.finally` (`?.then(`, `['then'](`, a\n * thenable such as a query builder) is reported once, however long the chain. A chain that is returned or stands\n * as a statement is not awaited and is not reported, nor is `await Promise.all(xs.map(f))`, `await new Promise(...)`,\n * `await x.then` (no call), or an `await` inside a callback of a chain.\n *\n * The fix is made for one shape only, `const|let x = await f().catch(() => <value>)` (see `planFix` for every\n * 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\n * `let`, a type annotation stays, the catch variable takes the handler's parameter name (`error` without one,\n * renamed when the name is taken), and is typed `any` when the value reads it, as the handler's parameter was.\n * The try also catches a synchronous throw of `f()`, which the chain let through. Everything else is reported.\n */\nexport class NoAwaitPromiseChainRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-await-promise-chain`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n fixable: 'code',\n schema: [],\n messages: {\n mixed:\n 'Do not `await` a promise chain (`.{{method}}(...)`): wrap `await f()` in try/catch, or drop the `await` and keep the chain.',\n mixedConst:\n 'Do not `await` a promise chain (`.{{method}}(...)`): wrap `await f()` in try/catch, or drop the `await` and keep the chain. The fix writes the try/catch and turns the `const` into a `let`.',\n },\n },\n create: (context) => {\n const { sourceCode } = context;\n\n return {\n [AstNodeTypes.AWAIT_EXPRESSION]: (node: Rule.Node) => {\n const method = PromiseChainSupport.chainMethodOf({\n node: AstNode.readField({ node, key: 'argument' }),\n });\n\n if (method === undefined) {\n return;\n }\n\n const plan = planFix({ awaitNode: node, sourceCode });\n\n context.report({\n node,\n messageId: plan?.keyword === 'const' ? 'mixedConst' : 'mixed',\n data: { method },\n fix: plan\n ? (fixer) => {\n const indent = AwaitSupport.indentOf({ node: plan.declaration, sourceCode });\n const inner = `${indent} `;\n // The optional catch binding when nothing reads the error: a named one would be an unused variable.\n const head = plan.isErrorRead ? `catch (${plan.catchName}: any)` : 'catch';\n\n return fixer.replaceText(\n plan.declaration,\n [\n `let ${plan.name}${plan.annotation};`,\n `${indent}try {`,\n `${inner}${plan.name} = await ${plan.receiverText};`,\n `${indent}} ${head} {`,\n `${inner}${plan.name} = ${plan.valueText};`,\n `${indent}}`,\n ].join('\\n'),\n );\n }\n : null,\n });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import type { TRuleSeverity } from '../rules/common';
3
3
  /**
4
- * `venizia/no-inline-await`. `await` stands alone: as a whole statement (`await f();`) or as the whole initializer
4
+ * `@venizia/no-inline-await`. `await` stands alone: as a whole statement (`await f();`) or as the whole initializer
5
5
  * of a declaration (`const result = await f();`). Inside any other expression - a call argument, a spread, an
6
6
  * array or object, a ternary, a logical operator, a template literal, a member access, an assignment - it is
7
7
  * reported, and `return g(await f())` is the same report. `return await f()` is `no-return-await`'s.
@@ -11,7 +11,7 @@ import type { TRuleSeverity } from '../rules/common';
11
11
  * test, an unbraced `if` branch or an arrow expression body; those cases are reported and left alone.
12
12
  */
13
13
  export declare class NoInlineAwaitRule {
14
- static readonly NAME = "venizia/no-inline-await";
14
+ static readonly NAME = "@venizia/no-inline-await";
15
15
  static readonly RULE: Rule.RuleModule;
16
16
  static build(opts?: {
17
17
  severity?: TRuleSeverity;
@@ -4,7 +4,7 @@ exports.NoInlineAwaitRule = void 0;
4
4
  const await_support_1 = require("./await-support");
5
5
  const common_1 = require("./common");
6
6
  /**
7
- * `venizia/no-inline-await`. `await` stands alone: as a whole statement (`await f();`) or as the whole initializer
7
+ * `@venizia/no-inline-await`. `await` stands alone: as a whole statement (`await f();`) or as the whole initializer
8
8
  * of a declaration (`const result = await f();`). Inside any other expression - a call argument, a spread, an
9
9
  * array or object, a ternary, a logical operator, a template literal, a member access, an assignment - it is
10
10
  * reported, and `return g(await f())` is the same report. `return await f()` is `no-return-await`'s.
@@ -1 +1 @@
1
- {"version":3,"file":"no-inline-await.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-inline-await.rule.ts"],"names":[],"mappings":";;;AAEA,mDAA+C;AAC/C,qCAAyE;AAEzE;;;;;;;;;GASG;AACH,MAAa,iBAAiB;aACZ,SAAI,GAAG,GAAG,+BAAsB,kBAAkB,CAAC;aAEnD,SAAI,GAAoB;QACtC,IAAI,EAAE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/common';\nimport { AwaitSupport } from './await-support';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/**\n * `venizia/no-inline-await`. `await` stands alone: as a whole statement (`await f();`) or as the whole initializer\n * of a declaration (`const result = await f();`). Inside any other expression - a call argument, a spread, an\n * array or object, a ternary, a logical operator, a template literal, a member access, an assignment - it is\n * reported, and `return g(await f())` is the same report. `return await f()` is `no-return-await`'s.\n *\n * The fix moves the `await` into a `const` in front of the statement. It is made only when nothing that does more\n * than read a value runs before the `await` inside the statement, and when the `await` is not in a branch, a loop\n * test, an unbraced `if` branch or an arrow expression body; those cases are reported and left alone.\n */\nexport class NoInlineAwaitRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-inline-await`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n fixable: 'code',\n schema: [],\n messages: {\n inline:\n '`await` stands alone as a statement or as the whole initializer of a declaration (`const result = await f();`), not inside an expression.',\n },\n },\n create: (context) => {\n const { sourceCode } = context;\n\n return {\n [AstNodeTypes.AWAIT_EXPRESSION]: (node: Rule.Node) => {\n const parent = AwaitSupport.parentOf({ node });\n const parentType = AstNode.getType({ node: parent });\n const isWhole =\n (parentType === AstNodeTypes.EXPRESSION_STATEMENT &&\n AstNode.readField({ node: parent, key: 'expression' }) === node) ||\n (parentType === AstNodeTypes.VARIABLE_DECLARATOR &&\n AstNode.readField({ node: parent, key: 'init' }) === node);\n const isReturned =\n (parentType === AstNodeTypes.RETURN_STATEMENT ||\n parentType === AstNodeTypes.ARROW_FUNCTION_EXPRESSION) &&\n (AstNode.readField({ node: parent, key: 'argument' }) === node ||\n AstNode.readField({ node: parent, key: 'body' }) === node);\n\n if (isWhole || isReturned) {\n return;\n }\n\n const statement = AwaitSupport.hoistTarget({ awaitNode: node });\n const canFix =\n statement !== undefined &&\n !AwaitSupport.hasEffectBefore({ statement, awaitNode: node, sourceCode });\n\n context.report({\n node,\n messageId: 'inline',\n fix: canFix\n ? (fixer) => {\n const name = AwaitSupport.freshName({ node, base: 'result', sourceCode });\n const [start, end] = AwaitSupport.replaceRangeOf({ awaitNode: node, sourceCode });\n const indent = AwaitSupport.indentOf({ node: statement, sourceCode });\n\n return [\n fixer.insertTextBefore(\n statement,\n `const ${name} = ${sourceCode.getText(node)};\\n${indent}`,\n ),\n fixer.replaceTextRange([start, end], name),\n ];\n }\n : null,\n });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
1
+ {"version":3,"file":"no-inline-await.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-inline-await.rule.ts"],"names":[],"mappings":";;;AAEA,mDAA+C;AAC/C,qCAAyE;AAEzE;;;;;;;;;GASG;AACH,MAAa,iBAAiB;aACZ,SAAI,GAAG,GAAG,+BAAsB,kBAAkB,CAAC;aAEnD,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,MAAM;YACf,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE;gBACR,MAAM,EACJ,2IAA2I;aAC9I;SACF;QACD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;YAE/B,OAAO;gBACL,CAAC,qBAAY,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;oBACnD,MAAM,MAAM,GAAG,4BAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC/C,MAAM,UAAU,GAAG,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;oBACrD,MAAM,OAAO,GACX,CAAC,UAAU,KAAK,qBAAY,CAAC,oBAAoB;wBAC/C,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,KA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AM,GAAG,4BAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;gCAEtE,OAAO;oCACL,KAAK,CAAC,gBAAgB,CACpB,SAAS,EACT,SAAS,IAAI,MAAM,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,MAAM,EAAE,CAC1D;oCACD,KAAK,CAAC,gBAAgB,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC;iCAC3C,CAAC;4BACJ,CAAC;4BACH,CAAC,CAAC,IAAI;qBACT,CAAC,CAAC;gBACL,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AAlEH,8CAmEC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AwaitSupport } from './await-support';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/**\n * `@venizia/no-inline-await`. `await` stands alone: as a whole statement (`await f();`) or as the whole initializer\n * of a declaration (`const result = await f();`). Inside any other expression - a call argument, a spread, an\n * array or object, a ternary, a logical operator, a template literal, a member access, an assignment - it is\n * reported, and `return g(await f())` is the same report. `return await f()` is `no-return-await`'s.\n *\n * The fix moves the `await` into a `const` in front of the statement. It is made only when nothing that does more\n * than read a value runs before the `await` inside the statement, and when the `await` is not in a branch, a loop\n * test, an unbraced `if` branch or an arrow expression body; those cases are reported and left alone.\n */\nexport class NoInlineAwaitRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-inline-await`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n fixable: 'code',\n schema: [],\n messages: {\n inline:\n '`await` stands alone as a statement or as the whole initializer of a declaration (`const result = await f();`), not inside an expression.',\n },\n },\n create: (context) => {\n const { sourceCode } = context;\n\n return {\n [AstNodeTypes.AWAIT_EXPRESSION]: (node: Rule.Node) => {\n const parent = AwaitSupport.parentOf({ node });\n const parentType = AstNode.getType({ node: parent });\n const isWhole =\n (parentType === AstNodeTypes.EXPRESSION_STATEMENT &&\n AstNode.readField({ node: parent, key: 'expression' }) === node) ||\n (parentType === AstNodeTypes.VARIABLE_DECLARATOR &&\n AstNode.readField({ node: parent, key: 'init' }) === node);\n const isReturned =\n (parentType === AstNodeTypes.RETURN_STATEMENT ||\n parentType === AstNodeTypes.ARROW_FUNCTION_EXPRESSION) &&\n (AstNode.readField({ node: parent, key: 'argument' }) === node ||\n AstNode.readField({ node: parent, key: 'body' }) === node);\n\n if (isWhole || isReturned) {\n return;\n }\n\n const statement = AwaitSupport.hoistTarget({ awaitNode: node });\n const canFix =\n statement !== undefined &&\n !AwaitSupport.hasEffectBefore({ statement, awaitNode: node, sourceCode });\n\n context.report({\n node,\n messageId: 'inline',\n fix: canFix\n ? (fixer) => {\n const name = AwaitSupport.freshName({ node, base: 'result', sourceCode });\n const [start, end] = AwaitSupport.replaceRangeOf({ awaitNode: node, sourceCode });\n const indent = AwaitSupport.indentOf({ node: statement, sourceCode });\n\n return [\n fixer.insertTextBefore(\n statement,\n `const ${name} = ${sourceCode.getText(node)};\\n${indent}`,\n ),\n fixer.replaceTextRange([start, end], name),\n ];\n }\n : null,\n });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import type { TRuleSeverity } from '../rules/common';
3
3
  /**
4
- * `venizia/no-leaked-render`. `{count && <X />}` draws `0` when `count` is `0`; draw nothing with
4
+ * `@venizia/no-leaked-render`. `{count && <X />}` draws `0` when `count` is `0`; draw nothing with
5
5
  * `cond ? <X /> : null`. Only a child of JSX is checked. The fix rewrites it to the ternary and keeps
6
6
  * any comment between `&&` and the drawn part.
7
7
  */
8
8
  export declare class NoLeakedRenderRule {
9
- static readonly NAME = "venizia/no-leaked-render";
9
+ static readonly NAME = "@venizia/no-leaked-render";
10
10
  static readonly RULE: Rule.RuleModule;
11
11
  static build(opts?: {
12
12
  severity?: TRuleSeverity;
@@ -7,7 +7,7 @@ const LEAKED_RENDER_SELECTOR = [common_1.AstNodeTypes.JSX_ELEMENT, common_1.AstN
7
7
  .map((parent) => `${parent} > ${common_1.AstNodeTypes.JSX_EXPRESSION_CONTAINER} > ${common_1.AstNodeTypes.LOGICAL_EXPRESSION}[operator='&&']`)
8
8
  .join(', ');
9
9
  /**
10
- * `venizia/no-leaked-render`. `{count && <X />}` draws `0` when `count` is `0`; draw nothing with
10
+ * `@venizia/no-leaked-render`. `{count && <X />}` draws `0` when `count` is `0`; draw nothing with
11
11
  * `cond ? <X /> : null`. Only a child of JSX is checked. The fix rewrites it to the ternary and keeps
12
12
  * any comment between `&&` and the drawn part.
13
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"no-leaked-render.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-leaked-render.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAgE;AAEhE,4FAA4F;AAC5F,MAAM,sBAAsB,GAAG,CAAC,qBAAY,CAAC,WAAW,EAAE,qBAAY,CAAC,YAAY,CAAC;KACjF,GAAG,CACF,CAAC,MAAM,EAAE,EAAE,CACT,GAAG,MAAM,MAAM,qBAAY,CAAC,wBAAwB,MAAM,qBAAY,CAAC,kBAAkB,iBAAiB,CAC7G;KACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAEd;;;;GAIG;AACH,MAAa,kBAAkB;aACb,SAAI,GAAG,GAAG,+BAAsB,mBAAmB,CAAC;aAEpD,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,MAAM;YACf,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE;gBACR,MAAM,EAAE,uEAAuE;aAChF;SACF;QACD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACpB,CAAC,sBAAsB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;gBAC5C,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAY,CAAC,kBAAkB,EAAE,CAAC;oBAClD,OAAO;gBACT,CAAC;gBAED,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;gBAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;gBAElF,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACd,OAAO;gBACT,CAAC;gBAED,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBAC3E,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,QAAQ;oBACnB,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;iBAC1F,CAAC,CAAC;YACL,CAAC;SACF,CAAC;KACH,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AArCH,gDAsCC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** `&&` directly under a JSX child: `disabled={a && b}` is a value, not something drawn. */\nconst LEAKED_RENDER_SELECTOR = [AstNodeTypes.JSX_ELEMENT, AstNodeTypes.JSX_FRAGMENT]\n .map(\n (parent) =>\n `${parent} > ${AstNodeTypes.JSX_EXPRESSION_CONTAINER} > ${AstNodeTypes.LOGICAL_EXPRESSION}[operator='&&']`,\n )\n .join(', ');\n\n/**\n * `venizia/no-leaked-render`. `{count && <X />}` draws `0` when `count` is `0`; draw nothing with\n * `cond ? <X /> : null`. Only a child of JSX is checked. The fix rewrites it to the ternary and keeps\n * any comment between `&&` and the drawn part.\n */\nexport class NoLeakedRenderRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-leaked-render`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n fixable: 'code',\n schema: [],\n messages: {\n leaked: 'Draw nothing with `cond ? <X /> : null`; `&&` draws 0 when cond is 0.',\n },\n },\n create: (context) => ({\n [LEAKED_RENDER_SELECTOR]: (node: Rule.Node) => {\n if (node.type !== AstNodeTypes.LOGICAL_EXPRESSION) {\n return;\n }\n\n const source = context.sourceCode;\n const operator = source.getTokenAfter(node.left, (token) => token.value === '&&');\n\n if (!operator) {\n return;\n }\n\n const drawn = source.text.slice(operator.range[1], node.range?.[1]).trim();\n context.report({\n node,\n messageId: 'leaked',\n fix: (fixer) => fixer.replaceText(node, `${source.getText(node.left)} ? ${drawn} : null`),\n });\n },\n }),\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
1
+ {"version":3,"file":"no-leaked-render.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-leaked-render.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAgE;AAEhE,4FAA4F;AAC5F,MAAM,sBAAsB,GAAG,CAAC,qBAAY,CAAC,WAAW,EAAE,qBAAY,CAAC,YAAY,CAAC;KACjF,GAAG,CACF,CAAC,MAAM,EAAE,EAAE,CACT,GAAG,MAAM,MAAM,qBAAY,CAAC,wBAAwB,MAAM,qBAAY,CAAC,kBAAkB,iBAAiB,CA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AK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AArCH,gDAsCC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** `&&` directly under a JSX child: `disabled={a && b}` is a value, not something drawn. */\nconst LEAKED_RENDER_SELECTOR = [AstNodeTypes.JSX_ELEMENT, AstNodeTypes.JSX_FRAGMENT]\n .map(\n (parent) =>\n `${parent} > ${AstNodeTypes.JSX_EXPRESSION_CONTAINER} > ${AstNodeTypes.LOGICAL_EXPRESSION}[operator='&&']`,\n )\n .join(', ');\n\n/**\n * `@venizia/no-leaked-render`. `{count && <X />}` draws `0` when `count` is `0`; draw nothing with\n * `cond ? <X /> : null`. Only a child of JSX is checked. The fix rewrites it to the ternary and keeps\n * any comment between `&&` and the drawn part.\n */\nexport class NoLeakedRenderRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-leaked-render`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n fixable: 'code',\n schema: [],\n messages: {\n leaked: 'Draw nothing with `cond ? <X /> : null`; `&&` draws 0 when cond is 0.',\n },\n },\n create: (context) => ({\n [LEAKED_RENDER_SELECTOR]: (node: Rule.Node) => {\n if (node.type !== AstNodeTypes.LOGICAL_EXPRESSION) {\n return;\n }\n\n const source = context.sourceCode;\n const operator = source.getTokenAfter(node.left, (token) => token.value === '&&');\n\n if (!operator) {\n return;\n }\n\n const drawn = source.text.slice(operator.range[1], node.range?.[1]).trim();\n context.report({\n node,\n messageId: 'leaked',\n fix: (fixer) => fixer.replaceText(node, `${source.getText(node.left)} ? ${drawn} : null`),\n });\n },\n }),\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import type { TRuleSeverity } from '../rules/common';
3
3
  /**
4
- * `venizia/no-new-error`. An error is thrown through `getError({ message })` (or an `ApplicationError`),
4
+ * `@venizia/no-new-error`. An error is thrown through `getError({ message })` (or an `ApplicationError`),
5
5
  * never `new Error(...)` or `Error(...)`: only an ApplicationError carries the status, the message code and
6
6
  * args, and the `extra` every IGNIS layer reads.
7
7
  */
8
8
  export declare class NoNewErrorRule {
9
- static readonly NAME = "venizia/no-new-error";
9
+ static readonly NAME = "@venizia/no-new-error";
10
10
  static readonly RULE: Rule.RuleModule;
11
11
  static build(opts?: {
12
12
  severity?: TRuleSeverity;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NoNewErrorRule = void 0;
4
4
  const common_1 = require("./common");
5
5
  /**
6
- * `venizia/no-new-error`. An error is thrown through `getError({ message })` (or an `ApplicationError`),
6
+ * `@venizia/no-new-error`. An error is thrown through `getError({ message })` (or an `ApplicationError`),
7
7
  * never `new Error(...)` or `Error(...)`: only an ApplicationError carries the status, the message code and
8
8
  * args, and the `extra` every IGNIS layer reads.
9
9
  */
@@ -14,7 +14,7 @@ class NoNewErrorRule {
14
14
  type: 'problem',
15
15
  schema: [],
16
16
  messages: {
17
- newError: 'Throw through getError({ message }) (or an ApplicationError), not `{{form}}`: only an ApplicationError carries the status, code and args.',
17
+ newError: "Throw through `getError({ message })` (or an ApplicationError), not `{{form}}`: only an ApplicationError carries the status, code and args: `import { getError } from '@venizia/ignis-helpers/core';`",
18
18
  },
19
19
  },
20
20
  create: (context) => {
@@ -1 +1 @@
1
- {"version":3,"file":"no-new-error.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-new-error.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE;;;;GAIG;AACH,MAAa,cAAc;aACT,SAAI,GAAG,GAAG,+BAAsB,eAAe,CAAC;aAEhD,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,SAAS;YACf,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AAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AArCH,wCAsCC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/**\n * `venizia/no-new-error`. An error is thrown through `getError({ message })` (or an `ApplicationError`),\n * never `new Error(...)` or `Error(...)`: only an ApplicationError carries the status, the message code and\n * args, and the `extra` every IGNIS layer reads.\n */\nexport class NoNewErrorRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-new-error`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n newError:\n 'Throw through getError({ message }) (or an ApplicationError), not `{{form}}`: only an ApplicationError carries the status, code and args.',\n },\n },\n create: (context) => {\n const report = (opts: { node: Rule.Node; form: string }) =>\n context.report({ node: opts.node, messageId: 'newError', data: { form: opts.form } });\n\n const isErrorIdentifier = (callee: unknown) =>\n AstNode.getType({ node: callee }) === AstNodeTypes.IDENTIFIER &&\n AstNode.readField({ node: callee, key: 'name' }) === 'Error';\n\n return {\n [AstNodeTypes.NEW_EXPRESSION]: (node: Rule.Node) => {\n if (isErrorIdentifier(AstNode.readField({ node, key: 'callee' }))) {\n report({ node, form: 'new Error(...)' });\n }\n },\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n if (isErrorIdentifier(AstNode.readField({ node, key: 'callee' }))) {\n report({ node, form: 'Error(...)' });\n }\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
1
+ {"version":3,"file":"no-new-error.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-new-error.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE;;;;GAIG;AACH,MAAa,cAAc;aACT,SAAI,GAAG,GAAG,+B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,CAAC;oBACvC,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AArCH,wCAsCC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/**\n * `@venizia/no-new-error`. An error is thrown through `getError({ message })` (or an `ApplicationError`),\n * never `new Error(...)` or `Error(...)`: only an ApplicationError carries the status, the message code and\n * args, and the `extra` every IGNIS layer reads.\n */\nexport class NoNewErrorRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-new-error`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n newError:\n \"Throw through `getError({ message })` (or an ApplicationError), not `{{form}}`: only an ApplicationError carries the status, code and args: `import { getError } from '@venizia/ignis-helpers/core';`\",\n },\n },\n create: (context) => {\n const report = (opts: { node: Rule.Node; form: string }) =>\n context.report({ node: opts.node, messageId: 'newError', data: { form: opts.form } });\n\n const isErrorIdentifier = (callee: unknown) =>\n AstNode.getType({ node: callee }) === AstNodeTypes.IDENTIFIER &&\n AstNode.readField({ node: callee, key: 'name' }) === 'Error';\n\n return {\n [AstNodeTypes.NEW_EXPRESSION]: (node: Rule.Node) => {\n if (isErrorIdentifier(AstNode.readField({ node, key: 'callee' }))) {\n report({ node, form: 'new Error(...)' });\n }\n },\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n if (isErrorIdentifier(AstNode.readField({ node, key: 'callee' }))) {\n report({ node, form: 'Error(...)' });\n }\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
@@ -0,0 +1,45 @@
1
+ import type { Linter, Rule } from 'eslint';
2
+ import type { TRuleSeverity } from '../rules/common';
3
+ /**
4
+ * `@venizia/no-parent-import`. An import that climbs out of its folder (`../x`) is written from the package's import map
5
+ * instead (`#src/x`): it keeps its meaning when the file moves, and reads the same from every depth.
6
+ *
7
+ * The fix is made only when the nearest `package.json` maps `#src/*` to a folder and the import lands inside that folder;
8
+ * every other finding is reported and left alone. A same-folder `./x` is never reported.
9
+ *
10
+ * No preset turns it on. A project that wants it adds, after the preset:
11
+ * `{ files: ['**\/*.{ts,tsx,mts,cts}'], rules: { '@venizia/no-parent-import': 'warn' } }`.
12
+ */
13
+ export declare class NoParentImportRule {
14
+ static readonly NAME = "@venizia/no-parent-import";
15
+ static readonly ALIAS = "#src";
16
+ /** One scan reads the same package.json for every file of a package. */
17
+ private static readonly maps;
18
+ /** A parsed JSON file (a package.json or a tsconfig without comments), or `undefined` when it cannot be read: a broken file never stops a lint run, the import is reported without a fix. */
19
+ private static readManifest;
20
+ /** The import map of the package that owns `directory`, or `undefined` when it has none for `#src/*`. */
21
+ private static mapOf;
22
+ /**
23
+ * `#src/<path>` for the specifier `specifier` written in `filename`, when the map reaches it AND the result resolves.
24
+ *
25
+ * What the map appends decides it. With `./src/*.js` (the preset) the written `.js`, `.ts` or `.tsx` goes (the map adds
26
+ * `.js`, and TypeScript reads that as the source), an extensionless file stays as it is, and a folder gets `/index`; any
27
+ * other extension is kept only when the map has a `#src/*<ext>` key for it. With a bare `./src/*` the path must keep the
28
+ * extension it is written with, because TypeScript does not guess one through `imports`; an extensionless specifier is
29
+ * reported and left alone.
30
+ */
31
+ private static aliasFor;
32
+ /**
33
+ * `/index` when the target is a folder and the package cannot resolve a folder through `#src/*`. A package.json `imports`
34
+ * map has no directory index, so `#src/folder` only resolves where the tsconfig `paths` entry `#src/*` also lists
35
+ * `./src/*\/index`; elsewhere the fix writes the file out. A target that is a file, or not on disk, is left as written.
36
+ */
37
+ private static indexSuffix;
38
+ /** Whether the package's tsconfig `paths` maps `#src/*` to a folder index as well. */
39
+ private static pathsResolveFolders;
40
+ static readonly RULE: Rule.RuleModule;
41
+ static build(opts?: {
42
+ severity?: TRuleSeverity;
43
+ }): Linter.RuleEntry;
44
+ }
45
+ //# sourceMappingURL=no-parent-import.rule.d.ts.map
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoParentImportRule = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const common_1 = require("./common");
7
+ /**
8
+ * `@venizia/no-parent-import`. An import that climbs out of its folder (`../x`) is written from the package's import map
9
+ * instead (`#src/x`): it keeps its meaning when the file moves, and reads the same from every depth.
10
+ *
11
+ * The fix is made only when the nearest `package.json` maps `#src/*` to a folder and the import lands inside that folder;
12
+ * every other finding is reported and left alone. A same-folder `./x` is never reported.
13
+ *
14
+ * No preset turns it on. A project that wants it adds, after the preset:
15
+ * `{ files: ['**\/*.{ts,tsx,mts,cts}'], rules: { '@venizia/no-parent-import': 'warn' } }`.
16
+ */
17
+ class NoParentImportRule {
18
+ static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/no-parent-import`; }
19
+ static { this.ALIAS = '#src'; }
20
+ /** One scan reads the same package.json for every file of a package. */
21
+ static { this.maps = new Map(); }
22
+ /** A parsed JSON file (a package.json or a tsconfig without comments), or `undefined` when it cannot be read: a broken file never stops a lint run, the import is reported without a fix. */
23
+ static readManifest(opts) {
24
+ try {
25
+ return JSON.parse((0, node_fs_1.readFileSync)(opts.file, 'utf8'));
26
+ // eslint-disable-next-line @venizia/no-silent-catch -- a package.json that does not parse only costs the autofix
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+ /** The import map of the package that owns `directory`, or `undefined` when it has none for `#src/*`. */
33
+ static mapOf(opts) {
34
+ const { directory } = opts;
35
+ const cached = NoParentImportRule.maps.get(directory);
36
+ if (cached !== undefined) {
37
+ return cached ?? undefined;
38
+ }
39
+ const manifest = (0, node_path_1.join)(directory, 'package.json');
40
+ let found;
41
+ if ((0, node_fs_1.existsSync)(manifest)) {
42
+ const parsed = NoParentImportRule.readManifest({ file: manifest });
43
+ const imports = common_1.AstNode.readField({ node: parsed, key: 'imports' });
44
+ const mapped = common_1.AstNode.readField({ node: imports, key: `${NoParentImportRule.ALIAS}/*` });
45
+ const value = typeof mapped === 'string' ? mapped : common_1.AstNode.readField({ node: mapped, key: 'default' });
46
+ // `./src/*` and the preset's `./src/*.js` both name the source folder; the suffix decides what a fix may write.
47
+ const shape = typeof value === 'string' ? /^(.*)\/\*((?:\.[a-z]+)?)$/.exec(value) : null;
48
+ if (shape?.[1] !== undefined) {
49
+ const extensions = new Set();
50
+ for (const key of Object.keys(typeof imports === 'object' && imports !== null ? imports : {})) {
51
+ const extension = new RegExp(`^${NoParentImportRule.ALIAS}/\\*(\\.[a-z0-9]+)$`).exec(key)?.[1];
52
+ if (extension !== undefined) {
53
+ extensions.add(extension);
54
+ }
55
+ }
56
+ found = {
57
+ root: directory,
58
+ target: (0, node_path_1.resolve)(directory, shape[1]),
59
+ suffix: shape[2] ?? '',
60
+ extensions,
61
+ };
62
+ }
63
+ // A package.json that has no map still ends the walk: the next one up belongs to another package.
64
+ NoParentImportRule.maps.set(directory, found ?? null);
65
+ return found;
66
+ }
67
+ const parent = (0, node_path_1.dirname)(directory);
68
+ const inherited = parent === directory ? undefined : NoParentImportRule.mapOf({ directory: parent });
69
+ NoParentImportRule.maps.set(directory, inherited ?? null);
70
+ return inherited;
71
+ }
72
+ /**
73
+ * `#src/<path>` for the specifier `specifier` written in `filename`, when the map reaches it AND the result resolves.
74
+ *
75
+ * What the map appends decides it. With `./src/*.js` (the preset) the written `.js`, `.ts` or `.tsx` goes (the map adds
76
+ * `.js`, and TypeScript reads that as the source), an extensionless file stays as it is, and a folder gets `/index`; any
77
+ * other extension is kept only when the map has a `#src/*<ext>` key for it. With a bare `./src/*` the path must keep the
78
+ * extension it is written with, because TypeScript does not guess one through `imports`; an extensionless specifier is
79
+ * reported and left alone.
80
+ */
81
+ static aliasFor(opts) {
82
+ const map = NoParentImportRule.mapOf({ directory: (0, node_path_1.dirname)(opts.filename) });
83
+ if (!map) {
84
+ return undefined;
85
+ }
86
+ const absolute = (0, node_path_1.resolve)((0, node_path_1.dirname)(opts.filename), opts.specifier);
87
+ const inside = (0, node_path_1.relative)(map.target, absolute);
88
+ if (inside === '' || inside.startsWith('..') || inside.startsWith(node_path_1.sep)) {
89
+ return undefined;
90
+ }
91
+ const path = inside.split(node_path_1.sep).join('/');
92
+ const extension = (0, node_path_1.extname)(path);
93
+ const sourceExtensions = ['.js', '.ts', '.tsx'];
94
+ if (extension === '') {
95
+ return map.suffix === ''
96
+ ? undefined
97
+ : `${NoParentImportRule.ALIAS}/${path}${NoParentImportRule.indexSuffix({ absolute, map })}`;
98
+ }
99
+ if (map.suffix === '.js' && sourceExtensions.includes(extension)) {
100
+ return `${NoParentImportRule.ALIAS}/${path.slice(0, -extension.length)}`;
101
+ }
102
+ if (map.suffix === '' || map.extensions.has(extension)) {
103
+ return `${NoParentImportRule.ALIAS}/${path}`;
104
+ }
105
+ return undefined;
106
+ }
107
+ /**
108
+ * `/index` when the target is a folder and the package cannot resolve a folder through `#src/*`. A package.json `imports`
109
+ * map has no directory index, so `#src/folder` only resolves where the tsconfig `paths` entry `#src/*` also lists
110
+ * `./src/*\/index`; elsewhere the fix writes the file out. A target that is a file, or not on disk, is left as written.
111
+ */
112
+ static indexSuffix(opts) {
113
+ const { absolute, map } = opts;
114
+ const extensions = ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.json'];
115
+ if (extensions.some((extension) => (0, node_fs_1.existsSync)(`${absolute}${extension}`))) {
116
+ return '';
117
+ }
118
+ const isFolder = ['index.ts', 'index.tsx', 'index.js'].some((name) => (0, node_fs_1.existsSync)((0, node_path_1.join)(absolute, name)));
119
+ return isFolder && !NoParentImportRule.pathsResolveFolders({ root: map.root }) ? '/index' : '';
120
+ }
121
+ /** Whether the package's tsconfig `paths` maps `#src/*` to a folder index as well. */
122
+ static pathsResolveFolders(opts) {
123
+ const config = NoParentImportRule.readManifest({ file: (0, node_path_1.join)(opts.root, 'tsconfig.json') });
124
+ const options = common_1.AstNode.readField({ node: config, key: 'compilerOptions' });
125
+ const paths = common_1.AstNode.readField({
126
+ node: common_1.AstNode.readField({ node: options, key: 'paths' }),
127
+ key: `${NoParentImportRule.ALIAS}/*`,
128
+ });
129
+ return (Array.isArray(paths) &&
130
+ paths.some((entry) => typeof entry === 'string' && entry.endsWith('/*/index')));
131
+ }
132
+ static { this.RULE = {
133
+ meta: {
134
+ type: 'suggestion',
135
+ fixable: 'code',
136
+ schema: [],
137
+ messages: {
138
+ parent: 'Import from the package import map (`#src/...`), not from a parent folder (`{{specifier}}`).',
139
+ },
140
+ },
141
+ create: (context) => {
142
+ const check = (node, opts = { fixable: true }) => {
143
+ const source = common_1.AstNode.readField({ node, key: 'source' });
144
+ const value = common_1.AstNode.readField({ node: source, key: 'value' });
145
+ if (typeof value !== 'string' || (value !== '..' && !value.startsWith('../'))) {
146
+ return;
147
+ }
148
+ const alias = NoParentImportRule.aliasFor({
149
+ filename: context.filename,
150
+ specifier: value,
151
+ });
152
+ context.report({
153
+ node,
154
+ messageId: 'parent',
155
+ data: { specifier: value },
156
+ fix: opts.fixable && alias !== undefined && common_1.AstNode.isNode(source)
157
+ ? (fixer) => fixer.replaceText(source, `'${alias}'`)
158
+ : null,
159
+ });
160
+ };
161
+ return {
162
+ [common_1.AstNodeTypes.IMPORT_DECLARATION]: (node) => check(node),
163
+ [common_1.AstNodeTypes.EXPORT_NAMED_DECLARATION]: (node) => check(node),
164
+ [common_1.AstNodeTypes.EXPORT_ALL_DECLARATION]: (node) => check(node),
165
+ // `import('../x')` is reported and left alone: its argument may be built, and the fix would not keep the laziness reading.
166
+ [common_1.AstNodeTypes.IMPORT_EXPRESSION]: (node) => check(node, { fixable: false }),
167
+ };
168
+ },
169
+ }; }
170
+ static build(opts = {}) {
171
+ const { severity = 'warn' } = opts;
172
+ return [severity];
173
+ }
174
+ }
175
+ exports.NoParentImportRule = NoParentImportRule;
176
+ //# sourceMappingURL=no-parent-import.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-parent-import.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-parent-import.rule.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,yCAA2E;AAG3E,qCAAyE;AAYzE;;;;;;;;;GASG;AACH,MAAa,kBAAkB;aACb,SAAI,GAAG,GAAG,+BAAsB,mBAAmB,CAAC;aAEpD,UAAK,GAAG,MAAM,CAAC;IAE/B,wEAAwE;aAChD,SAAI,GAAG,IAAI,GAAG,EAA6B,CAAC;IAEpE,6LAA6L;IACrL,MAAM,CAAC,YAAY,CAAC,IAAsB;QAChD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;YACnD,iHAAiH;QACnH,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,yGAAyG;IACjG,MAAM,CAAC,KAAK,CAAC,IAA2B;QAC9C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAC3B,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEtD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,MAAM,IAAI,SAAS,CAAC;QAC7B,CAAC;QAED,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACjD,IAAI,KAA6B,CAAC;QAElC,IAAI,IAAA,oBAAU,EAAC,QAAQ,CAAC,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,kBAAkB,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;YACnE,M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,OAAO;gBACL,CAAC,qBAAY,CAAC,kBAAkB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;gBACnE,CAAC,qBAAY,CAAC,wBAAwB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;gBACzE,CAAC,qBAAY,CAAC,sBAAsB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;gBACvE,2HAA2H;gBAC3H,CAAC,qBAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;aACvF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,MAAM,EAAE,QAAQ,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;QAEnC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;;AA7MH,gDA8MC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, extname, join, relative, resolve, sep } from 'node:path';\nimport type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** The `#src` import map of the package a file belongs to: its root and the directory `#src/*` points at. */\ninterface IImportMap {\n root: string;\n target: string;\n /** What the `#src/*` target appends to the matched path: `.js` in the preset (`./src/*.js`), nothing in `./src/*`. */\n suffix: string;\n /** The extensions that have a `#src/*<ext>` key of their own (`.json`): the only other files `#src/...` can name. */\n extensions: ReadonlySet<string>;\n}\n\n/**\n * `@venizia/no-parent-import`. An import that climbs out of its folder (`../x`) is written from the package's import map\n * instead (`#src/x`): it keeps its meaning when the file moves, and reads the same from every depth.\n *\n * The fix is made only when the nearest `package.json` maps `#src/*` to a folder and the import lands inside that folder;\n * every other finding is reported and left alone. A same-folder `./x` is never reported.\n *\n * No preset turns it on. A project that wants it adds, after the preset:\n * `{ files: ['**\\/*.{ts,tsx,mts,cts}'], rules: { '@venizia/no-parent-import': 'warn' } }`.\n */\nexport class NoParentImportRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-parent-import`;\n\n static readonly ALIAS = '#src';\n\n /** One scan reads the same package.json for every file of a package. */\n private static readonly maps = new Map<string, IImportMap | null>();\n\n /** A parsed JSON file (a package.json or a tsconfig without comments), or `undefined` when it cannot be read: a broken file never stops a lint run, the import is reported without a fix. */\n private static readManifest(opts: { file: string }): unknown {\n try {\n return JSON.parse(readFileSync(opts.file, 'utf8'));\n // eslint-disable-next-line @venizia/no-silent-catch -- a package.json that does not parse only costs the autofix\n } catch {\n return undefined;\n }\n }\n\n /** The import map of the package that owns `directory`, or `undefined` when it has none for `#src/*`. */\n private static mapOf(opts: { directory: string }): IImportMap | undefined {\n const { directory } = opts;\n const cached = NoParentImportRule.maps.get(directory);\n\n if (cached !== undefined) {\n return cached ?? undefined;\n }\n\n const manifest = join(directory, 'package.json');\n let found: IImportMap | undefined;\n\n if (existsSync(manifest)) {\n const parsed = NoParentImportRule.readManifest({ file: manifest });\n const imports = AstNode.readField({ node: parsed, key: 'imports' });\n const mapped = AstNode.readField({ node: imports, key: `${NoParentImportRule.ALIAS}/*` });\n const value =\n typeof mapped === 'string' ? mapped : AstNode.readField({ node: mapped, key: 'default' });\n\n // `./src/*` and the preset's `./src/*.js` both name the source folder; the suffix decides what a fix may write.\n const shape = typeof value === 'string' ? /^(.*)\\/\\*((?:\\.[a-z]+)?)$/.exec(value) : null;\n\n if (shape?.[1] !== undefined) {\n const extensions = new Set<string>();\n\n for (const key of Object.keys(\n typeof imports === 'object' && imports !== null ? imports : {},\n )) {\n const extension = new RegExp(`^${NoParentImportRule.ALIAS}/\\\\*(\\\\.[a-z0-9]+)$`).exec(\n key,\n )?.[1];\n\n if (extension !== undefined) {\n extensions.add(extension);\n }\n }\n\n found = {\n root: directory,\n target: resolve(directory, shape[1]),\n suffix: shape[2] ?? '',\n extensions,\n };\n }\n\n // A package.json that has no map still ends the walk: the next one up belongs to another package.\n NoParentImportRule.maps.set(directory, found ?? null);\n\n return found;\n }\n\n const parent = dirname(directory);\n const inherited =\n parent === directory ? undefined : NoParentImportRule.mapOf({ directory: parent });\n NoParentImportRule.maps.set(directory, inherited ?? null);\n\n return inherited;\n }\n\n /**\n * `#src/<path>` for the specifier `specifier` written in `filename`, when the map reaches it AND the result resolves.\n *\n * What the map appends decides it. With `./src/*.js` (the preset) the written `.js`, `.ts` or `.tsx` goes (the map adds\n * `.js`, and TypeScript reads that as the source), an extensionless file stays as it is, and a folder gets `/index`; any\n * other extension is kept only when the map has a `#src/*<ext>` key for it. With a bare `./src/*` the path must keep the\n * extension it is written with, because TypeScript does not guess one through `imports`; an extensionless specifier is\n * reported and left alone.\n */\n private static aliasFor(opts: { filename: string; specifier: string }): string | undefined {\n const map = NoParentImportRule.mapOf({ directory: dirname(opts.filename) });\n\n if (!map) {\n return undefined;\n }\n\n const absolute = resolve(dirname(opts.filename), opts.specifier);\n const inside = relative(map.target, absolute);\n\n if (inside === '' || inside.startsWith('..') || inside.startsWith(sep)) {\n return undefined;\n }\n\n const path = inside.split(sep).join('/');\n const extension = extname(path);\n const sourceExtensions = ['.js', '.ts', '.tsx'];\n\n if (extension === '') {\n return map.suffix === ''\n ? undefined\n : `${NoParentImportRule.ALIAS}/${path}${NoParentImportRule.indexSuffix({ absolute, map })}`;\n }\n\n if (map.suffix === '.js' && sourceExtensions.includes(extension)) {\n return `${NoParentImportRule.ALIAS}/${path.slice(0, -extension.length)}`;\n }\n\n if (map.suffix === '' || map.extensions.has(extension)) {\n return `${NoParentImportRule.ALIAS}/${path}`;\n }\n\n return undefined;\n }\n\n /**\n * `/index` when the target is a folder and the package cannot resolve a folder through `#src/*`. A package.json `imports`\n * map has no directory index, so `#src/folder` only resolves where the tsconfig `paths` entry `#src/*` also lists\n * `./src/*\\/index`; elsewhere the fix writes the file out. A target that is a file, or not on disk, is left as written.\n */\n private static indexSuffix(opts: { absolute: string; map: IImportMap }): string {\n const { absolute, map } = opts;\n const extensions = ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.json'];\n\n if (extensions.some((extension) => existsSync(`${absolute}${extension}`))) {\n return '';\n }\n\n const isFolder = ['index.ts', 'index.tsx', 'index.js'].some((name) =>\n existsSync(join(absolute, name)),\n );\n\n return isFolder && !NoParentImportRule.pathsResolveFolders({ root: map.root }) ? '/index' : '';\n }\n\n /** Whether the package's tsconfig `paths` maps `#src/*` to a folder index as well. */\n private static pathsResolveFolders(opts: { root: string }): boolean {\n const config = NoParentImportRule.readManifest({ file: join(opts.root, 'tsconfig.json') });\n const options = AstNode.readField({ node: config, key: 'compilerOptions' });\n const paths = AstNode.readField({\n node: AstNode.readField({ node: options, key: 'paths' }),\n key: `${NoParentImportRule.ALIAS}/*`,\n });\n\n return (\n Array.isArray(paths) &&\n paths.some((entry) => typeof entry === 'string' && entry.endsWith('/*/index'))\n );\n }\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n fixable: 'code',\n schema: [],\n messages: {\n parent:\n 'Import from the package import map (`#src/...`), not from a parent folder (`{{specifier}}`).',\n },\n },\n create: (context) => {\n const check = (node: Rule.Node, opts: { fixable: boolean } = { fixable: true }) => {\n const source = AstNode.readField({ node, key: 'source' });\n const value = AstNode.readField({ node: source, key: 'value' });\n\n if (typeof value !== 'string' || (value !== '..' && !value.startsWith('../'))) {\n return;\n }\n\n const alias = NoParentImportRule.aliasFor({\n filename: context.filename,\n specifier: value,\n });\n\n context.report({\n node,\n messageId: 'parent',\n data: { specifier: value },\n fix:\n opts.fixable && alias !== undefined && AstNode.isNode(source)\n ? (fixer) => fixer.replaceText(source, `'${alias}'`)\n : null,\n });\n };\n\n return {\n [AstNodeTypes.IMPORT_DECLARATION]: (node: Rule.Node) => check(node),\n [AstNodeTypes.EXPORT_NAMED_DECLARATION]: (node: Rule.Node) => check(node),\n [AstNodeTypes.EXPORT_ALL_DECLARATION]: (node: Rule.Node) => check(node),\n // `import('../x')` is reported and left alone: its argument may be built, and the fix would not keep the laziness reading.\n [AstNodeTypes.IMPORT_EXPRESSION]: (node: Rule.Node) => check(node, { fixable: false }),\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): Linter.RuleEntry {\n const { severity = 'warn' } = opts;\n\n return [severity];\n }\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import type { TRuleSeverity } from '../rules/common';
3
3
  /**
4
- * `venizia/no-return-await`. A function returns the promise (`return f()`), never `return await f()`. Where the
4
+ * `@venizia/no-return-await`. A function returns the promise (`return f()`), never `return await f()`. Where the
5
5
  * `await` matters (inside `try`, `catch` or `finally`) it is written on its own line:
6
6
  * `const result = await f(); return result;`. An arrow whose body is an `await` is the same: `() => f()`.
7
7
  */
8
8
  export declare class NoReturnAwaitRule {
9
- static readonly NAME = "venizia/no-return-await";
9
+ static readonly NAME = "@venizia/no-return-await";
10
10
  static readonly RULE: Rule.RuleModule;
11
11
  static build(opts?: {
12
12
  severity?: TRuleSeverity;
@@ -15,7 +15,7 @@ const isInTry = (node) => {
15
15
  return false;
16
16
  };
17
17
  /**
18
- * `venizia/no-return-await`. A function returns the promise (`return f()`), never `return await f()`. Where the
18
+ * `@venizia/no-return-await`. A function returns the promise (`return f()`), never `return await f()`. Where the
19
19
  * `await` matters (inside `try`, `catch` or `finally`) it is written on its own line:
20
20
  * `const result = await f(); return result;`. An arrow whose body is an `await` is the same: `() => f()`.
21
21
  */