Skip to content

Commit 9ed92fa

Browse files
committed
Build/Test Tools: Enable JSDocs to be linted with ESLint.
As part of the [Javascript Inline Docs Initiative](https://make.wordpress.org/core/handbook/docs/inline/js/) this add some tooling to lint Javascript docblocks. Two new commands: * `npm run lint:jsdoc` * `npm run lint:jsdoc:fix` The latter will run the linter and try to fix an possible issues automatically. Fixes #43828. Props netweb, atimmer, kamataryo, whyisjake. git-svn-id: https://develop.svn.wordpress.org/trunk@48650 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a1a1173 commit 9ed92fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+394
-348
lines changed

.eslintignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Files and folders related to build/test tools
2+
/build
3+
/node_modules
4+
/tests
5+
/vendor
6+
/tools
7+
8+
# Excluded files and folders based on `jsdoc.conf.json` exclusions
9+
/src/js/_enqueues/vendor
10+
11+
# Webpack built files
12+
/src/wp-includes/js/media-*
13+
14+
# Themes
15+
src/wp-content/themes/

.eslintrc-jsdoc.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
rules: {
3+
'require-jsdoc': 'off',
4+
'valid-jsdoc': [ 'error', {
5+
prefer: {
6+
arg: 'param',
7+
argument: 'param',
8+
extends: 'augments',
9+
returns: 'return',
10+
},
11+
preferType: {
12+
array: 'Array',
13+
bool: 'boolean',
14+
Boolean: 'boolean',
15+
float: 'number',
16+
Float: 'number',
17+
int: 'number',
18+
integer: 'number',
19+
Integer: 'number',
20+
Number: 'number',
21+
object: 'Object',
22+
String: 'string',
23+
Void: 'void',
24+
},
25+
requireParamDescription: false,
26+
requireReturn: false,
27+
} ],
28+
},
29+
};

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@
155155
"test": "grunt test",
156156
"watch": "grunt watch",
157157
"grunt": "grunt",
158+
"lint:jsdoc": "wp-scripts lint-js",
159+
"lint:jsdoc:fix": "wp-scripts lint-js --fix",
158160
"env:start": "node ./tools/local-env/scripts/start.js",
159161
"env:stop": "node ./tools/local-env/scripts/docker.js down",
160162
"env:restart": "npm run env:stop && npm run env:start",

src/js/_enqueues/admin/common.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ window.columns = {
137137
*
138138
* @since 3.1.0
139139
*
140-
* @param {int} diff The modifier for the column span.
140+
* @param {number} diff The modifier for the column span.
141141
*/
142142
colSpanChange : function(diff) {
143143
var $t = $('table').find('.colspanchange'), n;
@@ -384,7 +384,7 @@ $permalinkStructure.on( 'focus', function( event ) {
384384
* If the structure is already used in the custom permalink structure,
385385
* it will be disabled.
386386
*
387-
* @param {object} button Button jQuery object.
387+
* @param {Object} button Button jQuery object.
388388
*/
389389
function changeStructureTagButtonState( button ) {
390390
if ( -1 !== $permalinkStructure.val().indexOf( button.text().trim() ) ) {

src/js/_enqueues/admin/edit-comments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ var getCount, updateCount, updateCountText, updatePending, updateApproved,
159159
*
160160
* @since 5.2.0
161161
*
162-
* @param {object} response Ajax response from the server that includes a
162+
* @param {Object} response Ajax response from the server that includes a
163163
* translated "comments in moderation" message.
164164
*
165165
* @return {void}

src/js/_enqueues/admin/inline-edit-post.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ window.wp = window.wp || {};
389389
*
390390
* @since 2.7.0
391391
*
392-
* @param {int} id The ID for the post that has been changed.
392+
* @param {number} id The ID for the post that has been changed.
393393
* @return {boolean} False, so the form does not submit when pressing
394394
* Enter on a focused field.
395395
*/

src/js/_enqueues/admin/post.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ window.wp = window.wp || {};
3434
*
3535
* @memberof commentsBox
3636
*
37-
* @param {int} total Total number of comments for this post.
38-
* @param {int} num Optional. Number of comments to fetch, defaults to 20.
37+
* @param {number} total Total number of comments for this post.
38+
* @param {number} num Optional. Number of comments to fetch, defaults to 20.
3939
* @return {boolean} Always returns false.
4040
*/
4141
get : function(total, num) {
@@ -94,7 +94,7 @@ window.wp = window.wp || {};
9494
*
9595
* @memberof commentsBox
9696
*
97-
* @param {int} total Total number of comments to load.
97+
* @param {number} total Total number of comments to load.
9898
*/
9999
load: function(total){
100100
this.st = jQuery('#the-comment-list tr.comment:visible').length;
@@ -116,7 +116,7 @@ window.wp = window.wp || {};
116116
/**
117117
* Set the Image ID of the Featured Image
118118
*
119-
* @param {int} id The post_id of the image to use as Featured Image.
119+
* @param {number} id The post_id of the image to use as Featured Image.
120120
*
121121
* @global
122122
*/

src/js/_enqueues/admin/postbox.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@
154154
* @since 5.5.0
155155
*
156156
* @param {string} position The "previous" or "next" sortables area.
157-
* @param {object} button The jQuery object representing the button that was clicked.
158-
* @param {object} postbox The jQuery object representing the postbox to be moved.
157+
* @param {Object} button The jQuery object representing the button that was clicked.
158+
* @param {Object} postbox The jQuery object representing the postbox to be moved.
159159
*
160160
* @return {void}
161161
*/

src/js/_enqueues/admin/tags-suggest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
*
3131
* @since 4.7.0
3232
*
33-
* @param {object} options Options that are passed to UI Autocomplete. Can be used to override the default settings.
34-
* @return {object} jQuery instance.
33+
* @param {Object} options Options that are passed to UI Autocomplete. Can be used to override the default settings.
34+
* @return {Object} jQuery instance.
3535
*/
3636
$.fn.wpTagsSuggest = function( options ) {
3737
var cache;

src/js/_enqueues/admin/widgets.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ window.wpWidgets = {
234234
*
235235
* @ignore
236236
*
237-
* @param {object} event jQuery event object.
237+
* @param {Object} event jQuery event object.
238238
*/
239239
over: function( event ) {
240240
var $wrap = $( event.target ).parent();
@@ -259,7 +259,7 @@ window.wpWidgets = {
259259
*
260260
* @ignore
261261
*
262-
* @param {object} event jQuery event object.
262+
* @param {Object} event jQuery event object.
263263
*/
264264
out: function( event ) {
265265
if ( wpWidgets.hoveredSidebar ) {
@@ -729,7 +729,7 @@ window.wpWidgets = {
729729
*
730730
* Used when a Widget gets dragged in/out of the Sidebar and never dropped.
731731
*
732-
* @param {object} event jQuery event object.
732+
* @param {Object} event jQuery event object.
733733
*/
734734
closeSidebar: function( event ) {
735735
this.hoveredSidebar

src/js/_enqueues/lib/admin-bar.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@
294294
* @since 5.3.1
295295
*
296296
* @param {HTMLElement} element The HTML element.
297-
* @param {String} className The class name.
298-
* @return {bool} Whether the element has the className.
297+
* @param {string} className The class name.
298+
* @return {boolean} Whether the element has the className.
299299
*/
300300
function hasClass( element, className ) {
301301
var classNames;
@@ -320,7 +320,7 @@
320320
* @since 5.3.1
321321
*
322322
* @param {HTMLElement} element The HTML element.
323-
* @param {String} className The class name.
323+
* @param {string} className The class name.
324324
*/
325325
function addClass( element, className ) {
326326
if ( ! element ) {
@@ -344,7 +344,7 @@
344344
* @since 5.3.1
345345
*
346346
* @param {HTMLElement} element The HTML element.
347-
* @param {String} className The class name.
347+
* @param {string} className The class name.
348348
*/
349349
function removeClass( element, className ) {
350350
var testName,

src/js/_enqueues/lib/comment-reply.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ window.addComment = ( function( window ) {
265265
* @since 5.1.0
266266
*
267267
* @param {HTMLElement} Element DOM element with the attribute.
268-
* @param {String} Attribute the attribute to get.
268+
* @param {string} Attribute the attribute to get.
269269
*
270-
* @return {String}
270+
* @return {string}
271271
*/
272272
function getDataAttribute( element, attribute ) {
273273
if ( supportsDataset ) {
@@ -298,11 +298,11 @@ window.addComment = ( function( window ) {
298298
*
299299
* @memberOf addComment
300300
*
301-
* @param {String} addBelowId HTML ID of element the form follows.
302-
* @param {String} commentId Database ID of comment being replied to.
303-
* @param {String} respondId HTML ID of 'respond' element.
304-
* @param {String} postId Database ID of the post.
305-
* @param {String} replyTo Form heading content.
301+
* @param {string} addBelowId HTML ID of element the form follows.
302+
* @param {string} commentId Database ID of comment being replied to.
303+
* @param {string} respondId HTML ID of 'respond' element.
304+
* @param {string} postId Database ID of the post.
305+
* @param {string} replyTo Form heading content.
306306
*/
307307
function moveForm( addBelowId, commentId, respondId, postId, replyTo ) {
308308
// Get elements based on their IDs.

src/js/_enqueues/lib/image-edit.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
* @memberof imageEdit
7474
*
7575
* @param {jQuery} el The element that should be modified.
76-
* @param {bool|number} s The state for the element. If set to true
76+
* @param {boolean|number} s The state for the element. If set to true
7777
* the element is disabled,
7878
* otherwise the element is enabled.
7979
* The function is sometimes called with a 0 or 1
@@ -577,7 +577,7 @@
577577
*
578578
* @param {number} postid The post ID for the image.
579579
* @param {string} nonce The nonce to verify the request.
580-
* @param {object} view The image editor view to be used for the editing.
580+
* @param {Object} view The image editor view to be used for the editing.
581581
*
582582
* @return {void|promise} Either returns void if the button was already activated
583583
* or returns an instance of the image editor, wrapped in a promise.
@@ -774,10 +774,10 @@
774774
*
775775
* @ignore
776776
*
777-
* @param {object} img jQuery object representing the image.
778-
* @param {object} c The selection.
777+
* @param {Object} img jQuery object representing the image.
778+
* @param {Object} c The selection.
779779
*
780-
* @return {object}
780+
* @return {Object}
781781
*/
782782
onSelectEnd: function(img, c) {
783783
imageEdit.setCropSelection(postid, c);
@@ -788,8 +788,8 @@
788788
*
789789
* @ignore
790790
*
791-
* @param {object} img jQuery object representing the image.
792-
* @param {object} c The selection.
791+
* @param {Object} img jQuery object representing the image.
792+
* @param {Object} c The selection.
793793
*
794794
* @return {void}
795795
*/
@@ -809,7 +809,7 @@
809809
* @memberof imageEdit
810810
*
811811
* @param {number} postid The post ID.
812-
* @param {object} c The selection.
812+
* @param {Object} c The selection.
813813
*
814814
* @return {boolean}
815815
*/
@@ -841,9 +841,9 @@
841841
* @memberof imageEdit
842842
*
843843
* @param {number} postid The post ID.
844-
* @param {bool} warn Warning message.
844+
* @param {boolean} warn Warning message.
845845
*
846-
* @return {void|bool} Returns false if there is a warning.
846+
* @return {void|boolean} Returns false if there is a warning.
847847
*/
848848
close : function(postid, warn) {
849849
warn = warn || false;
@@ -908,7 +908,7 @@
908908
*
909909
* @memberof imageEdit
910910
*
911-
* @param {object} op The original position.
911+
* @param {Object} op The original position.
912912
* @param {number} postid The post ID.
913913
* @param {string} nonce The nonce.
914914
*
@@ -945,7 +945,7 @@
945945
* @param {string} angle The angle the image is rotated with.
946946
* @param {number} postid The post ID.
947947
* @param {string} nonce The nonce.
948-
* @param {object} t The target element.
948+
* @param {Object} t The target element.
949949
*
950950
* @return {boolean}
951951
*/
@@ -967,7 +967,7 @@
967967
* @param {number} axis The axle the image is flipped on.
968968
* @param {number} postid The post ID.
969969
* @param {string} nonce The nonce.
970-
* @param {object} t The target element.
970+
* @param {Object} t The target element.
971971
*
972972
* @return {boolean}
973973
*/
@@ -988,7 +988,7 @@
988988
*
989989
* @param {number} postid The post ID.
990990
* @param {string} nonce The nonce.
991-
* @param {object} t The target object.
991+
* @param {Object} t The target object.
992992
*
993993
* @return {void|boolean} Returns false if the crop button is disabled.
994994
*/

src/js/_enqueues/lib/lists.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ wpList = {
202202
* 6. 0 if none can be found.
203203
*
204204
* @param {jQuery} element Element that triggered the request.
205-
* @param {object} settings Settings for the Ajax request.
205+
* @param {Object} settings Settings for the Ajax request.
206206
* @return {string|number} Nonce
207207
*/
208208
nonce: function( element, settings ) {
@@ -258,9 +258,9 @@ wpList = {
258258
* Calls a confirm callback to verify the action that is about to be performed.
259259
*
260260
* @param {HTMLElement} list The DOM element.
261-
* @param {object} settings Settings for this list.
261+
* @param {Object} settings Settings for this list.
262262
* @param {string} action The type of action to perform: 'add', 'delete', or 'dim'.
263-
* @return {object|boolean} Settings if confirmed, false if not.
263+
* @return {Object|boolean} Settings if confirmed, false if not.
264264
*/
265265
pre: function( list, settings, action ) {
266266
var $element, backgroundColor, confirmed;
@@ -297,7 +297,7 @@ wpList = {
297297
* Adds an item to the list via Ajax.
298298
*
299299
* @param {HTMLElement} element The DOM element.
300-
* @param {object} settings Settings for this list.
300+
* @param {Object} settings Settings for this list.
301301
* @return {boolean} Whether the item was added.
302302
*/
303303
ajaxAdd: function( element, settings ) {
@@ -399,7 +399,7 @@ wpList = {
399399
* Delete an item in the list via Ajax.
400400
*
401401
* @param {HTMLElement} element A DOM element containing item data.
402-
* @param {object} settings Settings for this list.
402+
* @param {Object} settings Settings for this list.
403403
* @return {boolean} Whether the item was deleted.
404404
*/
405405
ajaxDel: function( element, settings ) {
@@ -486,7 +486,7 @@ wpList = {
486486
* Dim an item in the list via Ajax.
487487
*
488488
* @param {HTMLElement} element A DOM element containing item data.
489-
* @param {object} settings Settings for this list.
489+
* @param {Object} settings Settings for this list.
490490
* @return {boolean} Whether the item was dim'ed.
491491
*/
492492
ajaxDim: function( element, settings ) {
@@ -621,7 +621,7 @@ wpList = {
621621
* Adds something.
622622
*
623623
* @param {HTMLElement} element A DOM element containing item data.
624-
* @param {object} settings Settings for this list.
624+
* @param {Object} settings Settings for this list.
625625
* @return {boolean} Whether the item was added.
626626
*/
627627
add: function( element, settings ) {

0 commit comments

Comments
 (0)