diff --git a/.eslintrc.json b/.eslintrc.json index ad14be7d..fa8eb810 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,15 +18,10 @@ "rules": { "camelcase": 0, "eqeqeq": 0, - "jsdoc/check-param-names": 0, - "jsdoc/check-tag-names": 0, - "jsdoc/no-undefined-types": 0, + "jsdoc/require-param": 0, "jsdoc/require-param-type": 0, "jsdoc/require-returns": 0, - "jsdoc/require-returns-check": 0, - "jsdoc/valid-types": 0, "max-len": 0, - "max-statements-per-line": 0, "no-console": 0, "no-global-assign": 0, "no-implicit-globals": 0, @@ -36,12 +31,7 @@ "no-undef": 0, "no-underscore-dangle": 0, "no-unused-vars": 0, - "no-use-before-define": 0, - "no-useless-concat": 0, - "no-useless-escape": 0, - "one-var": 0, - "spaced-comment": 0, - "vars-on-top": 0 + "no-use-before-define": 0 }, "settings": { "jsdoc": { diff --git a/src/afch.js b/src/afch.js index 044cd37e..3dd81cd9 100644 --- a/src/afch.js +++ b/src/afch.js @@ -1,4 +1,4 @@ -// +// ( function () { // Check that we're in the right namespace and on the right page switch ( mw.config.get( 'wgNamespaceNumber' ) ) { @@ -43,4 +43,4 @@ } } ); }() ); -// +// diff --git a/src/modules/core.js b/src/modules/core.js index 5281e531..e823cb54 100644 --- a/src/modules/core.js +++ b/src/modules/core.js @@ -1,11 +1,11 @@ -// +// ( function ( AFCH, $, mw ) { $.extend( AFCH, { /** * Log anything to the console * - * @param {anything} thing(s) + * @param {any} thing(s) */ log: function () { var args = Array.prototype.slice.call( arguments ); @@ -46,7 +46,7 @@ /** * Prepares the AFCH gadget by setting constants and checking environment * - * @return {bool} Whether or not all setup functions executed successfully + * @return {boolean} Whether or not all setup functions executed successfully */ setup: function () { // Check requirements @@ -118,7 +118,7 @@ // the script, so long as there was a user whose name was // three characters long on the list! var $howToDisable, - sanitizedUser = user.replace( /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&' ), + sanitizedUser = user.replace( /[-[\]/{}()*+?.\\^$|]/g, '\\$&' ), userSysop = $.inArray( 'sysop', mw.config.get( 'wgUserGroups' ) ) > -1, userNPP = $.inArray( 'patroller', mw.config.get( 'wgUserGroups' ) ) > -1, userOnWhitelist = ( new RegExp( '\\|\\s*' + sanitizedUser + '\\s*}' ) ).test( text ), @@ -272,7 +272,7 @@ * Makes an API request to get a variety of details about the current * revision of the page, which it then sets. * - * @param {bool} usecache if true, will resolve immediately if function has + * @param {boolean} usecache if true, will resolve immediately if function has * run successfully before * @return {jQuery.Deferred} resolves when data set successfully */ @@ -307,7 +307,7 @@ /** * Gets the page text * - * @param {bool} usecache use cache if possible + * @param {boolean} usecache use cache if possible * @return {string} */ this.getText = function ( usecache ) { @@ -392,9 +392,9 @@ /** * Gets the categories from the page * - * @param {bool} useApi If true, use the api to get categories, instead of parsing the page. This is + * @param {boolean} useApi If true, use the api to get categories, instead of parsing the page. This is * necessary if you need info about transcluded categories. - * @param {bool} includeCategoryLinks If true, will also include links to categories (e.g. [[:Category:Foo]]). + * @param {boolean} includeCategoryLinks If true, will also include links to categories (e.g. [[:Category:Foo]]). * Note that if useApi is true, includeCategoryLinks must be false. * @return {Array} */ @@ -739,7 +739,7 @@ * @param {string} newTitle Move target * @param {string} reason Reason for moving; shown in move log * @param {Object} additionalParameters https://www.mediawiki.org/wiki/API:Move#Parameters - * @param {bool} hide Don't show the move in the status display + * @param {boolean} hide Don't show the move in the status display * @return {jQuery.Deferred} Resolves with success/failure */ movePage: function ( oldTitle, newTitle, reason, additionalParameters, hide ) { @@ -794,12 +794,11 @@ * Notifies a user. Follows redirects and appends a message * to the bottom of the user's talk page. * - * @param {string} user - * @param {Object} data object with properties + * @param {string} user + * @param {Object} options object with properties * - message: {string} * - summary: {string} edit summary * - hide: {bool}, default false - * @param options * @return {jQuery.Deferred} Resolves with success/failure */ notifyUser: function ( user, options ) { @@ -867,7 +866,7 @@ } ); } - appendText += ' ~~' + '~~' + '~\n'; + appendText += ' ~~~~~\n'; logPage.edit( { contents: appendText, @@ -910,7 +909,7 @@ } var byUser = ' by [[User:' + options.submitter + '|]]'; - var sig = ' ~~' + '~~' + '~\n'; + var sig = ' ~~~~~\n'; // Make log edit logPage.edit( { @@ -1001,7 +1000,7 @@ /** * Creates the status container * - * @param {selector} location String/jQuery selector for where the + * @param {string|jQuery} location String/jQuery selector for where the * status container should be prepended */ init: function ( location ) { @@ -1103,7 +1102,7 @@ $.each( substitutions, function ( original, replacement ) { text = text.replace( // Escape the original substitution key, then make it a global regex - new RegExp( original.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ), 'g' ), + new RegExp( original.replace( /[-/\\^$*+?.()|[\]{}]/g, '\\$&' ), 'g' ), replacement ); } ); @@ -1685,7 +1684,7 @@ * @param {Array} existingWikiProjects An array of associative arrays. The associative arrays contain the keys {string} displayName (example: Somalia), {string} templateName (example: WikiProject Somalia), and {boolean} alreadyOnPage * @param {boolean} alreadyHasWPBio * @param {null} existingWPBioTemplateName - * @returns {Object} { {string} talkText, {number} countOfWikiProjectsAdded, {number} countOfWikiProjectsRemoved } + * @return {Object} { {string} talkText, {number} countOfWikiProjectsAdded, {number} countOfWikiProjectsRemoved } */ addTalkPageBanners: function ( talkText, newAssessment, revId, isBiography, newWikiProjects, lifeStatus, subjectName, existingWikiProjects, alreadyHasWPBio, existingWPBioTemplateName ) { var talkTextPrefix = ''; @@ -1711,13 +1710,13 @@ } // Add and remove WikiProjects - /** @var {Array} */ + /** @member {Array} */ var wikiProjectsToAdd = newWikiProjects.filter( function ( newTemplateName ) { return !existingWikiProjects.some( function ( existingTplObj ) { return existingTplObj.templateName === newTemplateName; } ); } ); - /** @var {Array} */ + /** @member {Array} */ var wikiProjectsToRemove = existingWikiProjects.filter( function ( existingTplObj ) { return !newWikiProjects.some( function ( newTemplateName ) { return existingTplObj.templateName === newTemplateName; @@ -1841,7 +1840,7 @@ * * @param {string} string string to parse * @param mwstyle - * @return {Date|integer} + * @return {Date|number} */ parseForTimestamp: function ( string, mwstyle ) { var exp, match, date; @@ -1875,7 +1874,7 @@ * Parses a MediaWiki internal YYYYMMDDHHMMSS timestamp * * @param {string} string - * @return {Date|bool} if unable to parse, returns false + * @return {Date|boolean} if unable to parse, returns false */ mwTimestampToDate: function ( string ) { var date, dateMatches = /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/.exec( string ); @@ -1950,4 +1949,4 @@ } ); }( AFCH, jQuery, mediaWiki ) ); -// +// diff --git a/src/modules/submissions.js b/src/modules/submissions.js index ae049460..9e9e5a81 100644 --- a/src/modules/submissions.js +++ b/src/modules/submissions.js @@ -1,4 +1,4 @@ -// +// ( function ( AFCH, $, mw ) { var $afchLaunchLink, $afch, $afchWrapper, afchPage, afchSubmission, afchViews, afchViewer; @@ -365,9 +365,8 @@ * Sets the submission status * * @param {string} newStatus status to set, 'd'|'t'|'r'|'' - * @param {params} optional; params to add to the template whose status was set - * @param newParams - * @return {bool} success + * @param {Object} newParams optional; params to add to the template whose status was set + * @return {boolean} success */ AFCH.Submission.prototype.setStatus = function ( newStatus, newParams ) { var relevantTemplate = this.templates[ 0 ]; @@ -431,7 +430,7 @@ * Add a new comment to the beginning of this.comments * * @param {string} text comment text - * @return {bool} success + * @return {boolean} success */ AFCH.Submission.prototype.addNewComment = function ( text ) { var commentText = addSignature( text ); @@ -491,8 +490,6 @@ /** * Represents text of an AfC submission - * - * @param {[type]} text [description] */ AFCH.Text = function ( text ) { this.text = text; @@ -529,7 +526,7 @@ 'Once you have saved this page you will find a new yellow \'Review waiting\' box at the bottom of your submission page. ' + 'If you have submitted your page previously,(?: either)? the old pink \'Submission declined\' template or the old grey ' + '\'Draft\' template will still appear at the top of your submission page, but you should ignore (them|it). Again, please ' + - 'don\'t change anything in this text box. Just press the \"Save page\" button below.' + 'don\'t change anything in this text box. Just press the "Save page" button below.' ]; if ( isAccept ) { @@ -540,7 +537,7 @@ // Not removed if the |text= parameter is present, which could contain // arbitrary wikitext and therefore makes the end of the template harder // to detect - text = text.replace( /\{\{Draft(?!\|\s*text\s*=)(?: article(?!\|\s*text\s*=)(?:\|(?:subject=)?[^\|]+)?|\|(?:subject=)?[^\|]+)?\}\}/gi, '' ); + text = text.replace( /\{\{Draft(?!\|\s*text\s*=)(?: article(?!\|\s*text\s*=)(?:\|(?:subject=)?[^|]+)?|\|(?:subject=)?[^|]+)?\}\}/gi, '' ); // Uncomment cats and templates text = text.replace( /\[\[:Category:/gi, '[[Category:' ); @@ -591,21 +588,21 @@ text = text.replace( //gi, '$1' ); // Remove spaces/commas between tags - text = text.replace( /\s*(<\/\s*ref\s*\>)\s*[,]*\s*(<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>)[ \t]*$/gim, '$1$2' ); + text = text.replace( /\s*(<\/\s*ref\s*>)\s*[,]*\s*(<\s*ref\s*(name\s*=|group\s*=)*\s*[^/]*>)[ \t]*$/gim, '$1$2' ); // Remove whitespace before tags - text = text.replace( /[ \t]*(<\s*ref\s*(name\s*=|group\s*=)*\s*.*[^\/]+>)[ \t]*$/gim, '$1' ); + text = text.replace( /[ \t]*(<\s*ref\s*(name\s*=|group\s*=)*\s*.*[^/]+>)[ \t]*$/gim, '$1' ); // Move punctuation before tags - text = text.replace( /\s*((<\s*ref\s*(name\s*=|group\s*=)*\s*.*[\/]{1}>)|(<\s*ref\s*(name\s*=|group\s*=)*\s*[^\/]*>(?:<[^<\>]*\>|[^><])*<\/\s*ref\s*\>))[ \t]*([.!?,;:])+$/gim, '$6$1' ); + text = text.replace( /\s*((<\s*ref\s*(name\s*=|group\s*=)*\s*.*[/]{1}>)|(<\s*ref\s*(name\s*=|group\s*=)*\s*[^/]*>(?:<[^<>]*>|[^><])*<\/\s*ref\s*>))[ \t]*([.!?,;:])+$/gim, '$6$1' ); // Replace {{http://example.com/foo}} with "* http://example.com/foo" (common newbie error) - text = text.replace( /\n\{\{(http[s]?|ftp[s]?|irc|gopher|telnet)\:\/\/(.*?)\}\}/gi, '\n* $1://$3' ); + text = text.replace( /\n\{\{(http[s]?|ftp[s]?|irc|gopher|telnet):\/\/(.*?)\}\}/gi, '\n* $1://$3' ); // Convert http://-style links to other wikipages to wikicode syntax // FIXME: Break this out into its own core function? Will it be used elsewhere? function convertExternalLinksToWikilinks( text ) { - var linkRegex = /\[{1,2}(?:https?:)?\/\/(?:en.wikipedia.org\/wiki|enwp.org)\/([^\s\|\]\[]+)(?:\s|\|)?((?:\[\[[^\[\]]*\]\]|[^\]\[])*)\]{1,2}/ig, + var linkRegex = /\[{1,2}(?:https?:)?\/\/(?:en.wikipedia.org\/wiki|enwp.org)\/([^\s|\][]+)(?:\s|\|)?((?:\[\[[^[\]]*\]\]|[^\][])*)\]{1,2}/ig, linkMatch = linkRegex.exec( text ), title, displayTitle, newLink; @@ -673,8 +670,7 @@ * Removes old submission templates/comments and then adds new ones * specified by `new` * - * @param {string} new - * @param newCode + * @param {string} newCode */ AFCH.Text.prototype.updateAfcTemplates = function ( newCode ) { this.removeAfcTemplates(); @@ -908,12 +904,24 @@ AFCH.preferences.initLink( $afch.find( 'span.preferences-wrapper' ), 'preferences' ); // Set up click handlers - $afch.find( '#afchAccept' ).click( function () { spinnerAndRun( showAcceptOptions ); } ); - $afch.find( '#afchDecline' ).click( function () { spinnerAndRun( showDeclineOptions ); } ); - $afch.find( '#afchComment' ).click( function () { spinnerAndRun( showCommentOptions ); } ); - $afch.find( '#afchSubmit' ).click( function () { spinnerAndRun( showSubmitOptions ); } ); - $afch.find( '#afchClean' ).click( function () { handleCleanup(); } ); - $afch.find( '#afchMark' ).click( function () { handleMark( /* unmark */ submission.isUnderReview ); } ); + $afch.find( '#afchAccept' ).click( function () { + spinnerAndRun( showAcceptOptions ); + } ); + $afch.find( '#afchDecline' ).click( function () { + spinnerAndRun( showDeclineOptions ); + } ); + $afch.find( '#afchComment' ).click( function () { + spinnerAndRun( showCommentOptions ); + } ); + $afch.find( '#afchSubmit' ).click( function () { + spinnerAndRun( showSubmitOptions ); + } ); + $afch.find( '#afchClean' ).click( function () { + handleCleanup(); + } ); + $afch.find( '#afchMark' ).click( function () { + handleMark( /* unmark */ submission.isUnderReview ); + } ); // Load warnings about the page, then slide them in getSubmissionWarnings().done( function ( warnings ) { @@ -931,8 +939,12 @@ // but don't hold up the rest of the loading to do so submission.isG13Eligible().done( function ( eligible ) { $afch.find( '.g13-related' ).toggleClass( 'hidden', !eligible ); - $afch.find( '#afchG13' ).click( function () { handleG13(); } ); - $afch.find( '#afchPostponeG13' ).click( function () { spinnerAndRun( showPostponeG13Options ); } ); + $afch.find( '#afchG13' ).click( function () { + handleG13(); + } ); + $afch.find( '#afchPostponeG13' ).click( function () { + spinnerAndRun( showPostponeG13Options ); + } ); } ); } ); } @@ -950,7 +962,7 @@ * Adds a warning * * @param {string} message - * @param {string|bool} actionMessage set to false to hide action link + * @param {string|boolean} actionMessage set to false to hide action link * @param {Function|string} onAction function to call on success, or URL to browse to */ function addWarning( message, actionMessage, onAction ) { @@ -988,7 +1000,7 @@ return ref.indexOf( '/>', ref.length - 2 ) === -1; } ), - refEndRe = /<\/\s*ref\s*\>/ig, + refEndRe = /<\/\s*ref\s*>/ig, refEndMatches = text.match( refEndRe ) || [], reflistRe = /({{(ref(erence)?(\s|-)?list|listaref|refs|footnote|reference|referencias)(?:{{[^{}]*}}|[^}{])*}})|(<\s*references\s*\/?>)/ig, @@ -996,7 +1008,7 @@ // This isn't as good as a tokenizer, and believes that foo is // completely correct... but it's a good intermediate level solution. - malformedRefs = text.match( /<\s*ref\s*[^\/]*>?<\s*[^\/]*\s*ref\s*>/ig ) || []; + malformedRefs = text.match( /<\s*ref\s*[^/]*>?<\s*[^/]*\s*ref\s*>/ig ) || []; // Uneven (/unclosed) and tags if ( refBeginMatches.length !== refEndMatches.length ) { @@ -1009,7 +1021,7 @@ addWarning( 'The submission contains malformed tags.', 'View details', function () { var $toggleLink = $( this ).addClass( 'malformed-refs-toggle' ), $warningDiv = $( this ).parent(); - $malformedRefWrapper = $( '
' ) + var $malformedRefWrapper = $( '
' ) .addClass( 'malformed-refs' ) .appendTo( $warningDiv ); @@ -1135,7 +1147,7 @@ // Simulate cleanUp first so that we don't warn about HTML // comments that the script will remove anyway in the future text = ( new AFCH.Text( rawText ) ).cleanUp( true ), - longCommentRegex = /(?:)?/g, + longCommentRegex = /(?:)?/g, longCommentMatches = text.match( longCommentRegex ) || [], numberOfComments = longCommentMatches.length, oneComment = numberOfComments === 1; @@ -1227,7 +1239,7 @@ // $1 = article name // $2 = article class or '' if not available 'accepted-submission': headerBegin + - '[[$1]] has been accepted ==\n{{subst:Afc talk|$1|class=$2|sig=~~' + '~~}}', + '[[$1]] has been accepted ==\n{{subst:Afc talk|$1|class=$2|sig=~~~~}}', // $1 = full submission title // $2 = short title @@ -1254,9 +1266,9 @@ 'comment-on-submission': '{{subst:AFC notification|comment|article=$1}}', // $1 = article name - 'g13-submission': '{{subst:Db-afc-notice|$1}} ~~' + '~~', + 'g13-submission': '{{subst:Db-afc-notice|$1}} ~~~~', - 'teahouse-invite': '{{subst:Wikipedia:Teahouse/AFC invitation|sign=~~' + '~~}}' + 'teahouse-invite': '{{subst:Wikipedia:Teahouse/AFC invitation|sign=~~~~}}' } ); } @@ -1387,7 +1399,6 @@ * calls the passed function * * @param {Function} fn function to call when spinner has been displayed - * @return {[type]} [description] */ function spinnerAndRun( fn ) { var $spinner, $container = $afch.find( '#afchContent' ); @@ -1513,7 +1524,9 @@ // If any templates weren't in the WikiProject map, check if they were redirects if ( otherTemplates.length > 0 ) { - var titles = otherTemplates.map( function ( n ) { return 'Template:' + n; } ); + var titles = otherTemplates.map( function ( n ) { + return 'Template:' + n; + } ); titles = titles.slice( 0, 50 ); // prevent API error by capping max # of titles at 50 titles = titles.join( '|' ); return AFCH.api.post( { @@ -1569,7 +1582,9 @@ if ( !hasWikiProjects ) { mw.notify( 'Could not load WikiProject list!' ); } - var wikiProjectObjs = Object.keys( wikiProjectMap ).map( function ( key ) { return wikiProjectMap[ key ]; } ); + var wikiProjectObjs = Object.keys( wikiProjectMap ).map( function ( key ) { + return wikiProjectMap[ key ]; + } ); loadView( 'accept', { newTitle: afchSubmission.shortTitle, @@ -1906,7 +1921,9 @@ declineCounts = AFCH.userData.get( 'decline-counts', false ); if ( declineCounts ) { - declineList = $.map( declineCounts, function ( _, key ) { return key; } ); + var declineList = $.map( declineCounts, function ( _, key ) { + return key; + } ); // Sort list in descending order (most-used at beginning) declineList.sort( function ( a, b ) { @@ -2105,8 +2122,8 @@ function addSignature( text ) { text = text.trim(); - if ( text.indexOf( '~~' + '~~' ) === -1 ) { - text += ' ~~' + '~~'; + if ( text.indexOf( '~~~~' ) === -1 ) { + text += ' ~~~~'; } return text; } @@ -2868,7 +2885,7 @@ text = data.afchText, rawText = text.get(), postponeRegex = /\{\{AfC postpone G13\s*(?:\|\s*(\d*)\s*)?\}\}/ig; - match = postponeRegex.exec( rawText ); + var match = postponeRegex.exec( rawText ); // First add the postpone template if ( match ) { @@ -2899,4 +2916,4 @@ } }( AFCH, jQuery, mediaWiki ) ); -// +// diff --git a/src/templates/tpl-preferences.html b/src/templates/tpl-preferences.html index 346f2151..4e468eb6 100644 --- a/src/templates/tpl-preferences.html +++ b/src/templates/tpl-preferences.html @@ -1,4 +1,4 @@ -// +//
@@ -37,4 +37,4 @@
-//
+//
diff --git a/src/templates/tpl-submissions.html b/src/templates/tpl-submissions.html index 0f24ad56..145d5051 100644 --- a/src/templates/tpl-submissions.html +++ b/src/templates/tpl-submissions.html @@ -1,4 +1,4 @@ -// +//
@@ -382,4 +382,4 @@
-//
+//