@@ -22,7 +22,7 @@ const parseComment = (commentNode, indent) => {
22
22
} ;
23
23
24
24
const curryUtils = (
25
- functionNode ,
25
+ node ,
26
26
jsdoc ,
27
27
tagNamePreference ,
28
28
exampleCodeRegex ,
@@ -47,15 +47,15 @@ const curryUtils = (
47
47
const utils = { } ;
48
48
49
49
utils . getFunctionParameterNames = ( ) => {
50
- return jsdocUtils . getFunctionParameterNames ( functionNode ) ;
50
+ return jsdocUtils . getFunctionParameterNames ( node ) ;
51
51
} ;
52
52
53
53
utils . getFunctionSourceCode = ( ) => {
54
- return sourceCode . getText ( functionNode ) ;
54
+ return sourceCode . getText ( node ) ;
55
55
} ;
56
56
57
57
utils . isConstructor = ( ) => {
58
- return functionNode . parent && functionNode . parent . kind === 'constructor' ;
58
+ return node . parent && node . parent . kind === 'constructor' ;
59
59
} ;
60
60
61
61
utils . getJsdocParameterNamesDeep = ( ) => {
@@ -178,113 +178,131 @@ export {
178
178
parseComment
179
179
} ;
180
180
181
- export default ( iterator ) => {
182
- return ( context ) => {
183
- const sourceCode = context . getSourceCode ( ) ;
184
- const tagNamePreference = _ . get ( context , 'settings.jsdoc.tagNamePreference' ) || { } ;
185
- const exampleCodeRegex = _ . get ( context , 'settings.jsdoc.exampleCodeRegex' ) || null ;
186
- const rejectExampleCodeRegex = _ . get ( context , 'settings.jsdoc.rejectExampleCodeRegex' ) || null ;
187
- const matchingFileName = _ . get ( context , 'settings.jsdoc.matchingFileName' ) || null ;
188
- const additionalTagNames = _ . get ( context , 'settings.jsdoc.additionalTagNames' ) || { } ;
189
- const baseConfig = _ . get ( context , 'settings.jsdoc.baseConfig' ) || { } ;
190
- const configFile = _ . get ( context , 'settings.jsdoc.configFile' ) ;
191
- const eslintrcForExamples = _ . get ( context , 'settings.jsdoc.eslintrcForExamples' ) !== false ;
192
- const allowInlineConfig = _ . get ( context , 'settings.jsdoc.allowInlineConfig' ) !== false ;
193
- const allowEmptyNamepaths = _ . get ( context , 'settings.jsdoc.allowEmptyNamepaths' ) !== false ;
194
- const reportUnusedDisableDirectives = _ . get ( context , 'settings.jsdoc.reportUnusedDisableDirectives' ) !== false ;
195
- const captionRequired = Boolean ( _ . get ( context , 'settings.jsdoc.captionRequired' ) ) ;
196
- const noDefaultExampleRules = Boolean ( _ . get ( context , 'settings.jsdoc.noDefaultExampleRules' ) ) ;
197
- const allowOverrideWithoutParam = Boolean ( _ . get ( context , 'settings.jsdoc.allowOverrideWithoutParam' ) ) ;
198
- const allowImplementsWithoutParam = Boolean ( _ . get ( context , 'settings.jsdoc.allowImplementsWithoutParam' ) ) ;
199
- const allowAugmentsExtendsWithoutParam = Boolean ( _ . get ( context , 'settings.jsdoc.allowAugmentsExtendsWithoutParam' ) ) ;
200
- const checkSeesForNamepaths = Boolean ( _ . get ( context , 'settings.jsdoc.checkSeesForNamepaths' ) ) ;
201
-
202
- const checkJsdoc = ( functionNode ) => {
203
- const jsdocNode = sourceCode . getJSDocComment ( functionNode ) ;
204
-
205
- if ( ! jsdocNode ) {
206
- return ;
207
- }
181
+ export default ( iterator , options ) => {
182
+ const opts = options || { } ;
183
+
184
+ return {
185
+ /**
186
+ * The entrypoint for the JSDoc rule.
187
+ *
188
+ * @param {* } context
189
+ * a reference to the context which hold all important information
190
+ * like settings and the sourcecode to check.
191
+ * @returns {Object }
192
+ * a list with parser callback function.
193
+ */
194
+ create ( context ) {
195
+ const sourceCode = context . getSourceCode ( ) ;
196
+ const tagNamePreference = _ . get ( context , 'settings.jsdoc.tagNamePreference' ) || { } ;
197
+ const exampleCodeRegex = _ . get ( context , 'settings.jsdoc.exampleCodeRegex' ) || null ;
198
+ const rejectExampleCodeRegex = _ . get ( context , 'settings.jsdoc.rejectExampleCodeRegex' ) || null ;
199
+ const matchingFileName = _ . get ( context , 'settings.jsdoc.matchingFileName' ) || null ;
200
+ const additionalTagNames = _ . get ( context , 'settings.jsdoc.additionalTagNames' ) || { } ;
201
+ const baseConfig = _ . get ( context , 'settings.jsdoc.baseConfig' ) || { } ;
202
+ const configFile = _ . get ( context , 'settings.jsdoc.configFile' ) ;
203
+ const eslintrcForExamples = _ . get ( context , 'settings.jsdoc.eslintrcForExamples' ) !== false ;
204
+ const allowInlineConfig = _ . get ( context , 'settings.jsdoc.allowInlineConfig' ) !== false ;
205
+ const allowEmptyNamepaths = _ . get ( context , 'settings.jsdoc.allowEmptyNamepaths' ) !== false ;
206
+ const reportUnusedDisableDirectives = _ . get ( context , 'settings.jsdoc.reportUnusedDisableDirectives' ) !== false ;
207
+ const captionRequired = Boolean ( _ . get ( context , 'settings.jsdoc.captionRequired' ) ) ;
208
+ const noDefaultExampleRules = Boolean ( _ . get ( context , 'settings.jsdoc.noDefaultExampleRules' ) ) ;
209
+ const allowOverrideWithoutParam = Boolean ( _ . get ( context , 'settings.jsdoc.allowOverrideWithoutParam' ) ) ;
210
+ const allowImplementsWithoutParam = Boolean ( _ . get ( context , 'settings.jsdoc.allowImplementsWithoutParam' ) ) ;
211
+ const allowAugmentsExtendsWithoutParam = Boolean ( _ . get ( context , 'settings.jsdoc.allowAugmentsExtendsWithoutParam' ) ) ;
212
+ const checkSeesForNamepaths = Boolean ( _ . get ( context , 'settings.jsdoc.checkSeesForNamepaths' ) ) ;
213
+
214
+ const checkJsdoc = ( node ) => {
215
+ const jsdocNode = sourceCode . getJSDocComment ( node ) ;
216
+
217
+ if ( ! jsdocNode ) {
218
+ return ;
219
+ }
208
220
209
- const ancestors = context . getAncestors ( ) ;
221
+ const ancestors = context . getAncestors ( ) ;
210
222
211
- const indent = _ . repeat ( ' ' , jsdocNode . loc . start . column ) ;
223
+ const indent = _ . repeat ( ' ' , jsdocNode . loc . start . column ) ;
212
224
213
- const jsdoc = parseComment ( jsdocNode , indent ) ;
225
+ const jsdoc = parseComment ( jsdocNode , indent ) ;
214
226
215
- const report = ( message , fixer = null , jsdocLoc = null ) => {
216
- let loc ;
227
+ const report = ( message , fixer = null , jsdocLoc = null ) => {
228
+ let loc ;
217
229
218
- if ( jsdocLoc ) {
219
- const lineNumber = jsdocNode . loc . start . line + jsdocLoc . line ;
230
+ if ( jsdocLoc ) {
231
+ const lineNumber = jsdocNode . loc . start . line + jsdocLoc . line ;
220
232
221
- loc = {
222
- end : { line : lineNumber } ,
223
- start : { line : lineNumber }
224
- } ;
225
- if ( jsdocLoc . column ) {
226
- const colNumber = jsdocNode . loc . start . column + jsdocLoc . column ;
233
+ loc = {
234
+ end : { line : lineNumber } ,
235
+ start : { line : lineNumber }
236
+ } ;
237
+ if ( jsdocLoc . column ) {
238
+ const colNumber = jsdocNode . loc . start . column + jsdocLoc . column ;
227
239
228
- loc . end . column = colNumber ;
229
- loc . start . column = colNumber ;
240
+ loc . end . column = colNumber ;
241
+ loc . start . column = colNumber ;
242
+ }
230
243
}
231
- }
232
- if ( fixer === null ) {
233
- context . report ( {
234
- loc,
235
- message,
236
- node : jsdocNode
237
- } ) ;
238
- } else {
239
- context . report ( {
240
- fix : fixer ,
241
- loc,
242
- message,
243
- node : jsdocNode
244
- } ) ;
245
- }
244
+ if ( fixer === null ) {
245
+ context . report ( {
246
+ loc,
247
+ message,
248
+ node : jsdocNode
249
+ } ) ;
250
+ } else {
251
+ context . report ( {
252
+ fix : fixer ,
253
+ loc,
254
+ message,
255
+ node : jsdocNode
256
+ } ) ;
257
+ }
258
+ } ;
259
+
260
+ const utils = curryUtils (
261
+ node ,
262
+ jsdoc ,
263
+ tagNamePreference ,
264
+ exampleCodeRegex ,
265
+ rejectExampleCodeRegex ,
266
+ additionalTagNames ,
267
+ baseConfig ,
268
+ configFile ,
269
+ captionRequired ,
270
+ matchingFileName ,
271
+ eslintrcForExamples ,
272
+ allowInlineConfig ,
273
+ allowEmptyNamepaths ,
274
+ reportUnusedDisableDirectives ,
275
+ noDefaultExampleRules ,
276
+ allowOverrideWithoutParam ,
277
+ allowImplementsWithoutParam ,
278
+ allowAugmentsExtendsWithoutParam ,
279
+ checkSeesForNamepaths ,
280
+ ancestors ,
281
+ sourceCode
282
+ ) ;
283
+
284
+ iterator ( {
285
+ context,
286
+ indent,
287
+ jsdoc,
288
+ jsdocNode,
289
+ node,
290
+ report,
291
+ sourceCode,
292
+ utils
293
+ } ) ;
246
294
} ;
247
295
248
- const utils = curryUtils (
249
- functionNode ,
250
- jsdoc ,
251
- tagNamePreference ,
252
- exampleCodeRegex ,
253
- rejectExampleCodeRegex ,
254
- additionalTagNames ,
255
- baseConfig ,
256
- configFile ,
257
- captionRequired ,
258
- matchingFileName ,
259
- eslintrcForExamples ,
260
- allowInlineConfig ,
261
- allowEmptyNamepaths ,
262
- reportUnusedDisableDirectives ,
263
- noDefaultExampleRules ,
264
- allowOverrideWithoutParam ,
265
- allowImplementsWithoutParam ,
266
- allowAugmentsExtendsWithoutParam ,
267
- checkSeesForNamepaths ,
268
- ancestors ,
269
- sourceCode
270
- ) ;
271
-
272
- iterator ( {
273
- context,
274
- functionNode,
275
- indent,
276
- jsdoc,
277
- jsdocNode,
278
- report,
279
- sourceCode,
280
- utils
281
- } ) ;
282
- } ;
283
-
284
- return {
285
- ArrowFunctionExpression : checkJsdoc ,
286
- FunctionDeclaration : checkJsdoc ,
287
- FunctionExpression : checkJsdoc
288
- } ;
296
+ if ( opts . returns ) {
297
+ return opts . returns ( context , sourceCode , checkJsdoc ) ;
298
+ }
299
+
300
+ return {
301
+ ArrowFunctionExpression : checkJsdoc ,
302
+ FunctionDeclaration : checkJsdoc ,
303
+ FunctionExpression : checkJsdoc
304
+ } ;
305
+ } ,
306
+ meta : opts . meta
289
307
} ;
290
308
} ;
0 commit comments