@cbnventures/nova 0.19.0 → 0.20.0

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 (242) hide show
  1. package/build/package.json +6 -3
  2. package/build/src/cli/generate/github/issue-template.d.ts.map +1 -1
  3. package/build/src/cli/generate/github/issue-template.js +4 -93
  4. package/build/src/cli/generate/github/issue-template.js.map +1 -1
  5. package/build/src/cli/generate/must-haves/agent-conventions.d.ts.map +1 -1
  6. package/build/src/cli/generate/must-haves/agent-conventions.js +12 -3
  7. package/build/src/cli/generate/must-haves/agent-conventions.js.map +1 -1
  8. package/build/src/cli/generate/must-haves/dotenv.d.ts +4 -7
  9. package/build/src/cli/generate/must-haves/dotenv.d.ts.map +1 -1
  10. package/build/src/cli/generate/must-haves/dotenv.js +120 -417
  11. package/build/src/cli/generate/must-haves/dotenv.js.map +1 -1
  12. package/build/src/cli/generate/must-haves/gitignore.d.ts +0 -8
  13. package/build/src/cli/generate/must-haves/gitignore.d.ts.map +1 -1
  14. package/build/src/cli/generate/must-haves/gitignore.js +7 -395
  15. package/build/src/cli/generate/must-haves/gitignore.js.map +1 -1
  16. package/build/src/cli/recipe/github/sync-identity.js +1 -1
  17. package/build/src/cli/recipe/github/sync-identity.js.map +1 -1
  18. package/build/src/cli/recipe/github/sync-policies.d.ts.map +1 -1
  19. package/build/src/cli/recipe/github/sync-policies.js +8 -1
  20. package/build/src/cli/recipe/github/sync-policies.js.map +1 -1
  21. package/build/src/cli/utility/changelog.d.ts +2 -0
  22. package/build/src/cli/utility/changelog.d.ts.map +1 -1
  23. package/build/src/cli/utility/changelog.js +154 -2
  24. package/build/src/cli/utility/changelog.js.map +1 -1
  25. package/build/src/cli/utility/initialize.d.ts +3 -0
  26. package/build/src/cli/utility/initialize.d.ts.map +1 -1
  27. package/build/src/cli/utility/initialize.js +305 -1
  28. package/build/src/cli/utility/initialize.js.map +1 -1
  29. package/build/src/lib/dotenv.d.ts +3 -0
  30. package/build/src/lib/dotenv.d.ts.map +1 -0
  31. package/build/src/lib/dotenv.js +66 -0
  32. package/build/src/lib/dotenv.js.map +1 -0
  33. package/build/src/lib/file-discovery.d.ts +3 -0
  34. package/build/src/lib/file-discovery.d.ts.map +1 -0
  35. package/build/src/lib/file-discovery.js +32 -0
  36. package/build/src/lib/file-discovery.js.map +1 -0
  37. package/build/src/lib/item.d.ts +3 -1
  38. package/build/src/lib/item.d.ts.map +1 -1
  39. package/build/src/lib/item.js +9 -0
  40. package/build/src/lib/item.js.map +1 -1
  41. package/build/src/lib/markdown-slug.d.ts +4 -0
  42. package/build/src/lib/markdown-slug.d.ts.map +1 -0
  43. package/build/src/lib/markdown-slug.js +25 -0
  44. package/build/src/lib/markdown-slug.js.map +1 -0
  45. package/build/src/lib/nova-config.d.ts +5 -0
  46. package/build/src/lib/nova-config.d.ts.map +1 -1
  47. package/build/src/lib/nova-config.js +135 -13
  48. package/build/src/lib/nova-config.js.map +1 -1
  49. package/build/src/lib/regex.d.ts +68 -0
  50. package/build/src/lib/regex.d.ts.map +1 -1
  51. package/build/src/lib/regex.js +70 -2
  52. package/build/src/lib/regex.js.map +1 -1
  53. package/build/src/lib/type-declaration-engine.d.ts +32 -0
  54. package/build/src/lib/type-declaration-engine.d.ts.map +1 -0
  55. package/build/src/lib/type-declaration-engine.js +770 -0
  56. package/build/src/lib/type-declaration-engine.js.map +1 -0
  57. package/build/src/lib/utility.d.ts.map +1 -1
  58. package/build/src/lib/utility.js +8 -8
  59. package/build/src/lib/utility.js.map +1 -1
  60. package/build/src/rules/eslint/conventions/require-kebab-case-filename.d.ts.map +1 -1
  61. package/build/src/rules/eslint/conventions/require-kebab-case-filename.js.map +1 -1
  62. package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.d.ts.map +1 -1
  63. package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.js +3 -3
  64. package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.js.map +1 -1
  65. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.d.ts.map +1 -1
  66. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.js +3 -2
  67. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.js.map +1 -1
  68. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-name.js +2 -2
  69. package/build/src/rules/eslint/jsdoc/require-jsdoc-param-name.js.map +1 -1
  70. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.d.ts +1 -1
  71. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.d.ts.map +1 -1
  72. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.js +102 -6
  73. package/build/src/rules/eslint/jsdoc/require-jsdoc-since.js.map +1 -1
  74. package/build/src/rules/eslint/regex/no-regex-literals.d.ts +1 -0
  75. package/build/src/rules/eslint/regex/no-regex-literals.d.ts.map +1 -1
  76. package/build/src/rules/eslint/regex/no-regex-literals.js +39 -1
  77. package/build/src/rules/eslint/regex/no-regex-literals.js.map +1 -1
  78. package/build/src/rules/eslint/typescript/require-type-naming.js +2 -2
  79. package/build/src/rules/eslint/typescript/require-type-naming.js.map +1 -1
  80. package/build/src/rules/vitest/dotenv/register.d.ts +3 -0
  81. package/build/src/rules/vitest/dotenv/register.d.ts.map +1 -0
  82. package/build/src/rules/vitest/dotenv/register.js +21 -0
  83. package/build/src/rules/vitest/dotenv/register.js.map +1 -0
  84. package/build/src/rules/vitest/dotenv/rules.d.ts +3 -0
  85. package/build/src/rules/vitest/dotenv/rules.d.ts.map +1 -0
  86. package/build/src/rules/vitest/dotenv/rules.js +32 -0
  87. package/build/src/rules/vitest/dotenv/rules.js.map +1 -0
  88. package/build/src/rules/vitest/enable.d.ts +3 -0
  89. package/build/src/rules/vitest/enable.d.ts.map +1 -0
  90. package/build/src/rules/vitest/enable.js +7 -0
  91. package/build/src/rules/vitest/enable.js.map +1 -0
  92. package/build/src/rules/vitest/frontmatter/register.d.ts +3 -0
  93. package/build/src/rules/vitest/frontmatter/register.d.ts.map +1 -0
  94. package/build/src/rules/vitest/frontmatter/register.js +51 -0
  95. package/build/src/rules/vitest/frontmatter/register.js.map +1 -0
  96. package/build/src/rules/vitest/frontmatter/rules.d.ts +15 -0
  97. package/build/src/rules/vitest/frontmatter/rules.d.ts.map +1 -0
  98. package/build/src/rules/vitest/frontmatter/rules.js +498 -0
  99. package/build/src/rules/vitest/frontmatter/rules.js.map +1 -0
  100. package/build/src/rules/vitest/index.d.ts +8 -0
  101. package/build/src/rules/vitest/index.d.ts.map +1 -0
  102. package/build/src/rules/vitest/index.js +7 -0
  103. package/build/src/rules/vitest/index.js.map +1 -0
  104. package/build/src/rules/vitest/link/register.d.ts +3 -0
  105. package/build/src/rules/vitest/link/register.d.ts.map +1 -0
  106. package/build/src/rules/vitest/link/register.js +43 -0
  107. package/build/src/rules/vitest/link/register.js.map +1 -0
  108. package/build/src/rules/vitest/link/rules.d.ts +12 -0
  109. package/build/src/rules/vitest/link/rules.d.ts.map +1 -0
  110. package/build/src/rules/vitest/link/rules.js +313 -0
  111. package/build/src/rules/vitest/link/rules.js.map +1 -0
  112. package/build/src/rules/vitest/markdown-table/register.d.ts +3 -0
  113. package/build/src/rules/vitest/markdown-table/register.d.ts.map +1 -0
  114. package/build/src/rules/vitest/markdown-table/register.js +25 -0
  115. package/build/src/rules/vitest/markdown-table/register.js.map +1 -0
  116. package/build/src/rules/vitest/markdown-table/rules.d.ts +3 -0
  117. package/build/src/rules/vitest/markdown-table/rules.d.ts.map +1 -0
  118. package/build/src/rules/vitest/markdown-table/rules.js +99 -0
  119. package/build/src/rules/vitest/markdown-table/rules.js.map +1 -0
  120. package/build/src/rules/vitest/terminology/register.d.ts +3 -0
  121. package/build/src/rules/vitest/terminology/register.d.ts.map +1 -0
  122. package/build/src/rules/vitest/terminology/register.js +38 -0
  123. package/build/src/rules/vitest/terminology/register.js.map +1 -0
  124. package/build/src/rules/vitest/terminology/rules.d.ts +10 -0
  125. package/build/src/rules/vitest/terminology/rules.d.ts.map +1 -0
  126. package/build/src/rules/vitest/terminology/rules.js +202 -0
  127. package/build/src/rules/vitest/terminology/rules.js.map +1 -0
  128. package/build/src/rules/vitest/type-declarations/register.d.ts +3 -0
  129. package/build/src/rules/vitest/type-declarations/register.d.ts.map +1 -0
  130. package/build/src/rules/vitest/type-declarations/register.js +30 -0
  131. package/build/src/rules/vitest/type-declarations/register.js.map +1 -0
  132. package/build/src/rules/vitest/type-declarations/rules.d.ts +11 -0
  133. package/build/src/rules/vitest/type-declarations/rules.d.ts.map +1 -0
  134. package/build/src/rules/vitest/type-declarations/rules.js +666 -0
  135. package/build/src/rules/vitest/type-declarations/rules.js.map +1 -0
  136. package/build/src/toolkit/logger.d.ts.map +1 -1
  137. package/build/src/toolkit/logger.js +3 -1
  138. package/build/src/toolkit/logger.js.map +1 -1
  139. package/build/src/types/cli/generate/github/issue-template.d.ts +10 -30
  140. package/build/src/types/cli/generate/github/workflows.d.ts +7 -7
  141. package/build/src/types/cli/generate/must-haves/agent-conventions.d.ts +8 -1
  142. package/build/src/types/cli/generate/must-haves/dotenv.d.ts +79 -327
  143. package/build/src/types/cli/generate/must-haves/gitignore.d.ts +12 -342
  144. package/build/src/types/cli/recipe/github/sync-features.d.ts +1 -1
  145. package/build/src/types/cli/recipe/github/sync-identity.d.ts +2 -2
  146. package/build/src/types/cli/recipe/github/sync-policies.d.ts +3 -1
  147. package/build/src/types/cli/utility/changelog.d.ts +92 -0
  148. package/build/src/types/cli/utility/initialize.d.ts +195 -0
  149. package/build/src/types/lib/constants.d.ts +1 -1
  150. package/build/src/types/lib/dotenv.d.ts +67 -0
  151. package/build/src/types/lib/file-discovery.d.ts +40 -0
  152. package/build/src/types/lib/item.d.ts +19 -0
  153. package/build/src/types/lib/markdown-slug.d.ts +25 -0
  154. package/build/src/types/lib/nova-config.d.ts +108 -16
  155. package/build/src/types/lib/regex.d.ts +193 -18
  156. package/build/src/types/lib/type-declaration-engine.d.ts +1036 -0
  157. package/build/src/types/lib/utility.d.ts +2 -2
  158. package/build/src/types/lib/workflow-templates.d.ts +1 -1
  159. package/build/src/types/rules/eslint/jsdoc/require-jsdoc-hierarchy.d.ts +2 -2
  160. package/build/src/types/rules/eslint/jsdoc/require-jsdoc-since.d.ts +71 -1
  161. package/build/src/types/rules/eslint/regex/no-regex-literals.d.ts +44 -0
  162. package/build/src/types/rules/eslint/typescript/require-type-naming.d.ts +3 -3
  163. package/build/src/types/rules/vitest/dotenv/register.d.ts +31 -0
  164. package/build/src/types/rules/vitest/dotenv/rules.d.ts +29 -0
  165. package/build/src/types/rules/vitest/enable.d.ts +12 -0
  166. package/build/src/types/rules/vitest/frontmatter/register.d.ts +63 -0
  167. package/build/src/types/rules/vitest/frontmatter/rules.d.ts +430 -0
  168. package/build/src/types/rules/vitest/index.d.ts +399 -0
  169. package/build/src/types/rules/vitest/link/register.d.ts +79 -0
  170. package/build/src/types/rules/vitest/link/rules.d.ts +368 -0
  171. package/build/src/types/rules/vitest/markdown-table/register.d.ts +33 -0
  172. package/build/src/types/rules/vitest/markdown-table/rules.d.ts +55 -0
  173. package/build/src/types/rules/vitest/terminology/register.d.ts +48 -0
  174. package/build/src/types/rules/vitest/terminology/rules.d.ts +190 -0
  175. package/build/src/types/rules/vitest/type-declarations/register.d.ts +46 -0
  176. package/build/src/types/rules/vitest/type-declarations/rules.d.ts +820 -0
  177. package/build/src/types/shared.d.ts +71 -4
  178. package/build/src/types/tests/cli/generate/github/issue-template.test.d.ts +34 -17
  179. package/build/src/types/tests/cli/generate/github/workflows-helpers.test.d.ts +8 -8
  180. package/build/src/types/tests/cli/generate/must-haves/agent-conventions.test.d.ts +79 -11
  181. package/build/src/types/tests/cli/generate/must-haves/dotenv.test.d.ts +105 -15
  182. package/build/src/types/tests/cli/generate/must-haves/gitignore.test.d.ts +11 -20
  183. package/build/src/types/tests/cli/recipe/github/handle-gh-failure.test.d.ts +3 -3
  184. package/build/src/types/tests/cli/recipe/github/sync-features.test.d.ts +17 -17
  185. package/build/src/types/tests/cli/recipe/github/sync-identity.test.d.ts +69 -23
  186. package/build/src/types/tests/cli/recipe/github/sync-policies.test.d.ts +89 -20
  187. package/build/src/types/tests/cli/scaffold/docs/docusaurus.test.d.ts +4 -0
  188. package/build/src/types/tests/cli/utility/changelog.test.d.ts +262 -0
  189. package/build/src/types/tests/cli/utility/initialize.test.d.ts +31 -0
  190. package/build/src/types/tests/lib/dotenv.test.d.ts +95 -0
  191. package/build/src/types/tests/lib/file-discovery.test.d.ts +37 -0
  192. package/build/src/types/tests/lib/item.test.d.ts +21 -0
  193. package/build/src/types/tests/lib/markdown-slug.test.d.ts +24 -0
  194. package/build/src/types/tests/lib/nova-config.test.d.ts +263 -0
  195. package/build/src/types/tests/lib/regex.test.d.ts +252 -0
  196. package/build/src/types/tests/rules/eslint/jsdoc/require-jsdoc-since.test.d.ts +18 -0
  197. package/build/src/types/tests/rules/vitest/dotenv.test.d.ts +19 -0
  198. package/build/src/types/tests/rules/vitest/enable.test.d.ts +27 -0
  199. package/build/src/types/tests/rules/vitest/frontmatter.test.d.ts +8 -0
  200. package/build/src/types/tests/rules/vitest/link.test.d.ts +74 -0
  201. package/build/src/types/tests/rules/vitest/markdown-table.test.d.ts +28 -0
  202. package/build/src/types/tests/rules/vitest/terminology.test.d.ts +39 -0
  203. package/build/src/types/tests/rules/vitest/type-declarations.test.d.ts +10 -0
  204. package/build/src/types/tests/scaffold-version-drift.test.d.ts +42 -0
  205. package/build/src/types/tests/since-version.test.d.ts +137 -0
  206. package/build/src/types/tests/toolkit/logger.test.d.ts +45 -0
  207. package/build/src/types/tests/type-declarations.test.d.ts +34 -1821
  208. package/build/src/types/toolkit/logger.d.ts +4 -0
  209. package/build/templates/generators/github/workflows/check-sponsor-gated-issues/base.yml +1 -1
  210. package/build/templates/generators/github/workflows/publish/base.yml +1 -1
  211. package/build/templates/generators/github/workflows/publish/targets/aws-amplify-nextjs.yml +1 -1
  212. package/build/templates/generators/github/workflows/publish/targets/cloudflare-pages-docusaurus.yml +1 -1
  213. package/build/templates/generators/github/workflows/publish/targets/docker-hub.yml +1 -1
  214. package/build/templates/generators/github/workflows/publish/targets/ghcr.yml +1 -1
  215. package/build/templates/generators/github/workflows/publish/targets/github-action.yml +1 -1
  216. package/build/templates/generators/github/workflows/publish/targets/github-packages.yml +1 -1
  217. package/build/templates/generators/github/workflows/publish/targets/github-pages-docusaurus.yml +4 -4
  218. package/build/templates/generators/github/workflows/publish/targets/npm.yml +1 -1
  219. package/build/templates/generators/github/workflows/publish/targets/vercel-nextjs.yml +1 -1
  220. package/build/templates/generators/must-haves/agent-conventions/AGENTS.md +1 -2
  221. package/build/templates/generators/must-haves/agent-conventions/CLAUDE.md +1 -2
  222. package/build/templates/generators/must-haves/agent-conventions/conventions/java.md +5 -5
  223. package/build/templates/generators/must-haves/agent-conventions/conventions/kotlin.md +4 -4
  224. package/build/templates/generators/must-haves/agent-conventions/conventions/php.md +2 -2
  225. package/build/templates/generators/must-haves/agent-conventions/conventions/typescript.md +6 -6
  226. package/build/templates/generators/must-haves/dotenv/env +5 -2
  227. package/build/templates/generators/must-haves/dotenv/env.sample +6 -3
  228. package/build/templates/generators/must-haves/gitignore/gitignore +6 -0
  229. package/build/templates/scaffold/app/express/package.json +5 -5
  230. package/build/templates/scaffold/app/nextjs/package.json +7 -7
  231. package/build/templates/scaffold/app/vite/package.json +3 -3
  232. package/build/templates/scaffold/app/workers/package.json +3 -3
  233. package/build/templates/scaffold/docs/docusaurus/docs/intro.md +6 -0
  234. package/build/templates/scaffold/docs/docusaurus/package.json +11 -7
  235. package/build/templates/scaffold/docs/docusaurus/src/tests/frontmatter.test.ts +21 -0
  236. package/build/templates/scaffold/docs/docusaurus/src/tests/link.test.ts +14 -0
  237. package/build/templates/scaffold/docs/docusaurus/src/tests/markdown-table.test.ts +14 -0
  238. package/build/templates/scaffold/docs/docusaurus/src/tests/terminology.test.ts +14 -0
  239. package/build/templates/scaffold/docs/docusaurus/vitest.config.ts +22 -0
  240. package/build/templates/scaffold/docs/docusaurus/vitest.setup.ts +26 -0
  241. package/package.json +6 -3
  242. package/build/templates/generators/must-haves/agent-conventions/cursorrules +0 -55
@@ -0,0 +1,666 @@
1
+ import { strictEqual } from 'node:assert/strict';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { relative, sep, } from 'node:path';
4
+ import { it } from 'vitest';
5
+ import { LIB_REGEX_PATTERN_EXPORT_TYPE_NAME, LIB_REGEX_PATTERN_EXT_CJS_SUFFIX, LIB_REGEX_PATTERN_EXT_CTS_SUFFIX, LIB_REGEX_PATTERN_EXT_D_CTS_SUFFIX, LIB_REGEX_PATTERN_EXT_D_MTS_SUFFIX, LIB_REGEX_PATTERN_EXT_D_TS_SUFFIX, LIB_REGEX_PATTERN_EXT_JS_SUFFIX, LIB_REGEX_PATTERN_EXT_JSX_SUFFIX, LIB_REGEX_PATTERN_EXT_MJS_SUFFIX, LIB_REGEX_PATTERN_EXT_MTS_SUFFIX, LIB_REGEX_PATTERN_EXT_TS_SUFFIX, LIB_REGEX_PATTERN_EXT_TSX_SUFFIX, LIB_REGEX_PATTERN_EXTENSION_TEST_SUFFIX, LIB_REGEX_PATTERN_KEBAB_CASE_SEGMENT, LIB_REGEX_PATTERN_PASCAL_CASE_SEGMENT, LIB_REGEX_PATTERN_PASCAL_CASE_UNDERSCORE_TYPE_NAME, LIB_REGEX_PATTERN_THREE_CONSECUTIVE_CAPS, } from '../../../lib/regex.js';
6
+ import { buildDtsSections, buildSourceSectionMap, checkTypeNameUniqueness, deriveClassPrefix, deriveSourcePath, detectInlineTypedCallbacks, discoverSourceFiles, discoverTypeFiles, extractArrayTypes, extractBodyDeclarations, extractFunctionParams, extractFunctionReturns, extractImportedNames, extractObjectTypes, extractReferencedTypes, extractTopLevelIdentifiers, extractTypeNames, fileExists, findFirstOccurrence, isAliasToForeignType, isLocallyDefined, isReservedSuffix, stripUnderscorePrefix, validateLeaf, validateReturnType, } from '../../../lib/type-declaration-engine.js';
7
+ import { isEnabled } from '../enable.js';
8
+ export async function crossSectionReferences(config, enable) {
9
+ if (isEnabled('inspector-cross-section-references', enable) === false) {
10
+ return;
11
+ }
12
+ const files = await discoverTypeFiles(config);
13
+ const crossSectionCurrentDirectory = config['packageRoot'] ?? process.cwd();
14
+ for (const file of files) {
15
+ const crossSectionRelativePath = relative(crossSectionCurrentDirectory, file);
16
+ it(`no cross-section references in ${crossSectionRelativePath}`, async () => {
17
+ if (config['standaloneTypeFiles'].some((pattern) => file.endsWith(pattern)) === true) {
18
+ return;
19
+ }
20
+ const sourcePath = deriveSourcePath(file);
21
+ const sourceExists = await fileExists(sourcePath);
22
+ if (sourceExists === false) {
23
+ return;
24
+ }
25
+ const content = await readFile(file, 'utf-8');
26
+ const lines = content.split('\n');
27
+ const sourceContent = await readFile(sourcePath, 'utf-8');
28
+ const classPrefix = deriveClassPrefix(file, config);
29
+ const sectionMap = buildSourceSectionMap(sourcePath, sourceContent, classPrefix);
30
+ const sourceSectionSet = new Set(sectionMap.values());
31
+ const importedNames = extractImportedNames(lines);
32
+ const sections = buildDtsSections(lines, sourceSectionSet, classPrefix);
33
+ const sectionPrefixes = sections.map((section) => section['prefix']);
34
+ const violations = [];
35
+ for (const section of sections) {
36
+ const currentSectionPrefix = section['prefix'];
37
+ for (const line of section['typeLines']) {
38
+ const referencedTypes = extractReferencedTypes(line, classPrefix);
39
+ for (const referencedType of referencedTypes) {
40
+ const isSameSection = referencedType.startsWith(currentSectionPrefix) === true;
41
+ const isImported = importedNames.has(referencedType) === true;
42
+ const isOtherSection = sectionPrefixes.some((sectionPrefix) => {
43
+ return referencedType.startsWith(sectionPrefix) === true && sectionPrefix !== currentSectionPrefix;
44
+ });
45
+ if (isOtherSection === true
46
+ && isSameSection === false
47
+ && isImported === false) {
48
+ const violation = `Section "${currentSectionPrefix}" references "${referencedType}" from another section. Move shared types to a shared type file (e.g., shared.d.ts).`;
49
+ violations.push(violation);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ const violationMessage = violations.join('\n');
55
+ strictEqual(violations.length, 0, violationMessage);
56
+ return;
57
+ });
58
+ }
59
+ return;
60
+ }
61
+ export async function sectionAlphabeticalOrder(config, enable) {
62
+ if (isEnabled('inspector-section-alphabetical', enable) === false) {
63
+ return;
64
+ }
65
+ const files = await discoverTypeFiles(config);
66
+ const sectionOrderCurrentDirectory = config['packageRoot'] ?? process.cwd();
67
+ for (const file of files) {
68
+ const sectionOrderRelativePath = relative(sectionOrderCurrentDirectory, file);
69
+ it(`sections alphabetical in ${sectionOrderRelativePath}`, async () => {
70
+ if (config['standaloneTypeFiles'].some((pattern) => file.endsWith(pattern)) === true) {
71
+ return;
72
+ }
73
+ const sourcePath = deriveSourcePath(file);
74
+ const sourceExists = await fileExists(sourcePath);
75
+ if (sourceExists === false) {
76
+ return;
77
+ }
78
+ const content = await readFile(file, 'utf-8');
79
+ const lines = content.split('\n');
80
+ const sourceContent = await readFile(sourcePath, 'utf-8');
81
+ const classPrefix = deriveClassPrefix(file, config);
82
+ const sectionMap = buildSourceSectionMap(sourcePath, sourceContent, classPrefix);
83
+ const sourceSectionSet = new Set(sectionMap.values());
84
+ const sections = buildDtsSections(lines, sourceSectionSet, classPrefix);
85
+ const violations = [];
86
+ for (let i = 1; i < sections.length; i += 1) {
87
+ const previous = sections[i - 1];
88
+ const current = sections[i];
89
+ if (previous === undefined || current === undefined) {
90
+ continue;
91
+ }
92
+ const compareResult = previous['prefix'].localeCompare(current['prefix']);
93
+ if (compareResult > 0) {
94
+ const violation = `Section "${current['prefix']}" appears after section "${previous['prefix']}" but should come before it. Sections in a .d.ts file must be alphabetical by section prefix; move "${current['prefix']}"'s types above "${previous['prefix']}"'s types.`;
95
+ violations.push(violation);
96
+ }
97
+ }
98
+ const violationMessage = violations.join('\n');
99
+ strictEqual(violations.length, 0, violationMessage);
100
+ return;
101
+ });
102
+ }
103
+ return;
104
+ }
105
+ export async function firstComeFirstServeOrder(config, enable) {
106
+ if (isEnabled('inspector-first-come-first-serve-order', enable) === false) {
107
+ return;
108
+ }
109
+ const files = await discoverTypeFiles(config);
110
+ const orderCurrentDirectory = config['packageRoot'] ?? process.cwd();
111
+ for (const file of files) {
112
+ const orderRelativePath = relative(orderCurrentDirectory, file);
113
+ it(`types match source order in ${orderRelativePath}`, async () => {
114
+ if (config['standaloneTypeFiles'].some((pattern) => file.endsWith(pattern)) === true) {
115
+ return;
116
+ }
117
+ let sourcePath = deriveSourcePath(file);
118
+ let sourceExists = await fileExists(sourcePath);
119
+ if (sourceExists === false) {
120
+ const sourcePathAlternative = sourcePath.replace('.ts', '.tsx');
121
+ sourcePath = sourcePathAlternative;
122
+ sourceExists = await fileExists(sourcePath);
123
+ if (sourceExists === false) {
124
+ strictEqual(sourceExists, true, `Missing source file for ${orderRelativePath}. Expected: ${relative(orderCurrentDirectory, sourcePath)}`);
125
+ return;
126
+ }
127
+ }
128
+ const sourceContent = await readFile(sourcePath, 'utf-8');
129
+ const sourceLines = sourceContent.split('\n');
130
+ const dtsContent = await readFile(file, 'utf-8');
131
+ const dtsLines = dtsContent.split('\n');
132
+ const classPrefix = deriveClassPrefix(file, config);
133
+ const sectionMap = buildSourceSectionMap(sourcePath, sourceContent, classPrefix);
134
+ const sourceSectionSet = new Set(sectionMap.values());
135
+ const sections = buildDtsSections(dtsLines, sourceSectionSet, classPrefix);
136
+ const objectTypes = extractObjectTypes(dtsLines, classPrefix);
137
+ const objectPropertyTypeNames = new Set();
138
+ const arrayElementTypeNames = new Set();
139
+ for (const objectType of objectTypes) {
140
+ for (const property of objectType['properties']) {
141
+ objectPropertyTypeNames.add(property['valueType']);
142
+ }
143
+ }
144
+ const arrayTypesForOrder = extractArrayTypes(dtsLines);
145
+ for (const arrayType of arrayTypesForOrder) {
146
+ arrayElementTypeNames.add(arrayType['elementTypeName']);
147
+ }
148
+ const violations = [];
149
+ for (const section of sections) {
150
+ const typeNames = extractTypeNames(section['typeLines']);
151
+ const typePositions = [];
152
+ for (const typeName of typeNames) {
153
+ if (objectPropertyTypeNames.has(typeName) === true) {
154
+ continue;
155
+ }
156
+ if (arrayElementTypeNames.has(typeName) === true) {
157
+ continue;
158
+ }
159
+ const sourceLineIndex = findFirstOccurrence(sourceLines, typeName);
160
+ if (sourceLineIndex === -1) {
161
+ continue;
162
+ }
163
+ typePositions.push({
164
+ name: typeName,
165
+ sourceLine: sourceLineIndex,
166
+ });
167
+ }
168
+ const sortedPositions = [...typePositions].sort((positionA, positionB) => positionA['sourceLine'] - positionB['sourceLine']);
169
+ for (let j = 0; j < typePositions.length; j += 1) {
170
+ const actual = typePositions[j];
171
+ const expected = sortedPositions[j];
172
+ if (actual === undefined || expected === undefined) {
173
+ continue;
174
+ }
175
+ if (actual['name'] !== expected['name']) {
176
+ const violation = `Section "${section['prefix']}": at .d.ts position ${j + 1}, found "${actual['name']}" (first appears at source line ${actual['sourceLine'] + 1}) but expected "${expected['name']}" (first appears at source line ${expected['sourceLine'] + 1}, which comes earlier in source). Move "${expected['name']}" to position ${j + 1} so the .d.ts mirrors the source's first-come-first-serve order.`;
177
+ violations.push(violation);
178
+ }
179
+ }
180
+ }
181
+ const violationMessage = violations.join('\n');
182
+ strictEqual(violations.length, 0, violationMessage);
183
+ return;
184
+ });
185
+ }
186
+ return;
187
+ }
188
+ export async function objectPropertyTypes(config, enable) {
189
+ if (isEnabled('inspector-object-property-types', enable) === false) {
190
+ return;
191
+ }
192
+ const files = await discoverTypeFiles(config);
193
+ const objectPropsCurrentDirectory = config['packageRoot'] ?? process.cwd();
194
+ for (const file of files) {
195
+ const objectPropsRelativePath = relative(objectPropsCurrentDirectory, file);
196
+ it(`object properties use named types in ${objectPropsRelativePath}`, async () => {
197
+ const content = await readFile(file, 'utf-8');
198
+ const lines = content.split('\n');
199
+ const classPrefix = deriveClassPrefix(file, config);
200
+ const violations = [];
201
+ const definedTypes = new Set();
202
+ for (let i = 0; i < lines.length; i += 1) {
203
+ const line = lines[i];
204
+ if (line === undefined) {
205
+ continue;
206
+ }
207
+ const typeDefMatch = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
208
+ if (typeDefMatch !== null && typeDefMatch[1] !== undefined) {
209
+ definedTypes.add(typeDefMatch[1]);
210
+ }
211
+ }
212
+ const objectTypes = extractObjectTypes(lines, classPrefix);
213
+ for (const objectType of objectTypes) {
214
+ for (const property of objectType['properties']) {
215
+ const propertyExpectedPrefix = objectType['name'];
216
+ if (property['valueType'].startsWith(propertyExpectedPrefix) === false) {
217
+ const violation = `"${objectType['name']}": property "${property['key']}" must use a named type starting with "${propertyExpectedPrefix}" but found "${property['valueType']}".`;
218
+ violations.push(violation);
219
+ continue;
220
+ }
221
+ if (definedTypes.has(property['valueType']) === false) {
222
+ const violation2 = `"${objectType['name']}": property type "${property['valueType']}" is not defined in this file.`;
223
+ violations.push(violation2);
224
+ continue;
225
+ }
226
+ if (property['typeLineIndex'] > objectType['lineIndex']) {
227
+ const violation3 = `"${objectType['name']}": property type "${property['valueType']}" (line ${property['typeLineIndex'] + 1}) must be defined before the object type (line ${objectType['lineIndex'] + 1}).`;
228
+ violations.push(violation3);
229
+ }
230
+ }
231
+ }
232
+ const importedNames = extractImportedNames(lines);
233
+ const arrayTypes = extractArrayTypes(lines);
234
+ const typeDefLines = new Map();
235
+ for (let i = 0; i < lines.length; i += 1) {
236
+ const line2 = lines[i];
237
+ if (line2 === undefined) {
238
+ continue;
239
+ }
240
+ const defMatch = line2.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
241
+ if (defMatch !== null
242
+ && defMatch[1] !== undefined
243
+ && typeDefLines.has(defMatch[1]) === false) {
244
+ typeDefLines.set(defMatch[1], i);
245
+ }
246
+ }
247
+ for (const arrayType of arrayTypes) {
248
+ if (arrayType['arrayTypeName'].endsWith('Returns') === true
249
+ || arrayType['arrayTypeName'].endsWith('_Returns') === true
250
+ || arrayType['arrayTypeName'].endsWith('TypeGuard') === true
251
+ || arrayType['arrayTypeName'].endsWith('_TypeGuard') === true
252
+ || arrayType['arrayTypeName'].endsWith('Return') === true
253
+ || arrayType['arrayTypeName'].endsWith('_Return') === true) {
254
+ continue;
255
+ }
256
+ if (importedNames.has(arrayType['elementTypeName']) === true) {
257
+ continue;
258
+ }
259
+ if (definedTypes.has(arrayType['elementTypeName']) === false) {
260
+ continue;
261
+ }
262
+ const elementLine = typeDefLines.get(arrayType['elementTypeName']) ?? -1;
263
+ if (elementLine === -1) {
264
+ continue;
265
+ }
266
+ if (elementLine > arrayType['lineIndex']) {
267
+ const violation4 = `"${arrayType['arrayTypeName']}" (line ${arrayType['lineIndex'] + 1}): array element type "${arrayType['elementTypeName']}" (line ${elementLine + 1}) must be defined before the array type.`;
268
+ violations.push(violation4);
269
+ }
270
+ }
271
+ const violationMessage = violations.join('\n');
272
+ strictEqual(violations.length, 0, violationMessage);
273
+ return;
274
+ });
275
+ }
276
+ return;
277
+ }
278
+ export async function sectionCoverage(config, enable) {
279
+ if (isEnabled('inspector-section-coverage', enable) === false) {
280
+ return;
281
+ }
282
+ const files = await discoverTypeFiles(config);
283
+ const coverageCurrentDirectory = config['packageRoot'] ?? process.cwd();
284
+ for (const file of files) {
285
+ const coverageRelativePath = relative(coverageCurrentDirectory, file);
286
+ it(`source sections have matching .d.ts sections in ${coverageRelativePath}`, async () => {
287
+ if (config['standaloneTypeFiles'].some((pattern) => file.endsWith(pattern)) === true) {
288
+ return;
289
+ }
290
+ let sourcePath = deriveSourcePath(file);
291
+ let sourceExists = await fileExists(sourcePath);
292
+ if (sourceExists === false) {
293
+ const sourcePathAlternative = sourcePath.replace('.ts', '.tsx');
294
+ sourcePath = sourcePathAlternative;
295
+ sourceExists = await fileExists(sourcePath);
296
+ if (sourceExists === false) {
297
+ return;
298
+ }
299
+ }
300
+ const sourceContent = await readFile(sourcePath, 'utf-8');
301
+ const dtsContent = await readFile(file, 'utf-8');
302
+ const dtsLines = dtsContent.split('\n');
303
+ const classPrefix = deriveClassPrefix(file, config);
304
+ const sectionMap = buildSourceSectionMap(sourcePath, sourceContent, classPrefix);
305
+ const sourceSectionSet = new Set(sectionMap.values());
306
+ const dtsSections = buildDtsSections(dtsLines, sourceSectionSet, classPrefix);
307
+ const dtsSectionPrefixes = new Set(dtsSections.map((section) => section['prefix']));
308
+ const violations = [];
309
+ for (const sourceSectionPrefix of sourceSectionSet) {
310
+ if (sourceSectionPrefix === classPrefix) {
311
+ continue;
312
+ }
313
+ const isParent = Array.from(sourceSectionSet).some((otherSection) => {
314
+ return otherSection !== sourceSectionPrefix && otherSection.startsWith(`${sourceSectionPrefix}_`) === true;
315
+ });
316
+ if (isParent === true) {
317
+ continue;
318
+ }
319
+ if (dtsSectionPrefixes.has(sourceSectionPrefix) === false) {
320
+ const violation = `Source has section "${sourceSectionPrefix}" but .d.ts has no types belonging to it. Add an "export type" with that prefix, or remove the corresponding source identifier.`;
321
+ violations.push(violation);
322
+ }
323
+ }
324
+ const singleChunkTopLevelTypes = new Set();
325
+ for (const line of dtsLines) {
326
+ if (line.startsWith('export type ') === false) {
327
+ continue;
328
+ }
329
+ const singleChunkMatch = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
330
+ if (singleChunkMatch === null || singleChunkMatch[1] === undefined) {
331
+ continue;
332
+ }
333
+ const singleChunkTypeName = singleChunkMatch[1];
334
+ if (singleChunkTypeName.startsWith(`${classPrefix}_`) === false) {
335
+ continue;
336
+ }
337
+ const singleChunkAfterClassPrefix = singleChunkTypeName.slice(classPrefix.length + 1);
338
+ if (singleChunkAfterClassPrefix.includes('_') === false) {
339
+ singleChunkTopLevelTypes.add(singleChunkTypeName);
340
+ }
341
+ }
342
+ for (const line of dtsLines) {
343
+ if (line.startsWith('export type ') === false) {
344
+ continue;
345
+ }
346
+ const reverseMatch = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
347
+ if (reverseMatch === null || reverseMatch[1] === undefined) {
348
+ continue;
349
+ }
350
+ const reverseTypeName = reverseMatch[1];
351
+ if (reverseTypeName.startsWith(`${classPrefix}_`) === false) {
352
+ continue;
353
+ }
354
+ const reverseAfterClassPrefix = reverseTypeName.slice(classPrefix.length + 1);
355
+ const reverseChunks = reverseAfterClassPrefix.split('_');
356
+ if (reverseChunks.length <= 1) {
357
+ continue;
358
+ }
359
+ const reverseExpectedMethodSection = `${classPrefix}_${reverseChunks[0]}`;
360
+ if (singleChunkTopLevelTypes.has(reverseExpectedMethodSection) === true) {
361
+ continue;
362
+ }
363
+ if (sourceSectionSet.has(reverseExpectedMethodSection) === false) {
364
+ const violation2 = `.d.ts type "${reverseTypeName}" expects source section "${reverseExpectedMethodSection}" but no class/method/function/(string, fn) call by that name exists in the source file. Fix options: (a) rename the .d.ts type to match an existing source section, (b) add a matching source identifier (class, method, top-level function, or function-typed const), or (c) add this file to standaloneTypeFiles if the .d.ts is a domain type file with no source mirror.`;
365
+ violations.push(violation2);
366
+ }
367
+ }
368
+ const violationMessage = violations.join('\n');
369
+ strictEqual(violations.length, 0, violationMessage);
370
+ return;
371
+ });
372
+ }
373
+ return;
374
+ }
375
+ export async function variableTypeSymmetry(config, enable) {
376
+ if (isEnabled('inspector-variable-type-symmetry', enable) === false) {
377
+ return;
378
+ }
379
+ const files = await discoverSourceFiles(config);
380
+ const symmetryCurrentDirectory = config['packageRoot'] ?? process.cwd();
381
+ const symmetryMapping = config['mapping'];
382
+ for (const file of files) {
383
+ const symmetryRelativePath = relative(symmetryCurrentDirectory, file);
384
+ it(`variable type symmetry in ${symmetryRelativePath}`, async () => {
385
+ const content = await readFile(file, 'utf-8');
386
+ const lines = content.split('\n');
387
+ const classPrefix = deriveClassPrefix(file, config);
388
+ const sectionMap = buildSourceSectionMap(file, content, classPrefix);
389
+ const dtsPath = symmetryMapping.sourceToDts(file);
390
+ const dtsExists = await fileExists(dtsPath);
391
+ const dtsContent = (dtsExists === true) ? await readFile(dtsPath, 'utf-8') : '';
392
+ const violations = [];
393
+ const inlineCallbacks = detectInlineTypedCallbacks(file, content);
394
+ for (const callback of inlineCallbacks) {
395
+ const violation = `${symmetryRelativePath}:${callback['lineNumber']}: rule 7.4 violation: inline typed callback param "${callback['paramName']}: ${callback['typeName']}" is forbidden. Extract the callback to a named const so it follows rule 7.1.`;
396
+ violations.push(violation);
397
+ }
398
+ const bodyDecls = extractBodyDeclarations(lines);
399
+ const expectedNames = [];
400
+ for (const decl of bodyDecls) {
401
+ const sourceSection = sectionMap.get(decl['lineNumber']) ?? classPrefix;
402
+ if (isReservedSuffix(decl['typeName']) === true) {
403
+ const violation2 = `${symmetryRelativePath}:${decl['lineNumber']}: rule 7.3 violation: body var "${decl['varName']}: ${decl['typeName']}" uses a return-position-only suffix (Returns/TypeGuard/Return). Use a different type name without that suffix.`;
404
+ violations.push(violation2);
405
+ continue;
406
+ }
407
+ const leafResult = validateLeaf(decl['varName'], decl['typeName'], sourceSection, classPrefix);
408
+ if (leafResult !== null) {
409
+ const violation3 = `${symmetryRelativePath}:${decl['lineNumber']}: rule 7.1 violation: body var "${decl['varName']}: ${decl['typeName']}" -- expected leaf "${leafResult['expectedLeaf']}" but found "${leafResult['actualLeaf']}". Rename the type to "${sourceSection}_${leafResult['expectedLeaf']}" or "${classPrefix}_${leafResult['expectedLeaf']}".`;
410
+ violations.push(violation3);
411
+ }
412
+ if (dtsExists === true) {
413
+ if (isLocallyDefined(decl['typeName'], dtsContent) === false) {
414
+ const relativeDtsPath = dtsPath.replace(symmetryCurrentDirectory, '');
415
+ const cleanedDtsPath = (relativeDtsPath.startsWith('/') === true) ? relativeDtsPath.slice(1) : relativeDtsPath;
416
+ const violation4 = `${symmetryRelativePath}:${decl['lineNumber']}: rule 7.2 violation: body var type "${decl['typeName']}" is not defined in the corresponding .d.ts. Cross-module body-var types are forbidden -- define the type concretely in ${cleanedDtsPath}, or promote the shape to shared.d.ts, or skip the typed body var.`;
417
+ violations.push(violation4);
418
+ }
419
+ else if (isAliasToForeignType(decl['typeName'], dtsContent, classPrefix) === true) {
420
+ const relativeDtsPath2 = dtsPath.replace(symmetryCurrentDirectory, '');
421
+ const cleanedDtsPath2 = (relativeDtsPath2.startsWith('/') === true) ? relativeDtsPath2.slice(1) : relativeDtsPath2;
422
+ const violation5 = `${symmetryRelativePath}:${decl['lineNumber']}: rule 7.2 violation: body var type "${decl['typeName']}" is locally defined but only as an alias to a foreign type. Cross-module body-var types are forbidden -- escape hatches: (a) promote the shape to shared.d.ts, (b) redefine the concrete shape in ${cleanedDtsPath2}, or (c) inline the call to skip the typed body var.`;
423
+ violations.push(violation5);
424
+ }
425
+ }
426
+ const stripped = stripUnderscorePrefix(decl['varName']);
427
+ const titleVar = stripped.charAt(0).toUpperCase() + stripped.slice(1);
428
+ expectedNames.push({
429
+ name: decl['varName'],
430
+ typeName: `${sourceSection}_${titleVar}`,
431
+ lineNumber: decl['lineNumber'],
432
+ });
433
+ }
434
+ const params = extractFunctionParams(file, content);
435
+ for (const param of params) {
436
+ const sourceSection2 = sectionMap.get(param['lineNumber']) ?? classPrefix;
437
+ if (isReservedSuffix(param['typeName']) === true) {
438
+ const violation6 = `${symmetryRelativePath}:${param['lineNumber']}: rule 7.3 violation: param "${param['paramName']}: ${param['typeName']}" uses a return-position-only suffix (Returns/TypeGuard/Return). Use a different type name without that suffix.`;
439
+ violations.push(violation6);
440
+ continue;
441
+ }
442
+ const leafResult2 = validateLeaf(param['paramName'], param['typeName'], sourceSection2, classPrefix);
443
+ if (leafResult2 !== null) {
444
+ const violation7 = `${symmetryRelativePath}:${param['lineNumber']}: rule 7.1 violation: param "${param['paramName']}: ${param['typeName']}" -- expected leaf "${leafResult2['expectedLeaf']}" but found "${leafResult2['actualLeaf']}". Rename the type to "${sourceSection2}_${leafResult2['expectedLeaf']}" or "${classPrefix}_${leafResult2['expectedLeaf']}".`;
445
+ violations.push(violation7);
446
+ }
447
+ const stripped2 = stripUnderscorePrefix(param['paramName']);
448
+ const titleVar2 = stripped2.charAt(0).toUpperCase() + stripped2.slice(1);
449
+ expectedNames.push({
450
+ name: param['paramName'],
451
+ typeName: `${sourceSection2}_${titleVar2}`,
452
+ lineNumber: param['lineNumber'],
453
+ });
454
+ }
455
+ const fnReturnRecords = extractFunctionReturns(file, content);
456
+ for (const ret of fnReturnRecords) {
457
+ const returnValidationReason = validateReturnType(ret['returnType'], ret['isTypeGuard']);
458
+ if (returnValidationReason !== null) {
459
+ const violation8 = `${symmetryRelativePath}:${ret['lineNumber']}: rule 7.5/7.6/7.7 violation: ${returnValidationReason}`;
460
+ violations.push(violation8);
461
+ }
462
+ }
463
+ const uniquenessViolations = checkTypeNameUniqueness(expectedNames);
464
+ for (const uniquenessViolation of uniquenessViolations) {
465
+ const violation9 = `${symmetryRelativePath}: rule 7.8 violation: ${uniquenessViolation}`;
466
+ violations.push(violation9);
467
+ }
468
+ const violationMessage = violations.join('\n');
469
+ strictEqual(violations.length, 0, violationMessage);
470
+ return;
471
+ });
472
+ }
473
+ return;
474
+ }
475
+ export async function identifierVsFileName(config, enable) {
476
+ if (isEnabled('inspector-identifier-vs-filename', enable) === false) {
477
+ return;
478
+ }
479
+ const files = await discoverSourceFiles(config);
480
+ const identifierVsFileNameCurrentDirectory = config['packageRoot'] ?? process.cwd();
481
+ for (const file of files) {
482
+ const identifierVsFileNameRelativePath = relative(identifierVsFileNameCurrentDirectory, file);
483
+ it(`top-level identifiers in ${identifierVsFileNameRelativePath} do not equal file name`, async () => {
484
+ const content = await readFile(file, 'utf-8');
485
+ const classPrefix = deriveClassPrefix(file, config);
486
+ const segments = classPrefix.split('_');
487
+ const fileName = segments[segments.length - 1] ?? '';
488
+ const identifiers = extractTopLevelIdentifiers(file, content);
489
+ const violations = [];
490
+ for (const identifier of identifiers) {
491
+ if (identifier['name'] === fileName) {
492
+ const violation = `${identifierVsFileNameRelativePath}:${identifier['lineNumber']}: rule C1/C2/C3 violation: top-level ${identifier['kind']} name "${identifier['name']}" equals file name "${fileName}". Rename the ${identifier['kind']} (use a barrel re-export if consumers need to import the file-name as the public name).`;
493
+ violations.push(violation);
494
+ }
495
+ }
496
+ const violationMessage = violations.join('\n');
497
+ strictEqual(violations.length, 0, violationMessage);
498
+ return;
499
+ });
500
+ }
501
+ return;
502
+ }
503
+ export async function filenameValidation(config, enable) {
504
+ if (isEnabled('inspector-filename-validation', enable) === false) {
505
+ return;
506
+ }
507
+ const sourceFiles = await discoverSourceFiles(config);
508
+ const dtsFiles = await discoverTypeFiles(config);
509
+ const allFiles = [
510
+ ...sourceFiles,
511
+ ...dtsFiles,
512
+ ];
513
+ const filenameValidationCurrentDirectory = config['packageRoot'] ?? process.cwd();
514
+ for (const file of allFiles) {
515
+ const filenameValidationRelativePath = relative(filenameValidationCurrentDirectory, file);
516
+ it(`filename and path segments in ${filenameValidationRelativePath} are valid`, () => {
517
+ let cleaned = filenameValidationRelativePath;
518
+ for (const typeRoot of config['typeRoots']) {
519
+ cleaned = cleaned.replace(`${typeRoot}/types/`, '');
520
+ cleaned = cleaned.replace(`${typeRoot}/`, '');
521
+ }
522
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_D_TS_SUFFIX, '');
523
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_D_MTS_SUFFIX, '');
524
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_D_CTS_SUFFIX, '');
525
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_TSX_SUFFIX, '');
526
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_TS_SUFFIX, '');
527
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_MTS_SUFFIX, '');
528
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_CTS_SUFFIX, '');
529
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_JSX_SUFFIX, '');
530
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_JS_SUFFIX, '');
531
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_MJS_SUFFIX, '');
532
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXT_CJS_SUFFIX, '');
533
+ cleaned = cleaned.replace(LIB_REGEX_PATTERN_EXTENSION_TEST_SUFFIX, '');
534
+ const segments = cleaned.split(sep).join('/').split('/').filter((segment) => segment.length > 0);
535
+ const pattern = LIB_REGEX_PATTERN_KEBAB_CASE_SEGMENT;
536
+ const pascalCasePattern = LIB_REGEX_PATTERN_PASCAL_CASE_SEGMENT;
537
+ const violations = [];
538
+ for (const segment of segments) {
539
+ const matchesKebab = pattern.test(segment);
540
+ const matchesPascal = pascalCasePattern.test(segment);
541
+ if (matchesKebab === false && matchesPascal === false) {
542
+ const violation = `${filenameValidationRelativePath}: invalid path segment "${segment}". Path segments must be kebab-case (/^[a-z][a-z0-9-]*$/) or PascalCase (/^[A-Z][A-Za-z0-9]*$/). Recognized strippable suffixes: .d.ts, .d.mts, .d.cts, .tsx, .ts, .mts, .cts, .jsx, .js, .mjs, .cjs, .test. Underscores, dots, spaces, camelCase, and leading digits are rejected.`;
543
+ violations.push(violation);
544
+ }
545
+ }
546
+ const violationMessage = violations.join('\n');
547
+ strictEqual(violations.length, 0, violationMessage);
548
+ return;
549
+ });
550
+ }
551
+ return;
552
+ }
553
+ export async function standaloneTypeFiles(config, enable) {
554
+ if (isEnabled('inspector-standalone-type-files', enable) === false) {
555
+ return;
556
+ }
557
+ const standaloneSourceFiles = await discoverSourceFiles(config);
558
+ const standaloneDtsFiles = await discoverTypeFiles(config);
559
+ const topLevelPathPrefixes = new Set();
560
+ for (const sourceFile of standaloneSourceFiles) {
561
+ const sourceClassPrefix = deriveClassPrefix(sourceFile, config);
562
+ const firstChunk = sourceClassPrefix.split('_')[0];
563
+ if (firstChunk !== undefined && firstChunk !== '') {
564
+ topLevelPathPrefixes.add(firstChunk);
565
+ }
566
+ }
567
+ const standaloneFiles = standaloneDtsFiles.filter((dtsFile) => config['standaloneTypeFiles'].some((pattern) => dtsFile.endsWith(pattern)));
568
+ const standaloneCurrentDirectory = config['packageRoot'] ?? process.cwd();
569
+ if (standaloneFiles.length === 0) {
570
+ it(`standalone file rules in ${standaloneCurrentDirectory} (no standalone type files configured)`, () => {
571
+ return;
572
+ });
573
+ }
574
+ for (const file of standaloneFiles) {
575
+ const standaloneRelativePath = relative(standaloneCurrentDirectory, file);
576
+ it(`standalone file rules in ${standaloneRelativePath}`, async () => {
577
+ const content = await readFile(file, 'utf-8');
578
+ const lines = content.split('\n');
579
+ const typeLines = lines.filter((line) => line.startsWith('export type '));
580
+ const typeNames = extractTypeNames(typeLines);
581
+ const localTypeSet = new Set(typeNames);
582
+ const primitiveSet = new Set([
583
+ 'string',
584
+ 'number',
585
+ 'boolean',
586
+ 'unknown',
587
+ 'never',
588
+ 'void',
589
+ 'null',
590
+ 'undefined',
591
+ 'any',
592
+ 'object',
593
+ 'symbol',
594
+ 'bigint',
595
+ ]);
596
+ const pascalCasePattern = LIB_REGEX_PATTERN_PASCAL_CASE_UNDERSCORE_TYPE_NAME;
597
+ const brandCasePattern = LIB_REGEX_PATTERN_THREE_CONSECUTIVE_CAPS;
598
+ const violations = [];
599
+ for (const typeName of typeNames) {
600
+ if (pascalCasePattern.test(typeName) === false) {
601
+ const violation = `${standaloneRelativePath}: rule S1 violation: type "${typeName}" is not PascalCase. Standalone-file types must be PascalCase, optionally underscore-separated for nested properties (e.g., EntryItem, EntryItem_Category).`;
602
+ violations.push(violation);
603
+ continue;
604
+ }
605
+ if (brandCasePattern.test(typeName) === true) {
606
+ const violation2 = `${standaloneRelativePath}: rule S1 violation: type "${typeName}" uses brand casing (3+ consecutive uppercase letters). Use Pascal-cased acronyms instead (e.g., Url, Api, Cli -- not URL, API, CLI).`;
607
+ violations.push(violation2);
608
+ }
609
+ }
610
+ for (const typeName of typeNames) {
611
+ for (const pathPrefix of topLevelPathPrefixes) {
612
+ if (typeName.startsWith(`${pathPrefix}_`) === true) {
613
+ const violation3 = `${standaloneRelativePath}: rule S2 violation: type "${typeName}" looks like a path-prefix-style name (starts with "${pathPrefix}_" -- a known source-file top-level segment). Standalone-file types must be domain concepts, not path-derived.`;
614
+ violations.push(violation3);
615
+ break;
616
+ }
617
+ }
618
+ }
619
+ const objectTypes = extractObjectTypes(lines, '');
620
+ for (const objectType of objectTypes) {
621
+ const expectedPropertyPrefix = `${objectType['name']}_`;
622
+ for (const property of objectType['properties']) {
623
+ if (primitiveSet.has(property['valueType']) === true) {
624
+ continue;
625
+ }
626
+ if (localTypeSet.has(property['valueType']) === false) {
627
+ continue;
628
+ }
629
+ if (property['valueType'].startsWith(expectedPropertyPrefix) === false) {
630
+ const violation4 = `${standaloneRelativePath}: rule S3 violation: object type "${objectType['name']}" property "${property['key']}" uses local type "${property['valueType']}" which does not start with "${expectedPropertyPrefix}". Add an intermediate alias (e.g., "${expectedPropertyPrefix}${property['key'].charAt(0).toUpperCase() + property['key'].slice(1)} = ${property['valueType']};") to use the Parent_Property nesting form.`;
631
+ violations.push(violation4);
632
+ }
633
+ }
634
+ }
635
+ const arrayTypes = extractArrayTypes(lines);
636
+ const typePositions = new Map();
637
+ for (let i = 0; i < lines.length; i += 1) {
638
+ const lineToScan = lines[i];
639
+ if (lineToScan === undefined) {
640
+ continue;
641
+ }
642
+ const positionMatch = lineToScan.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
643
+ if (positionMatch !== null
644
+ && positionMatch[1] !== undefined
645
+ && typePositions.has(positionMatch[1]) === false) {
646
+ typePositions.set(positionMatch[1], i);
647
+ }
648
+ }
649
+ for (const arrayType of arrayTypes) {
650
+ const elementLine = typePositions.get(arrayType['elementTypeName']) ?? -1;
651
+ if (elementLine === -1) {
652
+ continue;
653
+ }
654
+ if (elementLine >= arrayType['lineIndex']) {
655
+ const violation5 = `${standaloneRelativePath}:${arrayType['lineIndex'] + 1}: rule S4 violation: array type "${arrayType['arrayTypeName']}" defined before its element type "${arrayType['elementTypeName']}" (element at line ${elementLine + 1}). Define element types before arrays.`;
656
+ violations.push(violation5);
657
+ }
658
+ }
659
+ const violationMessage = violations.join('\n');
660
+ strictEqual(violations.length, 0, violationMessage);
661
+ return;
662
+ });
663
+ }
664
+ return;
665
+ }
666
+ //# sourceMappingURL=rules.js.map