@thethracian/oxlint-config 0.2.1 → 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 +7 -0
  2. package/README.md +124 -18
  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 +156 -94
  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 -118
  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 -535
  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 +105 -680
  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 +38 -24
  176. package/dist/rules/effect-rule-core.d.ts.map +1 -1
  177. package/dist/rules/effect-rule-core.js +157 -344
  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 -358
  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 +372 -300
  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 +93 -384
  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 -725
  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 +52 -15
  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 +1 -0
  252. package/dist/rules/plugin.d.ts.map +1 -1
  253. package/dist/rules/plugin.js +164 -154
  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 +396 -221
  274. package/dist/rules/require-function-doc.js.map +1 -1
  275. package/dist/rules/source-cache.d.ts +13 -5
  276. package/dist/rules/source-cache.d.ts.map +1 -1
  277. package/dist/rules/source-cache.js +35 -22
  278. package/dist/rules/source-cache.js.map +1 -1
  279. package/package.json +10 -2
@@ -1,78 +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) {
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;
50
+ }
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++;
63
+ }
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)) {
70
+ return false;
71
+ }
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) => {
21
95
  let lineStart = 0;
22
96
  const len = jsdocBody.length;
23
97
  while (lineStart <= len) {
24
- const newlineIndex = jsdocBody.indexOf('\n', lineStart);
25
- const lineEnd = newlineIndex === -1 ? len : newlineIndex;
26
- let pos = lineStart;
27
- while (pos < lineEnd && isWhitespace(jsdocBody.charCodeAt(pos))) {
28
- pos++;
29
- }
30
- if (pos < lineEnd && jsdocBody.charCodeAt(pos) === 42) {
31
- pos++;
32
- while (pos < lineEnd && isWhitespace(jsdocBody.charCodeAt(pos))) {
33
- pos++;
34
- }
35
- }
36
- while (pos < lineEnd) {
37
- if (!isWhitespace(jsdocBody.charCodeAt(pos))) {
38
- return true;
39
- }
40
- pos++;
98
+ const result = hasDescriptionLine(jsdocBody, lineStart, len);
99
+ if (result.found) {
100
+ return true;
41
101
  }
42
- if (newlineIndex === -1) {
102
+ if (result.nextLineStart === undefined) {
43
103
  return false;
44
104
  }
45
- lineStart = newlineIndex + 1;
105
+ lineStart = result.nextLineStart;
46
106
  }
47
107
  return false;
48
- }
49
- function hasJSDocBefore(source, exportPos) {
50
- let pos = exportPos;
51
- while (pos > 0 && isWhitespace(source.charCodeAt(pos - 1))) {
52
- pos--;
108
+ };
109
+ const skipWhitespaceBack = (source, pos) => {
110
+ let cursor = pos;
111
+ while (cursor > 0 && isWhitespace(source.charCodeAt(cursor - 1))) {
112
+ cursor--;
53
113
  }
54
- if (pos < 2) {
55
- return false;
56
- }
57
- if (source.charCodeAt(pos - 2) !== 42 || source.charCodeAt(pos - 1) !== 47) {
58
- return false;
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();
59
122
  }
60
- const closeStar = pos - 2;
123
+ return undefined;
124
+ };
125
+ const previousJSDocContent = (source, closeStar) => {
61
126
  let open = closeStar - 1;
62
127
  while (open > 0) {
63
- if (source.charCodeAt(open) === 42 && source.charCodeAt(open - 1) === 47) {
64
- if (open + 1 < closeStar && source.charCodeAt(open + 1) === 42) {
65
- const content = source.slice(open + 3, closeStar).trim();
66
- 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;
67
133
  }
68
- open -= 2;
69
- continue;
134
+ open -= '/*'.length;
135
+ }
136
+ else {
137
+ open--;
70
138
  }
71
- open--;
72
139
  }
73
- return false;
74
- }
75
- 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) => {
76
152
  const end = pos + word.length;
77
153
  if (end > source.length) {
78
154
  return false;
@@ -84,196 +160,295 @@ function endsWithWord(source, pos, word) {
84
160
  return true;
85
161
  }
86
162
  const next = source.charCodeAt(end);
87
- return isWhitespace(next) || next === 40 || next === 123 || next === 59 || next === 60;
88
- }
89
- 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) => {
90
170
  const ch = source.charCodeAt(pos);
91
- if (ch === 102) {
171
+ if (ch === CHAR_CODE_LOWER_F) {
92
172
  return endsWithWord(source, pos, 'function');
93
173
  }
94
- if (ch === 99) {
174
+ if (ch === CHAR_CODE_LOWER_C) {
95
175
  return endsWithWord(source, pos, 'class');
96
176
  }
97
- if (ch === 105) {
177
+ if (ch === CHAR_CODE_LOWER_I) {
98
178
  return endsWithWord(source, pos, 'interface');
99
179
  }
100
180
  return false;
101
- }
181
+ };
102
182
  const AMBIENT_DECLARE_PREFIXES = ['declare module', 'declare namespace', 'declare global'];
103
- function isAmbientDeclarationFile(source) {
104
- let idx = 0;
105
- const len = source.length;
106
- while (idx < len && source.charCodeAt(idx) === 35) {
107
- idx = source.indexOf('\n', idx);
108
- if (idx === -1) {
109
- 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;
110
189
  }
111
- 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;
198
+ }
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);
112
222
  }
113
- while (idx < len) {
114
- const ch = source.charCodeAt(idx);
115
- if (isWhitespace(ch)) {
116
- idx++;
117
- continue;
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;
118
231
  }
119
- if (ch === 47 && idx + 1 < len && source.charCodeAt(idx + 1) === 42) {
120
- const close = source.indexOf('*/', idx + 2);
121
- if (close !== -1) {
122
- idx = close + 2;
123
- continue;
124
- }
125
- return false;
232
+ if (next === cursor) {
233
+ return cursor;
126
234
  }
127
- if (ch === 47 && idx + 1 < len && source.charCodeAt(idx + 1) === 47) {
128
- const nl = source.indexOf('\n', idx);
129
- if (nl !== -1) {
130
- idx = nl + 1;
131
- continue;
132
- }
133
- 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;
134
332
  }
135
- break;
136
333
  }
137
- 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)) {
138
411
  return false;
139
412
  }
140
- for (const prefix of AMBIENT_DECLARE_PREFIXES) {
141
- 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) {
142
433
  return true;
143
434
  }
435
+ pos = exportSearch.nextPOS;
144
436
  }
145
437
  return false;
146
- }
438
+ };
147
439
  /**
148
- * Returns true if all exported declarations have a non-empty JSDoc comment
149
- * preceding them. Returns false if any export is undocumented or has an
150
- * 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.
151
444
  */
152
445
  export default function hasRequiredFunctionDocs(source) {
153
- const len = source.length;
154
446
  if (!source.includes('export ')) {
155
447
  return true;
156
448
  }
157
449
  if (isAmbientDeclarationFile(source)) {
158
450
  return true;
159
451
  }
160
- let pos = 0;
161
- while (pos < len) {
162
- const exp = source.indexOf('export ', pos);
163
- if (exp === -1) {
164
- break;
165
- }
166
- if (exp > 0) {
167
- const prev = source.charCodeAt(exp - 1);
168
- if (prev !== 10 && prev !== 13 && prev !== 9 && prev !== 32) {
169
- pos = exp + 1;
170
- continue;
171
- }
172
- if (exp >= 8 && source.slice(exp - 8, exp) === 'declare ') {
173
- pos = exp + 7;
174
- continue;
175
- }
176
- }
177
- let after = exp + 7;
178
- while (after < len && isWhitespace(source.charCodeAt(after))) {
179
- after++;
180
- }
181
- if (after >= len) {
182
- break;
183
- }
184
- const c0 = source.charCodeAt(after);
185
- // Re-export block: export { ... }
186
- if (c0 === 123) {
187
- pos = exp + 7;
188
- continue;
189
- }
190
- // Wildcard re-export: export *
191
- if (c0 === 42) {
192
- pos = exp + 7;
193
- continue;
194
- }
195
- // Type re-export: export type { ... }
196
- if (c0 === 116 && after + 5 <= len && source.slice(after, after + 5) === 'type ') {
197
- const afterType = after + 5;
198
- if (afterType < len && source.charCodeAt(afterType) === 123) {
199
- pos = afterType;
200
- continue;
201
- }
202
- }
203
- let afterMod = after;
204
- let changed = true;
205
- let sawDefault = false;
206
- while (changed && afterMod < len) {
207
- changed = false;
208
- const ch = source.charCodeAt(afterMod);
209
- if (ch === 100 &&
210
- afterMod + 8 <= len &&
211
- source.slice(afterMod, afterMod + 8) === 'default ') {
212
- afterMod += 8;
213
- changed = true;
214
- sawDefault = true;
215
- }
216
- else if (ch === 97 &&
217
- afterMod + 6 <= len &&
218
- source.slice(afterMod, afterMod + 6) === 'async ') {
219
- afterMod += 6;
220
- changed = true;
221
- }
222
- else if (ch === 97 &&
223
- afterMod + 9 <= len &&
224
- source.slice(afterMod, afterMod + 9) === 'abstract ') {
225
- afterMod += 9;
226
- changed = true;
227
- }
228
- else if (ch === 116 &&
229
- afterMod + 5 <= len &&
230
- source.slice(afterMod, afterMod + 5) === 'type ') {
231
- afterMod += 5;
232
- changed = true;
233
- }
234
- else if (ch === 110 &&
235
- afterMod + 10 <= len &&
236
- source.slice(afterMod, afterMod + 10) === 'namespace ') {
237
- break;
238
- }
239
- if (changed) {
240
- while (afterMod < len && isWhitespace(source.charCodeAt(afterMod))) {
241
- afterMod++;
242
- }
243
- }
244
- }
245
- if (afterMod >= len) {
246
- break;
247
- }
248
- const next = source.charCodeAt(afterMod);
249
- // Declaration keyword check (case-insensitive first character):
250
- // First chars: f/F=function, c/C=class|const, i/I=interface, e/E=enum, l/L=let, v/V=var, n/N=namespace
251
- if (next === 102 ||
252
- next === 70 ||
253
- next === 99 ||
254
- next === 67 ||
255
- next === 105 ||
256
- next === 73 ||
257
- next === 101 ||
258
- next === 69 ||
259
- next === 108 ||
260
- next === 76 ||
261
- next === 118 ||
262
- next === 86 ||
263
- next === 110 ||
264
- next === 78) {
265
- if (sawDefault) {
266
- if (!isDefaultDeclaration(source, afterMod, len)) {
267
- pos = exp + 7;
268
- continue;
269
- }
270
- }
271
- if (!hasJSDocBefore(source, exp)) {
272
- return false;
273
- }
274
- }
275
- pos = exp + 7;
276
- }
277
- return true;
452
+ return !hasUndocumentedExport(source);
278
453
  }
279
454
  //# sourceMappingURL=require-function-doc.js.map