eslint-plugin-jsdoc 47.0.2 → 48.0.1

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 (257) hide show
  1. package/dist/{WarnSettings.js → WarnSettings.cjs} +2 -2
  2. package/dist/WarnSettings.cjs.map +1 -0
  3. package/dist/{alignTransform.js → alignTransform.cjs} +2 -2
  4. package/dist/alignTransform.cjs.map +1 -0
  5. package/dist/{defaultTagOrder.js → defaultTagOrder.cjs} +1 -1
  6. package/dist/defaultTagOrder.cjs.map +1 -0
  7. package/dist/{exportParser.js → exportParser.cjs} +32 -36
  8. package/dist/exportParser.cjs.map +1 -0
  9. package/dist/{generateRule.js → generateRule.cjs} +7 -4
  10. package/dist/generateRule.cjs.map +1 -0
  11. package/dist/{getDefaultTagStructureForMode.js → getDefaultTagStructureForMode.cjs} +1 -1
  12. package/dist/getDefaultTagStructureForMode.cjs.map +1 -0
  13. package/dist/{index.js → index.cjs} +55 -55
  14. package/dist/index.cjs.map +1 -0
  15. package/dist/{iterateJsdoc.js → iterateJsdoc.cjs} +16 -21
  16. package/dist/iterateJsdoc.cjs.map +1 -0
  17. package/dist/{jsdocUtils.js → jsdocUtils.cjs} +17 -17
  18. package/dist/jsdocUtils.cjs.map +1 -0
  19. package/dist/rules/{checkAccess.js → checkAccess.cjs} +2 -2
  20. package/dist/rules/checkAccess.cjs.map +1 -0
  21. package/dist/rules/{checkAlignment.js → checkAlignment.cjs} +2 -2
  22. package/dist/rules/checkAlignment.cjs.map +1 -0
  23. package/dist/rules/{checkExamples.js → checkExamples.cjs} +2 -2
  24. package/dist/rules/checkExamples.cjs.map +1 -0
  25. package/dist/rules/{checkIndentation.js → checkIndentation.cjs} +2 -2
  26. package/dist/rules/checkIndentation.cjs.map +1 -0
  27. package/dist/rules/{checkLineAlignment.js → checkLineAlignment.cjs} +3 -3
  28. package/dist/rules/checkLineAlignment.cjs.map +1 -0
  29. package/dist/rules/{checkParamNames.js → checkParamNames.cjs} +2 -2
  30. package/dist/rules/checkParamNames.cjs.map +1 -0
  31. package/dist/rules/{checkPropertyNames.js → checkPropertyNames.cjs} +2 -2
  32. package/dist/rules/checkPropertyNames.cjs.map +1 -0
  33. package/dist/rules/{checkSyntax.js → checkSyntax.cjs} +2 -2
  34. package/dist/rules/checkSyntax.cjs.map +1 -0
  35. package/dist/rules/{checkTagNames.js → checkTagNames.cjs} +2 -2
  36. package/dist/rules/checkTagNames.cjs.map +1 -0
  37. package/dist/rules/{checkTypes.js → checkTypes.cjs} +2 -2
  38. package/dist/rules/checkTypes.cjs.map +1 -0
  39. package/dist/rules/{checkValues.js → checkValues.cjs} +2 -2
  40. package/dist/rules/checkValues.cjs.map +1 -0
  41. package/dist/rules/{emptyTags.js → emptyTags.cjs} +2 -2
  42. package/dist/rules/emptyTags.cjs.map +1 -0
  43. package/dist/rules/{implementsOnClasses.js → implementsOnClasses.cjs} +2 -2
  44. package/dist/rules/implementsOnClasses.cjs.map +1 -0
  45. package/dist/rules/{importsAsDependencies.js → importsAsDependencies.cjs} +10 -12
  46. package/dist/rules/importsAsDependencies.cjs.map +1 -0
  47. package/dist/rules/{informativeDocs.js → informativeDocs.cjs} +2 -2
  48. package/dist/rules/informativeDocs.cjs.map +1 -0
  49. package/dist/rules/{matchDescription.js → matchDescription.cjs} +2 -2
  50. package/dist/rules/matchDescription.cjs.map +1 -0
  51. package/dist/rules/{matchName.js → matchName.cjs} +2 -2
  52. package/dist/rules/matchName.cjs.map +1 -0
  53. package/dist/rules/{multilineBlocks.js → multilineBlocks.cjs} +2 -2
  54. package/dist/rules/multilineBlocks.cjs.map +1 -0
  55. package/dist/rules/{noBadBlocks.js → noBadBlocks.cjs} +2 -2
  56. package/dist/rules/noBadBlocks.cjs.map +1 -0
  57. package/dist/rules/{noBlankBlockDescriptions.js → noBlankBlockDescriptions.cjs} +2 -2
  58. package/dist/rules/noBlankBlockDescriptions.cjs.map +1 -0
  59. package/dist/rules/{noBlankBlocks.js → noBlankBlocks.cjs} +2 -2
  60. package/dist/rules/noBlankBlocks.cjs.map +1 -0
  61. package/dist/rules/{noDefaults.js → noDefaults.cjs} +2 -2
  62. package/dist/rules/noDefaults.cjs.map +1 -0
  63. package/dist/rules/{noMissingSyntax.js → noMissingSyntax.cjs} +2 -2
  64. package/dist/rules/noMissingSyntax.cjs.map +1 -0
  65. package/dist/rules/{noMultiAsterisks.js → noMultiAsterisks.cjs} +2 -2
  66. package/dist/rules/noMultiAsterisks.cjs.map +1 -0
  67. package/dist/rules/{noRestrictedSyntax.js → noRestrictedSyntax.cjs} +2 -2
  68. package/dist/rules/noRestrictedSyntax.cjs.map +1 -0
  69. package/dist/rules/{noTypes.js → noTypes.cjs} +2 -2
  70. package/dist/rules/noTypes.cjs.map +1 -0
  71. package/dist/rules/{noUndefinedTypes.js → noUndefinedTypes.cjs} +5 -5
  72. package/dist/rules/noUndefinedTypes.cjs.map +1 -0
  73. package/dist/rules/{requireAsteriskPrefix.js → requireAsteriskPrefix.cjs} +2 -2
  74. package/dist/rules/requireAsteriskPrefix.cjs.map +1 -0
  75. package/dist/rules/{requireDescription.js → requireDescription.cjs} +2 -2
  76. package/dist/rules/requireDescription.cjs.map +1 -0
  77. package/dist/rules/{requireDescriptionCompleteSentence.js → requireDescriptionCompleteSentence.cjs} +2 -2
  78. package/dist/rules/requireDescriptionCompleteSentence.cjs.map +1 -0
  79. package/dist/rules/{requireExample.js → requireExample.cjs} +2 -2
  80. package/dist/rules/requireExample.cjs.map +1 -0
  81. package/dist/rules/{requireFileOverview.js → requireFileOverview.cjs} +2 -2
  82. package/dist/rules/requireFileOverview.cjs.map +1 -0
  83. package/dist/rules/{requireHyphenBeforeParamDescription.js → requireHyphenBeforeParamDescription.cjs} +2 -2
  84. package/dist/rules/requireHyphenBeforeParamDescription.cjs.map +1 -0
  85. package/dist/rules/{requireJsdoc.js → requireJsdoc.cjs} +5 -5
  86. package/dist/rules/requireJsdoc.cjs.map +1 -0
  87. package/dist/rules/{requireParam.js → requireParam.cjs} +2 -2
  88. package/dist/rules/requireParam.cjs.map +1 -0
  89. package/dist/rules/{requireParamDescription.js → requireParamDescription.cjs} +2 -2
  90. package/dist/rules/requireParamDescription.cjs.map +1 -0
  91. package/dist/rules/{requireParamName.js → requireParamName.cjs} +2 -2
  92. package/dist/rules/requireParamName.cjs.map +1 -0
  93. package/dist/rules/{requireParamType.js → requireParamType.cjs} +2 -2
  94. package/dist/rules/requireParamType.cjs.map +1 -0
  95. package/dist/rules/{requireProperty.js → requireProperty.cjs} +2 -2
  96. package/dist/rules/requireProperty.cjs.map +1 -0
  97. package/dist/rules/{requirePropertyDescription.js → requirePropertyDescription.cjs} +2 -2
  98. package/dist/rules/requirePropertyDescription.cjs.map +1 -0
  99. package/dist/rules/{requirePropertyName.js → requirePropertyName.cjs} +2 -2
  100. package/dist/rules/requirePropertyName.cjs.map +1 -0
  101. package/dist/rules/{requirePropertyType.js → requirePropertyType.cjs} +2 -2
  102. package/dist/rules/requirePropertyType.cjs.map +1 -0
  103. package/dist/rules/{requireReturns.js → requireReturns.cjs} +4 -4
  104. package/dist/rules/requireReturns.cjs.map +1 -0
  105. package/dist/rules/{requireReturnsCheck.js → requireReturnsCheck.cjs} +2 -2
  106. package/dist/rules/requireReturnsCheck.cjs.map +1 -0
  107. package/dist/rules/{requireReturnsDescription.js → requireReturnsDescription.cjs} +2 -2
  108. package/dist/rules/requireReturnsDescription.cjs.map +1 -0
  109. package/dist/rules/{requireReturnsType.js → requireReturnsType.cjs} +2 -2
  110. package/dist/rules/requireReturnsType.cjs.map +1 -0
  111. package/dist/rules/{requireThrows.js → requireThrows.cjs} +2 -2
  112. package/dist/rules/requireThrows.cjs.map +1 -0
  113. package/dist/rules/{requireYields.js → requireYields.cjs} +2 -2
  114. package/dist/rules/requireYields.cjs.map +1 -0
  115. package/dist/rules/{requireYieldsCheck.js → requireYieldsCheck.cjs} +2 -2
  116. package/dist/rules/requireYieldsCheck.cjs.map +1 -0
  117. package/dist/rules/{sortTags.js → sortTags.cjs} +4 -4
  118. package/dist/rules/sortTags.cjs.map +1 -0
  119. package/dist/rules/{tagLines.js → tagLines.cjs} +2 -2
  120. package/dist/rules/tagLines.cjs.map +1 -0
  121. package/dist/rules/{textEscaping.js → textEscaping.cjs} +2 -2
  122. package/dist/rules/textEscaping.cjs.map +1 -0
  123. package/dist/rules/{validTypes.js → validTypes.cjs} +2 -2
  124. package/dist/rules/validTypes.cjs.map +1 -0
  125. package/dist/{tagNames.js → tagNames.cjs} +1 -1
  126. package/dist/tagNames.cjs.map +1 -0
  127. package/dist/utils/{hasReturnValue.js → hasReturnValue.cjs} +14 -17
  128. package/dist/utils/hasReturnValue.cjs.map +1 -0
  129. package/{eslint.config.mjs → eslint.config.js} +34 -28
  130. package/package.json +15 -15
  131. package/src/WarnSettings.js +34 -0
  132. package/src/alignTransform.js +356 -0
  133. package/src/defaultTagOrder.js +168 -0
  134. package/src/exportParser.js +957 -0
  135. package/src/getDefaultTagStructureForMode.js +969 -0
  136. package/src/index.js +266 -0
  137. package/src/iterateJsdoc.js +2555 -0
  138. package/src/jsdocUtils.js +1693 -0
  139. package/src/rules/checkAccess.js +45 -0
  140. package/src/rules/checkAlignment.js +63 -0
  141. package/src/rules/checkExamples.js +594 -0
  142. package/src/rules/checkIndentation.js +75 -0
  143. package/src/rules/checkLineAlignment.js +364 -0
  144. package/src/rules/checkParamNames.js +404 -0
  145. package/src/rules/checkPropertyNames.js +152 -0
  146. package/src/rules/checkSyntax.js +30 -0
  147. package/src/rules/checkTagNames.js +314 -0
  148. package/src/rules/checkTypes.js +535 -0
  149. package/src/rules/checkValues.js +220 -0
  150. package/src/rules/emptyTags.js +88 -0
  151. package/src/rules/implementsOnClasses.js +64 -0
  152. package/src/rules/importsAsDependencies.js +131 -0
  153. package/src/rules/informativeDocs.js +182 -0
  154. package/src/rules/matchDescription.js +286 -0
  155. package/src/rules/matchName.js +147 -0
  156. package/src/rules/multilineBlocks.js +333 -0
  157. package/src/rules/noBadBlocks.js +109 -0
  158. package/src/rules/noBlankBlockDescriptions.js +69 -0
  159. package/src/rules/noBlankBlocks.js +53 -0
  160. package/src/rules/noDefaults.js +85 -0
  161. package/src/rules/noMissingSyntax.js +195 -0
  162. package/src/rules/noMultiAsterisks.js +134 -0
  163. package/src/rules/noRestrictedSyntax.js +91 -0
  164. package/src/rules/noTypes.js +73 -0
  165. package/src/rules/noUndefinedTypes.js +328 -0
  166. package/src/rules/requireAsteriskPrefix.js +189 -0
  167. package/src/rules/requireDescription.js +161 -0
  168. package/src/rules/requireDescriptionCompleteSentence.js +333 -0
  169. package/src/rules/requireExample.js +118 -0
  170. package/src/rules/requireFileOverview.js +154 -0
  171. package/src/rules/requireHyphenBeforeParamDescription.js +178 -0
  172. package/src/rules/requireJsdoc.js +629 -0
  173. package/src/rules/requireParam.js +592 -0
  174. package/src/rules/requireParamDescription.js +89 -0
  175. package/src/rules/requireParamName.js +55 -0
  176. package/src/rules/requireParamType.js +89 -0
  177. package/src/rules/requireProperty.js +48 -0
  178. package/src/rules/requirePropertyDescription.js +25 -0
  179. package/src/rules/requirePropertyName.js +25 -0
  180. package/src/rules/requirePropertyType.js +25 -0
  181. package/src/rules/requireReturns.js +238 -0
  182. package/src/rules/requireReturnsCheck.js +141 -0
  183. package/src/rules/requireReturnsDescription.js +59 -0
  184. package/src/rules/requireReturnsType.js +51 -0
  185. package/src/rules/requireThrows.js +111 -0
  186. package/src/rules/requireYields.js +216 -0
  187. package/src/rules/requireYieldsCheck.js +208 -0
  188. package/src/rules/sortTags.js +557 -0
  189. package/src/rules/tagLines.js +359 -0
  190. package/src/rules/textEscaping.js +146 -0
  191. package/src/rules/validTypes.js +368 -0
  192. package/src/tagNames.js +234 -0
  193. package/src/utils/hasReturnValue.js +549 -0
  194. package/dist/WarnSettings.js.map +0 -1
  195. package/dist/alignTransform.js.map +0 -1
  196. package/dist/defaultTagOrder.js.map +0 -1
  197. package/dist/exportParser.js.map +0 -1
  198. package/dist/generateRule.js.map +0 -1
  199. package/dist/getDefaultTagStructureForMode.js.map +0 -1
  200. package/dist/index.js.map +0 -1
  201. package/dist/iterateJsdoc.js.map +0 -1
  202. package/dist/jsdocUtils.js.map +0 -1
  203. package/dist/rules/checkAccess.js.map +0 -1
  204. package/dist/rules/checkAlignment.js.map +0 -1
  205. package/dist/rules/checkExamples.js.map +0 -1
  206. package/dist/rules/checkIndentation.js.map +0 -1
  207. package/dist/rules/checkLineAlignment.js.map +0 -1
  208. package/dist/rules/checkParamNames.js.map +0 -1
  209. package/dist/rules/checkPropertyNames.js.map +0 -1
  210. package/dist/rules/checkSyntax.js.map +0 -1
  211. package/dist/rules/checkTagNames.js.map +0 -1
  212. package/dist/rules/checkTypes.js.map +0 -1
  213. package/dist/rules/checkValues.js.map +0 -1
  214. package/dist/rules/emptyTags.js.map +0 -1
  215. package/dist/rules/implementsOnClasses.js.map +0 -1
  216. package/dist/rules/importsAsDependencies.js.map +0 -1
  217. package/dist/rules/informativeDocs.js.map +0 -1
  218. package/dist/rules/matchDescription.js.map +0 -1
  219. package/dist/rules/matchName.js.map +0 -1
  220. package/dist/rules/multilineBlocks.js.map +0 -1
  221. package/dist/rules/noBadBlocks.js.map +0 -1
  222. package/dist/rules/noBlankBlockDescriptions.js.map +0 -1
  223. package/dist/rules/noBlankBlocks.js.map +0 -1
  224. package/dist/rules/noDefaults.js.map +0 -1
  225. package/dist/rules/noMissingSyntax.js.map +0 -1
  226. package/dist/rules/noMultiAsterisks.js.map +0 -1
  227. package/dist/rules/noRestrictedSyntax.js.map +0 -1
  228. package/dist/rules/noTypes.js.map +0 -1
  229. package/dist/rules/noUndefinedTypes.js.map +0 -1
  230. package/dist/rules/requireAsteriskPrefix.js.map +0 -1
  231. package/dist/rules/requireDescription.js.map +0 -1
  232. package/dist/rules/requireDescriptionCompleteSentence.js.map +0 -1
  233. package/dist/rules/requireExample.js.map +0 -1
  234. package/dist/rules/requireFileOverview.js.map +0 -1
  235. package/dist/rules/requireHyphenBeforeParamDescription.js.map +0 -1
  236. package/dist/rules/requireJsdoc.js.map +0 -1
  237. package/dist/rules/requireParam.js.map +0 -1
  238. package/dist/rules/requireParamDescription.js.map +0 -1
  239. package/dist/rules/requireParamName.js.map +0 -1
  240. package/dist/rules/requireParamType.js.map +0 -1
  241. package/dist/rules/requireProperty.js.map +0 -1
  242. package/dist/rules/requirePropertyDescription.js.map +0 -1
  243. package/dist/rules/requirePropertyName.js.map +0 -1
  244. package/dist/rules/requirePropertyType.js.map +0 -1
  245. package/dist/rules/requireReturns.js.map +0 -1
  246. package/dist/rules/requireReturnsCheck.js.map +0 -1
  247. package/dist/rules/requireReturnsDescription.js.map +0 -1
  248. package/dist/rules/requireReturnsType.js.map +0 -1
  249. package/dist/rules/requireThrows.js.map +0 -1
  250. package/dist/rules/requireYields.js.map +0 -1
  251. package/dist/rules/requireYieldsCheck.js.map +0 -1
  252. package/dist/rules/sortTags.js.map +0 -1
  253. package/dist/rules/tagLines.js.map +0 -1
  254. package/dist/rules/textEscaping.js.map +0 -1
  255. package/dist/rules/validTypes.js.map +0 -1
  256. package/dist/tagNames.js.map +0 -1
  257. package/dist/utils/hasReturnValue.js.map +0 -1
@@ -0,0 +1,629 @@
1
+ import exportParser from '../exportParser.js';
2
+ import {
3
+ getSettings,
4
+ } from '../iterateJsdoc.js';
5
+ import jsdocUtils from '../jsdocUtils.js';
6
+ import {
7
+ getDecorator,
8
+ getJSDocComment,
9
+ getReducedASTNode,
10
+ } from '@es-joy/jsdoccomment';
11
+
12
+ /**
13
+ * @typedef {{
14
+ * ancestorsOnly: boolean,
15
+ * esm: boolean,
16
+ * initModuleExports: boolean,
17
+ * initWindow: boolean
18
+ * }} RequireJsdocOpts
19
+ */
20
+
21
+ /** @type {import('json-schema').JSONSchema4} */
22
+ const OPTIONS_SCHEMA = {
23
+ additionalProperties: false,
24
+ properties: {
25
+ checkConstructors: {
26
+ default: true,
27
+ type: 'boolean',
28
+ },
29
+ checkGetters: {
30
+ anyOf: [
31
+ {
32
+ type: 'boolean',
33
+ },
34
+ {
35
+ enum: [
36
+ 'no-setter',
37
+ ],
38
+ type: 'string',
39
+ },
40
+ ],
41
+ default: true,
42
+ },
43
+ checkSetters: {
44
+ anyOf: [
45
+ {
46
+ type: 'boolean',
47
+ },
48
+ {
49
+ enum: [
50
+ 'no-getter',
51
+ ],
52
+ type: 'string',
53
+ },
54
+ ],
55
+ default: true,
56
+ },
57
+ contexts: {
58
+ items: {
59
+ anyOf: [
60
+ {
61
+ type: 'string',
62
+ },
63
+ {
64
+ additionalProperties: false,
65
+ properties: {
66
+ context: {
67
+ type: 'string',
68
+ },
69
+ inlineCommentBlock: {
70
+ type: 'boolean',
71
+ },
72
+ minLineCount: {
73
+ type: 'integer',
74
+ },
75
+ },
76
+ type: 'object',
77
+ },
78
+ ],
79
+ },
80
+ type: 'array',
81
+ },
82
+ enableFixer: {
83
+ default: true,
84
+ type: 'boolean',
85
+ },
86
+ exemptEmptyConstructors: {
87
+ default: false,
88
+ type: 'boolean',
89
+ },
90
+ exemptEmptyFunctions: {
91
+ default: false,
92
+ type: 'boolean',
93
+ },
94
+ fixerMessage: {
95
+ default: '',
96
+ type: 'string',
97
+ },
98
+ minLineCount: {
99
+ type: 'integer',
100
+ },
101
+ publicOnly: {
102
+ oneOf: [
103
+ {
104
+ default: false,
105
+ type: 'boolean',
106
+ },
107
+ {
108
+ additionalProperties: false,
109
+ default: {},
110
+ properties: {
111
+ ancestorsOnly: {
112
+ type: 'boolean',
113
+ },
114
+ cjs: {
115
+ type: 'boolean',
116
+ },
117
+ esm: {
118
+ type: 'boolean',
119
+ },
120
+ window: {
121
+ type: 'boolean',
122
+ },
123
+ },
124
+ type: 'object',
125
+ },
126
+ ],
127
+ },
128
+ require: {
129
+ additionalProperties: false,
130
+ default: {},
131
+ properties: {
132
+ ArrowFunctionExpression: {
133
+ default: false,
134
+ type: 'boolean',
135
+ },
136
+ ClassDeclaration: {
137
+ default: false,
138
+ type: 'boolean',
139
+ },
140
+ ClassExpression: {
141
+ default: false,
142
+ type: 'boolean',
143
+ },
144
+ FunctionDeclaration: {
145
+ default: true,
146
+ type: 'boolean',
147
+ },
148
+ FunctionExpression: {
149
+ default: false,
150
+ type: 'boolean',
151
+ },
152
+ MethodDefinition: {
153
+ default: false,
154
+ type: 'boolean',
155
+ },
156
+ },
157
+ type: 'object',
158
+ },
159
+ },
160
+ type: 'object',
161
+ };
162
+
163
+ /**
164
+ * @param {import('eslint').Rule.RuleContext} context
165
+ * @param {import('json-schema').JSONSchema4Object} baseObject
166
+ * @param {string} option
167
+ * @param {string} key
168
+ * @returns {boolean|undefined}
169
+ */
170
+ const getOption = (context, baseObject, option, key) => {
171
+ if (context.options[0] && option in context.options[0] &&
172
+ // Todo: boolean shouldn't be returning property, but
173
+ // tests currently require
174
+ (typeof context.options[0][option] === 'boolean' ||
175
+ key in context.options[0][option])
176
+ ) {
177
+ return context.options[0][option][key];
178
+ }
179
+
180
+ return /** @type {{[key: string]: {default?: boolean|undefined}}} */ (
181
+ baseObject.properties
182
+ )[key].default;
183
+ };
184
+
185
+ /**
186
+ * @param {import('eslint').Rule.RuleContext} context
187
+ * @param {import('../iterateJsdoc.js').Settings} settings
188
+ * @returns {{
189
+ * contexts: (string|{
190
+ * context: string,
191
+ * inlineCommentBlock: boolean,
192
+ * minLineCount: import('../iterateJsdoc.js').Integer
193
+ * })[],
194
+ * enableFixer: boolean,
195
+ * exemptEmptyConstructors: boolean,
196
+ * exemptEmptyFunctions: boolean,
197
+ * fixerMessage: string,
198
+ * minLineCount: undefined|import('../iterateJsdoc.js').Integer,
199
+ * publicOnly: boolean|{[key: string]: boolean|undefined}
200
+ * require: {[key: string]: boolean|undefined}
201
+ * }}
202
+ */
203
+ const getOptions = (context, settings) => {
204
+ const {
205
+ publicOnly,
206
+ contexts = settings.contexts || [],
207
+ exemptEmptyConstructors = true,
208
+ exemptEmptyFunctions = false,
209
+ enableFixer = true,
210
+ fixerMessage = '',
211
+ minLineCount = undefined,
212
+ } = context.options[0] || {};
213
+
214
+ return {
215
+ contexts,
216
+ enableFixer,
217
+ exemptEmptyConstructors,
218
+ exemptEmptyFunctions,
219
+ fixerMessage,
220
+ minLineCount,
221
+ publicOnly: ((baseObj) => {
222
+ if (!publicOnly) {
223
+ return false;
224
+ }
225
+
226
+ /** @type {{[key: string]: boolean|undefined}} */
227
+ const properties = {};
228
+ for (const prop of Object.keys(
229
+ /** @type {import('json-schema').JSONSchema4Object} */ (
230
+ /** @type {import('json-schema').JSONSchema4Object} */ (
231
+ baseObj
232
+ ).properties),
233
+ )) {
234
+ const opt = getOption(
235
+ context,
236
+ /** @type {import('json-schema').JSONSchema4Object} */ (baseObj),
237
+ 'publicOnly',
238
+ prop,
239
+ );
240
+
241
+ properties[prop] = opt;
242
+ }
243
+
244
+ return properties;
245
+ })(
246
+ /** @type {import('json-schema').JSONSchema4Object} */
247
+ (
248
+ /** @type {import('json-schema').JSONSchema4Object} */
249
+ (
250
+ /** @type {import('json-schema').JSONSchema4Object} */
251
+ (
252
+ OPTIONS_SCHEMA.properties
253
+ ).publicOnly
254
+ ).oneOf
255
+ )[1],
256
+ ),
257
+ require: ((baseObj) => {
258
+ /** @type {{[key: string]: boolean|undefined}} */
259
+ const properties = {};
260
+ for (const prop of Object.keys(
261
+ /** @type {import('json-schema').JSONSchema4Object} */ (
262
+ /** @type {import('json-schema').JSONSchema4Object} */ (
263
+ baseObj
264
+ ).properties),
265
+ )) {
266
+ const opt = getOption(
267
+ context,
268
+ /** @type {import('json-schema').JSONSchema4Object} */
269
+ (baseObj),
270
+ 'require',
271
+ prop,
272
+ );
273
+ properties[prop] = opt;
274
+ }
275
+
276
+ return properties;
277
+ })(
278
+ /** @type {import('json-schema').JSONSchema4Object} */
279
+ (OPTIONS_SCHEMA.properties).require,
280
+ ),
281
+ };
282
+ };
283
+
284
+ /** @type {import('eslint').Rule.RuleModule} */
285
+ export default {
286
+ create (context) {
287
+ /* c8 ignore next -- Fallback to deprecated method */
288
+ const {
289
+ sourceCode = context.getSourceCode(),
290
+ } = context;
291
+ const settings = getSettings(context);
292
+ if (!settings) {
293
+ return {};
294
+ }
295
+
296
+ const opts = getOptions(context, settings);
297
+
298
+ const {
299
+ require: requireOption,
300
+ contexts,
301
+ exemptEmptyFunctions,
302
+ exemptEmptyConstructors,
303
+ enableFixer,
304
+ fixerMessage,
305
+ minLineCount,
306
+ } = opts;
307
+
308
+ const publicOnly =
309
+
310
+ /**
311
+ * @type {{
312
+ * [key: string]: boolean | undefined;
313
+ * }}
314
+ */ (
315
+ opts.publicOnly
316
+ );
317
+
318
+ /**
319
+ * @type {import('../iterateJsdoc.js').CheckJsdoc}
320
+ */
321
+ const checkJsDoc = (info, _handler, node) => {
322
+ if (
323
+ // Optimize
324
+ minLineCount !== undefined || contexts.some((ctxt) => {
325
+ if (typeof ctxt === 'string') {
326
+ return false;
327
+ }
328
+
329
+ const {
330
+ minLineCount: count,
331
+ } = ctxt;
332
+ return count !== undefined;
333
+ })
334
+ ) {
335
+ /**
336
+ * @param {undefined|import('../iterateJsdoc.js').Integer} count
337
+ */
338
+ const underMinLine = (count) => {
339
+ return count !== undefined && count >
340
+ (sourceCode.getText(node).match(/\n/gu)?.length ?? 0) + 1;
341
+ };
342
+
343
+ if (underMinLine(minLineCount)) {
344
+ return;
345
+ }
346
+
347
+ const {
348
+ minLineCount: contextMinLineCount,
349
+ } =
350
+ /**
351
+ * @type {{
352
+ * context: string;
353
+ * inlineCommentBlock: boolean;
354
+ * minLineCount: number;
355
+ * }}
356
+ */ (contexts.find((ctxt) => {
357
+ if (typeof ctxt === 'string') {
358
+ return false;
359
+ }
360
+
361
+ const {
362
+ context: ctx,
363
+ } = ctxt;
364
+ return ctx === (info.selector || node.type);
365
+ })) || {};
366
+ if (underMinLine(contextMinLineCount)) {
367
+ return;
368
+ }
369
+ }
370
+
371
+ const jsDocNode = getJSDocComment(sourceCode, node, settings);
372
+
373
+ if (jsDocNode) {
374
+ return;
375
+ }
376
+
377
+ // For those who have options configured against ANY constructors (or
378
+ // setters or getters) being reported
379
+ if (jsdocUtils.exemptSpeciaMethods(
380
+ {
381
+ description: '',
382
+ inlineTags: [],
383
+ problems: [],
384
+ source: [],
385
+ tags: [],
386
+ },
387
+ node,
388
+ context,
389
+ [
390
+ OPTIONS_SCHEMA,
391
+ ],
392
+ )) {
393
+ return;
394
+ }
395
+
396
+ if (
397
+ // Avoid reporting param-less, return-less functions (when
398
+ // `exemptEmptyFunctions` option is set)
399
+ exemptEmptyFunctions && info.isFunctionContext ||
400
+
401
+ // Avoid reporting param-less, return-less constructor methods (when
402
+ // `exemptEmptyConstructors` option is set)
403
+ exemptEmptyConstructors && jsdocUtils.isConstructor(node)
404
+ ) {
405
+ const functionParameterNames = jsdocUtils.getFunctionParameterNames(node);
406
+ if (!functionParameterNames.length && !jsdocUtils.hasReturnValue(node)) {
407
+ return;
408
+ }
409
+ }
410
+
411
+ const fix = /** @type {import('eslint').Rule.ReportFixer} */ (fixer) => {
412
+ // Default to one line break if the `minLines`/`maxLines` settings allow
413
+ const lines = settings.minLines === 0 && settings.maxLines >= 1 ? 1 : settings.minLines;
414
+ /** @type {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Decorator} */
415
+ let baseNode = getReducedASTNode(node, sourceCode);
416
+
417
+ const decorator = getDecorator(baseNode);
418
+ if (decorator) {
419
+ baseNode = decorator;
420
+ }
421
+
422
+ const indent = jsdocUtils.getIndent({
423
+ text: sourceCode.getText(
424
+ /** @type {import('eslint').Rule.Node} */ (baseNode),
425
+ /** @type {import('eslint').AST.SourceLocation} */
426
+ (
427
+ /** @type {import('eslint').Rule.Node} */ (baseNode).loc
428
+ ).start.column,
429
+ ),
430
+ });
431
+
432
+ const {
433
+ inlineCommentBlock,
434
+ } =
435
+ /**
436
+ * @type {{
437
+ * context: string,
438
+ * inlineCommentBlock: boolean,
439
+ * minLineCount: import('../iterateJsdoc.js').Integer
440
+ * }}
441
+ */ (contexts.find((contxt) => {
442
+ if (typeof contxt === 'string') {
443
+ return false;
444
+ }
445
+
446
+ const {
447
+ context: ctxt,
448
+ } = contxt;
449
+ return ctxt === node.type;
450
+ })) || {};
451
+ const insertion = (inlineCommentBlock ?
452
+ `/** ${fixerMessage}` :
453
+ `/**\n${indent}*${fixerMessage}\n${indent}`) +
454
+ `*/${'\n'.repeat(lines)}${indent.slice(0, -1)}`;
455
+
456
+ return fixer.insertTextBefore(
457
+ /** @type {import('eslint').Rule.Node} */
458
+ (baseNode),
459
+ insertion,
460
+ );
461
+ };
462
+
463
+ const report = () => {
464
+ const {
465
+ start,
466
+ } = /** @type {import('eslint').AST.SourceLocation} */ (node.loc);
467
+ const loc = {
468
+ end: {
469
+ column: 0,
470
+ line: start.line + 1,
471
+ },
472
+ start,
473
+ };
474
+ context.report({
475
+ fix: enableFixer ? fix : null,
476
+ loc,
477
+ messageId: 'missingJsDoc',
478
+ node,
479
+ });
480
+ };
481
+
482
+ if (publicOnly) {
483
+ /** @type {RequireJsdocOpts} */
484
+ const opt = {
485
+ ancestorsOnly: Boolean(publicOnly?.ancestorsOnly ?? false),
486
+ esm: Boolean(publicOnly?.esm ?? true),
487
+ initModuleExports: Boolean(publicOnly?.cjs ?? true),
488
+ initWindow: Boolean(publicOnly?.window ?? false),
489
+ };
490
+ const exported = exportParser.isUncommentedExport(node, sourceCode, opt, settings);
491
+
492
+ if (exported) {
493
+ report();
494
+ }
495
+ } else {
496
+ report();
497
+ }
498
+ };
499
+
500
+ /**
501
+ * @param {string} prop
502
+ * @returns {boolean}
503
+ */
504
+ const hasOption = (prop) => {
505
+ return requireOption[prop] || contexts.some((ctxt) => {
506
+ return typeof ctxt === 'object' ? ctxt.context === prop : ctxt === prop;
507
+ });
508
+ };
509
+
510
+ return {
511
+ ...jsdocUtils.getContextObject(
512
+ jsdocUtils.enforcedContexts(context, [], settings),
513
+ checkJsDoc,
514
+ ),
515
+ ArrowFunctionExpression (node) {
516
+ if (!hasOption('ArrowFunctionExpression')) {
517
+ return;
518
+ }
519
+
520
+ if (
521
+ [
522
+ 'VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration',
523
+ ].includes(node.parent.type) ||
524
+ [
525
+ 'Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition',
526
+ ].includes(node.parent.type) &&
527
+ node ===
528
+ /**
529
+ * @type {import('@typescript-eslint/types').TSESTree.Property|
530
+ * import('@typescript-eslint/types').TSESTree.PropertyDefinition
531
+ * }
532
+ */
533
+ (node.parent).value
534
+ ) {
535
+ checkJsDoc({
536
+ isFunctionContext: true,
537
+ }, null, node);
538
+ }
539
+ },
540
+
541
+ ClassDeclaration (node) {
542
+ if (!hasOption('ClassDeclaration')) {
543
+ return;
544
+ }
545
+
546
+ checkJsDoc({
547
+ isFunctionContext: false,
548
+ }, null, node);
549
+ },
550
+
551
+ ClassExpression (node) {
552
+ if (!hasOption('ClassExpression')) {
553
+ return;
554
+ }
555
+
556
+ checkJsDoc({
557
+ isFunctionContext: false,
558
+ }, null, node);
559
+ },
560
+
561
+ FunctionDeclaration (node) {
562
+ if (!hasOption('FunctionDeclaration')) {
563
+ return;
564
+ }
565
+
566
+ checkJsDoc({
567
+ isFunctionContext: true,
568
+ }, null, node);
569
+ },
570
+
571
+ FunctionExpression (node) {
572
+ if (!hasOption('FunctionExpression')) {
573
+ return;
574
+ }
575
+
576
+ if (
577
+ [
578
+ 'VariableDeclarator', 'AssignmentExpression', 'ExportDefaultDeclaration',
579
+ ].includes(node.parent.type) ||
580
+ [
581
+ 'Property', 'ObjectProperty', 'ClassProperty', 'PropertyDefinition',
582
+ ].includes(node.parent.type) &&
583
+ node ===
584
+ /**
585
+ * @type {import('@typescript-eslint/types').TSESTree.Property|
586
+ * import('@typescript-eslint/types').TSESTree.PropertyDefinition
587
+ * }
588
+ */
589
+ (node.parent).value
590
+ ) {
591
+ checkJsDoc({
592
+ isFunctionContext: true,
593
+ }, null, node);
594
+ }
595
+ },
596
+
597
+ MethodDefinition (node) {
598
+ if (!hasOption('MethodDefinition')) {
599
+ return;
600
+ }
601
+
602
+ checkJsDoc({
603
+ isFunctionContext: true,
604
+ selector: 'MethodDefinition',
605
+ }, null, /** @type {import('eslint').Rule.Node} */ (node.value));
606
+ },
607
+ };
608
+ },
609
+ meta: {
610
+ docs: {
611
+ category: 'Stylistic Issues',
612
+ description: 'Require JSDoc comments',
613
+ recommended: true,
614
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-jsdoc.md#repos-sticky-header',
615
+ },
616
+
617
+ fixable: 'code',
618
+
619
+ messages: {
620
+ missingJsDoc: 'Missing JSDoc comment.',
621
+ },
622
+
623
+ schema: [
624
+ OPTIONS_SCHEMA,
625
+ ],
626
+
627
+ type: 'suggestion',
628
+ },
629
+ };