@@ -25,28 +25,18 @@ const parseComment = (commentNode, indent) => {
25
25
const curryUtils = (
26
26
node ,
27
27
jsdoc ,
28
- tagNamePreference ,
29
- exampleCodeRegex ,
30
- rejectExampleCodeRegex ,
31
- additionalTagNames ,
32
- baseConfig ,
33
- configFile ,
34
- captionRequired ,
35
- matchingFileName ,
36
- eslintrcForExamples ,
37
- allowInlineConfig ,
38
- allowEmptyNamepaths ,
39
- reportUnusedDisableDirectives ,
40
- noDefaultExampleRules ,
41
- overrideReplacesDocs ,
42
- implementsReplacesDocs ,
43
- augmentsExtendsReplacesDocs ,
44
- allowOverrideWithoutParam ,
45
- allowImplementsWithoutParam ,
46
- allowAugmentsExtendsWithoutParam ,
47
- checkSeesForNamepaths ,
48
- forceRequireReturn ,
49
- avoidExampleOnConstructors ,
28
+ {
29
+ tagNamePreference,
30
+ additionalTagNames,
31
+ allowEmptyNamepaths,
32
+ overrideReplacesDocs,
33
+ implementsReplacesDocs,
34
+ augmentsExtendsReplacesDocs,
35
+ allowOverrideWithoutParam,
36
+ allowImplementsWithoutParam,
37
+ allowAugmentsExtendsWithoutParam,
38
+ checkSeesForNamepaths
39
+ } ,
50
40
ancestors ,
51
41
sourceCode ,
52
42
context
@@ -81,18 +71,6 @@ const curryUtils = (
81
71
return jsdocUtils . getPreferredTagName ( name , tagNamePreference ) ;
82
72
} ;
83
73
84
- utils . getExampleCodeRegex = ( ) => {
85
- return exampleCodeRegex ;
86
- } ;
87
-
88
- utils . getRejectExampleCodeRegex = ( ) => {
89
- return rejectExampleCodeRegex ;
90
- } ;
91
-
92
- utils . getMatchingFileName = ( ) => {
93
- return matchingFileName ;
94
- } ;
95
-
96
74
utils . isValidTag = ( name ) => {
97
75
return jsdocUtils . isValidTag ( name , additionalTagNames ) ;
98
76
} ;
@@ -105,34 +83,6 @@ const curryUtils = (
105
83
return jsdocUtils . hasTag ( jsdoc , name ) ;
106
84
} ;
107
85
108
- utils . useEslintrcForExamples = ( ) => {
109
- return eslintrcForExamples ;
110
- } ;
111
-
112
- utils . allowInlineConfig = ( ) => {
113
- return allowInlineConfig ;
114
- } ;
115
-
116
- utils . reportUnusedDisableDirectives = ( ) => {
117
- return reportUnusedDisableDirectives ;
118
- } ;
119
-
120
- utils . hasNoDefaultExampleRules = ( ) => {
121
- return noDefaultExampleRules ;
122
- } ;
123
-
124
- utils . getBaseConfig = ( ) => {
125
- return baseConfig ;
126
- } ;
127
-
128
- utils . getConfigFile = ( ) => {
129
- return configFile ;
130
- } ;
131
-
132
- utils . isCaptionRequired = ( ) => {
133
- return captionRequired ;
134
- } ;
135
-
136
86
// These settings are deprecated and may be removed in the future along with this method.
137
87
utils . avoidDocsParamOnly = ( ) => {
138
88
// These three checks are all for deprecated settings and may be removed in the future
@@ -186,10 +136,6 @@ const curryUtils = (
186
136
return jsdocUtils . isTagWithType ( tagName ) ;
187
137
} ;
188
138
189
- utils . avoidExampleOnConstructors = ( ) => {
190
- return avoidExampleOnConstructors ;
191
- } ;
192
-
193
139
utils . passesEmptyNamepathCheck = ( tag ) => {
194
140
return ! tag . name && allowEmptyNamepaths &&
195
141
jsdocUtils . isPotentiallyEmptyNamepathTag ( tag . tag ) ;
@@ -209,10 +155,6 @@ const curryUtils = (
209
155
} ) ;
210
156
} ;
211
157
212
- utils . isForceRequireReturn = ( ) => {
213
- return forceRequireReturn ;
214
- } ;
215
-
216
158
utils . filterTags = ( filter ) => {
217
159
return ( jsdoc . tags || [ ] ) . filter ( filter ) ;
218
160
} ;
@@ -257,11 +199,65 @@ const curryUtils = (
257
199
return utils ;
258
200
} ;
259
201
202
+ const getSettings = ( context ) => {
203
+ const settings = { } ;
204
+
205
+ // All rules
206
+ settings . ignorePrivate = Boolean ( _ . get ( context , 'settings.jsdoc.ignorePrivate' ) ) ;
207
+
208
+ // `check-tag-names` and many require/param rules
209
+ settings . tagNamePreference = _ . get ( context , 'settings.jsdoc.tagNamePreference' ) || { } ;
210
+
211
+ // `check-tag-names` only
212
+ settings . additionalTagNames = _ . get ( context , 'settings.jsdoc.additionalTagNames' ) || { } ;
213
+
214
+ // `check-examples` only
215
+ settings . exampleCodeRegex = _ . get ( context , 'settings.jsdoc.exampleCodeRegex' ) || null ;
216
+ settings . rejectExampleCodeRegex = _ . get ( context , 'settings.jsdoc.rejectExampleCodeRegex' ) || null ;
217
+ settings . matchingFileName = _ . get ( context , 'settings.jsdoc.matchingFileName' ) || null ;
218
+ settings . baseConfig = _ . get ( context , 'settings.jsdoc.baseConfig' ) || { } ;
219
+ settings . configFile = _ . get ( context , 'settings.jsdoc.configFile' ) ;
220
+ settings . eslintrcForExamples = _ . get ( context , 'settings.jsdoc.eslintrcForExamples' ) !== false ;
221
+ settings . allowInlineConfig = _ . get ( context , 'settings.jsdoc.allowInlineConfig' ) !== false ;
222
+ settings . reportUnusedDisableDirectives = _ . get ( context , 'settings.jsdoc.reportUnusedDisableDirectives' ) !== false ;
223
+ settings . captionRequired = Boolean ( _ . get ( context , 'settings.jsdoc.captionRequired' ) ) ;
224
+ settings . noDefaultExampleRules = Boolean ( _ . get ( context , 'settings.jsdoc.noDefaultExampleRules' ) ) ;
225
+
226
+ // `require-param`, `require-description`, `require-example`, `require-returns`
227
+ settings . overrideReplacesDocs = _ . get ( context , 'settings.jsdoc.overrideReplacesDocs' ) ;
228
+ settings . implementsReplacesDocs = _ . get ( context , 'settings.jsdoc.implementsReplacesDocs' ) ;
229
+ settings . augmentsExtendsReplacesDocs = _ . get ( context , 'settings.jsdoc.augmentsExtendsReplacesDocs' ) ;
230
+
231
+ // `require-param` only (deprecated)
232
+ settings . allowOverrideWithoutParam = _ . get ( context , 'settings.jsdoc.allowOverrideWithoutParam' ) ;
233
+ settings . allowImplementsWithoutParam = _ . get ( context , 'settings.jsdoc.allowImplementsWithoutParam' ) ;
234
+ settings . allowAugmentsExtendsWithoutParam = _ . get ( context , 'settings.jsdoc.allowAugmentsExtendsWithoutParam' ) ;
235
+
236
+ // `valid-types` only
237
+ settings . allowEmptyNamepaths = _ . get ( context , 'settings.jsdoc.allowEmptyNamepaths' ) !== false ;
238
+ settings . checkSeesForNamepaths = Boolean ( _ . get ( context , 'settings.jsdoc.checkSeesForNamepaths' ) ) ;
239
+
240
+ // `require-returns` only
241
+ settings . forceRequireReturn = Boolean ( _ . get ( context , 'settings.jsdoc.forceRequireReturn' ) ) ;
242
+
243
+ // `require-example` only
244
+ settings . avoidExampleOnConstructors = Boolean ( _ . get ( context , 'settings.jsdoc.avoidExampleOnConstructors' ) ) ;
245
+
246
+ return settings ;
247
+ } ;
248
+
260
249
export {
261
250
parseComment
262
251
} ;
263
252
264
- export default ( iterator , opts = { } ) => {
253
+ /**
254
+ * @typedef {ReturnType<typeof curryUtils> } Utils
255
+ * @typedef {ReturnType<typeof getSettings> } Settings
256
+ *
257
+ * @param {(arg: {utils: Utils, settings: Settings}) => any } iterator
258
+ * @param {{returns?: any} } opts
259
+ */
260
+ export default function iterateJsdoc ( iterator , opts = { } ) {
265
261
return {
266
262
/**
267
263
* The entrypoint for the JSDoc rule.
@@ -275,46 +271,7 @@ export default (iterator, opts = {}) => {
275
271
create ( context ) {
276
272
const sourceCode = context . getSourceCode ( ) ;
277
273
278
- // All rules
279
- const ignorePrivate = Boolean ( _ . get ( context , 'settings.jsdoc.ignorePrivate' ) ) ;
280
-
281
- // `check-tag-names` and many require/param rules
282
- const tagNamePreference = _ . get ( context , 'settings.jsdoc.tagNamePreference' ) || { } ;
283
-
284
- // `check-tag-names` only
285
- const additionalTagNames = _ . get ( context , 'settings.jsdoc.additionalTagNames' ) || { } ;
286
-
287
- // `check-examples` only
288
- const exampleCodeRegex = _ . get ( context , 'settings.jsdoc.exampleCodeRegex' ) || null ;
289
- const rejectExampleCodeRegex = _ . get ( context , 'settings.jsdoc.rejectExampleCodeRegex' ) || null ;
290
- const matchingFileName = _ . get ( context , 'settings.jsdoc.matchingFileName' ) || null ;
291
- const baseConfig = _ . get ( context , 'settings.jsdoc.baseConfig' ) || { } ;
292
- const configFile = _ . get ( context , 'settings.jsdoc.configFile' ) ;
293
- const eslintrcForExamples = _ . get ( context , 'settings.jsdoc.eslintrcForExamples' ) !== false ;
294
- const allowInlineConfig = _ . get ( context , 'settings.jsdoc.allowInlineConfig' ) !== false ;
295
- const reportUnusedDisableDirectives = _ . get ( context , 'settings.jsdoc.reportUnusedDisableDirectives' ) !== false ;
296
- const captionRequired = Boolean ( _ . get ( context , 'settings.jsdoc.captionRequired' ) ) ;
297
- const noDefaultExampleRules = Boolean ( _ . get ( context , 'settings.jsdoc.noDefaultExampleRules' ) ) ;
298
-
299
- // `require-param`, `require-description`, `require-example`, `require-returns`
300
- const overrideReplacesDocs = _ . get ( context , 'settings.jsdoc.overrideReplacesDocs' ) ;
301
- const implementsReplacesDocs = _ . get ( context , 'settings.jsdoc.implementsReplacesDocs' ) ;
302
- const augmentsExtendsReplacesDocs = _ . get ( context , 'settings.jsdoc.augmentsExtendsReplacesDocs' ) ;
303
-
304
- // `require-param` only (deprecated)
305
- const allowOverrideWithoutParam = _ . get ( context , 'settings.jsdoc.allowOverrideWithoutParam' ) ;
306
- const allowImplementsWithoutParam = _ . get ( context , 'settings.jsdoc.allowImplementsWithoutParam' ) ;
307
- const allowAugmentsExtendsWithoutParam = _ . get ( context , 'settings.jsdoc.allowAugmentsExtendsWithoutParam' ) ;
308
-
309
- // `valid-types` only
310
- const allowEmptyNamepaths = _ . get ( context , 'settings.jsdoc.allowEmptyNamepaths' ) !== false ;
311
- const checkSeesForNamepaths = Boolean ( _ . get ( context , 'settings.jsdoc.checkSeesForNamepaths' ) ) ;
312
-
313
- // `require-returns` only
314
- const forceRequireReturn = Boolean ( _ . get ( context , 'settings.jsdoc.forceRequireReturn' ) ) ;
315
-
316
- // `require-example` only
317
- const avoidExampleOnConstructors = Boolean ( _ . get ( context , 'settings.jsdoc.avoidExampleOnConstructors' ) ) ;
274
+ const settings = getSettings ( context ) ;
318
275
319
276
const checkJsdoc = ( node ) => {
320
277
const jsdocNode = getJSDocComment ( sourceCode , node ) ;
@@ -359,34 +316,13 @@ export default (iterator, opts = {}) => {
359
316
const utils = curryUtils (
360
317
node ,
361
318
jsdoc ,
362
- tagNamePreference ,
363
- exampleCodeRegex ,
364
- rejectExampleCodeRegex ,
365
- additionalTagNames ,
366
- baseConfig ,
367
- configFile ,
368
- captionRequired ,
369
- matchingFileName ,
370
- eslintrcForExamples ,
371
- allowInlineConfig ,
372
- allowEmptyNamepaths ,
373
- reportUnusedDisableDirectives ,
374
- noDefaultExampleRules ,
375
- overrideReplacesDocs ,
376
- implementsReplacesDocs ,
377
- augmentsExtendsReplacesDocs ,
378
- allowOverrideWithoutParam ,
379
- allowImplementsWithoutParam ,
380
- allowAugmentsExtendsWithoutParam ,
381
- checkSeesForNamepaths ,
382
- forceRequireReturn ,
383
- avoidExampleOnConstructors ,
319
+ settings ,
384
320
ancestors ,
385
321
sourceCode
386
322
) ;
387
323
388
324
if (
389
- ignorePrivate &&
325
+ settings . ignorePrivate &&
390
326
utils . hasTag ( 'private' )
391
327
) {
392
328
return ;
@@ -399,6 +335,7 @@ export default (iterator, opts = {}) => {
399
335
jsdocNode,
400
336
node,
401
337
report,
338
+ settings,
402
339
sourceCode,
403
340
utils
404
341
} ) ;
@@ -427,4 +364,4 @@ export default (iterator, opts = {}) => {
427
364
} ,
428
365
meta : opts . meta
429
366
} ;
430
- } ;
367
+ }
0 commit comments