Commit cf7b0fd50303564ca2a7208c55c3f8c5e77f3d63

Michael Schmidt 2021-05-01T14:40:00

ESLint: Added JSDoc plugin (#2869)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
diff --git a/.eslintrc.js b/.eslintrc.js
index a9b1b0b..ae60a75 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,6 +1,7 @@
 /** @type {import('eslint').Linter.Config} */
 module.exports = {
 	root: true,
+	plugins: ['jsdoc'],
 	extends: 'eslint:recommended',
 	rules: {
 		'no-use-before-define': ['error', { 'functions': false, 'classes': false }],
@@ -13,6 +14,18 @@ module.exports = {
 		'semi': 'warn',
 		'wrap-iife': 'warn',
 
+		// JSDoc
+		'jsdoc/check-alignment': 'warn',
+		'jsdoc/check-syntax': 'warn',
+		'jsdoc/check-param-names': 'warn',
+		'jsdoc/require-hyphen-before-param-description': ['warn', 'never'],
+		'jsdoc/check-tag-names': 'warn',
+		'jsdoc/check-types': 'warn',
+		'jsdoc/empty-tags': 'warn',
+		'jsdoc/newline-after-description': 'warn',
+		'jsdoc/require-param-name': 'warn',
+		'jsdoc/require-property-name': 'warn',
+
 		// I turned this rule off because we use `hasOwnProperty` in a lot of places
 		// TODO: Think about re-enabling this rule
 		'no-prototype-builtins': 'off',
@@ -27,6 +40,9 @@ module.exports = {
 		'no-empty-character-class': 'off',
 		'no-useless-escape': 'off'
 	},
+	settings: {
+		jsdoc: { mode: 'typescript' }
+	},
 	ignorePatterns: [
 		'*.min.js',
 		'vendor/',
diff --git a/components/prism-core.js b/components/prism-core.js
index f68943d..d19999d 100644
--- a/components/prism-core.js
+++ b/components/prism-core.js
@@ -1047,6 +1047,7 @@ function LinkedList() {
 
 /**
  * Adds a new node with the given value to the list.
+ *
  * @param {LinkedList<T>} list
  * @param {LinkedListNode<T>} node
  * @param {T} value
@@ -1066,6 +1067,7 @@ function addAfter(list, node, value) {
 }
 /**
  * Removes `count` nodes after the given node. The given node will not be removed.
+ *
  * @param {LinkedList<T>} list
  * @param {LinkedListNode<T>} node
  * @param {number} count
@@ -1190,7 +1192,7 @@ if (typeof global !== 'undefined') {
  * each another.
  * @global
  * @public
-*/
+ */
 
 /**
  * @typedef Grammar
@@ -1208,7 +1210,7 @@ if (typeof global !== 'undefined') {
  * @returns {void}
  * @global
  * @public
-*/
+ */
 
 /**
  * @callback HookCallback
diff --git a/components/prism-kumir.js b/components/prism-kumir.js
index 76fa06c..7d704e5 100644
--- a/components/prism-kumir.js
+++ b/components/prism-kumir.js
@@ -2,14 +2,16 @@
 
 	/**
 	 * Regular expression for characters that are not allowed in identifiers.
-	 * @type {String}
+	 *
+	 * @type {string}
 	 */
 	var nonId = /\s\x00-\x1f\x22-\x2f\x3a-\x3f\x5b-\x5e\x60\x7b-\x7e/.source;
 
 	/**
 	 * Surround a regular expression for IDs with patterns for non-ID sequences.
-	 * @param {String} pattern A regular expression for identifiers.
-	 * @param {String} [flags] The regular expression flags.
+	 *
+	 * @param {string} pattern A regular expression for identifiers.
+	 * @param {string} [flags] The regular expression flags.
 	 * @returns {RegExp} A wrapped regular expression for identifiers.
 	 */
 	function wrapId(pattern, flags) {
diff --git a/dependencies.js b/dependencies.js
index a9e25c3..ab35ae9 100644
--- a/dependencies.js
+++ b/dependencies.js
@@ -232,6 +232,7 @@ var getLoader = (function () {
 
 		/**
 		 * A set of ids of nodes which are not depended upon by any other node in the graph.
+		 *
 		 * @type {StringSet}
 		 */
 		var ends = {};
@@ -261,6 +262,7 @@ var getLoader = (function () {
 
 			/**
 			 * The value to be returned.
+			 *
 			 * @type {T}
 			 */
 			var value;
diff --git a/docs/global.html b/docs/global.html
index 0a4ffd8..550ab58 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -143,7 +143,7 @@
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1195">line 1195</a>
+        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1197">line 1197</a>
     </li></ul></dd>
     
 
@@ -274,7 +274,7 @@
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1174">line 1174</a>
+        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1176">line 1176</a>
     </li></ul></dd>
     
 
@@ -559,7 +559,7 @@ each another.</p></td>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1203">line 1203</a>
+        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1205">line 1205</a>
     </li></ul></dd>
     
 
@@ -713,7 +713,7 @@ each another.</p></td>
     
     <dt class="tag-source">Source:</dt>
     <dd class="tag-source"><ul class="dummy"><li>
-        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1213">line 1213</a>
+        <a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1215">line 1215</a>
     </li></ul></dd>
     
 
diff --git a/docs/prism-core.js.html b/docs/prism-core.js.html
index 4fe0ce3..229462b 100644
--- a/docs/prism-core.js.html
+++ b/docs/prism-core.js.html
@@ -1100,6 +1100,7 @@ function LinkedList() {
 
 /**
  * Adds a new node with the given value to the list.
+ *
  * @param {LinkedList&lt;T>} list
  * @param {LinkedListNode&lt;T>} node
  * @param {T} value
@@ -1119,6 +1120,7 @@ function addAfter(list, node, value) {
 }
 /**
  * Removes `count` nodes after the given node. The given node will not be removed.
+ *
  * @param {LinkedList&lt;T>} list
  * @param {LinkedListNode&lt;T>} node
  * @param {number} count
@@ -1243,7 +1245,7 @@ if (typeof global !== 'undefined') {
  * each another.
  * @global
  * @public
-*/
+ */
 
 /**
  * @typedef Grammar
@@ -1261,7 +1263,7 @@ if (typeof global !== 'undefined') {
  * @returns {void}
  * @global
  * @public
-*/
+ */
 
 /**
  * @callback HookCallback
diff --git a/package-lock.json b/package-lock.json
index 0694617..f13f064 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1263,6 +1263,12 @@
       "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==",
       "dev": true
     },
+    "comment-parser": {
+      "version": "1.1.2",
+      "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.1.2.tgz",
+      "integrity": "sha512-AOdq0i8ghZudnYv8RUnHrhTgafUGs61Rdz9jemU5x2lnZwAWyOq7vySo626K59e1fVKH1xSRorJwPVRLSWOoAQ==",
+      "dev": true
+    },
     "component-emitter": {
       "version": "1.3.0",
       "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
@@ -2267,6 +2273,63 @@
         }
       }
     },
+    "eslint-plugin-jsdoc": {
+      "version": "32.3.0",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.3.0.tgz",
+      "integrity": "sha512-zyx7kajDK+tqS1bHuY5sapkad8P8KT0vdd/lE55j47VPG2MeenSYuIY/M/Pvmzq5g0+3JB+P3BJGUXmHxtuKPQ==",
+      "dev": true,
+      "requires": {
+        "comment-parser": "1.1.2",
+        "debug": "^4.3.1",
+        "jsdoctypeparser": "^9.0.0",
+        "lodash": "^4.17.20",
+        "regextras": "^0.7.1",
+        "semver": "^7.3.4",
+        "spdx-expression-parse": "^3.0.1"
+      },
+      "dependencies": {
+        "debug": {
+          "version": "4.3.1",
+          "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
+          "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
+          "dev": true,
+          "requires": {
+            "ms": "2.1.2"
+          }
+        },
+        "lodash": {
+          "version": "4.17.21",
+          "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
+          "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
+          "dev": true
+        },
+        "ms": {
+          "version": "2.1.2",
+          "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
+          "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
+          "dev": true
+        },
+        "semver": {
+          "version": "7.3.5",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
+          "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
+          "dev": true,
+          "requires": {
+            "lru-cache": "^6.0.0"
+          }
+        },
+        "spdx-expression-parse": {
+          "version": "3.0.1",
+          "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz",
+          "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==",
+          "dev": true,
+          "requires": {
+            "spdx-exceptions": "^2.1.0",
+            "spdx-license-ids": "^3.0.0"
+          }
+        }
+      }
+    },
     "eslint-scope": {
       "version": "5.1.1",
       "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
@@ -3989,6 +4052,12 @@
         }
       }
     },
+    "jsdoctypeparser": {
+      "version": "9.0.0",
+      "resolved": "https://registry.npmjs.org/jsdoctypeparser/-/jsdoctypeparser-9.0.0.tgz",
+      "integrity": "sha512-jrTA2jJIL6/DAEILBEh2/w9QxCuwmvNXIry39Ay/HVfhE3o2yVV0U44blYkqdHA/OKloJEqvJy0xU+GSdE2SIw==",
+      "dev": true
+    },
     "jsdom": {
       "version": "13.2.0",
       "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-13.2.0.tgz",
@@ -5986,6 +6055,12 @@
       "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==",
       "dev": true
     },
+    "regextras": {
+      "version": "0.7.1",
+      "resolved": "https://registry.npmjs.org/regextras/-/regextras-0.7.1.tgz",
+      "integrity": "sha512-9YXf6xtW+qzQ+hcMQXx95MOvfqXFgsKDZodX3qZB0x2n5Z94ioetIITsBtvJbiOyxa/6s9AtyweBLCdPmPko/w==",
+      "dev": true
+    },
     "remove-bom-buffer": {
       "version": "3.0.0",
       "resolved": "https://registry.npmjs.org/remove-bom-buffer/-/remove-bom-buffer-3.0.0.tgz",
diff --git a/package.json b/package.json
index a6b14e0..a86c549 100755
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
     "del": "^4.1.1",
     "docdash": "^1.2.0",
     "eslint": "^7.22.0",
+    "eslint-plugin-jsdoc": "^32.3.0",
     "gulp": "^4.0.2",
     "gulp-concat": "^2.3.4",
     "gulp-header": "^2.0.7",
diff --git a/plugins/line-numbers/prism-line-numbers.js b/plugins/line-numbers/prism-line-numbers.js
index dd5cdc5..71e8b69 100644
--- a/plugins/line-numbers/prism-line-numbers.js
+++ b/plugins/line-numbers/prism-line-numbers.js
@@ -6,12 +6,14 @@
 
 	/**
 	 * Plugin name which is used as a class name for <pre> which is activating the plugin
-	 * @type {String}
+	 *
+	 * @type {string}
 	 */
 	var PLUGIN_NAME = 'line-numbers';
 
 	/**
 	 * Regular expression used for determining line breaks
+	 *
 	 * @type {RegExp}
 	 */
 	var NEW_LINE_EXP = /\n(?!$)/g;
@@ -23,9 +25,10 @@
 	var config = Prism.plugins.lineNumbers = {
 		/**
 		 * Get node for provided line number
+		 *
 		 * @param {Element} element pre element
-		 * @param {Number} number line number
-		 * @return {Element|undefined}
+		 * @param {number} number line number
+		 * @returns {Element|undefined}
 		 */
 		getLine: function (element, number) {
 			if (element.tagName !== 'PRE' || !element.classList.contains(PLUGIN_NAME)) {
@@ -55,6 +58,7 @@
 		 * Resizes the line numbers of the given element.
 		 *
 		 * This function will not add line numbers. It will only resize existing ones.
+		 *
 		 * @param {HTMLElement} element A `<pre>` element with line numbers.
 		 * @returns {void}
 		 */
@@ -169,6 +173,7 @@
 
 	/**
 	 * Returns style declarations for the element
+	 *
 	 * @param {Element} element
 	 */
 	function getStyles(element) {
diff --git a/plugins/previewers/prism-previewers.js b/plugins/previewers/prism-previewers.js
index 17e3389..a385af1 100644
--- a/plugins/previewers/prism-previewers.js
+++ b/plugins/previewers/prism-previewers.js
@@ -15,6 +15,7 @@
 
 				/**
 				 * Returns a W3C-valid linear gradient
+				 *
 				 * @param {string} prefix Vendor prefix if any ("-moz-", "-webkit-", etc.)
 				 * @param {string} func Gradient function name ("linear-gradient")
 				 * @param {string[]} values Array of the gradient function parameters (["0deg", "red 0%", "blue 100%"])
@@ -64,6 +65,7 @@
 
 				/**
 				 * Returns a W3C-valid radial gradient
+				 *
 				 * @param {string} prefix Vendor prefix if any ("-moz-", "-webkit-", etc.)
 				 * @param {string} func Gradient function name ("linear-gradient")
 				 * @param {string[]} values Array of the gradient function parameters (["0deg", "red 0%", "blue 100%"])
@@ -108,6 +110,7 @@
 				/**
 				 * Converts a gradient to a W3C-valid one
 				 * Does not support old webkit syntax (-webkit-gradient(linear...) and -webkit-gradient(radial...))
+				 *
 				 * @param {string} gradient The CSS gradient
 				 */
 				var convertToW3CGradient = function(gradient) {
@@ -461,6 +464,7 @@
 
 	/**
 	 * Returns the absolute X, Y offsets for an element
+	 *
 	 * @param {HTMLElement} element
 	 * @returns {{top: number, right: number, bottom: number, left: number, width: number, height: number}}
 	 */
@@ -488,11 +492,12 @@
 
 	/**
 	 * Previewer constructor
+	 *
 	 * @param {string} type Unique previewer type
-	 * @param {function} updater Function that will be called on mouseover.
-	 * @param {string[]|string=} supportedLanguages Aliases of the languages this previewer must be enabled for. Defaults to "*", all languages.
-	 * @param {function=} initializer Function that will be called on initialization.
-	 * @constructor
+	 * @param {Function} updater Function that will be called on mouseover.
+	 * @param {string[]|string} [supportedLanguages] Aliases of the languages this previewer must be enabled for. Defaults to "*", all languages.
+	 * @param {Function} [initializer] Function that will be called on initialization.
+	 * @class
 	 */
 	var Previewer = function (type, updater, supportedLanguages, initializer) {
 		this._elt = null;
@@ -555,6 +560,7 @@
 
 	/**
 	 * Checks the class name of each hovered element
+	 *
 	 * @param {Element} token
 	 */
 	Previewer.prototype.check = function (token) {
@@ -624,18 +630,21 @@
 
 	/**
 	 * Map of all registered previewers by language
+	 *
 	 * @type {{}}
 	 */
 	Previewer.byLanguages = {};
 
 	/**
 	 * Map of all registered previewers by type
+	 *
 	 * @type {{}}
 	 */
 	Previewer.byType = {};
 
 	/**
 	 * Initializes the mouseover event on the code block.
+	 *
 	 * @param {HTMLElement} elt The code block (env.element)
 	 * @param {string} lang The language (env.language)
 	 */
diff --git a/prism.js b/prism.js
index 2574874..95fb799 100644
--- a/prism.js
+++ b/prism.js
@@ -1052,6 +1052,7 @@ function LinkedList() {
 
 /**
  * Adds a new node with the given value to the list.
+ *
  * @param {LinkedList<T>} list
  * @param {LinkedListNode<T>} node
  * @param {T} value
@@ -1071,6 +1072,7 @@ function addAfter(list, node, value) {
 }
 /**
  * Removes `count` nodes after the given node. The given node will not be removed.
+ *
  * @param {LinkedList<T>} list
  * @param {LinkedListNode<T>} node
  * @param {number} count
@@ -1195,7 +1197,7 @@ if (typeof global !== 'undefined') {
  * each another.
  * @global
  * @public
-*/
+ */
 
 /**
  * @typedef Grammar
@@ -1213,7 +1215,7 @@ if (typeof global !== 'undefined') {
  * @returns {void}
  * @global
  * @public
-*/
+ */
 
 /**
  * @callback HookCallback
diff --git a/tests/helper/test-discovery.js b/tests/helper/test-discovery.js
index 053039a..9380e34 100644
--- a/tests/helper/test-discovery.js
+++ b/tests/helper/test-discovery.js
@@ -71,6 +71,7 @@ module.exports = {
 
 	/**
 	 * Returns whether a directory matches one of the given languages.
+	 *
 	 * @param {string} directory
 	 * @param {string|string[]} languages
 	 */
diff --git a/tests/identifier-test.js b/tests/identifier-test.js
index e69c027..bc8ef40 100644
--- a/tests/identifier-test.js
+++ b/tests/identifier-test.js
@@ -170,7 +170,7 @@ function isNotBroken(token) {
  * Tests all patterns in the given Prism instance.
  *
  * @param {any} Prism
- * @param {lang} Prism
+ * @param {string} lang
  */
 function testLiterals(Prism, lang) {