@thethracian/oxlint-config 0.2.0 → 0.3.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 (279) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +125 -19
  3. package/dist/codemod-fix/cli.d.ts +3 -0
  4. package/dist/codemod-fix/cli.d.ts.map +1 -0
  5. package/dist/codemod-fix/cli.js +22 -0
  6. package/dist/codemod-fix/cli.js.map +1 -0
  7. package/dist/codemod-fix/index.d.ts +44 -0
  8. package/dist/codemod-fix/index.d.ts.map +1 -0
  9. package/dist/codemod-fix/index.js +110 -0
  10. package/dist/codemod-fix/index.js.map +1 -0
  11. package/dist/codemods/arrow-body-style.d.ts +7 -0
  12. package/dist/codemods/arrow-body-style.d.ts.map +1 -0
  13. package/dist/codemods/arrow-body-style.js +106 -0
  14. package/dist/codemods/arrow-body-style.js.map +1 -0
  15. package/dist/codemods/comment-format.d.ts +24 -0
  16. package/dist/codemods/comment-format.d.ts.map +1 -0
  17. package/dist/codemods/comment-format.js +100 -0
  18. package/dist/codemods/comment-format.js.map +1 -0
  19. package/dist/codemods/explicit-return-types.d.ts +7 -0
  20. package/dist/codemods/explicit-return-types.d.ts.map +1 -0
  21. package/dist/codemods/explicit-return-types.js +350 -0
  22. package/dist/codemods/explicit-return-types.js.map +1 -0
  23. package/dist/codemods/format-file-header.d.ts +7 -0
  24. package/dist/codemods/format-file-header.d.ts.map +1 -0
  25. package/dist/codemods/format-file-header.js +163 -0
  26. package/dist/codemods/format-file-header.js.map +1 -0
  27. package/dist/codemods/format-jsdoc-comments.d.ts +7 -0
  28. package/dist/codemods/format-jsdoc-comments.d.ts.map +1 -0
  29. package/dist/codemods/format-jsdoc-comments.js +129 -0
  30. package/dist/codemods/format-jsdoc-comments.js.map +1 -0
  31. package/dist/codemods/function-declarations.d.ts +7 -0
  32. package/dist/codemods/function-declarations.d.ts.map +1 -0
  33. package/dist/codemods/function-declarations.js +202 -0
  34. package/dist/codemods/function-declarations.js.map +1 -0
  35. package/dist/codemods/inline-export-lists.d.ts +7 -0
  36. package/dist/codemods/inline-export-lists.d.ts.map +1 -0
  37. package/dist/codemods/inline-export-lists.js +168 -0
  38. package/dist/codemods/inline-export-lists.js.map +1 -0
  39. package/dist/codemods/internal-export-docs.d.ts +7 -0
  40. package/dist/codemods/internal-export-docs.d.ts.map +1 -0
  41. package/dist/codemods/internal-export-docs.js +93 -0
  42. package/dist/codemods/internal-export-docs.js.map +1 -0
  43. package/dist/codemods/no-ternary-branch-initializers.d.ts +14 -0
  44. package/dist/codemods/no-ternary-branch-initializers.d.ts.map +1 -0
  45. package/dist/codemods/no-ternary-branch-initializers.js +240 -0
  46. package/dist/codemods/no-ternary-branch-initializers.js.map +1 -0
  47. package/dist/codemods/no-ternary-variable-initializers.d.ts +14 -0
  48. package/dist/codemods/no-ternary-variable-initializers.d.ts.map +1 -0
  49. package/dist/codemods/no-ternary-variable-initializers.js +235 -0
  50. package/dist/codemods/no-ternary-variable-initializers.js.map +1 -0
  51. package/dist/codemods/no-ternary.d.ts +7 -0
  52. package/dist/codemods/no-ternary.d.ts.map +1 -0
  53. package/dist/codemods/no-ternary.js +215 -0
  54. package/dist/codemods/no-ternary.js.map +1 -0
  55. package/dist/codemods/rename-acronyms.d.ts +8 -0
  56. package/dist/codemods/rename-acronyms.d.ts.map +1 -0
  57. package/dist/codemods/rename-acronyms.js +193 -0
  58. package/dist/codemods/rename-acronyms.js.map +1 -0
  59. package/dist/codemods/run.d.ts +2 -0
  60. package/dist/codemods/run.d.ts.map +1 -0
  61. package/dist/codemods/run.js +14 -0
  62. package/dist/codemods/run.js.map +1 -0
  63. package/dist/codemods/sort-imports.d.ts +7 -0
  64. package/dist/codemods/sort-imports.d.ts.map +1 -0
  65. package/dist/codemods/sort-imports.js +235 -0
  66. package/dist/codemods/sort-imports.js.map +1 -0
  67. package/dist/index.d.ts +30 -96
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +157 -95
  70. package/dist/index.js.map +1 -1
  71. package/dist/rules/acronym-case.d.ts +7 -3
  72. package/dist/rules/acronym-case.d.ts.map +1 -1
  73. package/dist/rules/acronym-case.js +129 -120
  74. package/dist/rules/acronym-case.js.map +1 -1
  75. package/dist/rules/acronyms-1.d.ts +3 -0
  76. package/dist/rules/acronyms-1.d.ts.map +1 -0
  77. package/dist/rules/acronyms-1.js +407 -0
  78. package/dist/rules/acronyms-1.js.map +1 -0
  79. package/dist/rules/acronyms-2.d.ts +3 -0
  80. package/dist/rules/acronyms-2.d.ts.map +1 -0
  81. package/dist/rules/acronyms-2.js +407 -0
  82. package/dist/rules/acronyms-2.js.map +1 -0
  83. package/dist/rules/acronyms-3.d.ts +3 -0
  84. package/dist/rules/acronyms-3.d.ts.map +1 -0
  85. package/dist/rules/acronyms-3.js +407 -0
  86. package/dist/rules/acronyms-3.js.map +1 -0
  87. package/dist/rules/acronyms-4.d.ts +3 -0
  88. package/dist/rules/acronyms-4.d.ts.map +1 -0
  89. package/dist/rules/acronyms-4.js +377 -0
  90. package/dist/rules/acronyms-4.js.map +1 -0
  91. package/dist/rules/acronyms.d.ts +1 -8
  92. package/dist/rules/acronyms.d.ts.map +1 -1
  93. package/dist/rules/acronyms.js +14 -1578
  94. package/dist/rules/acronyms.js.map +1 -1
  95. package/dist/rules/boolean-prefix.d.ts +11 -2
  96. package/dist/rules/boolean-prefix.d.ts.map +1 -1
  97. package/dist/rules/boolean-prefix.js +95 -59
  98. package/dist/rules/boolean-prefix.js.map +1 -1
  99. package/dist/rules/camel-case-identifiers.d.ts +3 -4
  100. package/dist/rules/camel-case-identifiers.d.ts.map +1 -1
  101. package/dist/rules/camel-case-identifiers.js +59 -40
  102. package/dist/rules/camel-case-identifiers.js.map +1 -1
  103. package/dist/rules/char-class.d.ts +26 -13
  104. package/dist/rules/char-class.d.ts.map +1 -1
  105. package/dist/rules/char-class.js +56 -24
  106. package/dist/rules/char-class.js.map +1 -1
  107. package/dist/rules/diagnostic-guidance.d.ts +91 -0
  108. package/dist/rules/diagnostic-guidance.d.ts.map +1 -0
  109. package/dist/rules/diagnostic-guidance.js +243 -0
  110. package/dist/rules/diagnostic-guidance.js.map +1 -0
  111. package/dist/rules/effect-default-ast.d.ts +89 -0
  112. package/dist/rules/effect-default-ast.d.ts.map +1 -0
  113. package/dist/rules/effect-default-ast.js +208 -0
  114. package/dist/rules/effect-default-ast.js.map +1 -0
  115. package/dist/rules/effect-default-compat-rules.d.ts +76 -0
  116. package/dist/rules/effect-default-compat-rules.d.ts.map +1 -0
  117. package/dist/rules/effect-default-compat-rules.js +270 -0
  118. package/dist/rules/effect-default-compat-rules.js.map +1 -0
  119. package/dist/rules/effect-default-env-rules.d.ts +60 -0
  120. package/dist/rules/effect-default-env-rules.d.ts.map +1 -0
  121. package/dist/rules/effect-default-env-rules.js +259 -0
  122. package/dist/rules/effect-default-env-rules.js.map +1 -0
  123. package/dist/rules/effect-default-fiber-helpers.d.ts +13 -0
  124. package/dist/rules/effect-default-fiber-helpers.d.ts.map +1 -0
  125. package/dist/rules/effect-default-fiber-helpers.js +76 -0
  126. package/dist/rules/effect-default-fiber-helpers.js.map +1 -0
  127. package/dist/rules/effect-default-floating-helpers.d.ts +7 -0
  128. package/dist/rules/effect-default-floating-helpers.d.ts.map +1 -0
  129. package/dist/rules/effect-default-floating-helpers.js +113 -0
  130. package/dist/rules/effect-default-floating-helpers.js.map +1 -0
  131. package/dist/rules/effect-default-helpers.d.ts +8 -32
  132. package/dist/rules/effect-default-helpers.d.ts.map +1 -1
  133. package/dist/rules/effect-default-helpers.js +11 -458
  134. package/dist/rules/effect-default-helpers.js.map +1 -1
  135. package/dist/rules/effect-default-resource-helpers.d.ts +18 -4
  136. package/dist/rules/effect-default-resource-helpers.d.ts.map +1 -1
  137. package/dist/rules/effect-default-resource-helpers.js +30 -13
  138. package/dist/rules/effect-default-resource-helpers.js.map +1 -1
  139. package/dist/rules/effect-default-safety-helpers.d.ts +43 -0
  140. package/dist/rules/effect-default-safety-helpers.d.ts.map +1 -0
  141. package/dist/rules/effect-default-safety-helpers.js +126 -0
  142. package/dist/rules/effect-default-safety-helpers.js.map +1 -0
  143. package/dist/rules/effect-default-scan-helpers.d.ts +43 -0
  144. package/dist/rules/effect-default-scan-helpers.d.ts.map +1 -0
  145. package/dist/rules/effect-default-scan-helpers.js +141 -0
  146. package/dist/rules/effect-default-scan-helpers.js.map +1 -0
  147. package/dist/rules/effect-default-schema-helpers.d.ts +37 -0
  148. package/dist/rules/effect-default-schema-helpers.d.ts.map +1 -0
  149. package/dist/rules/effect-default-schema-helpers.js +104 -0
  150. package/dist/rules/effect-default-schema-helpers.js.map +1 -0
  151. package/dist/rules/effect-default-test-helpers.d.ts +18 -4
  152. package/dist/rules/effect-default-test-helpers.d.ts.map +1 -1
  153. package/dist/rules/effect-default-test-helpers.js +41 -20
  154. package/dist/rules/effect-default-test-helpers.js.map +1 -1
  155. package/dist/rules/effect-default-workflow-helpers.d.ts +91 -0
  156. package/dist/rules/effect-default-workflow-helpers.d.ts.map +1 -0
  157. package/dist/rules/effect-default-workflow-helpers.js +247 -0
  158. package/dist/rules/effect-default-workflow-helpers.js.map +1 -0
  159. package/dist/rules/effect-default.d.ts +1 -1
  160. package/dist/rules/effect-default.d.ts.map +1 -1
  161. package/dist/rules/effect-default.js +198 -637
  162. package/dist/rules/effect-default.js.map +1 -1
  163. package/dist/rules/effect-exported-declarations.d.ts +19 -0
  164. package/dist/rules/effect-exported-declarations.d.ts.map +1 -0
  165. package/dist/rules/effect-exported-declarations.js +237 -0
  166. package/dist/rules/effect-exported-declarations.js.map +1 -0
  167. package/dist/rules/effect-path-options.d.ts +49 -11
  168. package/dist/rules/effect-path-options.d.ts.map +1 -1
  169. package/dist/rules/effect-path-options.js +85 -52
  170. package/dist/rules/effect-path-options.js.map +1 -1
  171. package/dist/rules/effect-rule-aliases.d.ts +55 -0
  172. package/dist/rules/effect-rule-aliases.d.ts.map +1 -0
  173. package/dist/rules/effect-rule-aliases.js +278 -0
  174. package/dist/rules/effect-rule-aliases.js.map +1 -0
  175. package/dist/rules/effect-rule-core.d.ts +46 -24
  176. package/dist/rules/effect-rule-core.d.ts.map +1 -1
  177. package/dist/rules/effect-rule-core.js +263 -303
  178. package/dist/rules/effect-rule-core.js.map +1 -1
  179. package/dist/rules/effect-rule-names.d.ts +12 -3
  180. package/dist/rules/effect-rule-names.d.ts.map +1 -1
  181. package/dist/rules/effect-rule-names.js +15 -3
  182. package/dist/rules/effect-rule-names.js.map +1 -1
  183. package/dist/rules/effect-source-comments.d.ts +7 -0
  184. package/dist/rules/effect-source-comments.d.ts.map +1 -0
  185. package/dist/rules/effect-source-comments.js +227 -0
  186. package/dist/rules/effect-source-comments.js.map +1 -0
  187. package/dist/rules/effect-source-helpers.d.ts +4 -9
  188. package/dist/rules/effect-source-helpers.d.ts.map +1 -1
  189. package/dist/rules/effect-source-helpers.js +7 -333
  190. package/dist/rules/effect-source-helpers.js.map +1 -1
  191. package/dist/rules/effect-source-navigation.d.ts +25 -0
  192. package/dist/rules/effect-source-navigation.d.ts.map +1 -0
  193. package/dist/rules/effect-source-navigation.js +244 -0
  194. package/dist/rules/effect-source-navigation.js.map +1 -0
  195. package/dist/rules/effect-source-scan.d.ts +30 -7
  196. package/dist/rules/effect-source-scan.d.ts.map +1 -1
  197. package/dist/rules/effect-source-scan.js +377 -297
  198. package/dist/rules/effect-source-scan.js.map +1 -1
  199. package/dist/rules/effect-strict-ast-specs.d.ts +8 -0
  200. package/dist/rules/effect-strict-ast-specs.d.ts.map +1 -0
  201. package/dist/rules/effect-strict-ast-specs.js +166 -0
  202. package/dist/rules/effect-strict-ast-specs.js.map +1 -0
  203. package/dist/rules/effect-strict-boundary-helpers.d.ts +25 -0
  204. package/dist/rules/effect-strict-boundary-helpers.d.ts.map +1 -0
  205. package/dist/rules/effect-strict-boundary-helpers.js +127 -0
  206. package/dist/rules/effect-strict-boundary-helpers.js.map +1 -0
  207. package/dist/rules/effect-strict-core-specs.d.ts +8 -0
  208. package/dist/rules/effect-strict-core-specs.d.ts.map +1 -0
  209. package/dist/rules/effect-strict-core-specs.js +334 -0
  210. package/dist/rules/effect-strict-core-specs.js.map +1 -0
  211. package/dist/rules/effect-strict-external-helpers.d.ts +25 -0
  212. package/dist/rules/effect-strict-external-helpers.d.ts.map +1 -0
  213. package/dist/rules/effect-strict-external-helpers.js +87 -0
  214. package/dist/rules/effect-strict-external-helpers.js.map +1 -0
  215. package/dist/rules/effect-strict-helpers.d.ts +75 -33
  216. package/dist/rules/effect-strict-helpers.d.ts.map +1 -1
  217. package/dist/rules/effect-strict-helpers.js +124 -246
  218. package/dist/rules/effect-strict-helpers.js.map +1 -1
  219. package/dist/rules/effect-strict-internals.d.ts +198 -0
  220. package/dist/rules/effect-strict-internals.d.ts.map +1 -0
  221. package/dist/rules/effect-strict-internals.js +477 -0
  222. package/dist/rules/effect-strict-internals.js.map +1 -0
  223. package/dist/rules/effect-strict-segment-helpers.d.ts +79 -0
  224. package/dist/rules/effect-strict-segment-helpers.d.ts.map +1 -0
  225. package/dist/rules/effect-strict-segment-helpers.js +308 -0
  226. package/dist/rules/effect-strict-segment-helpers.js.map +1 -0
  227. package/dist/rules/effect-strict.d.ts +1 -1
  228. package/dist/rules/effect-strict.d.ts.map +1 -1
  229. package/dist/rules/effect-strict.js +10 -661
  230. package/dist/rules/effect-strict.js.map +1 -1
  231. package/dist/rules/max-import-depth.d.ts +2 -2
  232. package/dist/rules/max-import-depth.d.ts.map +1 -1
  233. package/dist/rules/max-import-depth.js +52 -17
  234. package/dist/rules/max-import-depth.js.map +1 -1
  235. package/dist/rules/max-line-length.d.ts +9 -2
  236. package/dist/rules/max-line-length.d.ts.map +1 -1
  237. package/dist/rules/max-line-length.js +62 -7
  238. package/dist/rules/max-line-length.js.map +1 -1
  239. package/dist/rules/no-commented-out-code.d.ts +3 -7
  240. package/dist/rules/no-commented-out-code.d.ts.map +1 -1
  241. package/dist/rules/no-commented-out-code.js +157 -102
  242. package/dist/rules/no-commented-out-code.js.map +1 -1
  243. package/dist/rules/pascal-case-types.d.ts +1 -1
  244. package/dist/rules/pascal-case-types.d.ts.map +1 -1
  245. package/dist/rules/pascal-case-types.js +65 -46
  246. package/dist/rules/pascal-case-types.js.map +1 -1
  247. package/dist/rules/plugin-commented-out-code-rule.d.ts +32 -0
  248. package/dist/rules/plugin-commented-out-code-rule.d.ts.map +1 -0
  249. package/dist/rules/plugin-commented-out-code-rule.js +135 -0
  250. package/dist/rules/plugin-commented-out-code-rule.js.map +1 -0
  251. package/dist/rules/plugin.d.ts +3 -121
  252. package/dist/rules/plugin.d.ts.map +1 -1
  253. package/dist/rules/plugin.js +195 -201
  254. package/dist/rules/plugin.js.map +1 -1
  255. package/dist/rules/private-underscore.d.ts +1 -1
  256. package/dist/rules/private-underscore.d.ts.map +1 -1
  257. package/dist/rules/private-underscore.js +11 -4
  258. package/dist/rules/private-underscore.js.map +1 -1
  259. package/dist/rules/require-file-doc.d.ts +5 -6
  260. package/dist/rules/require-file-doc.d.ts.map +1 -1
  261. package/dist/rules/require-file-doc.js +127 -78
  262. package/dist/rules/require-file-doc.js.map +1 -1
  263. package/dist/rules/require-function-doc-ignored-text.d.ts +7 -0
  264. package/dist/rules/require-function-doc-ignored-text.d.ts.map +1 -0
  265. package/dist/rules/require-function-doc-ignored-text.js +67 -0
  266. package/dist/rules/require-function-doc-ignored-text.js.map +1 -0
  267. package/dist/rules/require-function-doc-local-exports.d.ts +7 -0
  268. package/dist/rules/require-function-doc-local-exports.d.ts.map +1 -0
  269. package/dist/rules/require-function-doc-local-exports.js +114 -0
  270. package/dist/rules/require-function-doc-local-exports.js.map +1 -0
  271. package/dist/rules/require-function-doc.d.ts +3 -18
  272. package/dist/rules/require-function-doc.d.ts.map +1 -1
  273. package/dist/rules/require-function-doc.js +404 -218
  274. package/dist/rules/require-function-doc.js.map +1 -1
  275. package/dist/rules/source-cache.d.ts +19 -0
  276. package/dist/rules/source-cache.d.ts.map +1 -0
  277. package/dist/rules/source-cache.js +63 -0
  278. package/dist/rules/source-cache.js.map +1 -0
  279. package/package.json +15 -10
@@ -1,63 +1,154 @@
1
- /**
2
- * Require-function-doc ensures every exported declaration has a non-empty JSDoc comment.
3
- *
4
- * Checks:
5
- * - `export function`, `export class`, `export const`, `export let`, `export var`
6
- * - `export default function`, `export default class`
7
- * - `export type`, `export interface`, `export enum`
8
- * - `export abstract class`
9
- *
10
- * Skips:
11
- * - `export { ... } from ...` (re-exports)
12
- * - `export * from ...` (wildcard re-exports)
13
- * - `export type { ... } from ...` (type re-exports)
14
- * - `export default <expression>` (not a declaration)
15
- * - Non-exported declarations
16
- */
17
- function isWhitespace(code) {
18
- return code === 32 || code === 9 || code === 10 || code === 13;
19
- }
20
- function hasDescriptionContent(jsdocBody) {
21
- const stripped = jsdocBody
22
- .split('\n')
23
- .map((line) => {
24
- let strippedLine = line.trimStart();
25
- if (strippedLine.startsWith('*')) {
26
- strippedLine = strippedLine.slice(1).trimStart();
27
- }
28
- return strippedLine;
29
- })
30
- .join('\n')
31
- .trim();
32
- return stripped.length > 0;
33
- }
34
- function hasJSDocBefore(source, exportPos) {
35
- let pos = exportPos;
36
- while (pos > 0 && isWhitespace(source.charCodeAt(pos - 1))) {
37
- pos--;
1
+ /* -------------------------------------------------------------------------- */
2
+ /* Exported-declaration documentation requirement helper for custom Oxlint */
3
+ /* Rules. */
4
+ /* -------------------------------------------------------------------------- */
5
+ import { isDocumentedLocalExportList } from './require-function-doc-local-exports.js';
6
+ import { isInsideIgnoredText } from './require-function-doc-ignored-text.js';
7
+ const CHAR_CODE_SPACE = 32;
8
+ const CHAR_CODE_TAB = 9;
9
+ const CHAR_CODE_NEWLINE = 10;
10
+ const CHAR_CODE_CARRIAGE_RETURN = 13;
11
+ const CHAR_CODE_ASTERISK = 42;
12
+ const CHAR_CODE_SLASH = 47;
13
+ const CHAR_CODE_HASH = 35;
14
+ const CHAR_CODE_AT_SIGN = 64;
15
+ const CHAR_CODE_OPEN_PAREN = 40;
16
+ const CHAR_CODE_OPEN_BRACE = 123;
17
+ const CHAR_CODE_SEMICOLON = 59;
18
+ const CHAR_CODE_LESS_THAN = 60;
19
+ const CHAR_CODE_LOWER_A = 97;
20
+ const CHAR_CODE_LOWER_C = 99;
21
+ const CHAR_CODE_LOWER_D = 100;
22
+ const CHAR_CODE_LOWER_E = 101;
23
+ const CHAR_CODE_LOWER_F = 102;
24
+ const CHAR_CODE_LOWER_I = 105;
25
+ const CHAR_CODE_LOWER_L = 108;
26
+ const CHAR_CODE_LOWER_N = 110;
27
+ const CHAR_CODE_LOWER_T = 116;
28
+ const CHAR_CODE_LOWER_V = 118;
29
+ const CHAR_CODE_UPPER_C = 67;
30
+ const CHAR_CODE_UPPER_E = 69;
31
+ const CHAR_CODE_UPPER_F = 70;
32
+ const CHAR_CODE_UPPER_I = 73;
33
+ const CHAR_CODE_UPPER_L = 76;
34
+ const CHAR_CODE_UPPER_N = 78;
35
+ const CHAR_CODE_UPPER_V = 86;
36
+ const ASYNC_KEYWORD_LENGTH = 'async '.length;
37
+ const TYPE_KEYWORD_LENGTH = 'type '.length;
38
+ const EXPORT_KEYWORD_LENGTH = 'export '.length;
39
+ const DEFAULT_KEYWORD_LENGTH = 'default '.length;
40
+ const DECLARE_KEYWORD_LENGTH = 'declare '.length;
41
+ const ABSTRACT_KEYWORD_LENGTH = 'abstract '.length;
42
+ const isWhitespace = (code) => code === CHAR_CODE_SPACE ||
43
+ code === CHAR_CODE_TAB ||
44
+ code === CHAR_CODE_NEWLINE ||
45
+ code === CHAR_CODE_CARRIAGE_RETURN;
46
+ const lineEndFor = (source, lineStart, len) => {
47
+ const newlineIndex = source.indexOf('\n', lineStart);
48
+ if (newlineIndex === -1) {
49
+ return len;
38
50
  }
39
- if (pos < 2) {
40
- return false;
51
+ return newlineIndex;
52
+ };
53
+ const skipLinePrefix = (source, pos, lineEnd) => {
54
+ let cursor = pos;
55
+ while (cursor < lineEnd && isWhitespace(source.charCodeAt(cursor))) {
56
+ cursor++;
57
+ }
58
+ if (cursor < lineEnd && source.charCodeAt(cursor) === CHAR_CODE_ASTERISK) {
59
+ cursor++;
60
+ }
61
+ while (cursor < lineEnd && isWhitespace(source.charCodeAt(cursor))) {
62
+ cursor++;
41
63
  }
42
- if (source.charCodeAt(pos - 2) !== 42 || source.charCodeAt(pos - 1) !== 47) {
64
+ return cursor;
65
+ };
66
+ const isJSDocTagLine = (source, pos, lineEnd) => pos < lineEnd && source.charCodeAt(pos) === CHAR_CODE_AT_SIGN;
67
+ const lineHasDescriptionContent = (source, lineStart, lineEnd) => {
68
+ let pos = skipLinePrefix(source, lineStart, lineEnd);
69
+ if (isJSDocTagLine(source, pos, lineEnd)) {
43
70
  return false;
44
71
  }
45
- const closeStar = pos - 2;
72
+ while (pos < lineEnd) {
73
+ if (!isWhitespace(source.charCodeAt(pos))) {
74
+ return true;
75
+ }
76
+ pos++;
77
+ }
78
+ return false;
79
+ };
80
+ const nextDescriptionLineStart = (newlineIndex) => {
81
+ if (newlineIndex === -1) {
82
+ return undefined;
83
+ }
84
+ return newlineIndex + 1;
85
+ };
86
+ const hasDescriptionLine = (jsdocBody, lineStart, len) => {
87
+ const newlineIndex = jsdocBody.indexOf('\n', lineStart);
88
+ const lineEnd = lineEndFor(jsdocBody, lineStart, len);
89
+ if (lineHasDescriptionContent(jsdocBody, lineStart, lineEnd)) {
90
+ return { found: true };
91
+ }
92
+ return { found: false, nextLineStart: nextDescriptionLineStart(newlineIndex) };
93
+ };
94
+ const hasDescriptionContent = (jsdocBody) => {
95
+ let lineStart = 0;
96
+ const len = jsdocBody.length;
97
+ while (lineStart <= len) {
98
+ const result = hasDescriptionLine(jsdocBody, lineStart, len);
99
+ if (result.found) {
100
+ return true;
101
+ }
102
+ if (result.nextLineStart === undefined) {
103
+ return false;
104
+ }
105
+ lineStart = result.nextLineStart;
106
+ }
107
+ return false;
108
+ };
109
+ const skipWhitespaceBack = (source, pos) => {
110
+ let cursor = pos;
111
+ while (cursor > 0 && isWhitespace(source.charCodeAt(cursor - 1))) {
112
+ cursor--;
113
+ }
114
+ return cursor;
115
+ };
116
+ const hasBlockCommentCloseAt = (source, pos) => pos >= '*/'.length &&
117
+ source.charCodeAt(pos - '*/'.length) === CHAR_CODE_ASTERISK &&
118
+ source.charCodeAt(pos - 1) === CHAR_CODE_SLASH;
119
+ const jsdocContentBeforeClose = (source, open, closeStar) => {
120
+ if (open + 1 < closeStar && source.charCodeAt(open + 1) === CHAR_CODE_ASTERISK) {
121
+ return source.slice(open + '/**'.length, closeStar).trim();
122
+ }
123
+ return undefined;
124
+ };
125
+ const previousJSDocContent = (source, closeStar) => {
46
126
  let open = closeStar - 1;
47
127
  while (open > 0) {
48
- if (source.charCodeAt(open) === 42 && source.charCodeAt(open - 1) === 47) {
49
- if (open + 1 < closeStar && source.charCodeAt(open + 1) === 42) {
50
- const content = source.slice(open + 3, closeStar).trim();
51
- return hasDescriptionContent(content);
128
+ if (source.charCodeAt(open) === CHAR_CODE_ASTERISK &&
129
+ source.charCodeAt(open - 1) === CHAR_CODE_SLASH) {
130
+ const content = jsdocContentBeforeClose(source, open, closeStar);
131
+ if (content !== undefined) {
132
+ return content;
52
133
  }
53
- open -= 2;
54
- continue;
134
+ open -= '/*'.length;
135
+ }
136
+ else {
137
+ open--;
55
138
  }
56
- open--;
57
139
  }
58
- return false;
59
- }
60
- function endsWithWord(source, pos, word) {
140
+ return undefined;
141
+ };
142
+ const hasJSDocBefore = (source, exportPOS) => {
143
+ const pos = skipWhitespaceBack(source, exportPOS);
144
+ if (!hasBlockCommentCloseAt(source, pos)) {
145
+ return false;
146
+ }
147
+ const closeStar = pos - '*/'.length;
148
+ const content = previousJSDocContent(source, closeStar);
149
+ return content !== undefined && hasDescriptionContent(content);
150
+ };
151
+ const endsWithWord = (source, pos, word) => {
61
152
  const end = pos + word.length;
62
153
  if (end > source.length) {
63
154
  return false;
@@ -69,200 +160,295 @@ function endsWithWord(source, pos, word) {
69
160
  return true;
70
161
  }
71
162
  const next = source.charCodeAt(end);
72
- return isWhitespace(next) || next === 40 || next === 123 || next === 59 || next === 60;
73
- }
74
- function isDefaultDeclaration(source, pos, _len) {
163
+ return (isWhitespace(next) ||
164
+ next === CHAR_CODE_OPEN_PAREN ||
165
+ next === CHAR_CODE_OPEN_BRACE ||
166
+ next === CHAR_CODE_SEMICOLON ||
167
+ next === CHAR_CODE_LESS_THAN);
168
+ };
169
+ const isDefaultDeclaration = (source, pos, _len) => {
75
170
  const ch = source.charCodeAt(pos);
76
- if (ch === 102) {
171
+ if (ch === CHAR_CODE_LOWER_F) {
77
172
  return endsWithWord(source, pos, 'function');
78
173
  }
79
- if (ch === 99) {
174
+ if (ch === CHAR_CODE_LOWER_C) {
80
175
  return endsWithWord(source, pos, 'class');
81
176
  }
82
- if (ch === 105) {
177
+ if (ch === CHAR_CODE_LOWER_I) {
83
178
  return endsWithWord(source, pos, 'interface');
84
179
  }
85
180
  return false;
86
- }
181
+ };
87
182
  const AMBIENT_DECLARE_PREFIXES = ['declare module', 'declare namespace', 'declare global'];
88
- function isAmbientDeclarationFile(source) {
89
- let idx = 0;
90
- const len = source.length;
91
- while (idx < len && source.charCodeAt(idx) === 35) {
92
- idx = source.indexOf('\n', idx);
93
- if (idx === -1) {
94
- return false;
183
+ const skipShebangComments = (source, idx) => {
184
+ let cursor = idx;
185
+ while (cursor < source.length && source.charCodeAt(cursor) === CHAR_CODE_HASH) {
186
+ cursor = source.indexOf('\n', cursor);
187
+ if (cursor === -1) {
188
+ return undefined;
95
189
  }
96
- idx++;
190
+ cursor++;
191
+ }
192
+ return cursor;
193
+ };
194
+ const skipBlockComment = (source, idx) => {
195
+ const close = source.indexOf('*/', idx + '/*'.length);
196
+ if (close === -1) {
197
+ return undefined;
97
198
  }
98
- while (idx < len) {
99
- const ch = source.charCodeAt(idx);
100
- if (isWhitespace(ch)) {
101
- idx++;
102
- continue;
199
+ return close + '*/'.length;
200
+ };
201
+ const skipLineComment = (source, idx) => {
202
+ const nl = source.indexOf('\n', idx);
203
+ if (nl === -1) {
204
+ return undefined;
205
+ }
206
+ return nl + 1;
207
+ };
208
+ const skipTriviaToken = (source, idx) => {
209
+ const ch = source.charCodeAt(idx);
210
+ if (isWhitespace(ch)) {
211
+ return idx + 1;
212
+ }
213
+ if (ch === CHAR_CODE_SLASH &&
214
+ idx + 1 < source.length &&
215
+ source.charCodeAt(idx + 1) === CHAR_CODE_ASTERISK) {
216
+ return skipBlockComment(source, idx);
217
+ }
218
+ if (ch === CHAR_CODE_SLASH &&
219
+ idx + 1 < source.length &&
220
+ source.charCodeAt(idx + 1) === CHAR_CODE_SLASH) {
221
+ return skipLineComment(source, idx);
222
+ }
223
+ return idx;
224
+ };
225
+ const skipLeadingTrivia = (source, idx) => {
226
+ let cursor = idx;
227
+ while (cursor < source.length) {
228
+ const next = skipTriviaToken(source, cursor);
229
+ if (next === undefined) {
230
+ return undefined;
103
231
  }
104
- if (ch === 47 && idx + 1 < len && source.charCodeAt(idx + 1) === 42) {
105
- const close = source.indexOf('*/', idx + 2);
106
- if (close !== -1) {
107
- idx = close + 2;
108
- continue;
109
- }
110
- return false;
232
+ if (next === cursor) {
233
+ return cursor;
111
234
  }
112
- if (ch === 47 && idx + 1 < len && source.charCodeAt(idx + 1) === 47) {
113
- const nl = source.indexOf('\n', idx);
114
- if (nl !== -1) {
115
- idx = nl + 1;
116
- continue;
117
- }
118
- return false;
235
+ cursor = next;
236
+ }
237
+ return cursor;
238
+ };
239
+ const hasAmbientPrefixAt = (source, idx) => AMBIENT_DECLARE_PREFIXES.some((prefix) => idx + prefix.length <= source.length && source.slice(idx, idx + prefix.length) === prefix);
240
+ const isAmbientDeclarationFile = (source) => {
241
+ const shebangEnd = skipShebangComments(source, 0);
242
+ if (shebangEnd === undefined) {
243
+ return false;
244
+ }
245
+ const idx = skipLeadingTrivia(source, shebangEnd);
246
+ if (idx === undefined || idx >= source.length) {
247
+ return false;
248
+ }
249
+ return hasAmbientPrefixAt(source, idx);
250
+ };
251
+ const nextExportPosition = (source, start) => {
252
+ const exp = source.indexOf('export ', start);
253
+ if (exp === -1) {
254
+ return undefined;
255
+ }
256
+ return exp;
257
+ };
258
+ const isStandaloneExportKeyword = (source, exp) => {
259
+ if (exp === 0) {
260
+ return true;
261
+ }
262
+ return isWhitespace(source.charCodeAt(exp - 1));
263
+ };
264
+ const isDeclareExport = (source, exp) => exp >= DECLARE_KEYWORD_LENGTH && source.slice(exp - DECLARE_KEYWORD_LENGTH, exp) === 'declare ';
265
+ const skipWhitespace = (source, pos) => {
266
+ let cursor = pos;
267
+ while (cursor < source.length && isWhitespace(source.charCodeAt(cursor))) {
268
+ cursor++;
269
+ }
270
+ return cursor;
271
+ };
272
+ const isReExportAt = (source, afterExport) => {
273
+ if (afterExport >= source.length) {
274
+ return false;
275
+ }
276
+ const c0 = source.charCodeAt(afterExport);
277
+ if (c0 === CHAR_CODE_OPEN_BRACE || c0 === CHAR_CODE_ASTERISK) {
278
+ return true;
279
+ }
280
+ if (c0 !== CHAR_CODE_LOWER_T ||
281
+ afterExport + TYPE_KEYWORD_LENGTH > source.length ||
282
+ source.slice(afterExport, afterExport + TYPE_KEYWORD_LENGTH) !== 'type ') {
283
+ return false;
284
+ }
285
+ const afterType = afterExport + TYPE_KEYWORD_LENGTH;
286
+ return afterType < source.length && source.charCodeAt(afterType) === CHAR_CODE_OPEN_BRACE;
287
+ };
288
+ const modifierSpecs = [
289
+ {
290
+ charCode: CHAR_CODE_LOWER_D,
291
+ isDefault: true,
292
+ length: DEFAULT_KEYWORD_LENGTH,
293
+ shouldStop: false,
294
+ text: 'default ',
295
+ },
296
+ {
297
+ charCode: CHAR_CODE_LOWER_A,
298
+ isDefault: false,
299
+ length: ASYNC_KEYWORD_LENGTH,
300
+ shouldStop: false,
301
+ text: 'async ',
302
+ },
303
+ {
304
+ charCode: CHAR_CODE_LOWER_A,
305
+ isDefault: false,
306
+ length: ABSTRACT_KEYWORD_LENGTH,
307
+ shouldStop: false,
308
+ text: 'abstract ',
309
+ },
310
+ {
311
+ charCode: CHAR_CODE_LOWER_T,
312
+ isDefault: false,
313
+ length: TYPE_KEYWORD_LENGTH,
314
+ shouldStop: false,
315
+ text: 'type ',
316
+ },
317
+ {
318
+ charCode: CHAR_CODE_LOWER_N,
319
+ isDefault: false,
320
+ length: 0,
321
+ shouldStop: true,
322
+ text: 'namespace ',
323
+ },
324
+ ];
325
+ const modifierSpecMatches = (source, pos, spec) => source.charCodeAt(pos) === spec.charCode &&
326
+ pos + spec.text.length <= source.length &&
327
+ source.slice(pos, pos + spec.text.length) === spec.text;
328
+ const modifierLengthAt = (source, pos) => {
329
+ for (const spec of modifierSpecs) {
330
+ if (modifierSpecMatches(source, pos, spec)) {
331
+ return spec;
119
332
  }
120
- break;
121
333
  }
122
- if (idx >= len) {
334
+ return undefined;
335
+ };
336
+ const scanExportModifiers = (source, start) => {
337
+ let pos = start;
338
+ let hasSawDefault = false;
339
+ let modifier = modifierLengthAt(source, pos);
340
+ while (modifier && !modifier.shouldStop) {
341
+ hasSawDefault ||= modifier.isDefault;
342
+ pos = skipWhitespace(source, pos + modifier.length);
343
+ modifier = modifierLengthAt(source, pos);
344
+ }
345
+ return { hasSawDefault, pos };
346
+ };
347
+ const declarationStartCodes = new Set([
348
+ CHAR_CODE_LOWER_F,
349
+ CHAR_CODE_UPPER_F,
350
+ CHAR_CODE_LOWER_C,
351
+ CHAR_CODE_UPPER_C,
352
+ CHAR_CODE_LOWER_I,
353
+ CHAR_CODE_UPPER_I,
354
+ CHAR_CODE_LOWER_E,
355
+ CHAR_CODE_UPPER_E,
356
+ CHAR_CODE_LOWER_L,
357
+ CHAR_CODE_UPPER_L,
358
+ CHAR_CODE_LOWER_V,
359
+ CHAR_CODE_UPPER_V,
360
+ CHAR_CODE_LOWER_N,
361
+ CHAR_CODE_UPPER_N,
362
+ ]);
363
+ const isDeclarationStartCode = (code) => declarationStartCodes.has(code);
364
+ const canSkipDocumentedExport = (source, modifiers) => {
365
+ if (modifiers.pos >= source.length) {
366
+ return true;
367
+ }
368
+ const next = source.charCodeAt(modifiers.pos);
369
+ if (!isDeclarationStartCode(next)) {
370
+ return true;
371
+ }
372
+ return modifiers.hasSawDefault && !isDefaultDeclaration(source, modifiers.pos, source.length);
373
+ };
374
+ const documentedLocalExportListResult = (source, after, exp) => isDocumentedLocalExportList(source, after, exp, hasJSDocBefore);
375
+ const exhaustedExportDocResult = (source, after) => {
376
+ if (after >= source.length) {
377
+ return true;
378
+ }
379
+ return undefined;
380
+ };
381
+ const earlyExportDocResult = (source, after, exp) => {
382
+ const exhaustedExport = exhaustedExportDocResult(source, after);
383
+ if (exhaustedExport !== undefined) {
384
+ return exhaustedExport;
385
+ }
386
+ const localExportList = documentedLocalExportListResult(source, after, exp);
387
+ if (localExportList !== undefined) {
388
+ return localExportList;
389
+ }
390
+ if (isReExportAt(source, after)) {
391
+ return true;
392
+ }
393
+ return undefined;
394
+ };
395
+ const isDocumentedExportDeclaration = (source, exp) => {
396
+ const after = skipWhitespace(source, exp + EXPORT_KEYWORD_LENGTH);
397
+ const earlyResult = earlyExportDocResult(source, after, exp);
398
+ if (earlyResult !== undefined) {
399
+ return earlyResult;
400
+ }
401
+ const modifiers = scanExportModifiers(source, after);
402
+ if (canSkipDocumentedExport(source, modifiers)) {
403
+ return true;
404
+ }
405
+ return hasJSDocBefore(source, exp);
406
+ };
407
+ const isUndocumentedExportAt = (source, exp) => {
408
+ if (isInsideIgnoredText(source, exp) ||
409
+ !isStandaloneExportKeyword(source, exp) ||
410
+ isDeclareExport(source, exp)) {
123
411
  return false;
124
412
  }
125
- for (const prefix of AMBIENT_DECLARE_PREFIXES) {
126
- if (idx + prefix.length <= len && source.slice(idx, idx + prefix.length) === prefix) {
413
+ return isDocumentedExportDeclaration(source, exp) === false;
414
+ };
415
+ const nextExportSearchPosition = (source, pos) => {
416
+ const exp = nextExportPosition(source, pos);
417
+ if (exp === undefined) {
418
+ return undefined;
419
+ }
420
+ return {
421
+ nextPOS: exp + EXPORT_KEYWORD_LENGTH,
422
+ undocumented: isUndocumentedExportAt(source, exp),
423
+ };
424
+ };
425
+ const hasUndocumentedExport = (source) => {
426
+ let pos = 0;
427
+ while (pos < source.length) {
428
+ const exportSearch = nextExportSearchPosition(source, pos);
429
+ if (!exportSearch) {
430
+ return false;
431
+ }
432
+ if (exportSearch.undocumented) {
127
433
  return true;
128
434
  }
435
+ pos = exportSearch.nextPOS;
129
436
  }
130
437
  return false;
131
- }
438
+ };
132
439
  /**
133
- * Returns true if all exported declarations have a non-empty JSDoc comment
134
- * preceding them. Returns false if any export is undocumented or has an
135
- * empty JSDoc.
440
+ * Checks whether exported declarations have meaningful JSDoc comments.
441
+ *
442
+ * @param source - TypeScript source text to inspect.
443
+ * @returns True when every public declaration is documented or no public declarations exist.
136
444
  */
137
445
  export default function hasRequiredFunctionDocs(source) {
138
- const len = source.length;
139
- if (isAmbientDeclarationFile(source)) {
446
+ if (!source.includes('export ')) {
140
447
  return true;
141
448
  }
142
- let pos = 0;
143
- const exportPositions = [];
144
- while (pos < len) {
145
- const exp = source.indexOf('export ', pos);
146
- if (exp === -1) {
147
- break;
148
- }
149
- if (exp > 0) {
150
- const prev = source.charCodeAt(exp - 1);
151
- if (prev !== 10 && prev !== 13 && prev !== 9 && prev !== 32) {
152
- pos = exp + 1;
153
- continue;
154
- }
155
- if (exp >= 8 && source.slice(exp - 8, exp) === 'declare ') {
156
- pos = exp + 7;
157
- continue;
158
- }
159
- }
160
- let after = exp + 7;
161
- while (after < len && isWhitespace(source.charCodeAt(after))) {
162
- after++;
163
- }
164
- if (after >= len) {
165
- break;
166
- }
167
- const c0 = source.charCodeAt(after);
168
- // Re-export block: export { ... }
169
- if (c0 === 123) {
170
- pos = exp + 7;
171
- continue;
172
- }
173
- // Wildcard re-export: export *
174
- if (c0 === 42) {
175
- pos = exp + 7;
176
- continue;
177
- }
178
- // Type re-export: export type { ... }
179
- if (c0 === 116 && after + 5 <= len && source.slice(after, after + 5) === 'type ') {
180
- const afterType = after + 5;
181
- if (afterType < len && source.charCodeAt(afterType) === 123) {
182
- pos = afterType;
183
- continue;
184
- }
185
- }
186
- let afterMod = after;
187
- let changed = true;
188
- let sawDefault = false;
189
- while (changed && afterMod < len) {
190
- changed = false;
191
- const ch = source.charCodeAt(afterMod);
192
- if (ch === 100 &&
193
- afterMod + 8 <= len &&
194
- source.slice(afterMod, afterMod + 8) === 'default ') {
195
- afterMod += 8;
196
- changed = true;
197
- sawDefault = true;
198
- }
199
- else if (ch === 97 &&
200
- afterMod + 6 <= len &&
201
- source.slice(afterMod, afterMod + 6) === 'async ') {
202
- afterMod += 6;
203
- changed = true;
204
- }
205
- else if (ch === 97 &&
206
- afterMod + 9 <= len &&
207
- source.slice(afterMod, afterMod + 9) === 'abstract ') {
208
- afterMod += 9;
209
- changed = true;
210
- }
211
- else if (ch === 116 &&
212
- afterMod + 5 <= len &&
213
- source.slice(afterMod, afterMod + 5) === 'type ') {
214
- afterMod += 5;
215
- changed = true;
216
- }
217
- else if (ch === 110 &&
218
- afterMod + 10 <= len &&
219
- source.slice(afterMod, afterMod + 10) === 'namespace ') {
220
- break;
221
- }
222
- if (changed) {
223
- while (afterMod < len && isWhitespace(source.charCodeAt(afterMod))) {
224
- afterMod++;
225
- }
226
- }
227
- }
228
- if (afterMod >= len) {
229
- break;
230
- }
231
- const next = source.charCodeAt(afterMod);
232
- // Declaration keyword check (case-insensitive first character):
233
- // First chars: f/F=function, c/C=class|const, i/I=interface, e/E=enum, l/L=let, v/V=var, n/N=namespace
234
- if (next === 102 ||
235
- next === 70 ||
236
- next === 99 ||
237
- next === 67 ||
238
- next === 105 ||
239
- next === 73 ||
240
- next === 101 ||
241
- next === 69 ||
242
- next === 108 ||
243
- next === 76 ||
244
- next === 118 ||
245
- next === 86 ||
246
- next === 110 ||
247
- next === 78) {
248
- if (sawDefault) {
249
- if (!isDefaultDeclaration(source, afterMod, len)) {
250
- pos = exp + 7;
251
- continue;
252
- }
253
- }
254
- exportPositions.push(exp);
255
- }
256
- pos = exp + 7;
257
- }
258
- if (exportPositions.length === 0) {
449
+ if (isAmbientDeclarationFile(source)) {
259
450
  return true;
260
451
  }
261
- for (let idx = 0; idx < exportPositions.length; idx++) {
262
- if (!hasJSDocBefore(source, exportPositions[idx])) {
263
- return false;
264
- }
265
- }
266
- return true;
452
+ return !hasUndocumentedExport(source);
267
453
  }
268
454
  //# sourceMappingURL=require-function-doc.js.map