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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +15 -11
  2. package/dist/checks/purity/manifest.js +11 -3
  3. package/dist/checks/purity/manifest.js.map +1 -1
  4. package/dist/checks/purity/probe.js +19 -2
  5. package/dist/checks/purity/probe.js.map +1 -1
  6. package/dist/checks/split-report.js +2 -1
  7. package/dist/checks/split-report.js.map +1 -1
  8. package/dist/checks/test-controls.d.ts +9 -1
  9. package/dist/checks/test-controls.js +9 -3
  10. package/dist/checks/test-controls.js.map +1 -1
  11. package/dist/checks/test-dead-code.d.ts +9 -1
  12. package/dist/checks/test-dead-code.js +13 -2
  13. package/dist/checks/test-dead-code.js.map +1 -1
  14. package/dist/checks/test-mutate.d.ts +9 -1
  15. package/dist/checks/test-mutate.js +12 -6
  16. package/dist/checks/test-mutate.js.map +1 -1
  17. package/dist/cli/check.d.ts +0 -1
  18. package/dist/cli/check.js +42 -68
  19. package/dist/cli/check.js.map +1 -1
  20. package/dist/cli/clean.js +3 -2
  21. package/dist/cli/clean.js.map +1 -1
  22. package/dist/cli/codemod/any-aliases.js +13 -12
  23. package/dist/cli/codemod/any-aliases.js.map +1 -1
  24. package/dist/cli/codemod/async-style.d.ts +1 -1
  25. package/dist/cli/codemod/async-style.js +17 -16
  26. package/dist/cli/codemod/async-style.js.map +1 -1
  27. package/dist/cli/codemod/binding-keys.js +14 -13
  28. package/dist/cli/codemod/binding-keys.js.map +1 -1
  29. package/dist/cli/codemod/class-renames.d.ts +1 -1
  30. package/dist/cli/codemod/class-renames.js +30 -11
  31. package/dist/cli/codemod/class-renames.js.map +1 -1
  32. package/dist/cli/codemod/connector-imports.js +12 -11
  33. package/dist/cli/codemod/connector-imports.js.map +1 -1
  34. package/dist/cli/codemod/const-classes.d.ts +1 -1
  35. package/dist/cli/codemod/const-classes.js +21 -20
  36. package/dist/cli/codemod/const-classes.js.map +1 -1
  37. package/dist/cli/codemod/drop-redundant-casts.d.ts +6 -1
  38. package/dist/cli/codemod/drop-redundant-casts.js +27 -19
  39. package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
  40. package/dist/cli/codemod/env-get.d.ts +3 -3
  41. package/dist/cli/codemod/env-get.js +18 -17
  42. package/dist/cli/codemod/env-get.js.map +1 -1
  43. package/dist/cli/codemod/files.js +2 -2
  44. package/dist/cli/codemod/files.js.map +1 -1
  45. package/dist/cli/codemod/function-to-arrow.d.ts +76 -0
  46. package/dist/cli/codemod/function-to-arrow.js +357 -0
  47. package/dist/cli/codemod/function-to-arrow.js.map +1 -0
  48. package/dist/cli/codemod/index.js +19 -4
  49. package/dist/cli/codemod/index.js.map +1 -1
  50. package/dist/cli/codemod/namespace-functions/index.js +13 -12
  51. package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
  52. package/dist/cli/codemod/typed-route-context.d.ts +27 -0
  53. package/dist/cli/codemod/typed-route-context.js +570 -0
  54. package/dist/cli/codemod/typed-route-context.js.map +1 -0
  55. package/dist/cli/index.js +5 -5
  56. package/dist/cli/index.js.map +1 -1
  57. package/dist/common/cli-output.d.ts +16 -0
  58. package/dist/common/cli-output.js +49 -0
  59. package/dist/common/cli-output.js.map +1 -0
  60. package/dist/compilers/bun.js +1 -1
  61. package/dist/compilers/bun.js.map +1 -1
  62. package/dist/linters/eslint.js +1 -1
  63. package/dist/linters/eslint.js.map +1 -1
  64. package/dist/linters/house/browser-api-patterns.d.ts +1 -3
  65. package/dist/linters/house/browser-api-patterns.js +1 -3
  66. package/dist/linters/house/browser-api-patterns.js.map +1 -1
  67. package/dist/linters/house/common.d.ts +8 -2
  68. package/dist/linters/house/common.js +8 -2
  69. package/dist/linters/house/common.js.map +1 -1
  70. package/dist/linters/house/configs.js +8 -6
  71. package/dist/linters/house/configs.js.map +1 -1
  72. package/dist/linters/house/const-class-values.rule.d.ts +2 -2
  73. package/dist/linters/house/const-class-values.rule.js +14 -5
  74. package/dist/linters/house/const-class-values.rule.js.map +1 -1
  75. package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +2 -2
  76. package/dist/linters/house/effect-cleanup-consistency.rule.js +1 -1
  77. package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -1
  78. package/dist/linters/house/framework-api-patterns.d.ts +54 -0
  79. package/dist/linters/house/framework-api-patterns.js +62 -0
  80. package/dist/linters/house/framework-api-patterns.js.map +1 -0
  81. package/dist/linters/house/framework-exports.d.ts +1 -1
  82. package/dist/linters/house/framework-exports.js +13 -13
  83. package/dist/linters/house/framework-exports.js.map +1 -1
  84. package/dist/linters/house/index.d.ts +3 -4
  85. package/dist/linters/house/index.js +4 -6
  86. package/dist/linters/house/index.js.map +1 -1
  87. package/dist/linters/house/max-params-own.rule.d.ts +2 -2
  88. package/dist/linters/house/max-params-own.rule.js +1 -1
  89. package/dist/linters/house/max-params-own.rule.js.map +1 -1
  90. package/dist/linters/house/no-async-hook-callback.rule.d.ts +2 -2
  91. package/dist/linters/house/no-async-hook-callback.rule.js +1 -1
  92. package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -1
  93. package/dist/linters/house/no-await-new-chain.rule.d.ts +2 -2
  94. package/dist/linters/house/no-await-new-chain.rule.js +1 -1
  95. package/dist/linters/house/no-await-new-chain.rule.js.map +1 -1
  96. package/dist/linters/house/no-await-promise-chain.rule.d.ts +2 -2
  97. package/dist/linters/house/no-await-promise-chain.rule.js +5 -5
  98. package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -1
  99. package/dist/linters/house/no-inline-await.rule.d.ts +2 -2
  100. package/dist/linters/house/no-inline-await.rule.js +1 -1
  101. package/dist/linters/house/no-inline-await.rule.js.map +1 -1
  102. package/dist/linters/house/no-leaked-render.rule.d.ts +2 -2
  103. package/dist/linters/house/no-leaked-render.rule.js +1 -1
  104. package/dist/linters/house/no-leaked-render.rule.js.map +1 -1
  105. package/dist/linters/house/no-new-error.rule.d.ts +2 -2
  106. package/dist/linters/house/no-new-error.rule.js +2 -2
  107. package/dist/linters/house/no-new-error.rule.js.map +1 -1
  108. package/dist/linters/house/no-parent-import.rule.d.ts +5 -2
  109. package/dist/linters/house/no-parent-import.rule.js +5 -2
  110. package/dist/linters/house/no-parent-import.rule.js.map +1 -1
  111. package/dist/linters/house/no-return-await.rule.d.ts +2 -2
  112. package/dist/linters/house/no-return-await.rule.js +1 -1
  113. package/dist/linters/house/no-return-await.rule.js.map +1 -1
  114. package/dist/linters/house/no-shadow-framework-type.rule.d.ts +2 -2
  115. package/dist/linters/house/no-shadow-framework-type.rule.js +2 -2
  116. package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -1
  117. package/dist/linters/house/no-silent-catch.rule.d.ts +2 -2
  118. package/dist/linters/house/no-silent-catch.rule.js +3 -3
  119. package/dist/linters/house/no-silent-catch.rule.js.map +1 -1
  120. package/dist/linters/house/no-unbraced-case.rule.d.ts +2 -2
  121. package/dist/linters/house/no-unbraced-case.rule.js +1 -1
  122. package/dist/linters/house/no-unbraced-case.rule.js.map +1 -1
  123. package/dist/linters/house/plugin.d.ts +1 -1
  124. package/dist/linters/house/plugin.js +6 -5
  125. package/dist/linters/house/plugin.js.map +1 -1
  126. package/dist/linters/house/prefer-framework-api.rule.d.ts +39 -7
  127. package/dist/linters/house/prefer-framework-api.rule.js +285 -12
  128. package/dist/linters/house/prefer-framework-api.rule.js.map +1 -1
  129. package/dist/linters/house/prefer-promise-sleep.rule.d.ts +2 -2
  130. package/dist/linters/house/prefer-promise-sleep.rule.js +3 -2
  131. package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -1
  132. package/dist/linters/house/prefer-tnullable.rule.d.ts +2 -2
  133. package/dist/linters/house/prefer-tnullable.rule.js +2 -2
  134. package/dist/linters/house/prefer-tnullable.rule.js.map +1 -1
  135. package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
  136. package/dist/linters/house/typed-route-context.rule.js +322 -0
  137. package/dist/linters/house/typed-route-context.rule.js.map +1 -0
  138. package/dist/linters/house/zod-schema-convention.rule.d.ts +82 -0
  139. package/dist/linters/house/zod-schema-convention.rule.js +477 -0
  140. package/dist/linters/house/zod-schema-convention.rule.js.map +1 -0
  141. package/dist/linters/oxlint.js +11 -1
  142. package/dist/linters/oxlint.js.map +1 -1
  143. package/dist/linters/react-eslint.js.map +1 -1
  144. package/dist/linters/rules/naming-convention.rule.d.ts +4 -1
  145. package/dist/linters/rules/naming-convention.rule.js +30 -1
  146. package/dist/linters/rules/naming-convention.rule.js.map +1 -1
  147. package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
  148. package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
  149. package/dist/testing/spawn.utility.js +1 -1
  150. package/dist/testing/spawn.utility.js.map +1 -1
  151. package/package.json +5 -5
  152. package/dist/checks/use-when-baseline.d.ts +0 -25
  153. package/dist/checks/use-when-baseline.js +0 -38
  154. package/dist/checks/use-when-baseline.js.map +0 -1
  155. package/dist/linters/house/framework-rule-apis.d.ts +0 -24
  156. package/dist/linters/house/framework-rule-apis.js +0 -48
  157. package/dist/linters/house/framework-rule-apis.js.map +0 -1
  158. package/dist/linters/house/public-surface.d.ts +0 -57
  159. package/dist/linters/house/public-surface.js +0 -174
  160. package/dist/linters/house/public-surface.js.map +0 -1
  161. package/dist/linters/house/published-package-configs.d.ts +0 -23
  162. package/dist/linters/house/published-package-configs.js +0 -42
  163. package/dist/linters/house/published-package-configs.js.map +0 -1
  164. package/dist/linters/house/require-use-when.rule.d.ts +0 -42
  165. package/dist/linters/house/require-use-when.rule.js +0 -175
  166. package/dist/linters/house/require-use-when.rule.js.map +0 -1
@@ -13,11 +13,12 @@ const max_params_own_rule_1 = require("./max-params-own.rule");
13
13
  const no_async_hook_callback_rule_1 = require("./no-async-hook-callback.rule");
14
14
  const no_leaked_render_rule_1 = require("./no-leaked-render.rule");
15
15
  const no_new_error_rule_1 = require("./no-new-error.rule");
16
- const no_parent_import_rule_1 = require("./no-parent-import.rule");
17
16
  const no_shadow_framework_type_rule_1 = require("./no-shadow-framework-type.rule");
18
17
  const prefer_framework_api_rule_1 = require("./prefer-framework-api.rule");
19
18
  const prefer_promise_sleep_rule_1 = require("./prefer-promise-sleep.rule");
20
19
  const prefer_tnullable_rule_1 = require("./prefer-tnullable.rule");
20
+ const typed_route_context_rule_1 = require("./typed-route-context.rule");
21
+ const zod_schema_convention_rule_1 = require("./zod-schema-convention.rule");
21
22
  const plugin_1 = require("./plugin");
22
23
  const SOURCE_FILES = ['**/*.{ts,tsx,mts,cts}'];
23
24
  const TEST_FILES = ['**/__tests__/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'];
@@ -45,8 +46,10 @@ const houseRuleConfigs = [
45
46
  [no_shadow_framework_type_rule_1.NoShadowFrameworkTypeRule.NAME]: no_shadow_framework_type_rule_1.NoShadowFrameworkTypeRule.build(),
46
47
  [prefer_tnullable_rule_1.PreferTNullableRule.NAME]: prefer_tnullable_rule_1.PreferTNullableRule.build(),
47
48
  [prefer_promise_sleep_rule_1.PreferPromiseSleepRule.NAME]: prefer_promise_sleep_rule_1.PreferPromiseSleepRule.build(),
48
- [no_parent_import_rule_1.NoParentImportRule.NAME]: no_parent_import_rule_1.NoParentImportRule.build(),
49
+ [prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: prefer_framework_api_rule_1.PreferFrameworkApiRule.build({ hooks: false }),
49
50
  [const_class_values_rule_1.ConstClassValuesRule.NAME]: const_class_values_rule_1.ConstClassValuesRule.build({ severity: 'warn' }),
51
+ [zod_schema_convention_rule_1.ZodSchemaConventionRule.NAME]: zod_schema_convention_rule_1.ZodSchemaConventionRule.build(),
52
+ [typed_route_context_rule_1.TypedRouteContextRule.NAME]: typed_route_context_rule_1.TypedRouteContextRule.build(),
50
53
  [NO_CAST_RULE]: ['warn', { assertionStyle: 'never' }],
51
54
  },
52
55
  },
@@ -56,7 +59,7 @@ const houseRuleConfigs = [
56
59
  [no_new_error_rule_1.NoNewErrorRule.NAME]: 'off',
57
60
  [no_shadow_framework_type_rule_1.NoShadowFrameworkTypeRule.NAME]: 'off',
58
61
  [prefer_promise_sleep_rule_1.PreferPromiseSleepRule.NAME]: 'off',
59
- [no_parent_import_rule_1.NoParentImportRule.NAME]: 'off',
62
+ [prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: 'off',
60
63
  [const_class_values_rule_1.ConstClassValuesRule.NAME]: 'off',
61
64
  [NO_CAST_RULE]: 'off',
62
65
  },
@@ -92,8 +95,7 @@ const reactRuleConfigs = [
92
95
  ];
93
96
  /**
94
97
  * The hook rules: a hook never gets an async function (`no-async-hook-callback`), and an effect callback returns a
95
- * cleanup on every path or on none (`effect-cleanup-consistency`), and `prefer-framework-api` (a browser API ardor-react wraps
96
- * in a hook is used through the hook). Hooks live in `.ts` files too, so it covers all
98
+ * cleanup on every path or on none (`effect-cleanup-consistency`). Hooks live in `.ts` files too, so it covers all
97
99
  * source files.
98
100
  */
99
101
  const reactHookRuleConfigs = [
@@ -109,7 +111,7 @@ const reactHookRuleConfigs = [
109
111
  {
110
112
  files: SOURCE_FILES,
111
113
  plugins: { [common_1.HOUSE_PLUGIN_NAMESPACE]: plugin_1.houseEslintPlugin },
112
- rules: { [prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: prefer_framework_api_rule_1.PreferFrameworkApiRule.build() },
114
+ rules: { [prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: prefer_framework_api_rule_1.PreferFrameworkApiRule.build({ hooks: true }) },
113
115
  },
114
116
  { files: TEST_FILES, rules: { [prefer_framework_api_rule_1.PreferFrameworkApiRule.NAME]: 'off' } },
115
117
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/linters/house/configs.ts"],"names":[],"mappings":";;;AACA,sCAAoD;AACpD,4CAAyC;AACzC,wCAA4C;AAC5C,kDAA+D;AAC/D,+CAAiD;AACjD,qCAAkD;AAClD,uEAAiE;AACjE,uFAAiF;AACjF,+DAAyD;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AAK,EAAE,EAAE;CACvE,CAAC;AAEF,yJAAyJ;AAC5I,QAAA,iBAAiB,GAAoB;IAChD,GAAG,2CAA4B;IAC/B,GAAG,gBAAgB;IACnB,GAAG,8BAAgB;IACnB,GAAG,wBAAc;IACjB,GAAG,gBAAgB;IACnB,GAAG,oBAAoB;CACxB,CAAC","sourcesContent":["import type { Linter } from 'eslint';\nimport { namingConventionConfigs } from '../eslint';\nimport { JSX_FILES } from '../jsx-files';\nimport { paddingConfigs } from '../padding';\nimport { reactNamingConventionConfigs } from '../react-eslint';\nimport { asyncRuleConfigs } from './async-rules';\nimport { HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { ConstClassValuesRule } from './const-class-values.rule';\nimport { EffectCleanupConsistencyRule } from './effect-cleanup-consistency.rule';\nimport { MaxParamsOwnRule } from './max-params-own.rule';\nimport { NoAsyncHookCallbackRule } from './no-async-hook-callback.rule';\nimport { NoLeakedRenderRule } from './no-leaked-render.rule';\nimport { NoNewErrorRule } from './no-new-error.rule';\nimport { NoParentImportRule } from './no-parent-import.rule';\nimport { NoShadowFrameworkTypeRule } from './no-shadow-framework-type.rule';\nimport { PreferFrameworkApiRule } from './prefer-framework-api.rule';\nimport { PreferPromiseSleepRule } from './prefer-promise-sleep.rule';\nimport { PreferTNullableRule } from './prefer-tnullable.rule';\nimport { houseEslintPlugin } from './plugin';\n\nconst SOURCE_FILES = ['**/*.{ts,tsx,mts,cts}'];\nconst TEST_FILES = ['**/__tests__/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'];\n\n/**\n * V-C-10: no explicit cast. `as const` is always allowed; `satisfies`, a generic or a narrower type\n * replaces the rest.\n */\nconst NO_CAST_RULE = '@typescript-eslint/consistent-type-assertions';\n\n/**\n * The house rules: at most 5 positional parameters on a function we write, and errors thrown through\n * `getError` only. Tests are exempt from `no-new-error`: a test throws a plain `Error` on purpose, to\n * stand in for what a driver or a third-party library throws.\n *\n * Two rules only warn, so a project adopts them without failing its lint: `const-class-values` (V-C-08, a\n * string-literal union in an exported declaration) and `consistent-type-assertions` (V-C-10, an `as X`\n * cast). Tests are exempt from both: a test stubs what it does not build.\n */\nconst houseRuleConfigs: Linter.Config[] = [\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: {\n [MaxParamsOwnRule.NAME]: MaxParamsOwnRule.build(),\n [NoNewErrorRule.NAME]: NoNewErrorRule.build(),\n [NoShadowFrameworkTypeRule.NAME]: NoShadowFrameworkTypeRule.build(),\n [PreferTNullableRule.NAME]: PreferTNullableRule.build(),\n [PreferPromiseSleepRule.NAME]: PreferPromiseSleepRule.build(),\n [NoParentImportRule.NAME]: NoParentImportRule.build(),\n [ConstClassValuesRule.NAME]: ConstClassValuesRule.build({ severity: 'warn' }),\n [NO_CAST_RULE]: ['warn', { assertionStyle: 'never' }],\n },\n },\n {\n files: TEST_FILES,\n rules: {\n [NoNewErrorRule.NAME]: 'off',\n [NoShadowFrameworkTypeRule.NAME]: 'off',\n [PreferPromiseSleepRule.NAME]: 'off',\n [NoParentImportRule.NAME]: 'off',\n [ConstClassValuesRule.NAME]: 'off',\n [NO_CAST_RULE]: 'off',\n },\n },\n];\n\n/**\n * The ESLint side of a project that lints with oxlint: the naming convention, the house rules and the async style\n * rules - everything oxlint cannot express. Run it next to `oxlintConfigs`.\n *\n * ```js\n * // .configs/lints/eslint.config.mjs\n * import { houseConfigs } from '@venizia/dev-configs/linters';\n *\n * export default houseConfigs;\n * ```\n */\nexport const houseConfigs: Linter.Config[] = [\n ...namingConventionConfigs,\n ...houseRuleConfigs,\n ...asyncRuleConfigs,\n ...paddingConfigs,\n];\n\n/**\n * The React house rule: a JSX child is drawn with `cond ? <X /> : null`, never `cond && <X />`, which\n * draws `0` when `cond` is `0`.\n */\nconst reactRuleConfigs: Linter.Config[] = [\n {\n files: JSX_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: { [NoLeakedRenderRule.NAME]: NoLeakedRenderRule.build() },\n },\n];\n\n/**\n * The hook rules: a hook never gets an async function (`no-async-hook-callback`), and an effect callback returns a\n * cleanup on every path or on none (`effect-cleanup-consistency`), and `prefer-framework-api` (a browser API ardor-react wraps\n * in a hook is used through the hook). Hooks live in `.ts` files too, so it covers all\n * source files.\n */\nconst reactHookRuleConfigs: Linter.Config[] = [\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: {\n [NoAsyncHookCallbackRule.NAME]: NoAsyncHookCallbackRule.build(),\n [EffectCleanupConsistencyRule.NAME]: EffectCleanupConsistencyRule.build(),\n },\n },\n // A hook or a util in a `.ts` file reaches the browser as well as a component does; a test stubs the browser on purpose.\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: { [PreferFrameworkApiRule.NAME]: PreferFrameworkApiRule.build() },\n },\n { files: TEST_FILES, rules: { [PreferFrameworkApiRule.NAME]: 'off' } },\n];\n\n/** `houseConfigs` for a React project: `reactNamingConventionConfigs`, the house rules, the async style rules, `no-leaked-render` and the hook rules. */\nexport const reactHouseConfigs: Linter.Config[] = [\n ...reactNamingConventionConfigs,\n ...houseRuleConfigs,\n ...asyncRuleConfigs,\n ...paddingConfigs,\n ...reactRuleConfigs,\n ...reactHookRuleConfigs,\n];\n"]}
1
+ {"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/linters/house/configs.ts"],"names":[],"mappings":";;;AACA,sCAAoD;AACpD,4CAAyC;AACzC,wCAA4C;AAC5C,kDAA+D;AAC/D,+CAAiD;AACjD,qCAAkD;AAClD,uEAAiE;AACjE,uFAAiF;AACjF,+DAAyD;AACzD,+EAAwE;AACxE,mEAA6D;AAC7D,2DAAqD;AACrD,mFAA4E;AAC5E,2EAAqE;AACrE,2EAAqE;AACrE,mEAA8D;AAC9D,yEAAmE;AACnE,6EAAuE;AACvE,qCAA6C;AAE7C,MAAM,YA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U,EAAE,KAAK,EAAE,EAAE,CAAC,kDAAsB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;CACvE,CAAC;AAEF,yJAAyJ;AAC5I,QAAA,iBAAiB,GAAoB;IAChD,GAAG,2CAA4B;IAC/B,GAAG,gBAAgB;IACnB,GAAG,8BAAgB;IACnB,GAAG,wBAAc;IACjB,GAAG,gBAAgB;IACnB,GAAG,oBAAoB;CACxB,CAAC","sourcesContent":["import type { Linter } from 'eslint';\nimport { namingConventionConfigs } from '../eslint';\nimport { JSX_FILES } from '../jsx-files';\nimport { paddingConfigs } from '../padding';\nimport { reactNamingConventionConfigs } from '../react-eslint';\nimport { asyncRuleConfigs } from './async-rules';\nimport { HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { ConstClassValuesRule } from './const-class-values.rule';\nimport { EffectCleanupConsistencyRule } from './effect-cleanup-consistency.rule';\nimport { MaxParamsOwnRule } from './max-params-own.rule';\nimport { NoAsyncHookCallbackRule } from './no-async-hook-callback.rule';\nimport { NoLeakedRenderRule } from './no-leaked-render.rule';\nimport { NoNewErrorRule } from './no-new-error.rule';\nimport { NoShadowFrameworkTypeRule } from './no-shadow-framework-type.rule';\nimport { PreferFrameworkApiRule } from './prefer-framework-api.rule';\nimport { PreferPromiseSleepRule } from './prefer-promise-sleep.rule';\nimport { PreferTNullableRule } from './prefer-tnullable.rule';\nimport { TypedRouteContextRule } from './typed-route-context.rule';\nimport { ZodSchemaConventionRule } from './zod-schema-convention.rule';\nimport { houseEslintPlugin } from './plugin';\n\nconst SOURCE_FILES = ['**/*.{ts,tsx,mts,cts}'];\nconst TEST_FILES = ['**/__tests__/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'];\n\n/**\n * V-C-10: no explicit cast. `as const` is always allowed; `satisfies`, a generic or a narrower type\n * replaces the rest.\n */\nconst NO_CAST_RULE = '@typescript-eslint/consistent-type-assertions';\n\n/**\n * The house rules: at most 5 positional parameters on a function we write, and errors thrown through\n * `getError` only. Tests are exempt from `no-new-error`: a test throws a plain `Error` on purpose, to\n * stand in for what a driver or a third-party library throws.\n *\n * Two rules only warn, so a project adopts them without failing its lint: `const-class-values` (V-C-08, a\n * string-literal union in an exported declaration) and `consistent-type-assertions` (V-C-10, an `as X`\n * cast). Tests are exempt from both: a test stubs what it does not build.\n */\nconst houseRuleConfigs: Linter.Config[] = [\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: {\n [MaxParamsOwnRule.NAME]: MaxParamsOwnRule.build(),\n [NoNewErrorRule.NAME]: NoNewErrorRule.build(),\n [NoShadowFrameworkTypeRule.NAME]: NoShadowFrameworkTypeRule.build(),\n [PreferTNullableRule.NAME]: PreferTNullableRule.build(),\n [PreferPromiseSleepRule.NAME]: PreferPromiseSleepRule.build(),\n [PreferFrameworkApiRule.NAME]: PreferFrameworkApiRule.build({ hooks: false }),\n [ConstClassValuesRule.NAME]: ConstClassValuesRule.build({ severity: 'warn' }),\n [ZodSchemaConventionRule.NAME]: ZodSchemaConventionRule.build(),\n [TypedRouteContextRule.NAME]: TypedRouteContextRule.build(),\n [NO_CAST_RULE]: ['warn', { assertionStyle: 'never' }],\n },\n },\n {\n files: TEST_FILES,\n rules: {\n [NoNewErrorRule.NAME]: 'off',\n [NoShadowFrameworkTypeRule.NAME]: 'off',\n [PreferPromiseSleepRule.NAME]: 'off',\n [PreferFrameworkApiRule.NAME]: 'off',\n [ConstClassValuesRule.NAME]: 'off',\n [NO_CAST_RULE]: 'off',\n },\n },\n];\n\n/**\n * The ESLint side of a project that lints with oxlint: the naming convention, the house rules and the async style\n * rules - everything oxlint cannot express. Run it next to `oxlintConfigs`.\n *\n * ```js\n * // .configs/lints/eslint.config.mjs\n * import { houseConfigs } from '@venizia/dev-configs/linters';\n *\n * export default houseConfigs;\n * ```\n */\nexport const houseConfigs: Linter.Config[] = [\n ...namingConventionConfigs,\n ...houseRuleConfigs,\n ...asyncRuleConfigs,\n ...paddingConfigs,\n];\n\n/**\n * The React house rule: a JSX child is drawn with `cond ? <X /> : null`, never `cond && <X />`, which\n * draws `0` when `cond` is `0`.\n */\nconst reactRuleConfigs: Linter.Config[] = [\n {\n files: JSX_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: { [NoLeakedRenderRule.NAME]: NoLeakedRenderRule.build() },\n },\n];\n\n/**\n * The hook rules: a hook never gets an async function (`no-async-hook-callback`), and an effect callback returns a\n * cleanup on every path or on none (`effect-cleanup-consistency`). Hooks live in `.ts` files too, so it covers all\n * source files.\n */\nconst reactHookRuleConfigs: Linter.Config[] = [\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: {\n [NoAsyncHookCallbackRule.NAME]: NoAsyncHookCallbackRule.build(),\n [EffectCleanupConsistencyRule.NAME]: EffectCleanupConsistencyRule.build(),\n },\n },\n // A hook or a util in a `.ts` file reaches the browser as well as a component does; a test stubs the browser on purpose.\n {\n files: SOURCE_FILES,\n plugins: { [HOUSE_PLUGIN_NAMESPACE]: houseEslintPlugin },\n rules: { [PreferFrameworkApiRule.NAME]: PreferFrameworkApiRule.build({ hooks: true }) },\n },\n { files: TEST_FILES, rules: { [PreferFrameworkApiRule.NAME]: 'off' } },\n];\n\n/** `houseConfigs` for a React project: `reactNamingConventionConfigs`, the house rules, the async style rules, `no-leaked-render` and the hook rules. */\nexport const reactHouseConfigs: Linter.Config[] = [\n ...reactNamingConventionConfigs,\n ...houseRuleConfigs,\n ...asyncRuleConfigs,\n ...paddingConfigs,\n ...reactRuleConfigs,\n ...reactHookRuleConfigs,\n];\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { Linter, Rule } from 'eslint';
2
2
  import type { TRuleSeverity } from '../rules/common';
3
3
  /**
4
- * `venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,
4
+ * `@venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,
5
5
  * never a union of string literals in an exported declaration: a type alias, an interface member, a
6
6
  * generic constraint, a parameter or a return type of an exported function or class.
7
7
  *
@@ -11,7 +11,7 @@ import type { TRuleSeverity } from '../rules/common';
11
11
  * matches it (`(State|Status)$`), for a project that adopts the rule one name at a time.
12
12
  */
13
13
  export declare class ConstClassValuesRule {
14
- static readonly NAME = "venizia/const-class-values";
14
+ static readonly NAME = "@venizia/const-class-values";
15
15
  static readonly RULE: Rule.RuleModule;
16
16
  static build(opts?: {
17
17
  severity?: TRuleSeverity;
@@ -4,6 +4,12 @@ exports.ConstClassValuesRule = void 0;
4
4
  const common_1 = require("./common");
5
5
  /** Utility types whose type argument is a set of keys, not an enumerable value: `Pick<T, 'a' | 'b'>`. */
6
6
  const KEY_SET_TYPES = new Set(['Pick', 'Omit', 'Extract', 'Exclude', 'Record']);
7
+ /** The node types that take type arguments, each with the field that holds the type's name. */
8
+ const TYPE_NAME_KEYS = new Map([
9
+ [common_1.AstNodeTypes.TYPE_REFERENCE, 'typeName'],
10
+ [common_1.AstNodeTypes.INTERFACE_HERITAGE, 'expression'],
11
+ [common_1.AstNodeTypes.CLASS_IMPLEMENTS, 'expression'],
12
+ ]);
7
13
  /** The union is a type argument of a key-set utility type, or the key range of a mapped type. */
8
14
  const isKeySet = (opts) => {
9
15
  const parent = common_1.AstNode.readField({ node: opts.node, key: 'parent' });
@@ -14,12 +20,15 @@ const isKeySet = (opts) => {
14
20
  return false;
15
21
  }
16
22
  const reference = common_1.AstNode.readField({ node: parent, key: 'parent' });
23
+ const key = TYPE_NAME_KEYS.get(String(common_1.AstNode.getType({ node: reference })));
24
+ if (key === undefined) {
25
+ return false;
26
+ }
17
27
  const name = common_1.AstNode.readField({
18
- node: common_1.AstNode.readField({ node: reference, key: 'typeName' }),
28
+ node: common_1.AstNode.readField({ node: reference, key }),
19
29
  key: 'name',
20
30
  });
21
- return (common_1.AstNode.getType({ node: reference }) === common_1.AstNodeTypes.TYPE_REFERENCE &&
22
- KEY_SET_TYPES.has(String(name)));
31
+ return KEY_SET_TYPES.has(String(name));
23
32
  };
24
33
  /** The statement of the module that holds the node: the node's last ancestor before `Program`. */
25
34
  const topLevelStatement = (opts) => {
@@ -46,7 +55,7 @@ const isNullish = (opts) => {
46
55
  return type === common_1.AstNodeTypes.NULL_KEYWORD || type === common_1.AstNodeTypes.UNDEFINED_KEYWORD;
47
56
  };
48
57
  /**
49
- * `venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,
58
+ * `@venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,
50
59
  * never a union of string literals in an exported declaration: a type alias, an interface member, a
51
60
  * generic constraint, a parameter or a return type of an exported function or class.
52
61
  *
@@ -62,7 +71,7 @@ class ConstClassValuesRule {
62
71
  type: 'suggestion',
63
72
  schema: [{ type: 'object', properties: { namePattern: { type: 'string' } } }],
64
73
  messages: {
65
- constClass: 'An enumerable string is a const class plus TConstValue<typeof X>, not a union of string literals.',
74
+ constClass: "An enumerable string is a class that extends `ConstClass`, typed as `TConstValue<typeof X>`, not a union of string literals: `import { ConstClass, type TConstValue } from '@venizia/ignis-helpers/common';`",
66
75
  },
67
76
  },
68
77
  create: (context) => {
@@ -1 +1 @@
1
- {"version":3,"file":"const-class-values.rule.js","sourceRoot":"","sources":["../../../src/linters/house/const-class-values.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE,yGAAyG;AACzG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEhF,iGAAiG;AACjG,MAAM,QAAQ,GAAG,CAAC,IAAuB,EAAW,EAAE;IACpD,MAAM,MAAM,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IAErE,IAAI,gBAAO,CAAC,OAAO,CAAC,E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nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** Utility types whose type argument is a set of keys, not an enumerable value: `Pick<T, 'a' | 'b'>`. */\nconst KEY_SET_TYPES = new Set(['Pick', 'Omit', 'Extract', 'Exclude', 'Record']);\n\n/** The union is a type argument of a key-set utility type, or the key range of a mapped type. */\nconst isKeySet = (opts: { node: unknown }): boolean => {\n const parent = AstNode.readField({ node: opts.node, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.MAPPED_TYPE) {\n return true;\n }\n\n if (AstNode.getType({ node: parent }) !== AstNodeTypes.TYPE_PARAMETER_INSTANTIATION) {\n return false;\n }\n\n const reference = AstNode.readField({ node: parent, key: 'parent' });\n const name = AstNode.readField({\n node: AstNode.readField({ node: reference, key: 'typeName' }),\n key: 'name',\n });\n\n return (\n AstNode.getType({ node: reference }) === AstNodeTypes.TYPE_REFERENCE &&\n KEY_SET_TYPES.has(String(name))\n );\n};\n\n/** The statement of the module that holds the node: the node's last ancestor before `Program`. */\nconst topLevelStatement = (opts: { node: unknown }): unknown => {\n let current = opts.node;\n\n while (current) {\n const parent = AstNode.readField({ node: current, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.PROGRAM) {\n return current;\n }\n\n current = parent;\n }\n\n return undefined;\n};\n\nconst isStringLiteral = (opts: { member: unknown }): boolean => {\n const { member } = opts;\n\n return (\n AstNode.getType({ node: member }) === AstNodeTypes.LITERAL_TYPE &&\n typeof AstNode.readField({\n node: AstNode.readField({ node: member, key: 'literal' }),\n key: 'value',\n }) === 'string'\n );\n};\n\nconst isNullish = (opts: { member: unknown }): boolean => {\n const type = AstNode.getType({ node: opts.member });\n\n return type === AstNodeTypes.NULL_KEYWORD || type === AstNodeTypes.UNDEFINED_KEYWORD;\n};\n\n/**\n * `venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,\n * never a union of string literals in an exported declaration: a type alias, an interface member, a\n * generic constraint, a parameter or a return type of an exported function or class.\n *\n * Not counted: a union that is not all string literals (a `null` or `undefined` member is ignored),\n * a key set (`Pick`, `Omit`, `Extract`, `Exclude`, `Record` arguments and mapped-type keys), and a\n * declaration that is not exported. `namePattern` narrows the rule to exported type aliases whose name\n * matches it (`(State|Status)$`), for a project that adopts the rule one name at a time.\n */\nexport class ConstClassValuesRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/const-class-values`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [{ type: 'object', properties: { namePattern: { type: 'string' } } }],\n messages: {\n constClass:\n 'An enumerable string is a const class plus TConstValue<typeof X>, not a union of string literals.',\n },\n },\n create: (context) => {\n const options: unknown = context.options[0];\n const configured = AstNode.readField({ node: options, key: 'namePattern' });\n const namePattern = typeof configured === 'string' ? new RegExp(configured) : undefined;\n\n const isNamed = (opts: { statement: unknown; node: unknown }) => {\n const { statement, node } = opts;\n const declaration = AstNode.readField({ node: statement, key: 'declaration' });\n const name = AstNode.readField({\n node: AstNode.readField({ node: declaration, key: 'id' }),\n key: 'name',\n });\n\n return (\n namePattern === undefined ||\n (AstNode.getType({ node: declaration }) === AstNodeTypes.TYPE_ALIAS_DECLARATION &&\n AstNode.readField({ node: declaration, key: 'typeAnnotation' }) === node &&\n typeof name === 'string' &&\n namePattern.test(name))\n );\n };\n\n return {\n [AstNodeTypes.UNION_TYPE]: (node: Rule.Node) => {\n const members = AstNode.readField({ node, key: 'types' });\n\n if (!Array.isArray(members)) {\n return;\n }\n\n const values = members.filter((member) => !isNullish({ member }));\n\n if (values.length < 2 || !values.every((member) => isStringLiteral({ member }))) {\n return;\n }\n\n const statement = topLevelStatement({ node });\n const statementType = AstNode.getType({ node: statement });\n const isExported =\n statementType === AstNodeTypes.EXPORT_NAMED_DECLARATION ||\n statementType === AstNodeTypes.EXPORT_DEFAULT_DECLARATION;\n\n if (!isExported || isKeySet({ node }) || !isNamed({ statement, node })) {\n return;\n }\n\n context.report({ node, messageId: 'constClass' });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity; namePattern?: string } = {}): Linter.RuleEntry {\n const { severity = 'error', namePattern } = opts;\n\n return namePattern === undefined ? [severity] : [severity, { namePattern }];\n }\n}\n"]}
1
+ {"version":3,"file":"const-class-values.rule.js","sourceRoot":"","sources":["../../../src/linters/house/const-class-values.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE,yGAAyG;AACzG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEhF,+FAA+F;AAC/F,MAAM,cAAc,GAAgC,IAAI,GAAG,CAAC;IAC1D,CAAC,qBAAY,CAAC,cAAc,EAAE,UAAU,CAAC;IACzC,CAAC,qBAAY,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAC/C,CAAC,qBAAY,CAAC,gBAAgB,EAAE,YAAY,CAAC;CAC9C,CAAC,CAAC;AAEH,iGAAiG;AACjG,MAAM,QAAQ,GAAG,CAAC,IAAuB,EAAW,EAAE;IACpD,MAAM,MAAM,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IAErE,IAAI,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,qBAAY,CAAC,WAAW,EAAE,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,qBAAY,CAAC,4BAA4B,EAAE,CAAC;QACpF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC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EAAE,CAAC,CAAC,EAAE,CAAC;wBAChF,OAAO;oBACT,CAAC;oBAED,MAAM,SAAS,GAAG,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC9C,MAAM,aAAa,GAAG,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;oBAC3D,MAAM,UAAU,GACd,aAAa,KAAK,qBAAY,CAAC,wBAAwB;wBACvD,aAAa,KAAK,qBAAY,CAAC,0BAA0B,CAAC;oBAE5D,IAAI,CAAC,UAAU,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;wBACvE,OAAO;oBACT,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;gBACpD,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAA2D,EAAE;QACxE,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QAEjD,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9E,CAAC;;AApEH,oDAqEC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/** Utility types whose type argument is a set of keys, not an enumerable value: `Pick<T, 'a' | 'b'>`. */\nconst KEY_SET_TYPES = new Set(['Pick', 'Omit', 'Extract', 'Exclude', 'Record']);\n\n/** The node types that take type arguments, each with the field that holds the type's name. */\nconst TYPE_NAME_KEYS: ReadonlyMap<string, string> = new Map([\n [AstNodeTypes.TYPE_REFERENCE, 'typeName'],\n [AstNodeTypes.INTERFACE_HERITAGE, 'expression'],\n [AstNodeTypes.CLASS_IMPLEMENTS, 'expression'],\n]);\n\n/** The union is a type argument of a key-set utility type, or the key range of a mapped type. */\nconst isKeySet = (opts: { node: unknown }): boolean => {\n const parent = AstNode.readField({ node: opts.node, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.MAPPED_TYPE) {\n return true;\n }\n\n if (AstNode.getType({ node: parent }) !== AstNodeTypes.TYPE_PARAMETER_INSTANTIATION) {\n return false;\n }\n\n const reference = AstNode.readField({ node: parent, key: 'parent' });\n const key = TYPE_NAME_KEYS.get(String(AstNode.getType({ node: reference })));\n\n if (key === undefined) {\n return false;\n }\n\n const name = AstNode.readField({\n node: AstNode.readField({ node: reference, key }),\n key: 'name',\n });\n\n return KEY_SET_TYPES.has(String(name));\n};\n\n/** The statement of the module that holds the node: the node's last ancestor before `Program`. */\nconst topLevelStatement = (opts: { node: unknown }): unknown => {\n let current = opts.node;\n\n while (current) {\n const parent = AstNode.readField({ node: current, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.PROGRAM) {\n return current;\n }\n\n current = parent;\n }\n\n return undefined;\n};\n\nconst isStringLiteral = (opts: { member: unknown }): boolean => {\n const { member } = opts;\n\n return (\n AstNode.getType({ node: member }) === AstNodeTypes.LITERAL_TYPE &&\n typeof AstNode.readField({\n node: AstNode.readField({ node: member, key: 'literal' }),\n key: 'value',\n }) === 'string'\n );\n};\n\nconst isNullish = (opts: { member: unknown }): boolean => {\n const type = AstNode.getType({ node: opts.member });\n\n return type === AstNodeTypes.NULL_KEYWORD || type === AstNodeTypes.UNDEFINED_KEYWORD;\n};\n\n/**\n * `@venizia/const-class-values`. An enumerable string is a const class plus `TConstValue<typeof X>`,\n * never a union of string literals in an exported declaration: a type alias, an interface member, a\n * generic constraint, a parameter or a return type of an exported function or class.\n *\n * Not counted: a union that is not all string literals (a `null` or `undefined` member is ignored),\n * a key set (`Pick`, `Omit`, `Extract`, `Exclude`, `Record` arguments and mapped-type keys), and a\n * declaration that is not exported. `namePattern` narrows the rule to exported type aliases whose name\n * matches it (`(State|Status)$`), for a project that adopts the rule one name at a time.\n */\nexport class ConstClassValuesRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/const-class-values`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [{ type: 'object', properties: { namePattern: { type: 'string' } } }],\n messages: {\n constClass:\n \"An enumerable string is a class that extends `ConstClass`, typed as `TConstValue<typeof X>`, not a union of string literals: `import { ConstClass, type TConstValue } from '@venizia/ignis-helpers/common';`\",\n },\n },\n create: (context) => {\n const options: unknown = context.options[0];\n const configured = AstNode.readField({ node: options, key: 'namePattern' });\n const namePattern = typeof configured === 'string' ? new RegExp(configured) : undefined;\n\n const isNamed = (opts: { statement: unknown; node: unknown }) => {\n const { statement, node } = opts;\n const declaration = AstNode.readField({ node: statement, key: 'declaration' });\n const name = AstNode.readField({\n node: AstNode.readField({ node: declaration, key: 'id' }),\n key: 'name',\n });\n\n return (\n namePattern === undefined ||\n (AstNode.getType({ node: declaration }) === AstNodeTypes.TYPE_ALIAS_DECLARATION &&\n AstNode.readField({ node: declaration, key: 'typeAnnotation' }) === node &&\n typeof name === 'string' &&\n namePattern.test(name))\n );\n };\n\n return {\n [AstNodeTypes.UNION_TYPE]: (node: Rule.Node) => {\n const members = AstNode.readField({ node, key: 'types' });\n\n if (!Array.isArray(members)) {\n return;\n }\n\n const values = members.filter((member) => !isNullish({ member }));\n\n if (values.length < 2 || !values.every((member) => isStringLiteral({ member }))) {\n return;\n }\n\n const statement = topLevelStatement({ node });\n const statementType = AstNode.getType({ node: statement });\n const isExported =\n statementType === AstNodeTypes.EXPORT_NAMED_DECLARATION ||\n statementType === AstNodeTypes.EXPORT_DEFAULT_DECLARATION;\n\n if (!isExported || isKeySet({ node }) || !isNamed({ statement, node })) {\n return;\n }\n\n context.report({ node, messageId: 'constClass' });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity; namePattern?: string } = {}): Linter.RuleEntry {\n const { severity = 'error', namePattern } = opts;\n\n return namePattern === undefined ? [severity] : [severity, { namePattern }];\n }\n}\n"]}
@@ -1,14 +1,14 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import type { TRuleSeverity } from '../rules/common';
3
3
  /**
4
- * `venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`
4
+ * `@venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`
5
5
  * returns a cleanup on every path or on none. An early `return;` beside a later `return () => {}` leaves React
6
6
  * with a cleanup on some runs only; the early exit returns a no-op instead. A bare `return;` and falling off the
7
7
  * end both mean "no value". It uses ESLint's code path analysis the way `consistent-return` does, so an
8
8
  * unreachable end of the function is not a path. A nested function's own `return` is not counted.
9
9
  */
10
10
  export declare class EffectCleanupConsistencyRule {
11
- static readonly NAME = "venizia/effect-cleanup-consistency";
11
+ static readonly NAME = "@venizia/effect-cleanup-consistency";
12
12
  static readonly RULE: Rule.RuleModule;
13
13
  static build(opts?: {
14
14
  severity?: TRuleSeverity;
@@ -4,7 +4,7 @@ exports.EffectCleanupConsistencyRule = void 0;
4
4
  const common_1 = require("./common");
5
5
  const hook_support_1 = require("./hook-support");
6
6
  /**
7
- * `venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`
7
+ * `@venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`
8
8
  * returns a cleanup on every path or on none. An early `return;` beside a later `return () => {}` leaves React
9
9
  * with a cleanup on some runs only; the early exit returns a no-op instead. A bare `return;` and falling off the
10
10
  * end both mean "no value". It uses ESLint's code path analysis the way `consistent-return` does, so an
@@ -1 +1 @@
1
- {"version":3,"file":"effect-cleanup-consistency.rule.js","sourceRoot":"","sources":["../../../src/linters/house/effect-cleanup-consistency.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C5E,+BAA+B,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC7E,CAAC,qBAAY,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;oBACnD,IAAI,CAAC,KAAK,EAAE,CAAC;wBACX,OAAO;oBACT,CAAC;oBAED,IAAI,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;wBACjD,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;oBAC5B,CAAC;yBAAM,CAAC;wBACN,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC;oBAC9B,CAAC;gBACH,CAAC;gBACD,yBAAyB,EAAE,SAAS;gBACpC,8BAA8B,EAAE,SAAS;aAC1C,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AAtFH,oEAuFC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { HookSupport } from './hook-support';\n\n/** What the rule knows about the function whose code path is open; one per function, so a nested function is its own. */\ninterface IFunctionFrame {\n upper: IFunctionFrame | undefined;\n hook: string | undefined;\n returnsValue: boolean;\n returnsNothing: boolean;\n segments: Set<{ reachable: boolean }>;\n}\n\n/**\n * `venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`\n * returns a cleanup on every path or on none. An early `return;` beside a later `return () => {}` leaves React\n * with a cleanup on some runs only; the early exit returns a no-op instead. A bare `return;` and falling off the\n * end both mean \"no value\". It uses ESLint's code path analysis the way `consistent-return` does, so an\n * unreachable end of the function is not a path. A nested function's own `return` is not counted.\n */\nexport class EffectCleanupConsistencyRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/effect-cleanup-consistency`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n inconsistent:\n 'The callback of `{{hook}}` returns a cleanup on some paths only; return one on every path (a no-op `() => {}` for an early exit) or on none.',\n },\n },\n create: (context) => {\n const targets = new Map<unknown, string>();\n let frame: IFunctionFrame | undefined;\n\n const checkExit = (node: Rule.Node) => {\n const current = frame;\n\n if (\n !current?.hook ||\n AstNode.getType({ node: AstNode.readField({ node, key: 'body' }) }) !==\n AstNodeTypes.BLOCK_STATEMENT\n ) {\n return;\n }\n\n const endIsReachable = [...current.segments].some((segment) => segment.reachable);\n\n if (current.returnsValue && (current.returnsNothing || endIsReachable)) {\n context.report({ node, messageId: 'inconsistent', data: { hook: current.hook } });\n }\n };\n\n return {\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n const hook = HookSupport.calleeName({ call: node });\n const args = AstNode.readField({ node, key: 'arguments' });\n\n if (\n !HookSupport.isEffectHook({ name: hook }) ||\n hook === undefined ||\n !Array.isArray(args)\n ) {\n return;\n }\n\n if (HookSupport.isCallback({ node: args[0] })) {\n targets.set(args[0], hook);\n }\n },\n onCodePathStart: (_codePath, node) => {\n frame = {\n upper: frame,\n hook: targets.get(node),\n returnsValue: false,\n returnsNothing: false,\n segments: new Set(),\n };\n },\n onCodePathEnd: () => {\n frame = frame?.upper;\n },\n onCodePathSegmentStart: (segment) => frame?.segments.add(segment),\n onCodePathSegmentEnd: (segment) => frame?.segments.delete(segment),\n onUnreachableCodePathSegmentStart: (segment) => frame?.segments.add(segment),\n onUnreachableCodePathSegmentEnd: (segment) => frame?.segments.delete(segment),\n [AstNodeTypes.RETURN_STATEMENT]: (node: Rule.Node) => {\n if (!frame) {\n return;\n }\n\n if (AstNode.readField({ node, key: 'argument' })) {\n frame.returnsValue = true;\n } else {\n frame.returnsNothing = true;\n }\n },\n 'FunctionExpression:exit': checkExit,\n 'ArrowFunctionExpression:exit': checkExit,\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
1
+ {"version":3,"file":"effect-cleanup-consistency.rule.js","sourceRoot":"","sources":["../../../src/linters/house/effect-cleanup-consistency.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AACzE,iDAA6C;AAW7C;;;;;;GAMG;AACH,MAAa,4BAA4B;aACvB,SAAI,GAAG,GAAG,+BAAsB,6BAA6B,CAAC;aAE9D,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE;gBACR,YAAY,EACV,8IAA8I;aACjJ;SACF;QACD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;YAC3C,IAAI,KAAiC,CAAC;YAEtC,MAAM,SAAS,GAAG,CAAC,IAAe,EAAE,EAAE;gBACpC,MAAM,OAAO,GAAG,KAAK,CAAC;gBAEtB,IACE,CAAC,OAAO,EAAE,IAAI;oBACd,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;wBACjE,qBAAY,CAAC,eAAe,EAC9B,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,MAAM,cAAc,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;gBAElF,IAAI,OAAO,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,cAAc,IAAI,cAAc,CAAC,EAAE,CAAC;oBACvE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,E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jE,oBAAoB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;gBAClE,iCAAiC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC5E,+BAA+B,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC7E,CAAC,qBAAY,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;oBACnD,IAAI,CAAC,KAAK,EAAE,CAAC;wBACX,OAAO;oBACT,CAAC;oBAED,IAAI,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;wBACjD,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;oBAC5B,CAAC;yBAAM,CAAC;wBACN,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC;oBAC9B,CAAC;gBACH,CAAC;gBACD,yBAAyB,EAAE,SAAS;gBACpC,8BAA8B,EAAE,SAAS;aAC1C,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AAtFH,oEAuFC","sourcesContent":["import type { Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { HookSupport } from './hook-support';\n\n/** What the rule knows about the function whose code path is open; one per function, so a nested function is its own. */\ninterface IFunctionFrame {\n upper: IFunctionFrame | undefined;\n hook: string | undefined;\n returnsValue: boolean;\n returnsNothing: boolean;\n segments: Set<{ reachable: boolean }>;\n}\n\n/**\n * `@venizia/effect-cleanup-consistency`. The callback of `useEffect`, `useLayoutEffect` and `useInsertionEffect`\n * returns a cleanup on every path or on none. An early `return;` beside a later `return () => {}` leaves React\n * with a cleanup on some runs only; the early exit returns a no-op instead. A bare `return;` and falling off the\n * end both mean \"no value\". It uses ESLint's code path analysis the way `consistent-return` does, so an\n * unreachable end of the function is not a path. A nested function's own `return` is not counted.\n */\nexport class EffectCleanupConsistencyRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/effect-cleanup-consistency`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n inconsistent:\n 'The callback of `{{hook}}` returns a cleanup on some paths only; return one on every path (a no-op `() => {}` for an early exit) or on none.',\n },\n },\n create: (context) => {\n const targets = new Map<unknown, string>();\n let frame: IFunctionFrame | undefined;\n\n const checkExit = (node: Rule.Node) => {\n const current = frame;\n\n if (\n !current?.hook ||\n AstNode.getType({ node: AstNode.readField({ node, key: 'body' }) }) !==\n AstNodeTypes.BLOCK_STATEMENT\n ) {\n return;\n }\n\n const endIsReachable = [...current.segments].some((segment) => segment.reachable);\n\n if (current.returnsValue && (current.returnsNothing || endIsReachable)) {\n context.report({ node, messageId: 'inconsistent', data: { hook: current.hook } });\n }\n };\n\n return {\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n const hook = HookSupport.calleeName({ call: node });\n const args = AstNode.readField({ node, key: 'arguments' });\n\n if (\n !HookSupport.isEffectHook({ name: hook }) ||\n hook === undefined ||\n !Array.isArray(args)\n ) {\n return;\n }\n\n if (HookSupport.isCallback({ node: args[0] })) {\n targets.set(args[0], hook);\n }\n },\n onCodePathStart: (_codePath, node) => {\n frame = {\n upper: frame,\n hook: targets.get(node),\n returnsValue: false,\n returnsNothing: false,\n segments: new Set(),\n };\n },\n onCodePathEnd: () => {\n frame = frame?.upper;\n },\n onCodePathSegmentStart: (segment) => frame?.segments.add(segment),\n onCodePathSegmentEnd: (segment) => frame?.segments.delete(segment),\n onUnreachableCodePathSegmentStart: (segment) => frame?.segments.add(segment),\n onUnreachableCodePathSegmentEnd: (segment) => frame?.segments.delete(segment),\n [AstNodeTypes.RETURN_STATEMENT]: (node: Rule.Node) => {\n if (!frame) {\n return;\n }\n\n if (AstNode.readField({ node, key: 'argument' })) {\n frame.returnsValue = true;\n } else {\n frame.returnsNothing = true;\n }\n },\n 'FunctionExpression:exit': checkExit,\n 'ArrowFunctionExpression:exit': checkExit,\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import type { TBrowserApiMatch } from './browser-api-patterns';
2
+ /** How a hand-written form shows up in code. */
3
+ export type TFrameworkApiMatch = TBrowserApiMatch
4
+ /**
5
+ * A member of a global object read or called: `localStorage.getItem`; `window.` in front is the same object. With
6
+ * `property`, the source of a regular expression, only a member whose name matches it. With `isReadOnly`, an
7
+ * assignment to it and a `delete` of it pass.
8
+ */
9
+ | {
10
+ type: 'member';
11
+ objects: ReadonlyArray<string>;
12
+ property?: string;
13
+ isReadOnly?: boolean;
14
+ }
15
+ /**
16
+ * A string or a template whose text matches `pattern`, the source of a regular expression. With
17
+ * `isFallbackOnly`, only where it stands in for a missing value: after `??`, `||`, `??=` or `||=`, a
18
+ * parameter default, or a `default`, `defaultValue` or `fallback` property.
19
+ */
20
+ | {
21
+ type: 'literal';
22
+ pattern: string;
23
+ isFallbackOnly?: boolean;
24
+ }
25
+ /** An `import` or `import()` of one of these modules; `import type` is not one. */
26
+ | {
27
+ type: 'import';
28
+ sources: ReadonlyArray<string>;
29
+ }
30
+ /** Every node an ESLint selector matches. */
31
+ | {
32
+ type: 'selector';
33
+ selector: string;
34
+ };
35
+ /** One hand-written form `@venizia/prefer-framework-api` reports anywhere in a file. */
36
+ export interface IFrameworkApiPattern {
37
+ /** The name `ignore` takes to switch the row off. */
38
+ id: string;
39
+ match: TFrameworkApiMatch;
40
+ /** The whole message. */
41
+ message: string;
42
+ /** The row applies only in a package that depends on a package whose name starts with this. */
43
+ dependsOn?: string;
44
+ /** The package that writes the API: the row is not reported in it. */
45
+ owner?: string;
46
+ }
47
+ /**
48
+ * The forms the framework replaces outside React, one row each. Unlike `BrowserApiPatterns`, a row counts anywhere in a
49
+ * file: a service or a module function can call the API as well as a component.
50
+ */
51
+ export declare class FrameworkApiPatterns {
52
+ static readonly TABLE: ReadonlyArray<IFrameworkApiPattern>;
53
+ }
54
+ //# sourceMappingURL=framework-api-patterns.d.ts.map
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FrameworkApiPatterns = void 0;
4
+ /**
5
+ * The forms the framework replaces outside React, one row each. Unlike `BrowserApiPatterns`, a row counts anywhere in a
6
+ * file: a service or a module function can call the API as well as a component.
7
+ */
8
+ class FrameworkApiPatterns {
9
+ static { this.TABLE = [
10
+ {
11
+ id: 'application-error-instanceof',
12
+ match: {
13
+ type: 'selector',
14
+ selector: "BinaryExpression[operator='instanceof'][right.name='ApplicationError']",
15
+ },
16
+ message: "Use `isApplicationError(error)`, not `instanceof ApplicationError`, which fails across two installed copies: `import { isApplicationError } from '@venizia/ignis-helpers/core';`",
17
+ dependsOn: '@venizia/ignis',
18
+ owner: '@venizia/ignis-inversion',
19
+ },
20
+ {
21
+ id: 'process-env',
22
+ // Only the names `AppEnvs` keeps: it drops a key without its prefix, such as `PORT`.
23
+ match: { type: 'member', objects: ['process.env'], property: '^APP_ENV_', isReadOnly: true },
24
+ message: "Read an `APP_ENV_` name with `AppEnvs.get(key)`, not `process.env`: `import { AppEnvs } from '@venizia/ignis-helpers';`",
25
+ dependsOn: '@venizia/ignis',
26
+ owner: '@venizia/ignis-helpers',
27
+ },
28
+ {
29
+ id: 'env-boolean-comparison',
30
+ match: {
31
+ type: 'selector',
32
+ selector: ['left', 'right']
33
+ .map((side) => {
34
+ const other = side === 'left' ? 'right' : 'left';
35
+ return `BinaryExpression[operator=/^[!=]==?$/][${side}.callee.property.name='get'][${side}.callee.object.name=/^(AppEnvs|applicationEnvironment)$/][${other}.value=/^(true|false)$/]`;
36
+ })
37
+ .join(', '),
38
+ },
39
+ message: "Read a boolean setting with `ParseUtility.toBoolean({ input: AppEnvs.get(key) })`, not a comparison with `'true'` or `'false'`: `import { ParseUtility } from '@venizia/ignis-helpers/core';`",
40
+ dependsOn: '@venizia/ignis',
41
+ owner: '@venizia/ignis-helpers',
42
+ },
43
+ {
44
+ id: 'web-storage',
45
+ match: { type: 'member', objects: ['localStorage', 'sessionStorage'] },
46
+ message: "Use `BrowserStorage` (or the `useStoredState` hook), not `localStorage` / `sessionStorage`: it never throws: `import { BrowserStorage } from '@venizia/ardor-kernel';`",
47
+ dependsOn: '@venizia/ardor',
48
+ owner: '@venizia/ardor-kernel',
49
+ },
50
+ {
51
+ id: 'localhost-url',
52
+ match: {
53
+ type: 'literal',
54
+ pattern: '^https?://(?:localhost|127\\.0\\.0\\.1)(?![\\w.-])',
55
+ isFallbackOnly: true,
56
+ },
57
+ message: "Require the value instead, a `localhost` URL as a fallback is used wherever the setting is missing: `AppEnvs.getRequired(key)` (`import { AppEnvs } from '@venizia/ignis-helpers';`) or `RuntimeConfig.getRequired({ key })` (`import { RuntimeConfig } from '@venizia/ardor-kernel';`).",
58
+ },
59
+ ]; }
60
+ }
61
+ exports.FrameworkApiPatterns = FrameworkApiPatterns;
62
+ //# sourceMappingURL=framework-api-patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-api-patterns.js","sourceRoot":"","sources":["../../../src/linters/house/framework-api-patterns.ts"],"names":[],"mappings":";;;AAmCA;;;GAGG;AACH,MAAa,oBAAoB;aACf,UAAK,GAAwC;QAC3D;YACE,EAAE,EAAE,8BAA8B;YAClC,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,wEAAwE;aACnF;YACD,OAAO,EACL,kLAAkL;YACpL,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,0BAA0B;SAClC;QACD;YACE,EAAE,EAAE,aAAa;YACjB,qFAAqF;YACrF,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE;YAC5F,OAAO,EACL,yHAAyH;YAC3H,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,wBAAwB;SAChC;QACD;YACE,EAAE,EAAE,wBAAwB;YAC5B,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;qBACxB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;oBACZ,MAAM,KAAK,GAAG,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;oBAEjD,OAAO,0CAA0C,IAAI,gCAAgC,IAAI,6DAA6D,KAAK,0BAA0B,CAAC;gBACxL,CAAC,CAAC;qBACD,IAAI,CAAC,IAAI,CAAC;aACd;YACD,OAAO,EACL,+LAA+L;YACjM,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,wBAAwB;SAChC;QACD;YACE,EAAE,EAAE,aAAa;YACjB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,cAAc,EAAE,gBAAgB,CAAC,EAAE;YACtE,OAAO,EACL,wKAAwK;YAC1K,SAAS,EAAE,gBAAgB;YAC3B,KAAK,EAAE,uBAAuB;SAC/B;QACD;YACE,EAAE,EAAE,eAAe;YACnB,KAAK,EAAE;gBACL,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,oDAAoD;gBAC7D,cAAc,EAAE,IAAI;aACrB;YACD,OAAO,EACL,0RAA0R;SAC7R;KACF,CAAC;;AAzDJ,oDA0DC","sourcesContent":["import type { TBrowserApiMatch } from './browser-api-patterns';\n\n/** How a hand-written form shows up in code. */\nexport type TFrameworkApiMatch =\n | TBrowserApiMatch\n /**\n * A member of a global object read or called: `localStorage.getItem`; `window.` in front is the same object. With\n * `property`, the source of a regular expression, only a member whose name matches it. With `isReadOnly`, an\n * assignment to it and a `delete` of it pass.\n */\n | { type: 'member'; objects: ReadonlyArray<string>; property?: string; isReadOnly?: boolean }\n /**\n * A string or a template whose text matches `pattern`, the source of a regular expression. With\n * `isFallbackOnly`, only where it stands in for a missing value: after `??`, `||`, `??=` or `||=`, a\n * parameter default, or a `default`, `defaultValue` or `fallback` property.\n */\n | { type: 'literal'; pattern: string; isFallbackOnly?: boolean }\n /** An `import` or `import()` of one of these modules; `import type` is not one. */\n | { type: 'import'; sources: ReadonlyArray<string> }\n /** Every node an ESLint selector matches. */\n | { type: 'selector'; selector: string };\n\n/** One hand-written form `@venizia/prefer-framework-api` reports anywhere in a file. */\nexport interface IFrameworkApiPattern {\n /** The name `ignore` takes to switch the row off. */\n id: string;\n match: TFrameworkApiMatch;\n /** The whole message. */\n message: string;\n /** The row applies only in a package that depends on a package whose name starts with this. */\n dependsOn?: string;\n /** The package that writes the API: the row is not reported in it. */\n owner?: string;\n}\n\n/**\n * The forms the framework replaces outside React, one row each. Unlike `BrowserApiPatterns`, a row counts anywhere in a\n * file: a service or a module function can call the API as well as a component.\n */\nexport class FrameworkApiPatterns {\n static readonly TABLE: ReadonlyArray<IFrameworkApiPattern> = [\n {\n id: 'application-error-instanceof',\n match: {\n type: 'selector',\n selector: \"BinaryExpression[operator='instanceof'][right.name='ApplicationError']\",\n },\n message:\n \"Use `isApplicationError(error)`, not `instanceof ApplicationError`, which fails across two installed copies: `import { isApplicationError } from '@venizia/ignis-helpers/core';`\",\n dependsOn: '@venizia/ignis',\n owner: '@venizia/ignis-inversion',\n },\n {\n id: 'process-env',\n // Only the names `AppEnvs` keeps: it drops a key without its prefix, such as `PORT`.\n match: { type: 'member', objects: ['process.env'], property: '^APP_ENV_', isReadOnly: true },\n message:\n \"Read an `APP_ENV_` name with `AppEnvs.get(key)`, not `process.env`: `import { AppEnvs } from '@venizia/ignis-helpers';`\",\n dependsOn: '@venizia/ignis',\n owner: '@venizia/ignis-helpers',\n },\n {\n id: 'env-boolean-comparison',\n match: {\n type: 'selector',\n selector: ['left', 'right']\n .map((side) => {\n const other = side === 'left' ? 'right' : 'left';\n\n return `BinaryExpression[operator=/^[!=]==?$/][${side}.callee.property.name='get'][${side}.callee.object.name=/^(AppEnvs|applicationEnvironment)$/][${other}.value=/^(true|false)$/]`;\n })\n .join(', '),\n },\n message:\n \"Read a boolean setting with `ParseUtility.toBoolean({ input: AppEnvs.get(key) })`, not a comparison with `'true'` or `'false'`: `import { ParseUtility } from '@venizia/ignis-helpers/core';`\",\n dependsOn: '@venizia/ignis',\n owner: '@venizia/ignis-helpers',\n },\n {\n id: 'web-storage',\n match: { type: 'member', objects: ['localStorage', 'sessionStorage'] },\n message:\n \"Use `BrowserStorage` (or the `useStoredState` hook), not `localStorage` / `sessionStorage`: it never throws: `import { BrowserStorage } from '@venizia/ardor-kernel';`\",\n dependsOn: '@venizia/ardor',\n owner: '@venizia/ardor-kernel',\n },\n {\n id: 'localhost-url',\n match: {\n type: 'literal',\n pattern: '^https?://(?:localhost|127\\\\.0\\\\.0\\\\.1)(?![\\\\w.-])',\n isFallbackOnly: true,\n },\n message:\n \"Require the value instead, a `localhost` URL as a fallback is used wherever the setting is missing: `AppEnvs.getRequired(key)` (`import { AppEnvs } from '@venizia/ignis-helpers';`) or `RuntimeConfig.getRequired({ key })` (`import { RuntimeConfig } from '@venizia/ardor-kernel';`).\",\n },\n ];\n}\n"]}
@@ -45,7 +45,7 @@ export declare class FrameworkExports {
45
45
  private static resolveRelative;
46
46
  /**
47
47
  * The names `file` exports, each with what it is, following `export *` into relative files and into other `@venizia/*`
48
- * packages (an umbrella package re-exports its siblings). A name re-exported by `export { X } from` takes the kind it has
48
+ * packages (an umbrella package re-exports its siblings). A name re-exported by `export { X } from` takes the type it has
49
49
  * where it is declared; `export type { X }` is a type whatever the target says.
50
50
  */
51
51
  private static namesOf;
@@ -32,7 +32,7 @@ class FrameworkExports {
32
32
  static readText(opts) {
33
33
  try {
34
34
  return (0, node_fs_1.readFileSync)(opts.file, 'utf8');
35
- // eslint-disable-next-line venizia/no-silent-catch -- an unreadable file only means fewer names
35
+ // eslint-disable-next-line @venizia/no-silent-catch -- an unreadable file only means fewer names
36
36
  }
37
37
  catch {
38
38
  return undefined;
@@ -46,7 +46,7 @@ class FrameworkExports {
46
46
  }
47
47
  try {
48
48
  return JSON.parse(text);
49
- // eslint-disable-next-line venizia/no-silent-catch -- a package.json that does not parse only means fewer names
49
+ // eslint-disable-next-line @venizia/no-silent-catch -- a package.json that does not parse only means fewer names
50
50
  }
51
51
  catch {
52
52
  return undefined;
@@ -77,7 +77,7 @@ class FrameworkExports {
77
77
  FrameworkExports.typescripts.set(directory, loaded);
78
78
  return loaded;
79
79
  }
80
- // eslint-disable-next-line venizia/no-silent-catch -- not installed at this start: the next one is tried
80
+ // eslint-disable-next-line @venizia/no-silent-catch -- not installed at this start: the next one is tried
81
81
  }
82
82
  catch {
83
83
  continue;
@@ -152,7 +152,7 @@ class FrameworkExports {
152
152
  }
153
153
  /**
154
154
  * The names `file` exports, each with what it is, following `export *` into relative files and into other `@venizia/*`
155
- * packages (an umbrella package re-exports its siblings). A name re-exported by `export { X } from` takes the kind it has
155
+ * packages (an umbrella package re-exports its siblings). A name re-exported by `export { X } from` takes the type it has
156
156
  * where it is declared; `export type { X }` is a type whatever the target says.
157
157
  */
158
158
  static namesOf(opts) {
@@ -164,7 +164,7 @@ class FrameworkExports {
164
164
  }
165
165
  seen.add(file);
166
166
  const source = typescript.createSourceFile(file, text, typescript.ScriptTarget.Latest, false);
167
- const kindOf = (node) => typescript.isInterfaceDeclaration(node) || typescript.isTypeAliasDeclaration(node)
167
+ const typeOf = (node) => typescript.isInterfaceDeclaration(node) || typescript.isTypeAliasDeclaration(node)
168
168
  ? 'type'
169
169
  : 'value';
170
170
  const isExported = (node) => typescript.canHaveModifiers(node) &&
@@ -188,7 +188,7 @@ class FrameworkExports {
188
188
  statement.name &&
189
189
  typescript.isIdentifier(statement.name)) {
190
190
  // An interface merged with a class or a namespace of the same name has a value too.
191
- locals.set(statement.name.text, locals.get(statement.name.text) === 'value' ? 'value' : kindOf(statement));
191
+ locals.set(statement.name.text, locals.get(statement.name.text) === 'value' ? 'value' : typeOf(statement));
192
192
  }
193
193
  }
194
194
  for (const statement of source.statements) {
@@ -206,25 +206,25 @@ class FrameworkExports {
206
206
  : undefined;
207
207
  for (const element of clause.elements) {
208
208
  const original = (element.propertyName ?? element.name).text;
209
- const kind = statement.isTypeOnly || element.isTypeOnly
209
+ const declared = statement.isTypeOnly || element.isTypeOnly
210
210
  ? 'type'
211
211
  : specifier === undefined
212
212
  ? locals.get(original)
213
213
  : there?.get(original);
214
- if (kind !== undefined) {
215
- names.set(element.name.text, kind);
214
+ if (declared !== undefined) {
215
+ names.set(element.name.text, declared);
216
216
  }
217
217
  }
218
218
  }
219
219
  else if (!clause && specifier?.startsWith('.') === true) {
220
220
  const target = FrameworkExports.resolveRelative({ from: file, specifier });
221
221
  if (target) {
222
- for (const [name, kind] of FrameworkExports.namesOf({
222
+ for (const [name, declared] of FrameworkExports.namesOf({
223
223
  typescript,
224
224
  file: target,
225
225
  seen,
226
226
  })) {
227
- names.set(name, kind);
227
+ names.set(name, declared);
228
228
  }
229
229
  }
230
230
  }
@@ -256,7 +256,7 @@ class FrameworkExports {
256
256
  typescript.isModuleDeclaration(statement)) &&
257
257
  statement.name &&
258
258
  typescript.isIdentifier(statement.name)) {
259
- names.set(statement.name.text, locals.get(statement.name.text) ?? kindOf(statement));
259
+ names.set(statement.name.text, locals.get(statement.name.text) ?? typeOf(statement));
260
260
  }
261
261
  }
262
262
  return names;
@@ -284,7 +284,7 @@ class FrameworkExports {
284
284
  continue;
285
285
  }
286
286
  const declared = FrameworkExports.namesOf({ typescript, file: path, seen: new Set() });
287
- const types = [...declared].filter(([, kind]) => kind === 'type').map(([entry]) => entry);
287
+ const types = [...declared].filter(([, type]) => type === 'type').map(([entry]) => entry);
288
288
  for (const entry of types) {
289
289
  if (types.length < (sizes.get(entry) ?? Number.POSITIVE_INFINITY)) {
290
290
  sizes.set(entry, types.length);