From a6afebb6dbec68e115f40815ff592ee749361a5c Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:41:14 -0800 Subject: [PATCH 1/8] tests: turn on eslint (#2123) * tests: turn on eslint I had it off. I guess because it needs a different config (wikimedia/server). This patch sets that up. Will run autofixes in the next patch. Should be able to get rid of a bunch of rule exceptions by running the autofixes. * add rule exception --- .eslintignore | 1 - tests/.eslintrc.json | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/.eslintrc.json diff --git a/.eslintignore b/.eslintignore index c56157704..9d2449b36 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,2 @@ scripts/ -tests/ lib/ diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json new file mode 100644 index 000000000..05e943f8e --- /dev/null +++ b/tests/.eslintrc.json @@ -0,0 +1,31 @@ +{ + "extends": [ + "wikimedia/server" + ], + "env": { + "jest": true + }, + "root": true, + "rules": { + "array-bracket-spacing": "off", + "computed-property-spacing": "off", + "no-shadow": "off", + "object-curly-spacing": "off", + "space-in-parens": "off", + + "camelcase": "warn", + "comma-dangle": "warn", + "eol-last": "warn", + "new-cap": "warn", + "prefer-arrow-callback": "warn", + "prefer-const": "warn", + "no-trailing-spaces": "warn", + "no-undef": "warn", + "no-useless-escape": "warn", + "no-var": "warn", + "semi": "warn", + "strict": "warn", + "quotes": "warn", + "unicorn/prefer-date-now": "warn" + } +} From ad012f7c1104f34f7bac408bbab7e06019266d24 Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:46:17 -0800 Subject: [PATCH 2/8] eslint: replace es-x/no-array-prototype-includes with unicorn/prefer-includes (#2125) * eslint: turn off es-x/no-array-prototype-includes after discussion in #2101 * turn on unicorn/prefer-includes * more autofixes * fix linter error --- .eslintrc.json | 3 ++- modules/twinklebatchdelete.js | 2 +- modules/twinkleblock.js | 6 ++--- modules/twinkleconfig.js | 8 +++---- modules/twinkleimage.js | 2 +- modules/twinkleprod.js | 2 +- modules/twinkleprotect.js | 6 ++--- modules/twinklerollback.js | 28 +++++++++++------------ modules/twinklespeedy.js | 38 +++++++++++++++---------------- modules/twinkletag.js | 42 +++++++++++++++++------------------ modules/twinkleunlink.js | 4 ++-- modules/twinklewarn.js | 4 ++-- modules/twinklexfd.js | 22 +++++++++--------- morebits.js | 26 +++++++++++----------- twinkle.js | 4 ++-- 15 files changed, 99 insertions(+), 98 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index e3f7dd7bb..2df51e665 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,6 +13,7 @@ "rules": { "array-bracket-spacing": "off", "computed-property-spacing": "off", + "es-x/no-array-prototype-includes": "off", "indent": "off", "jsdoc/require-param": "off", "jsdoc/require-returns": "off", @@ -38,9 +39,9 @@ "selector": "MemberExpression > Identifier[name=\"fail\"]" } ], + "unicorn/prefer-includes": "error", "camelcase": ["warn", {"properties": "never"}], - "es-x/no-array-prototype-includes": "warn", "es-x/no-object-values": "warn", "mediawiki/class-doc": "warn", "new-cap": "warn", diff --git a/modules/twinklebatchdelete.js b/modules/twinklebatchdelete.js index 11a4b0940..59872c2fc 100644 --- a/modules/twinklebatchdelete.js +++ b/modules/twinklebatchdelete.js @@ -305,7 +305,7 @@ Twinkle.batchdelete.callback.toggleSubpages = function twDbatchToggleSubpages(e) const pageTitle = mw.Title.newFromText(pageName); // No need to look for subpages in main/file/mediawiki space - if ([0, 6, 8].indexOf(pageTitle.namespace) > -1) { + if ([0, 6, 8].includes(pageTitle.namespace)) { subpageLister.workerSuccess(); return; } diff --git a/modules/twinkleblock.js b/modules/twinkleblock.js index f4342aa1c..49b410e9b 100644 --- a/modules/twinkleblock.js +++ b/modules/twinkleblock.js @@ -170,7 +170,7 @@ Twinkle.block.processUserInfo = function twinkleblockProcessUserInfo(data, fn) { Twinkle.block.isRegistered = !!userinfo.userid; if (Twinkle.block.isRegistered) { - Twinkle.block.userIsBot = !!userinfo.groupmemberships && userinfo.groupmemberships.map((e) => e.group).indexOf('bot') !== -1; + Twinkle.block.userIsBot = !!userinfo.groupmemberships && userinfo.groupmemberships.map((e) => e.group).includes('bot'); } else { Twinkle.block.userIsBot = false; } @@ -1548,7 +1548,7 @@ Twinkle.block.callback.toggle_see_alsos = function twinkleblockCallbackToggleSee if (!Twinkle.block.seeAlsos.length) { this.form.reason.value = reason; - } else if (reason.indexOf('{{') !== -1) { + } else if (reason.includes('{{')) { this.form.reason.value = reason + ' '; } else { this.form.reason.value = reason + '; see also ' + seeAlsoMessage; @@ -1760,7 +1760,7 @@ Twinkle.block.callback.evaluate = function twinkleblockCallbackEvaluate(e) { if (toBlock) { if (blockoptions.partial) { - if (blockoptions.disabletalk && blockoptions.namespacerestrictions.indexOf('3') === -1) { + if (blockoptions.disabletalk && !blockoptions.namespacerestrictions.includes('3')) { return alert('Partial blocks cannot prevent talk page access unless also restricting them from editing User talk space!'); } if (!blockoptions.namespacerestrictions && !blockoptions.pagerestrictions) { diff --git a/modules/twinkleconfig.js b/modules/twinkleconfig.js index c88e74ebf..2f83cc6bc 100644 --- a/modules/twinkleconfig.js +++ b/modules/twinkleconfig.js @@ -1171,12 +1171,12 @@ Twinkle.config.init = function twinkleconfigInit() { check.setAttribute('type', 'checkbox'); check.setAttribute('id', pref.name + '_' + itemkey); check.setAttribute('name', pref.name + '_' + itemkey); - if (gotPref && gotPref.indexOf(itemkey) !== -1) { + if (gotPref && gotPref.includes(itemkey)) { check.setAttribute('checked', 'checked'); } // cater for legacy integer array values for unlinkNamespaces (this can be removed a few years down the track...) if (pref.name === 'unlinkNamespaces') { - if (gotPref && gotPref.indexOf(parseInt(itemkey, 10)) !== -1) { + if (gotPref && gotPref.includes(parseInt(itemkey, 10))) { check.setAttribute('checked', 'checked'); } } @@ -1314,7 +1314,7 @@ Twinkle.config.init = function twinkleconfigInit() { box.appendChild(document.createTextNode(', or by editing this page.')); $(box).insertAfter($('#contentSub')); - } else if (['monobook', 'vector', 'vector-2022', 'cologneblue', 'modern', 'timeless', 'minerva', 'common'].indexOf(scriptPageName) !== -1) { + } else if (['monobook', 'vector', 'vector-2022', 'cologneblue', 'modern', 'timeless', 'minerva', 'common'].includes(scriptPageName)) { // place "Looking for Twinkle options?" notice box.setAttribute('class', 'config-userskin-box'); @@ -1537,7 +1537,7 @@ Twinkle.config.resetPref = function twinkleconfigResetPref(pref) { case 'set': $.each(pref.setValues, (itemkey) => { if (document.getElementById(pref.name + '_' + itemkey)) { - document.getElementById(pref.name + '_' + itemkey).checked = Twinkle.defaultConfig[pref.name].indexOf(itemkey) !== -1; + document.getElementById(pref.name + '_' + itemkey).checked = Twinkle.defaultConfig[pref.name].includes(itemkey); } }); break; diff --git a/modules/twinkleimage.js b/modules/twinkleimage.js index 593370098..f27583501 100644 --- a/modules/twinkleimage.js +++ b/modules/twinkleimage.js @@ -209,7 +209,7 @@ Twinkle.image.callback.evaluate = function twinkleimageCallbackEvaluate(event) { throw new Error('Twinkle.image.callback.evaluate: unknown criterion'); } - const lognomination = Twinkle.getPref('logSpeedyNominations') && Twinkle.getPref('noLogOnSpeedyNomination').indexOf(csdcrit.toLowerCase()) === -1; + const lognomination = Twinkle.getPref('logSpeedyNominations') && !Twinkle.getPref('noLogOnSpeedyNomination').includes(csdcrit.toLowerCase()); const templatename = input.derivative ? 'dw ' + input.type : input.type; const params = $.extend({ diff --git a/modules/twinkleprod.js b/modules/twinkleprod.js index 7c46c9922..d72fe3510 100644 --- a/modules/twinkleprod.js +++ b/modules/twinkleprod.js @@ -11,7 +11,7 @@ */ Twinkle.prod = function twinkleprod() { - if (([0, 6].indexOf(mw.config.get('wgNamespaceNumber')) === -1) || + if ((![0, 6].includes(mw.config.get('wgNamespaceNumber'))) || !mw.config.get('wgCurRevisionId') || Morebits.isPageRedirect()) { return; diff --git a/modules/twinkleprotect.js b/modules/twinkleprotect.js index 3bc6ada64..2f651bbc5 100644 --- a/modules/twinkleprotect.js +++ b/modules/twinkleprotect.js @@ -1274,7 +1274,7 @@ Twinkle.protect.callback.evaluate = function twinkleprotectCallbackEvaluate(e) { break; case 'unprotect': var admins = $.map(Twinkle.protect.currentProtectionLevels, (pl) => { - if (!pl.admin || Twinkle.protect.trustedBots.indexOf(pl.admin) !== -1) { + if (!pl.admin || Twinkle.protect.trustedBots.includes(pl.admin)) { return null; } return 'User:' + pl.admin; @@ -1401,7 +1401,7 @@ Twinkle.protect.callback.annotateProtectReason = function twinkleprotectCallback $(form.protectReason_notes_rfppRevid).parent().hide(); } } else if (this.name === 'protectReason_notes_rfppRevid') { - Twinkle.protect.protectReasonAnnotations = Twinkle.protect.protectReasonAnnotations.filter((el) => el.indexOf('[[Special:Permalink') === -1); + Twinkle.protect.protectReasonAnnotations = Twinkle.protect.protectReasonAnnotations.filter((el) => !el.includes('[[Special:Permalink')); if (e.target.value.length) { const permalink = '[[Special:Permalink/' + e.target.value + '#' + Morebits.pageNameNorm + ']]'; Twinkle.protect.protectReasonAnnotations.push(permalink); @@ -1459,7 +1459,7 @@ Twinkle.protect.callbacks = { return; } } else { - const needsTagToBeCommentedOut = ['javascript', 'css', 'sanitized-css'].indexOf(protectedPage.getContentModel()) !== -1; + const needsTagToBeCommentedOut = ['javascript', 'css', 'sanitized-css'].includes(protectedPage.getContentModel()); if (needsTagToBeCommentedOut) { if (params.noinclude) { tag = '/* {{' + tag + '}} */'; diff --git a/modules/twinklerollback.js b/modules/twinklerollback.js index 747022784..0b215f04c 100644 --- a/modules/twinklerollback.js +++ b/modules/twinklerollback.js @@ -192,9 +192,9 @@ Twinkle.rollback.addLinks = { if (mw.config.exists('wgRelevantUserName') || isRange) { // Get the username these contributions are for let username = mw.config.get('wgRelevantUserName'); - if (Twinkle.getPref('showRollbackLinks').indexOf('contribs') !== -1 || - (mw.config.get('wgUserName') !== username && Twinkle.getPref('showRollbackLinks').indexOf('others') !== -1) || - (mw.config.get('wgUserName') === username && Twinkle.getPref('showRollbackLinks').indexOf('mine') !== -1)) { + if (Twinkle.getPref('showRollbackLinks').includes('contribs') || + (mw.config.get('wgUserName') !== username && Twinkle.getPref('showRollbackLinks').includes('others')) || + (mw.config.get('wgUserName') === username && Twinkle.getPref('showRollbackLinks').includes('mine'))) { const $list = $('#mw-content-text').find('ul li:has(span.mw-uctop):has(.mw-changeslist-diff)'); $list.each((key, current) => { @@ -218,7 +218,7 @@ Twinkle.rollback.addLinks = { }, recentchanges: function() { - if (Twinkle.getPref('showRollbackLinks').indexOf('recent') !== -1) { + if (Twinkle.getPref('showRollbackLinks').includes('recent')) { // Latest and revertable (not page creations, logs, categorizations, etc.) let $list = $('.mw-changeslist .mw-changeslist-last.mw-changeslist-src-mw-edit'); // Exclude top-level header if "group changes" preference is used @@ -238,7 +238,7 @@ Twinkle.rollback.addLinks = { }, history: function() { - if (Twinkle.getPref('showRollbackLinks').indexOf('history') !== -1) { + if (Twinkle.getPref('showRollbackLinks').includes('history')) { // All revs const histList = $('#pagehistory li').toArray(); @@ -286,7 +286,7 @@ Twinkle.rollback.addLinks = { extraParams += xtitle === 'otitle' ? mw.config.get('wgDiffOldId') : mw.config.get('wgDiffNewId'); const href = $talkLink.attr('href'); - if (href.indexOf('?') === -1) { + if (!href.includes('?')) { $talkLink.attr('href', href + '?' + extraParams); } else { $talkLink.attr('href', href + '&' + extraParams); @@ -311,7 +311,7 @@ Twinkle.rollback.addLinks = { // Not latest revision, add [restore this revision] link to newer revision const newTitle = document.getElementById('mw-diff-ntitle1').parentNode; newTitle.insertBefore(Twinkle.rollback.linkBuilder.restoreThisRevisionLink('wgDiffNewId'), newTitle.firstChild); - } else if (Twinkle.getPref('showRollbackLinks').indexOf('diff') !== -1 && mw.config.get('wgDiffOldId') && (mw.config.get('wgDiffOldId') !== mw.config.get('wgDiffNewId') || document.getElementById('differences-prevlink'))) { + } else if (Twinkle.getPref('showRollbackLinks').includes('diff') && mw.config.get('wgDiffOldId') && (mw.config.get('wgDiffOldId') !== mw.config.get('wgDiffNewId') || document.getElementById('differences-prevlink'))) { // Normally .mw-userlink is a link, but if the // username is hidden, it will be a span with // .history-deleted as well. When a sysop views the @@ -459,11 +459,11 @@ Twinkle.rollback.callbacks = { undoafter: revertToRevID, basetimestamp: touched, starttimestamp: loadtimestamp, - minor: Twinkle.getPref('markRevertedPagesAsMinor').indexOf('torev') !== -1 ? true : undefined, + minor: Twinkle.getPref('markRevertedPagesAsMinor').includes('torev') ? true : undefined, format: 'json' }; // Handle watching, possible expiry - if (Twinkle.getPref('watchRevertedPages').indexOf('torev') !== -1) { + if (Twinkle.getPref('watchRevertedPages').includes('torev')) { const watchOrExpiry = Twinkle.getPref('watchRevertedExpiry'); if (!watchOrExpiry || watchOrExpiry === 'no') { @@ -541,7 +541,7 @@ Twinkle.rollback.callbacks = { } else if (params.type === 'vand' && // Okay to test on user since it will either fail or sysop will correctly access it // Besides, none of the trusted bots are going to be revdel'd - Twinkle.rollback.trustedBots.indexOf(top.user) !== -1 && revs.length > 1 && + Twinkle.rollback.trustedBots.includes(top.user) && revs.length > 1 && revs[1].revid === params.revid) { Morebits.Status.info('Info', [ 'Latest revision was made by ', Morebits.htmlNode('strong', lastuser), ', a trusted bot, and the revision before was made by our vandal, so we will proceed with the revert.' ]); index = 2; @@ -557,7 +557,7 @@ Twinkle.rollback.callbacks = { userNorm = params.user || Twinkle.rollback.hiddenName; } - if (Twinkle.rollback.trustedBots.indexOf(params.user) !== -1) { + if (Twinkle.rollback.trustedBots.includes(params.user)) { switch (params.type) { case 'vand': Morebits.Status.info('Info', [ 'Vandalism revert was chosen on ', Morebits.htmlNode('strong', userNorm), '. As this is a trusted bot, we assume you wanted to revert vandalism made by the previous user instead.' ]); @@ -685,7 +685,7 @@ Twinkle.rollback.callbacks = { } // Decide whether to notify the user on success - if (!Twinkle.rollback.skipTalk && Twinkle.getPref('openTalkPage').indexOf(params.type) !== -1 && + if (!Twinkle.rollback.skipTalk && Twinkle.getPref('openTalkPage').includes(params.type) && !params.userHidden && mw.config.get('wgUserName') !== params.user) { params.notifyUser = true; // Pass along to the warn module @@ -712,11 +712,11 @@ Twinkle.rollback.callbacks = { undoafter: params.goodid, basetimestamp: touched, starttimestamp: loadtimestamp, - minor: Twinkle.getPref('markRevertedPagesAsMinor').indexOf(params.type) !== -1 ? true : undefined, + minor: Twinkle.getPref('markRevertedPagesAsMinor').includes(params.type) ? true : undefined, format: 'json' }; // Handle watching, possible expiry - if (Twinkle.getPref('watchRevertedPages').indexOf(params.type) !== -1) { + if (Twinkle.getPref('watchRevertedPages').includes(params.type)) { const watchOrExpiry = Twinkle.getPref('watchRevertedExpiry'); if (!watchOrExpiry || watchOrExpiry === 'no') { diff --git a/modules/twinklespeedy.js b/modules/twinklespeedy.js index 308f894a8..9d685f60e 100644 --- a/modules/twinklespeedy.js +++ b/modules/twinklespeedy.js @@ -437,10 +437,10 @@ Twinkle.speedy.generateCsdList = function twinklespeedyGenerateCsdList(list, mod return null; } - if (criterion.showInNamespaces && criterion.showInNamespaces.indexOf(pageNamespace) < 0) { + if (criterion.showInNamespaces && !criterion.showInNamespaces.includes(pageNamespace)) { return null; } - if (criterion.hideInNamespaces && criterion.hideInNamespaces.indexOf(pageNamespace) > -1) { + if (criterion.hideInNamespaces && criterion.hideInNamespaces.includes(pageNamespace)) { return null; } @@ -713,7 +713,7 @@ Twinkle.speedy.userList = [ label: 'U1: User request', value: 'userreq', tooltip: 'Personal subpages, upon request by their user. In some rare cases there may be administrative need to retain the page. Also, sometimes, main user pages may be deleted as well. See Wikipedia:User page for full instructions and guidelines', - subgroup: mw.config.get('wgNamespaceNumber') === 3 && mw.config.get('wgTitle').indexOf('/') === -1 ? { + subgroup: mw.config.get('wgNamespaceNumber') === 3 && !mw.config.get('wgTitle').includes('/') ? { name: 'userreq_rationale', type: 'input', label: 'A mandatory rationale to explain why this user talk page should be deleted:', @@ -1169,7 +1169,7 @@ Twinkle.speedy.callbacks = { notifytext += (params.welcomeuser ? '' : '|nowelcome=yes') + '}} ~~~~'; editsummary = 'Notification: speedy deletion' + (params.warnUser ? '' : ' nomination'); - if (params.normalizeds.indexOf('g10') === -1) { // no article name in summary for G10 taggings + if (!params.normalizeds.includes('g10')) { // no article name in summary for G10 taggings editsummary += ' of [[:' + Morebits.pageNameNorm + ']].'; } else { editsummary += ' of an attack page.'; @@ -1371,12 +1371,12 @@ Twinkle.speedy.callbacks = { params.utparams = buildData[1]; // Set the correct value for |ts= parameter in {{db-g13}} - if (params.normalizeds.indexOf('g13') !== -1) { + if (params.normalizeds.includes('g13')) { code = code.replace('$TIMESTAMP', pageobj.getLastEditTime()); } // Tag if possible, post on talk if not - if (pageobj.canEdit() && ['wikitext', 'Scribunto', 'javascript', 'css', 'sanitized-css'].indexOf(pageobj.getContentModel()) !== -1 && mw.config.get('wgNamespaceNumber') !== 710 /* TimedText */) { + if (pageobj.canEdit() && ['wikitext', 'Scribunto', 'javascript', 'css', 'sanitized-css'].includes(pageobj.getContentModel()) && mw.config.get('wgNamespaceNumber') !== 710 /* TimedText */) { let text = pageobj.getPageText(); statelem.status('Checking for tags on the page...'); @@ -1412,7 +1412,7 @@ Twinkle.speedy.callbacks = { } if (params.requestsalt) { - if (params.normalizeds.indexOf('g10') === -1) { + if (!params.normalizeds.includes('g10')) { code += '\n{{salt}}'; } else { code = '{{salt}}\n' + code; @@ -1422,11 +1422,11 @@ Twinkle.speedy.callbacks = { if (mw.config.get('wgPageContentModel') === 'Scribunto') { // Scribunto isn't parsed like wikitext, so CSD templates on modules need special handling to work let equals = ''; - while (code.indexOf(']' + equals + ']') !== -1) { + while (code.includes(']' + equals + ']')) { equals += '='; } code = "require('Module:Module wikitext')._addText([" + equals + '[' + code + ']' + equals + ']);'; - } else if (['javascript', 'css', 'sanitized-css'].indexOf(mw.config.get('wgPageContentModel')) !== -1) { + } else if (['javascript', 'css', 'sanitized-css'].includes(mw.config.get('wgPageContentModel'))) { // Likewise for JS/CSS pages code = '/* ' + code + ' */'; } @@ -1447,7 +1447,7 @@ Twinkle.speedy.callbacks = { } // Blank attack pages - if (params.normalizeds.indexOf('g10') !== -1) { + if (params.normalizeds.includes('g10')) { text = code; } else { // Insert tag after short description or any hatnotes @@ -1532,7 +1532,7 @@ Twinkle.speedy.callbacks = { let editsummary = 'Logging speedy deletion nomination'; let appendText = '# [[:' + Morebits.pageNameNorm; - if (params.normalizeds.indexOf('g10') === -1) { // no article name in log for G10 taggings + if (!params.normalizeds.includes('g10')) { // no article name in log for G10 taggings appendText += ']]' + fileLogLink + ': '; editsummary += ' of [[:' + Morebits.pageNameNorm + ']].'; } else { @@ -1900,18 +1900,18 @@ Twinkle.speedy.callback.evaluateSysop = function twinklespeedyCallbackEvaluateSy // analyse each criterion to determine whether to watch the page, prompt for summary, or notify the creator let watchPage, promptForSummary; normalizeds.forEach((norm) => { - if (Twinkle.getPref('watchSpeedyPages').indexOf(norm) !== -1) { + if (Twinkle.getPref('watchSpeedyPages').includes(norm)) { watchPage = Twinkle.getPref('watchSpeedyExpiry'); } - if (Twinkle.getPref('promptForSpeedyDeletionSummary').indexOf(norm) !== -1) { + if (Twinkle.getPref('promptForSpeedyDeletionSummary').includes(norm)) { promptForSummary = true; } }); - const warnusertalk = form.warnusertalk.checked && normalizeds.some((norm, index) => Twinkle.getPref('warnUserOnSpeedyDelete').indexOf(norm) !== -1 && + const warnusertalk = form.warnusertalk.checked && normalizeds.some((norm, index) => Twinkle.getPref('warnUserOnSpeedyDelete').includes(norm) && !(norm === 'g6' && values[index] !== 'copypaste')); - const welcomeuser = warnusertalk && normalizeds.some((norm) => Twinkle.getPref('welcomeUserOnSpeedyDeletionNotification').indexOf(norm) !== -1); + const welcomeuser = warnusertalk && normalizeds.some((norm) => Twinkle.getPref('welcomeUserOnSpeedyDeletionNotification').includes(norm)); const params = { values: values, @@ -1953,12 +1953,12 @@ Twinkle.speedy.callback.evaluateUser = function twinklespeedyCallbackEvaluateUse const normalizeds = values.map((value) => Twinkle.speedy.normalizeHash[value]); // analyse each criterion to determine whether to watch the page/notify the creator - const watchPage = normalizeds.some((csdCriteria) => Twinkle.getPref('watchSpeedyPages').indexOf(csdCriteria) !== -1) && Twinkle.getPref('watchSpeedyExpiry'); + const watchPage = normalizeds.some((csdCriteria) => Twinkle.getPref('watchSpeedyPages').includes(csdCriteria)) && Twinkle.getPref('watchSpeedyExpiry'); - const notifyuser = form.notify.checked && normalizeds.some((norm, index) => Twinkle.getPref('notifyUserOnSpeedyDeletionNomination').indexOf(norm) !== -1 && + const notifyuser = form.notify.checked && normalizeds.some((norm, index) => Twinkle.getPref('notifyUserOnSpeedyDeletionNomination').includes(norm) && !(norm === 'g6' && values[index] !== 'copypaste')); - const welcomeuser = notifyuser && normalizeds.some((norm) => Twinkle.getPref('welcomeUserOnSpeedyDeletionNotification').indexOf(norm) !== -1); - const csdlog = Twinkle.getPref('logSpeedyNominations') && normalizeds.some((norm) => Twinkle.getPref('noLogOnSpeedyNomination').indexOf(norm) === -1); + const welcomeuser = notifyuser && normalizeds.some((norm) => Twinkle.getPref('welcomeUserOnSpeedyDeletionNotification').includes(norm)); + const csdlog = Twinkle.getPref('logSpeedyNominations') && normalizeds.some((norm) => !Twinkle.getPref('noLogOnSpeedyNomination').includes(norm)); const params = { values: values, diff --git a/modules/twinkletag.js b/modules/twinkletag.js index 3185f45e4..3478c8b24 100644 --- a/modules/twinkletag.js +++ b/modules/twinkletag.js @@ -21,7 +21,7 @@ Twinkle.tag = function twinkletag() { Twinkle.tag.mode = 'file'; Twinkle.addPortletLink(Twinkle.tag.callback, 'Tag', 'twinkle-tag', 'Add maintenance tags to file'); // article/draft article tagging - } else if ([0, 118].indexOf(mw.config.get('wgNamespaceNumber')) !== -1 && mw.config.get('wgCurRevisionId')) { + } else if ([0, 118].includes(mw.config.get('wgNamespaceNumber')) && mw.config.get('wgCurRevisionId')) { Twinkle.tag.mode = 'article'; // Can't remove tags when not viewing current version Twinkle.tag.canRemove = (mw.config.get('wgCurRevisionId') === mw.config.get('wgRevisionId')) && @@ -372,7 +372,7 @@ Twinkle.tag.updateSortOrder = function(e) { const makeCheckbox = function (item) { const tag = item.tag, description = item.description; const checkbox = { value: tag, label: '{{' + tag + '}}: ' + description }; - if (Twinkle.tag.checkedTags.indexOf(tag) !== -1) { + if (Twinkle.tag.checkedTags.includes(tag)) { checkbox.checked = true; } checkbox.subgroup = item.subgroup; @@ -389,7 +389,7 @@ Twinkle.tag.updateSortOrder = function(e) { { value: tag, label: '{{' + tag + '}}' + (Twinkle.tag.article.flatObject[tag] ? ': ' + Twinkle.tag.article.flatObject[tag].description : ''), - checked: unCheckedTags.indexOf(tag) === -1, + checked: !unCheckedTags.includes(tag), style: 'font-style: italic' }; @@ -407,7 +407,7 @@ Twinkle.tag.updateSortOrder = function(e) { const doCategoryCheckboxes = function(subdiv, subgroup) { const checkboxes = []; $.each(subgroup, (k, item) => { - if (Twinkle.tag.alreadyPresentTags.indexOf(item.tag) === -1) { + if (!Twinkle.tag.alreadyPresentTags.includes(item.tag)) { checkboxes.push(makeCheckbox(item)); } }); @@ -445,7 +445,7 @@ Twinkle.tag.updateSortOrder = function(e) { Twinkle.tag.article.alphabeticalList = Twinkle.tag.article.alphabeticalList || Object.keys(Twinkle.tag.article.flatObject).sort(); const checkboxes = []; Twinkle.tag.article.alphabeticalList.forEach((tag) => { - if (Twinkle.tag.alreadyPresentTags.indexOf(tag) === -1) { + if (!Twinkle.tag.alreadyPresentTags.includes(tag)) { checkboxes.push(makeCheckbox(Twinkle.tag.article.flatObject[tag])); } }); @@ -461,7 +461,7 @@ Twinkle.tag.updateSortOrder = function(e) { container.append({ type: 'header', label: 'Custom tags' }); container.append({ type: 'checkbox', name: 'tags', list: Twinkle.getPref('customTagList').map((el) => { - el.checked = Twinkle.tag.checkedTags.indexOf(el.value) !== -1; + el.checked = Twinkle.tag.checkedTags.includes(el.value); return el; }) }); @@ -512,8 +512,8 @@ var generateLinks = function(checkbox) { link.setAttribute('class', 'tag-template-link'); const tagname = checkbox.values; link.setAttribute('href', mw.util.getUrl( - (tagname.indexOf(':') === -1 ? 'Template:' : '') + - (tagname.indexOf('|') === -1 ? tagname : tagname.slice(0, tagname.indexOf('|'))) + (!tagname.includes(':') ? 'Template:' : '') + + (!tagname.includes('|') ? tagname : tagname.slice(0, tagname.indexOf('|'))) )); link.setAttribute('target', '_blank'); $(checkbox).parent().append(['\u00A0', link]); @@ -1353,10 +1353,10 @@ Twinkle.tag.callbacks = { const makeTemplateLink = function(tag) { let text = '{{[['; // if it is a custom tag with a parameter - if (tag.indexOf('|') !== -1) { + if (tag.includes('|')) { tag = tag.slice(0, tag.indexOf('|')); } - text += tag.indexOf(':') !== -1 ? tag : 'Template:' + tag + '|' + tag; + text += tag.includes(':') ? tag : 'Template:' + tag + '|' + tag; return text + ']]}}'; }; @@ -1381,7 +1381,7 @@ Twinkle.tag.callbacks = { pageobj.setPageText(pageText); pageobj.setEditSummary(summaryText); - if ((mw.config.get('wgNamespaceNumber') === 0 && Twinkle.getPref('watchTaggedVenues').indexOf('articles') !== -1) || (mw.config.get('wgNamespaceNumber') === 118 && Twinkle.getPref('watchTaggedVenues').indexOf('drafts') !== -1)) { + if ((mw.config.get('wgNamespaceNumber') === 0 && Twinkle.getPref('watchTaggedVenues').includes('articles')) || (mw.config.get('wgNamespaceNumber') === 118 && Twinkle.getPref('watchTaggedVenues').includes('drafts'))) { pageobj.setWatchlist(Twinkle.getPref('watchTaggedPages')); } pageobj.setMinorEdit(Twinkle.getPref('markTaggedPagesAsMinor')); @@ -1447,13 +1447,13 @@ Twinkle.tag.callbacks = { let templateText; let text, summary; - if (params.tags.indexOf('Rough translation') !== -1) { + if (params.tags.includes('Rough translation')) { templateText = '{{subst:Dual fluency request|pg=' + Morebits.pageNameNorm + '|Language=' + (lang || 'uncertain') + '|Comments=' + reason.trim() + '}} ~~~~'; // Place in section == Translated pages that could still use some cleanup == text = oldText + '\n\n' + templateText; summary = 'Translation cleanup requested on '; - } else if (params.tags.indexOf('Not English') !== -1) { + } else if (params.tags.includes('Not English')) { templateText = '{{subst:Translation request|pg=' + Morebits.pageNameNorm + '|Language=' + (lang || 'uncertain') + '|Comments=' + reason.trim() + '}} ~~~~'; // Place in section == Pages for consideration == @@ -1694,7 +1694,7 @@ Twinkle.tag.callbacks = { Morebits.Status.warn('Info', 'Found {{' + tag + '}} on the article already...excluding'); // don't do anything else with merge tags - if (['Merge', 'Merge to'].indexOf(tag) !== -1) { + if (['Merge', 'Merge to'].includes(tag)) { params.mergeTarget = params.mergeReason = params.mergeTagOther = null; } } @@ -1835,7 +1835,7 @@ Twinkle.tag.callbacks = { } } - summaryText += ' {{[[:' + (tagName.indexOf(':') !== -1 ? tagName : 'Template:' + tagName + '|' + tagName) + ']]}}'; + summaryText += ' {{[[:' + (tagName.includes(':') ? tagName : 'Template:' + tagName + '|' + tagName) + ']]}}'; }; if (!tags.length) { @@ -1874,7 +1874,7 @@ Twinkle.tag.callbacks = { pageobj.setPageText(pageText); pageobj.setEditSummary(summaryText); - if (Twinkle.getPref('watchTaggedVenues').indexOf('redirects') !== -1) { + if (Twinkle.getPref('watchTaggedVenues').includes('redirects')) { pageobj.setWatchlist(Twinkle.getPref('watchTaggedPages')); } pageobj.setMinorEdit(Twinkle.getPref('markTaggedPagesAsMinor')); @@ -1898,7 +1898,7 @@ Twinkle.tag.callbacks = { let tagtext = '', currentTag; $.each(params.tags, (k, tag) => { // when other commons-related tags are placed, remove "move to Commons" tag - if (['Keep local', 'Do not move to Commons'].indexOf(tag) !== -1) { + if (['Keep local', 'Do not move to Commons'].includes(tag)) { text = text.replace(/\{\{(mtc|(copy |move )?to ?commons|move to wikimedia commons|copy to wikimedia commons)[^}]*\}\}/gi, ''); } @@ -1987,7 +1987,7 @@ Twinkle.tag.callbacks = { pageobj.setPageText(text); pageobj.setEditSummary(summary.substring(0, summary.length - 2)); pageobj.setChangeTags(Twinkle.changeTags); - if (Twinkle.getPref('watchTaggedVenues').indexOf('files') !== -1) { + if (Twinkle.getPref('watchTaggedVenues').includes('files')) { pageobj.setWatchlist(Twinkle.getPref('watchTaggedPages')); } pageobj.setMinorEdit(Twinkle.getPref('markTaggedPagesAsMinor')); @@ -2033,12 +2033,12 @@ Twinkle.tag.callback.evaluate = function twinkletagCallbackEvaluate(e) { params.tagsToRemove = form.getUnchecked('existingTags'); // not in `input` params.tagsToRemain = params.existingTags || []; // container not created if none present - if ((params.tags.indexOf('Merge') !== -1) || (params.tags.indexOf('Merge from') !== -1) || - (params.tags.indexOf('Merge to') !== -1)) { + if ((params.tags.includes('Merge')) || (params.tags.includes('Merge from')) || + (params.tags.includes('Merge to'))) { if (Twinkle.tag.checkIncompatible(['Merge', 'Merge from', 'Merge to'], params.tags, 'If several merges are required, use {{Merge}} and separate the article names with pipes (although in this case Twinkle cannot tag the other articles automatically).')) { return; } - if ((params.mergeTagOther || params.mergeReason) && params.mergeTarget.indexOf('|') !== -1) { + if ((params.mergeTagOther || params.mergeReason) && params.mergeTarget.includes('|')) { alert('Tagging multiple articles in a merge, and starting a discussion for multiple articles, is not supported at the moment. Please turn off "tag other article", and/or clear out the "reason" box, and try again.'); return; } diff --git a/modules/twinkleunlink.js b/modules/twinkleunlink.js index a7a547398..281c3cba7 100644 --- a/modules/twinkleunlink.js +++ b/modules/twinkleunlink.js @@ -122,8 +122,8 @@ Twinkle.unlink.callback.evaluate = function twinkleunlinkCallbackEvaluate(event) const wikipedia_page = new Morebits.wiki.Page(pageName, 'Unlinking in page "' + pageName + '"'); wikipedia_page.setBotEdit(true); // unlink considered a floody operation wikipedia_page.setCallbackParameters($.extend({ - doBacklinks: input.backlinks.indexOf(pageName) !== -1, - doImageusage: input.imageusage.indexOf(pageName) !== -1 + doBacklinks: input.backlinks.includes(pageName), + doImageusage: input.imageusage.includes(pageName) }, params)); wikipedia_page.load(Twinkle.unlink.callbacks.unlinkBacklinks); }); diff --git a/modules/twinklewarn.js b/modules/twinklewarn.js index dbbc7675b..2dc5347a3 100644 --- a/modules/twinklewarn.js +++ b/modules/twinklewarn.js @@ -36,7 +36,7 @@ Twinkle.warn = function twinklewarn() { // Can't provide vanarticlerevid as only wgCurRevisionId is provided const extraParam = 'vanarticle=' + mw.util.rawurlencode(Morebits.pageNameNorm); const href = $vandalTalkLink.attr('href'); - if (href.indexOf('?') === -1) { + if (!href.includes('?')) { $vandalTalkLink.attr('href', href + '?' + extraParam); } else { $vandalTalkLink.attr('href', href + '&' + extraParam); @@ -1634,7 +1634,7 @@ Twinkle.warn.callback.change_subcategory = function twinklewarnCallbackChangeSub 'uw-aiv': 'Optional username that was reported (without User:) ' }; - const hasLevel = ['singlenotice', 'singlewarn', 'singlecombined', 'kitchensink'].indexOf(selected_main_group) !== -1; + const hasLevel = ['singlenotice', 'singlewarn', 'singlecombined', 'kitchensink'].includes(selected_main_group); if (hasLevel) { if (notLinkedArticle[selected_template]) { if (Twinkle.warn.prev_article === null) { diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 964a97c9a..ebaaaf838 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -143,7 +143,7 @@ Twinkle.xfd.callback = function twinklexfdCallback() { categories.append({ type: 'option', label: 'TfD (Templates for discussion)', - selected: [ 10, 828 ].indexOf(namespace) !== -1, // Template and module namespaces + selected: [ 10, 828 ].includes(namespace), // Template and module namespaces value: 'tfd' }); categories.append({ @@ -166,7 +166,7 @@ Twinkle.xfd.callback = function twinklexfdCallback() { categories.append({ type: 'option', label: 'MfD (Miscellany for deletion)', - selected: [ 0, 6, 10, 14, 828 ].indexOf(namespace) === -1 || Morebits.pageNameNorm.indexOf('Template:User ', 0) === 0, + selected: ![ 0, 6, 10, 14, 828 ].includes(namespace) || Morebits.pageNameNorm.indexOf('Template:User ', 0) === 0, // Other namespaces, and userboxes in template namespace value: 'mfd' }); @@ -249,7 +249,7 @@ Twinkle.xfd.callback.wrongVenueWarning = function twinklexfdWrongVenueWarning(ve } break; case 'cfd': - if ([ 10, 14 ].indexOf(namespace) === -1) { + if (![ 10, 14 ].includes(namespace)) { text = 'CfD is only for categories and stub templates.'; } break; @@ -266,7 +266,7 @@ Twinkle.xfd.callback.wrongVenueWarning = function twinklexfdWrongVenueWarning(ve case 'rm': if (namespace === 14) { // category text = 'Please use CfD or CfDS for category renames.'; - } else if ([118, 119, 2, 3].indexOf(namespace) > -1) { // draft, draft talk, user, user talk + } else if ([118, 119, 2, 3].includes(namespace)) { // draft, draft talk, user, user talk text = 'RMs are not permitted in draft and userspace, unless they are uncontroversial technical requests.'; } break; @@ -981,7 +981,7 @@ Twinkle.xfd.callbacks = { } }, addToLog: function(params, initialContrib) { - if (!Twinkle.getPref('logXfdNominations') || Twinkle.getPref('noLogOnXfdNomination').indexOf(params.venue) !== -1) { + if (!Twinkle.getPref('logXfdNominations') || Twinkle.getPref('noLogOnXfdNomination').includes(params.venue)) { return; } @@ -1360,7 +1360,7 @@ Twinkle.xfd.callbacks = { page.setCallbackParameters(params); page.lookupCreation((innerpage) => { const username = innerpage.getCreator(); - if (seenusers.indexOf(username) === -1) { + if (!seenusers.includes(username)) { seenusers.push(username); // Only log once on merge nominations, for the initial template Twinkle.xfd.callbacks.notifyUser(innerpage.getCallbackParameters(), username, @@ -1382,7 +1382,7 @@ Twinkle.xfd.callbacks = { 'Templates used by Ultraviolet': 'Wikipedia talk:Ultraviolet' }; $.each(categoryNotificationPageMap, (category, page) => { - if (inCategories.indexOf(category) !== -1) { + if (inCategories.includes(category)) { Twinkle.xfd.callbacks.notifyUser(params, page, true, 'Notifying ' + page + ' of template nomination'); } }); @@ -1404,7 +1404,7 @@ Twinkle.xfd.callbacks = { params.tagText += params.templatetype === 'standard' || params.templatetype === 'sidebar' || params.templatetype === 'disabled' ? '\n' : ''; // No newline for inline } - if (pageobj.canEdit() && ['wikitext', 'sanitized-css'].indexOf(pageobj.getContentModel()) !== -1) { + if (pageobj.canEdit() && ['wikitext', 'sanitized-css'].includes(pageobj.getContentModel())) { pageobj.setPageText(params.tagText + text); pageobj.setEditSummary('Nominated for deletion; see [[:' + params.discussionpage + ']].'); pageobj.setChangeTags(Twinkle.changeTags); @@ -1433,7 +1433,7 @@ Twinkle.xfd.callbacks = { params.tagText += params.templatetype === 'standard' || params.templatetype === 'sidebar' || params.templatetype === 'disabled' ? '\n' : ''; // No newline for inline } - if (pageobj.canEdit() && ['wikitext', 'sanitized-css'].indexOf(pageobj.getContentModel()) !== -1) { + if (pageobj.canEdit() && ['wikitext', 'sanitized-css'].includes(pageobj.getContentModel())) { pageobj.setPageText(params.tagText + text); pageobj.setEditSummary('Listed for merging with [[:' + params.otherTemplateName + ']]; see [[:' + params.discussionpage + ']].'); pageobj.setChangeTags(Twinkle.changeTags); @@ -1558,7 +1558,7 @@ Twinkle.xfd.callbacks = { params.tagText = '{{' + (params.number === '' ? 'mfd' : 'mfdx|' + params.number) + '|help=off}}'; - if (['javascript', 'css', 'sanitized-css'].indexOf(mw.config.get('wgPageContentModel')) !== -1) { + if (['javascript', 'css', 'sanitized-css'].includes(mw.config.get('wgPageContentModel'))) { params.tagText = '/* ' + params.tagText + ' */\n'; } else { params.tagText += '\n'; @@ -1567,7 +1567,7 @@ Twinkle.xfd.callbacks = { } } - if (pageobj.canEdit() && ['wikitext', 'javascript', 'css', 'sanitized-css'].indexOf(pageobj.getContentModel()) !== -1) { + if (pageobj.canEdit() && ['wikitext', 'javascript', 'css', 'sanitized-css'].includes(pageobj.getContentModel())) { pageobj.setPageText(params.tagText + text); pageobj.setEditSummary('Nominated for deletion; see [[:' + params.discussionpage + ']].'); pageobj.setChangeTags(Twinkle.changeTags); diff --git a/morebits.js b/morebits.js index 8d0269ba0..e0285e7a5 100644 --- a/morebits.js +++ b/morebits.js @@ -131,7 +131,7 @@ Morebits.l10n = { * @return {boolean} */ Morebits.userIsInGroup = function (group) { - return mw.config.get('wgUserGroups').indexOf(group) !== -1; + return mw.config.get('wgUserGroups').includes(group); }; /** * Hardcodes whether the user is a sysop, used a lot. @@ -269,7 +269,7 @@ Morebits.namespaceRegex = function(namespaces) { const aliases = []; let regex; $.each(mw.config.get('wgNamespaceIds'), (name, number) => { - if (namespaces.indexOf(number) !== -1) { + if (namespaces.includes(number)) { // Namespaces are completely agnostic as to case, // and a regex string is more useful/compatible than a RegExp object, // so we accept any casing for any letter. @@ -1557,7 +1557,7 @@ Morebits.string = { * @return {boolean} */ isInfinity: function morebitsStringIsInfinity(expiry) { - return ['indefinite', 'infinity', 'infinite', 'never'].indexOf(expiry) !== -1; + return ['indefinite', 'infinity', 'infinite', 'never'].includes(expiry); }, /** @@ -1653,7 +1653,7 @@ Morebits.select2 = { const result = originalMatcher(params, data); if (result && params.term && - data.text.toUpperCase().indexOf(params.term.toUpperCase()) !== -1) { + data.text.toUpperCase().includes(params.term.toUpperCase())) { result.children = data.children; } return result; @@ -2284,7 +2284,7 @@ Morebits.wiki.api = function(currentAction, query, onSuccess, statusElement, onE this.query = query; this.query.assert = 'user'; // Enforce newer error formats, preferring html - if (!query.errorformat || ['wikitext', 'plaintext'].indexOf(query.errorformat) === -1) { + if (!query.errorformat || !['wikitext', 'plaintext'].includes(query.errorformat)) { this.query.errorformat = 'html'; } // Explicitly use the wiki's content language to minimize confusion, @@ -2305,12 +2305,12 @@ Morebits.wiki.api = function(currentAction, query, onSuccess, statusElement, onE this.query.format = 'xml'; } else if (query.format === 'json' && !query.formatversion) { this.query.formatversion = '2'; - } else if (['xml', 'json'].indexOf(query.format) === -1) { + } else if (!['xml', 'json'].includes(query.format)) { this.statelem.error('Invalid API format: only xml and json are supported.'); } // Ignore tags for queries and most common unsupported actions, produces warnings - if (query.action && ['query', 'review', 'stabilize', 'pagetriageaction', 'watch'].indexOf(query.action) !== -1) { + if (query.action && ['query', 'review', 'stabilize', 'pagetriageaction', 'watch'].includes(query.action)) { delete query.tags; } else if (!query.tags && morebitsWikiChangeTag) { query.tags = morebitsWikiChangeTag; @@ -2900,7 +2900,7 @@ Morebits.wiki.page = function(pageName, status) { break; } - if (['recreate', 'createonly', 'nocreate'].indexOf(ctx.createOption) !== -1) { + if (['recreate', 'createonly', 'nocreate'].includes(ctx.createOption)) { query[ctx.createOption] = ''; } @@ -3432,7 +3432,7 @@ Morebits.wiki.page = function(pageName, status) { /** @return {boolean} whether or not you can edit the page */ this.canEdit = function() { - return !!ctx.testActions && ctx.testActions.indexOf('edit') !== -1; + return !!ctx.testActions && ctx.testActions.includes('edit'); }; /** @@ -3594,7 +3594,7 @@ Morebits.wiki.page = function(pageName, status) { */ this.triage = function() { // Fall back to patrol if not a valid triage namespace - if (mw.config.get('pageTriageNamespaces').indexOf(new mw.Title(ctx.pageName).getNamespaceId()) === -1) { + if (!mw.config.get('pageTriageNamespaces').includes(new mw.Title(ctx.pageName).getNamespaceId())) { this.patrol(); } else { if (!Morebits.userIsSysop && !Morebits.userIsInGroup('patroller')) { @@ -3778,7 +3778,7 @@ Morebits.wiki.page = function(pageName, status) { // wgRestrictionEdit is null on non-existent pages, // so this neatly handles nonexistent pages const editRestriction = mw.config.get('wgRestrictionEdit'); - if (!editRestriction || editRestriction.indexOf('sysop') !== -1) { + if (!editRestriction || editRestriction.includes('sysop')) { return false; } } @@ -4231,7 +4231,7 @@ Morebits.wiki.page = function(pageName, status) { const missing = response.pages[0].missing; // No undelete as an existing page could have deleted revisions - const actionMissing = missing && ['delete', 'stabilize', 'move'].indexOf(action) !== -1; + const actionMissing = missing && ['delete', 'stabilize', 'move'].includes(action); const protectMissing = action === 'protect' && missing && (ctx.protectEdit || ctx.protectMove); const saltMissing = action === 'protect' && !missing && ctx.protectCreate; @@ -4944,7 +4944,7 @@ Morebits.wikitext.page.prototype = { // For most namespaces, unlink both [[User:Test]] and [[:User:Test]] // For files and categories, only unlink [[:Category:Test]]. Do not unlink [[Category:Test]] - const isFileOrCategory = [6, 14].indexOf(namespaceID) !== -1; + const isFileOrCategory = [6, 14].includes(namespaceID); const colon = isFileOrCategory ? ':' : ':?'; const simple_link_regex = new RegExp('\\[\\[' + colon + '(' + link_regex_string + ')\\]\\]', 'g'); diff --git a/twinkle.js b/twinkle.js index 1ba4ae3c0..f4c85f6a7 100644 --- a/twinkle.js +++ b/twinkle.js @@ -363,7 +363,7 @@ Twinkle.load = function () { activeSpecialPageList = activeSpecialPageList.concat([ 'DeletedContributions', 'Prefixindex' ]); } if (mw.config.get('wgNamespaceNumber') === -1 && - activeSpecialPageList.indexOf(mw.config.get('wgCanonicalSpecialPageName')) === -1) { + !activeSpecialPageList.includes(mw.config.get('wgCanonicalSpecialPageName'))) { return; } @@ -380,7 +380,7 @@ Twinkle.load = function () { // Redefine addInitCallback so that any modules being loaded now on are directly // initialised rather than added to initCallbacks array Twinkle.addInitCallback = function(func, name) { - if (!name || Twinkle.disabledModules.indexOf(name) === -1) { + if (!name || !Twinkle.disabledModules.includes(name)) { func(); } }; From c7b2abe1567a4980438ed80016ddcb2495288de1 Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Thu, 12 Dec 2024 00:56:29 -0800 Subject: [PATCH 3/8] eslint: apply autofixes to tests (#2126) * eslint: apply autofixes to tests * alphabetical --- tests/.eslintrc.json | 11 +-- tests/jest.setup.js | 6 +- tests/morebits.batchOperation.js | 14 ++-- tests/morebits.createHtml.js | 8 +- tests/morebits.date.js | 8 +- tests/morebits.quickForm.js | 130 ++++++++++++++++--------------- tests/morebits.string.js | 16 ++-- tests/morebits.taskManager.js | 10 +-- tests/morebits.unbinder.js | 4 +- tests/morebits.wikitext.js | 30 +++---- tests/twinkletag.test.js | 2 +- tests/twinklewarn.test.js | 12 +-- tests/twinklexfd.test.js | 14 ++-- 13 files changed, 130 insertions(+), 135 deletions(-) diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json index 05e943f8e..bf15fcf20 100644 --- a/tests/.eslintrc.json +++ b/tests/.eslintrc.json @@ -14,18 +14,9 @@ "space-in-parens": "off", "camelcase": "warn", - "comma-dangle": "warn", - "eol-last": "warn", "new-cap": "warn", - "prefer-arrow-callback": "warn", - "prefer-const": "warn", - "no-trailing-spaces": "warn", "no-undef": "warn", "no-useless-escape": "warn", - "no-var": "warn", - "semi": "warn", - "strict": "warn", - "quotes": "warn", - "unicorn/prefer-date-now": "warn" + "strict": "warn" } } diff --git a/tests/jest.setup.js b/tests/jest.setup.js index 96a9a1696..a63a116eb 100644 --- a/tests/jest.setup.js +++ b/tests/jest.setup.js @@ -1,7 +1,7 @@ // Tweak some mw.configs as needed by tests mw.config.set({ wgPageName: 'Macbeth,_King_of_Scotland', - wgUserGroups: ['interface-admin', 'sysop', '*', 'user', 'autoconfirmed'], + wgUserGroups: ['interface-admin', 'sysop', '*', 'user', 'autoconfirmed'] }); require('../morebits.js'); @@ -20,9 +20,9 @@ assert.true = function (arg, message) { if (arg !== true) { throw new Error(message); } -} +}; assert.false = function (arg, message) { if (arg !== false) { throw new Error(message); } -} +}; diff --git a/tests/morebits.batchOperation.js b/tests/morebits.batchOperation.js index 38ec8e6b4..76bab9616 100644 --- a/tests/morebits.batchOperation.js +++ b/tests/morebits.batchOperation.js @@ -2,14 +2,14 @@ describe('Morebits.batchOperation', () => { test('Contruction', () => { assert.true(new Morebits.batchOperation() instanceof Morebits.batchOperation, 'Correct instance'); }); - var batch = new Morebits.batchOperation(); - var pageList = ['Macbeth', 'Hamlet', 'Romeo and Juliet', 'Much Ado About Nothing', 'Tempest']; + const batch = new Morebits.batchOperation(); + const pageList = ['Macbeth', 'Hamlet', 'Romeo and Juliet', 'Much Ado About Nothing', 'Tempest']; batch.setPageList(pageList); - var chunkLength = 2; + const chunkLength = 2; batch.setOption('chunkSize', chunkLength); test('Run', () => { - var all = ''; - var runFunc = function (page) { + let all = ''; + const runFunc = function (page) { all += page; batch.workerSuccess(); }; @@ -18,8 +18,8 @@ describe('Morebits.batchOperation', () => { }); // Will leave a run hanging, who cares? test('Chunksize', () => { - var list = []; - var runFunc = function (page) { + const list = []; + const runFunc = function (page) { list.push(page); }; batch.run(runFunc); diff --git a/tests/morebits.createHtml.js b/tests/morebits.createHtml.js index d6e2a97c5..63563c9e4 100644 --- a/tests/morebits.createHtml.js +++ b/tests/morebits.createHtml.js @@ -23,17 +23,17 @@ describe('Morebits.createHtml', () => { test('renderWikilinks', () => { assert.strictEqual( Morebits.createHtml.renderWikilinks('[[Main Page]]'), - `Main Page`, + 'Main Page', 'simple link' ); assert.strictEqual( Morebits.createHtml.renderWikilinks('surrounding text [[Main Page|the main page]]'), - `surrounding text the main page`, + 'surrounding text the main page', 'link with display text' ); assert.strictEqual( Morebits.createHtml.renderWikilinks('surrounding text [["Weird Al" Yankovic]]'), - `surrounding text "Weird Al" Yankovic`, + 'surrounding text "Weird Al" Yankovic', // jsdom in node turns " in title attribute into " whereas Chrome seems turns it into " // but it works either way 'link with double quote' @@ -41,7 +41,7 @@ describe('Morebits.createHtml', () => { assert.strictEqual( Morebits.createHtml.renderWikilinks('[[CODE]] [[Yankovic]]'), - `[[CODE]] Yankovic`, + '[[CODE]] Yankovic', 'wikilink in tag' ); }); diff --git a/tests/morebits.date.js b/tests/morebits.date.js index 6b7a2ef87..c39cbef26 100644 --- a/tests/morebits.date.js +++ b/tests/morebits.date.js @@ -1,10 +1,10 @@ describe('Morebits.date', () => { - var now = Date.now(); - var ts_mw = '16:26, 7 November 2020 (UTC)', ts_iso = '2020-11-07T16:26:00.000Z', naive = 20201107162600; + const now = Date.now(); + const ts_mw = '16:26, 7 November 2020 (UTC)', ts_iso = '2020-11-07T16:26:00.000Z', naive = 20201107162600; test('Construction', () => { // getTime and toISOString imply testing of inherited methods // Allow off-by-one values in milliseconds for not-quite-simultaneous date contructions - expect(Math.abs(new Morebits.date().getTime() - new Date().getTime())).toBeLessThanOrEqual(1); + expect(Math.abs(new Morebits.date().getTime() - Date.now())).toBeLessThanOrEqual(1); assert.strictEqual(new Morebits.date(now).getTime(), new Date(now).getTime(), 'Constructor from timestring'); assert.strictEqual(new Morebits.date(2020, 11, 7, 16, 26).getTime(), new Date(2020, 11, 7, 16, 26).getTime(), 'Constructor from parts'); @@ -14,7 +14,7 @@ describe('Morebits.date', () => { assert.strictEqual(new Morebits.date(parseInt(naive / 10, 10)).toISOString(), new Date(parseInt(naive / 10, 10)).toISOString(), 'native 13 digit'); assert.strictEqual(new Morebits.date(naive * 10).toISOString(), new Date(naive * 10).toISOString(), 'native 15 digit'); }); - var date = new Morebits.date(ts_mw); + const date = new Morebits.date(ts_mw); test('Methods', () => { assert.true(date.isValid(), 'Valid'); // Logs a message; not a failure, but annoying diff --git a/tests/morebits.quickForm.js b/tests/morebits.quickForm.js index 42b7817aa..964aa59dd 100644 --- a/tests/morebits.quickForm.js +++ b/tests/morebits.quickForm.js @@ -1,77 +1,81 @@ -/** Simple helper to render a quickform element */ +/** + * Simple helper to render a quickform element + * + * @param data + */ function renderElement(data) { return new Morebits.quickForm.element(data).render(); } -describe("quickform", () => { - let inputConfig = { - type: "input", - label: "Label", - name: "inputname", - value: "prefilled value", +describe('quickform', () => { + const inputConfig = { + type: 'input', + label: 'Label', + name: 'inputname', + value: 'prefilled value' }; - let selectConfig = { - type: "select", - label: "Select label", - name: "selectname", + const selectConfig = { + type: 'select', + label: 'Select label', + name: 'selectname', list: [ - { label: "select label 1", value: "selectvalue1" }, - { label: "select label 2", value: "selectvalue2" }, - ], + { label: 'select label 1', value: 'selectvalue1' }, + { label: 'select label 2', value: 'selectvalue2' } + ] }; - let checkboxListConfig = { - type: "checkbox", - name: "checkboxlist1", + const checkboxListConfig = { + type: 'checkbox', + name: 'checkboxlist1', list: [ - { label: "checkbox 1", value: "checkval1" }, - { label: "checkbox 2", value: "checkval2", checked: true }, - ], + { label: 'checkbox 1', value: 'checkval1' }, + { label: 'checkbox 2', value: 'checkval2', checked: true } + ] }; - let checkboxesConfig = { - type: "checkbox", + const checkboxesConfig = { + type: 'checkbox', list: [ { - label: "checkbox 1", - value: "checkval1", - name: "checkname1", - checked: true, + label: 'checkbox 1', + value: 'checkval1', + name: 'checkname1', + checked: true }, - { label: "checkbox 2", value: "checkval2", name: "checkname2" }, - ], + { label: 'checkbox 2', value: 'checkval2', name: 'checkname2' } + ] }; - let radiosConfig = { - type: "radio", - name: "radiolist1", + const radiosConfig = { + type: 'radio', + name: 'radiolist1', list: [ { - label: "radio 1", - value: "radioval1", - name: "radioname1", + label: 'radio 1', + value: 'radioval1', + name: 'radioname1' }, { - label: "radio 2", - value: "radioval2", - name: "radioname2", - checked: true, - }, - ], + label: 'radio 2', + value: 'radioval2', + name: 'radioname2', + checked: true + } + ] }; - let textareaConfig = { - type: "textarea", - name: "textareaname1", - value: "textarea prefilled value", - cols: 4, + const textareaConfig = { + type: 'textarea', + name: 'textareaname1', + value: 'textarea prefilled value', + cols: 4 }; - let submitConfig = { - type: "submit", + const submitConfig = { + type: 'submit' }; - let buttonConfig = { - type: "button", - label: "button label", + const buttonConfig = { + type: 'button', + label: 'button label' }; - let getRenderedForm = () => { - let form = new Morebits.quickForm(function () {}); + const getRenderedForm = () => { + const form = new Morebits.quickForm(() => {}); form.append(inputConfig); form.append(checkboxesConfig); form.append(checkboxListConfig); @@ -80,42 +84,42 @@ describe("quickform", () => { form.append(submitConfig); form.append(buttonConfig); return form.render(); - } + }; - test("input element", () => { + test('input element', () => { expect(renderElement(inputConfig)).toMatchSnapshot(); }); - test("select element", () => { + test('select element', () => { expect(renderElement(selectConfig)).toMatchSnapshot(); }); - test("checkbox elements", () => { + test('checkbox elements', () => { expect(renderElement(checkboxListConfig)).toMatchSnapshot(); }); - test("checkbox elements (with data-single attribute)", () => { + test('checkbox elements (with data-single attribute)', () => { expect(renderElement(checkboxesConfig)).toMatchSnapshot(); }); - test("radio elements", () => { + test('radio elements', () => { expect(renderElement(radiosConfig)).toMatchSnapshot(); }); - test("textarea element", () => { + test('textarea element', () => { expect(renderElement(textareaConfig)).toMatchSnapshot(); }); - test("submit", () => { + test('submit', () => { expect(renderElement(submitConfig)).toMatchSnapshot(); }); - test("getInputData", () => { + test('getInputData', () => { expect(Morebits.quickForm.getInputData(getRenderedForm())).toMatchSnapshot(); }); - test("getElements", () => { - let form = getRenderedForm(); + test('getElements', () => { + const form = getRenderedForm(); expect(Morebits.quickForm.getElements(form, 'checkboxlist1')).toMatchSnapshot(); }); diff --git a/tests/morebits.string.js b/tests/morebits.string.js index 43505b9c7..cdedfc1f0 100644 --- a/tests/morebits.string.js +++ b/tests/morebits.string.js @@ -4,24 +4,24 @@ describe('Morebits.string', () => { assert.strictEqual(Morebits.string.escapeRegExp('Four_score_and_seven_years_ago'), 'Four[_ ]score[_ ]and[_ ]seven[_ ]years[_ ]ago', 'Underscores'); }); test('formatReasonForLog', () => { - var reason = 'They were wrong'; + const reason = 'They were wrong'; assert.strictEqual(Morebits.string.formatReasonForLog(reason), reason, 'Simple, unchanged'); - var more = 'Really wrong'; + const more = 'Really wrong'; assert.strictEqual(Morebits.string.formatReasonForLog(reason + '\n' + more), reason + '{{pb}}' + more, '\n -> {{pb}}'); assert.strictEqual(Morebits.string.formatReasonForLog('#' + reason + '\n' + more), '##' + reason + '{{pb}}' + more, 'Prepend extra #'); assert.strictEqual(Morebits.string.formatReasonForLog('*' + reason + '\n' + more), '#*' + reason + '{{pb}}' + more, 'Prepend extra #'); }); test('formatReasonText', () => { - var reason = 'They were correct'; + let reason = 'They were correct'; assert.strictEqual(Morebits.string.formatReasonText(reason), reason, 'Simple, unchanged'); assert.strictEqual(Morebits.string.formatReasonText(reason, true), reason + ' ~~~~', 'Simple'); - var more = 'Technically correct'; + const more = 'Technically correct'; assert.strictEqual(Morebits.string.formatReasonText(reason + '|' + more), reason + '{{subst:!}}' + more, 'Replace pipe'); assert.strictEqual(Morebits.string.formatReasonText(reason + '|' + more, true), reason + '{{subst:!}}' + more + ' ~~~~', 'Replace pipe'); reason += 'The {{best|kind|of}} correct: '; assert.strictEqual(Morebits.string.formatReasonText(reason + more), reason + more, 'No replace in nowiki'); assert.strictEqual(Morebits.string.formatReasonText(), '', 'Empty'); - var alreadySigned = 'already signed ~~~~'; + const alreadySigned = 'already signed ~~~~'; assert.strictEqual(Morebits.string.formatReasonText(alreadySigned, true), alreadySigned, 'No sig duplication'); assert.strictEqual(Morebits.string.formatReasonText('alreadySigned~~~~ ', true), 'alreadySigned~~~~', 'trims and avoids duplicating sig'); assert.strictEqual(Morebits.string.formatReasonText('Wow', true), 'Wow ~~~~', '3-letter reason'); @@ -38,13 +38,13 @@ describe('Morebits.string', () => { assert.false(Morebits.string.isInfinity('2020-04-17T09:31:00.000Z'), 'ISO string'); }); test('safeReplace', () => { - var string = '{{subst:board|thread=$SECTION|but=$NOTTHIS}} ~~~~'; + const string = '{{subst:board|thread=$SECTION|but=$NOTTHIS}} ~~~~'; assert.strictEqual(Morebits.string.safeReplace(string, '$SECTIONAL', 'thread$'), string, 'No replacement'); assert.strictEqual(Morebits.string.safeReplace(string, '$SECTION', 'thread$'), '{{subst:board|thread=thread$|but=$NOTTHIS}} ~~~~', 'Replacement'); }); test('splitWeightedByKeys', () => { - var split = ['{{thisis|one|template}}', '{{another|one}}', '[[heresalink]]', '[[thislink|ispiped]]']; - var text = split.join(' also '); + const split = ['{{thisis|one|template}}', '{{another|one}}', '[[heresalink]]', '[[thislink|ispiped]]']; + const text = split.join(' also '); assert.deepEqual(Morebits.string.splitWeightedByKeys(text, '{{', '}}'), split.slice(0, 2), 'Templates'); assert.deepEqual(Morebits.string.splitWeightedByKeys(text, '[[', ']]'), split.slice(2), 'Links'); assert.deepEqual(Morebits.string.splitWeightedByKeys(text, '{{', '}}', split[0]), [split[1]], 'Skiplist, non-array'); diff --git a/tests/morebits.taskManager.js b/tests/morebits.taskManager.js index e3d8e48bf..b44ad04fc 100644 --- a/tests/morebits.taskManager.js +++ b/tests/morebits.taskManager.js @@ -1,13 +1,13 @@ describe('Morebits.taskManager', () => { test('Contruction', () => { - var tm = new Morebits.taskManager(); + const tm = new Morebits.taskManager(); assert.true(tm instanceof Morebits.taskManager, 'Correct instance'); }); // Helper to generate functions as well as testing output in proper order; // verifySteps not used because it would require some extra duplication - var data = {}; - var generateFuncs = () => { + const data = {}; + const generateFuncs = () => { data.out = []; ['one', 'two', 'three', 'four'].forEach((step) => { data[step] = () => { @@ -19,7 +19,7 @@ describe('Morebits.taskManager', () => { test('Simple', () => { generateFuncs(); - var simple = new Morebits.taskManager(); + const simple = new Morebits.taskManager(); simple.add(data.one, []); simple.add(data.two, [data.one]); simple.add(data.three, [data.two]); @@ -30,7 +30,7 @@ describe('Morebits.taskManager', () => { }); test('Complex', () => { generateFuncs(); - var complex = new Morebits.taskManager(); + const complex = new Morebits.taskManager(); complex.add(data.one, [data.two]); complex.add(data.two, [data.three, data.four]); complex.add(data.three, []); diff --git a/tests/morebits.unbinder.js b/tests/morebits.unbinder.js index fa3419557..2540f457c 100644 --- a/tests/morebits.unbinder.js +++ b/tests/morebits.unbinder.js @@ -2,13 +2,13 @@ describe('Morebits.unbinder', () => { test('Construction', () => { assert.throws(() => new Morebits.unbinder(), 'throws: no string'); assert.throws(() => new Morebits.unbinder([42]), 'throws: not a string'); - var u = new Morebits.unbinder('Hello world'); + const u = new Morebits.unbinder('Hello world'); assert.true(u instanceof Morebits.unbinder, 'Correct instance'); assert.throws(() => u.unbind(), 'throws: Missing prefix'); assert.throws(() => u.unbind('w'), 'throws: Missing postfix'); }); test('Run', () => { - var u = new Morebits.unbinder('Hello world world'); + let u = new Morebits.unbinder('Hello world world'); u.unbind(''); u.content = u.content.replace(/world/g, 'earth'); assert.strictEqual(u.rebind(), 'Hello earth earth', 'Simple replace'); diff --git a/tests/morebits.wikitext.js b/tests/morebits.wikitext.js index c1942878d..2bf15abd0 100644 --- a/tests/morebits.wikitext.js +++ b/tests/morebits.wikitext.js @@ -1,15 +1,15 @@ describe('Morebits.wikitext', () => { test('parseTemplate', () => { // Function to help build a template from a sample object - var makeTemplate = function (data) { - var template = '{{' + data.name; - Object.keys(data.parameters).forEach(function (key) { + const makeTemplate = function (data) { + let template = '{{' + data.name; + Object.keys(data.parameters).forEach((key) => { template += '|' + key + '=' + data.parameters[key]; }); return template + '}}'; }; - var simple = { + const simple = { name: 'prod', parameters: { reason: 'because', @@ -19,7 +19,7 @@ describe('Morebits.wikitext', () => { }; assert.deepEqual(Morebits.wikitext.parseTemplate('Template: ' + makeTemplate(simple) + ' in text', 10), simple, 'Basic parameters'); - var involved = { + const involved = { name: 'Proposed deletion/dated', parameters: { concern: 'Text (paren) then [[piped|link]] and [[WP:WP/LINK]] {{{plural|with|a|template}}} then question?', @@ -31,10 +31,10 @@ describe('Morebits.wikitext', () => { assert.deepEqual(Morebits.wikitext.parseTemplate(makeTemplate(involved)), involved, 'Involved parameters'); // Try a variety of whitespace options - var whitespace = '{{' + involved.name + ' |concern = ' + involved.parameters.concern + ' | timestamp =' + involved.parameters.timestamp + '| nom= ' + involved.parameters.nom + '|help = ' + involved.parameters.help + ' }}'; + const whitespace = '{{' + involved.name + ' |concern = ' + involved.parameters.concern + ' | timestamp =' + involved.parameters.timestamp + '| nom= ' + involved.parameters.nom + '|help = ' + involved.parameters.help + ' }}'; assert.deepEqual(Morebits.wikitext.parseTemplate(whitespace), involved, 'Involved parameters with whitespace'); - var unnamed = { + const unnamed = { name: 'db-meta', parameters: { criterion: 'G13', @@ -43,10 +43,10 @@ describe('Morebits.wikitext', () => { 2: 'extra' } }; - var unnamedTemplate = '{{' + unnamed.name + '|criterion=' + unnamed.parameters.criterion + '||' + unnamed.parameters['1'] + '| middle =|2= ' + unnamed.parameters['2'] + '|}}'; + const unnamedTemplate = '{{' + unnamed.name + '|criterion=' + unnamed.parameters.criterion + '||' + unnamed.parameters['1'] + '| middle =|2= ' + unnamed.parameters['2'] + '|}}'; assert.deepEqual(Morebits.wikitext.parseTemplate(unnamedTemplate), unnamed, 'Unnamed and empty parameters'); - var multiLevel = { + const multiLevel = { name: 'toplevel', parameters: { named: '{{namedtop}}', @@ -56,7 +56,7 @@ describe('Morebits.wikitext', () => { } }; assert.deepEqual(Morebits.wikitext.parseTemplate(makeTemplate(multiLevel)), multiLevel, 'Multiple levels'); - var parser = { + const parser = { name: 'toplevel', parameters: { named: '{{namedtop}}', @@ -67,7 +67,7 @@ describe('Morebits.wikitext', () => { }; assert.deepEqual(Morebits.wikitext.parseTemplate(makeTemplate(parser)), parser, 'Parser function'); - var internal = { + const internal = { name: 'internal', parameters: { named: 'parameter {{tq|with an internal}} template', @@ -80,8 +80,8 @@ describe('Morebits.wikitext', () => { }); test('Morebits.wikitext.page', () => { - var text = '{{short description}}{{about}}[[File:Fee.svg]]O, [[Juliet|she]] doth {{plural|teach}} the torches to burn bright!'; - var page = new Morebits.wikitext.page(text); + const text = '{{short description}}{{about}}[[File:Fee.svg]]O, [[Juliet|she]] doth {{plural|teach}} the torches to burn bright!'; + const page = new Morebits.wikitext.page(text); assert.true(page instanceof Morebits.wikitext.page, 'Correct instance'); assert.strictEqual(page.getText(), text, 'Got text'); @@ -91,7 +91,7 @@ describe('Morebits.wikitext', () => { // Define all the tests individually, with the appropriate method, // input, expected output, and (spreaded) parameters. - var tests = [ + const tests = [ { name: 'simple', method: 'removeLink', @@ -354,7 +354,7 @@ describe('Morebits.wikitext', () => { ]; tests.forEach((test) => { - var page = new Morebits.wikitext.page(test.input); + const page = new Morebits.wikitext.page(test.input); assert.strictEqual(page[test.method](...test.params).getText(), test.expected, test.method + ' - ' + test.name); }); }); diff --git a/tests/twinkletag.test.js b/tests/twinkletag.test.js index 16f913d55..dc9586b0d 100644 --- a/tests/twinkletag.test.js +++ b/tests/twinkletag.test.js @@ -6,7 +6,7 @@ describe('modules/twinkletag', () => { const expected = undefined; expect(Twinkle.tag.checkIncompatible(incompatibleTags, tagsToCheck)).toBe(expected); }); - + test('no conflicts, 1 tag to check', () => { const incompatibleTags = ['Bad GIF', 'Bad JPEG', 'Bad SVG', 'Bad format']; const tagsToCheck = ['Better source requested']; diff --git a/tests/twinklewarn.test.js b/tests/twinklewarn.test.js index de88f45cf..3684775a1 100644 --- a/tests/twinklewarn.test.js +++ b/tests/twinklewarn.test.js @@ -1,6 +1,6 @@ describe('modules/twinklewarn', () => { describe('getTemplateProperty', () => { - let templates = { + const templates = { levels: { 'Common warnings': { 'uw-vandalism': { @@ -24,7 +24,7 @@ describe('modules/twinklewarn', () => { label: 'Vandalism', summary: 'Only warning: Vandalism' } - }, + } } }, @@ -34,15 +34,15 @@ describe('modules/twinklewarn', () => { summary: 'Notice: Not using edit summary', hideLinkedPage: true, hideReason: true - }, + } }, - + singlewarn: { 'uw-attack': { label: 'Creating attack pages', summary: 'Warning: Creating attack pages', suppressArticleInSummary: true - }, + } } }; @@ -74,4 +74,4 @@ describe('modules/twinklewarn', () => { expect(Twinkle.warn.getTemplateProperty(templates, 'uw-editsummary2', 'hideLinkedPage')).toBe(true); }); }); -}); \ No newline at end of file +}); diff --git a/tests/twinklexfd.test.js b/tests/twinklexfd.test.js index b96b87a8f..0fd9812bb 100644 --- a/tests/twinklexfd.test.js +++ b/tests/twinklexfd.test.js @@ -4,7 +4,7 @@ describe('modules/twinklexfd', () => { const pageWikitext = ` ==== Requests to revert undiscussed moves ====`; - const wikitextToInsert = `* {{RMassist/core}}`; + const wikitextToInsert = '* {{RMassist/core}}'; const expected = ` * {{RMassist/core}} @@ -18,7 +18,7 @@ describe('modules/twinklexfd', () => { ` ==== Requests to revert undiscussed moves ====`; - const wikitextToInsert = `* {{RMassist/core}}`; + const wikitextToInsert = '* {{RMassist/core}}'; const expected = ` * {{RMassist/core}} @@ -33,7 +33,7 @@ describe('modules/twinklexfd', () => { ==== Requests to revert undiscussed moves ====`; - const wikitextToInsert = `* {{RMassist/core}}`; + const wikitextToInsert = '* {{RMassist/core}}'; const expected = ` * {{RMassist/core}} @@ -47,7 +47,7 @@ describe('modules/twinklexfd', () => { ` * {{RMassist/core2}} ==== Requests to revert undiscussed moves ====`; - const wikitextToInsert = `* {{RMassist/core}}`; + const wikitextToInsert = '* {{RMassist/core}}'; const expected = ` * {{RMassist/core2}} @@ -63,7 +63,7 @@ describe('modules/twinklexfd', () => { * {{RMassist/core2}} * {{RMassist/core3}} ==== Requests to revert undiscussed moves ====`; - const wikitextToInsert = `* {{RMassist/core}}`; + const wikitextToInsert = '* {{RMassist/core}}'; const expected = ` * {{RMassist/core2}} @@ -80,7 +80,7 @@ describe('modules/twinklexfd', () => { * {{RMassist/core2}} ==== Requests to revert undiscussed moves ====`; - const wikitextToInsert = `* {{RMassist/core}}`; + const wikitextToInsert = '* {{RMassist/core}}'; const expected = ` * {{RMassist/core2}} @@ -97,7 +97,7 @@ describe('modules/twinklexfd', () => { ==== Requests to revert undiscussed moves ====`; - const wikitextToInsert = `* {{RMassist/core}}`; + const wikitextToInsert = '* {{RMassist/core}}'; const expected = ` * {{RMassist/core2}} From 6812d902daa03a0da249d962d2f1205afd698ddf Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:28:12 -0800 Subject: [PATCH 4/8] eslint: fix camelcase in tests (#2127) manual fixes using F2 rename variable in VS Code --- tests/.eslintrc.json | 1 - tests/morebits.date.js | 38 +++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json index bf15fcf20..d8e4a4e58 100644 --- a/tests/.eslintrc.json +++ b/tests/.eslintrc.json @@ -13,7 +13,6 @@ "object-curly-spacing": "off", "space-in-parens": "off", - "camelcase": "warn", "new-cap": "warn", "no-undef": "warn", "no-useless-escape": "warn", diff --git a/tests/morebits.date.js b/tests/morebits.date.js index c39cbef26..9327c471a 100644 --- a/tests/morebits.date.js +++ b/tests/morebits.date.js @@ -1,6 +1,6 @@ describe('Morebits.date', () => { const now = Date.now(); - const ts_mw = '16:26, 7 November 2020 (UTC)', ts_iso = '2020-11-07T16:26:00.000Z', naive = 20201107162600; + const timestampMediaWiki = '16:26, 7 November 2020 (UTC)', timestampIso = '2020-11-07T16:26:00.000Z', naive = 20201107162600; test('Construction', () => { // getTime and toISOString imply testing of inherited methods // Allow off-by-one values in milliseconds for not-quite-simultaneous date contructions @@ -8,13 +8,13 @@ describe('Morebits.date', () => { assert.strictEqual(new Morebits.date(now).getTime(), new Date(now).getTime(), 'Constructor from timestring'); assert.strictEqual(new Morebits.date(2020, 11, 7, 16, 26).getTime(), new Date(2020, 11, 7, 16, 26).getTime(), 'Constructor from parts'); - assert.strictEqual(new Morebits.date(ts_mw).toISOString(), ts_iso, 'enWiki timestamp format'); - assert.strictEqual(new Morebits.date(naive).toISOString(), ts_iso, 'MediaWiki 14-digit number'); - assert.strictEqual(new Morebits.date(naive.toString()).toISOString(), ts_iso, 'MediaWiki 14-digit string'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).toISOString(), timestampIso, 'enWiki timestamp format'); + assert.strictEqual(new Morebits.date(naive).toISOString(), timestampIso, 'MediaWiki 14-digit number'); + assert.strictEqual(new Morebits.date(naive.toString()).toISOString(), timestampIso, 'MediaWiki 14-digit string'); assert.strictEqual(new Morebits.date(parseInt(naive / 10, 10)).toISOString(), new Date(parseInt(naive / 10, 10)).toISOString(), 'native 13 digit'); assert.strictEqual(new Morebits.date(naive * 10).toISOString(), new Date(naive * 10).toISOString(), 'native 15 digit'); }); - const date = new Morebits.date(ts_mw); + const date = new Morebits.date(timestampMediaWiki); test('Methods', () => { assert.true(date.isValid(), 'Valid'); // Logs a message; not a failure, but annoying @@ -41,22 +41,22 @@ describe('Morebits.date', () => { assert.false(date.monthHeaderRegex().test('==December 2020=='), 'Wrong month'); }); test('add/subtract', () => { - assert.strictEqual(new Morebits.date(ts_mw).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day'); - assert.strictEqual(new Morebits.date(ts_mw).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day'); - assert.strictEqual(new Morebits.date(ts_mw).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string"); - assert.strictEqual(new Morebits.date(ts_mw).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day'); - assert.strictEqual(new Morebits.date(ts_mw).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks'); - assert.strictEqual(new Morebits.date(ts_mw).add(2, 'weeks').subtract(2, 'weeks').toISOString(), ts_iso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string"); + assert.strictEqual(new Morebits.date(timestampMediaWiki).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').subtract(2, 'weeks').toISOString(), timestampIso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST - assert.strictEqual(new Morebits.date(ts_mw).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second'); - assert.strictEqual(new Morebits.date(ts_mw).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute'); - assert.strictEqual(new Morebits.date(ts_mw).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour'); - assert.strictEqual(new Morebits.date(ts_mw).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month'); - assert.strictEqual(new Morebits.date(ts_mw).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month'); + assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year'); - assert.throws(() => new Morebits.date(ts_mw).add('forty-two'), 'throws: non-number provided'); - assert.throws(() => new Morebits.date(ts_mw).add(1), 'throws: no unit'); - assert.throws(() => new Morebits.date(ts_mw).subtract(1, 'dayo'), 'throws: bad unit'); + assert.throws(() => new Morebits.date(timestampMediaWiki).add('forty-two'), 'throws: non-number provided'); + assert.throws(() => new Morebits.date(timestampMediaWiki).add(1), 'throws: no unit'); + assert.throws(() => new Morebits.date(timestampMediaWiki).subtract(1, 'dayo'), 'throws: bad unit'); }); test('Formats', () => { assert.strictEqual(new Morebits.date(now).format('YYYY-MM-DDTHH:mm:ss.SSSZ', 'utc'), new Date(now).toISOString(), 'ISO format'); From c2874ba15709622743266a469a1e6f7c49084d47 Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:28:45 -0800 Subject: [PATCH 5/8] eslint: fix `strict` in tests (#2128) * eslint: fix `strict` in tests manual fixes * forgot a file * remove comma --- tests/.eslintrc.json | 3 +-- tests/jest.setup.js | 2 ++ tests/morebits.array.js | 2 ++ tests/morebits.batchOperation.js | 2 ++ tests/morebits.createHtml.js | 2 ++ tests/morebits.date.js | 2 ++ tests/morebits.ip.js | 2 ++ tests/morebits.js | 2 ++ tests/morebits.quickForm.js | 2 ++ tests/morebits.string.js | 2 ++ tests/morebits.taskManager.js | 2 ++ tests/morebits.unbinder.js | 2 ++ tests/morebits.wikitext.js | 2 ++ tests/twinkleblock.test.js | 2 ++ tests/twinkletag.test.js | 2 ++ tests/twinklewarn.test.js | 2 ++ tests/twinklexfd.test.js | 2 ++ 17 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json index d8e4a4e58..9ad47d2d9 100644 --- a/tests/.eslintrc.json +++ b/tests/.eslintrc.json @@ -15,7 +15,6 @@ "new-cap": "warn", "no-undef": "warn", - "no-useless-escape": "warn", - "strict": "warn" + "no-useless-escape": "warn" } } diff --git a/tests/jest.setup.js b/tests/jest.setup.js index a63a116eb..3cb094332 100644 --- a/tests/jest.setup.js +++ b/tests/jest.setup.js @@ -1,3 +1,5 @@ +'use strict'; + // Tweak some mw.configs as needed by tests mw.config.set({ wgPageName: 'Macbeth,_King_of_Scotland', diff --git a/tests/morebits.array.js b/tests/morebits.array.js index c64b9d8a9..b8c29542c 100644 --- a/tests/morebits.array.js +++ b/tests/morebits.array.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.array', () => { test('chunk', () => { assert.deepEqual(Morebits.array.chunk([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3), [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]], '10 over 3'); diff --git a/tests/morebits.batchOperation.js b/tests/morebits.batchOperation.js index 76bab9616..06aed974a 100644 --- a/tests/morebits.batchOperation.js +++ b/tests/morebits.batchOperation.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.batchOperation', () => { test('Contruction', () => { assert.true(new Morebits.batchOperation() instanceof Morebits.batchOperation, 'Correct instance'); diff --git a/tests/morebits.createHtml.js b/tests/morebits.createHtml.js index 63563c9e4..07be8fe88 100644 --- a/tests/morebits.createHtml.js +++ b/tests/morebits.createHtml.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.createHtml', () => { test('createHtml', () => { diff --git a/tests/morebits.date.js b/tests/morebits.date.js index 9327c471a..b9d535948 100644 --- a/tests/morebits.date.js +++ b/tests/morebits.date.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.date', () => { const now = Date.now(); const timestampMediaWiki = '16:26, 7 November 2020 (UTC)', timestampIso = '2020-11-07T16:26:00.000Z', naive = 20201107162600; diff --git a/tests/morebits.ip.js b/tests/morebits.ip.js index 06e5b5516..d4f2da800 100644 --- a/tests/morebits.ip.js +++ b/tests/morebits.ip.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.ip', () => { test('sanitizeIPv6', () => { assert.strictEqual(Morebits.ip.sanitizeIPv6('2001:0db8:0010:0000:0000:0000:0000:0001'), '2001:DB8:10:0:0:0:0:1', 'Shorten IPv6'); diff --git a/tests/morebits.js b/tests/morebits.js index 741eb212a..13083740c 100644 --- a/tests/morebits.js +++ b/tests/morebits.js @@ -1,3 +1,5 @@ +'use strict'; + describe('constants', () => { test('userIsSysop', () => { assert.true(Morebits.userIsSysop, 'Is sysop'); diff --git a/tests/morebits.quickForm.js b/tests/morebits.quickForm.js index 964aa59dd..de48acb10 100644 --- a/tests/morebits.quickForm.js +++ b/tests/morebits.quickForm.js @@ -1,3 +1,5 @@ +'use strict'; + /** * Simple helper to render a quickform element * diff --git a/tests/morebits.string.js b/tests/morebits.string.js index cdedfc1f0..bce71c9b9 100644 --- a/tests/morebits.string.js +++ b/tests/morebits.string.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.string', () => { test('escapeRegExp', () => { assert.strictEqual(Morebits.string.escapeRegExp('Four score and seven years ago'), 'Four[_ ]score[_ ]and[_ ]seven[_ ]years[_ ]ago', 'Spaces'); diff --git a/tests/morebits.taskManager.js b/tests/morebits.taskManager.js index b44ad04fc..7d5ea5f00 100644 --- a/tests/morebits.taskManager.js +++ b/tests/morebits.taskManager.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.taskManager', () => { test('Contruction', () => { const tm = new Morebits.taskManager(); diff --git a/tests/morebits.unbinder.js b/tests/morebits.unbinder.js index 2540f457c..98e7362ec 100644 --- a/tests/morebits.unbinder.js +++ b/tests/morebits.unbinder.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.unbinder', () => { test('Construction', () => { assert.throws(() => new Morebits.unbinder(), 'throws: no string'); diff --git a/tests/morebits.wikitext.js b/tests/morebits.wikitext.js index 2bf15abd0..6d7a8b5e1 100644 --- a/tests/morebits.wikitext.js +++ b/tests/morebits.wikitext.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Morebits.wikitext', () => { test('parseTemplate', () => { // Function to help build a template from a sample object diff --git a/tests/twinkleblock.test.js b/tests/twinkleblock.test.js index 732af83da..83ffe60bb 100644 --- a/tests/twinkleblock.test.js +++ b/tests/twinkleblock.test.js @@ -1,3 +1,5 @@ +'use strict'; + describe('modules/twinkleblock', () => { describe('combineFormDataAndFieldTemplateOptions', () => { // https://github.com/wikimedia-gadgets/twinkle/issues/2106 diff --git a/tests/twinkletag.test.js b/tests/twinkletag.test.js index dc9586b0d..eeb228d24 100644 --- a/tests/twinkletag.test.js +++ b/tests/twinkletag.test.js @@ -1,3 +1,5 @@ +'use strict'; + describe('modules/twinkletag', () => { describe('checkIncompatible', () => { test('no conflicts, 0 tags to check', () => { diff --git a/tests/twinklewarn.test.js b/tests/twinklewarn.test.js index 3684775a1..5e054df2c 100644 --- a/tests/twinklewarn.test.js +++ b/tests/twinklewarn.test.js @@ -1,3 +1,5 @@ +'use strict'; + describe('modules/twinklewarn', () => { describe('getTemplateProperty', () => { const templates = { diff --git a/tests/twinklexfd.test.js b/tests/twinklexfd.test.js index 0fd9812bb..c895b249d 100644 --- a/tests/twinklexfd.test.js +++ b/tests/twinklexfd.test.js @@ -1,3 +1,5 @@ +'use strict'; + describe('modules/twinklexfd', () => { describe('insertRMTR', () => { test('0 rows, 1 line breaks', () => { From 95efda0b444582c8e5817fc0ec217c2434f66e1e Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:32:31 -0800 Subject: [PATCH 6/8] eslint: fix new-cap in tests (#2129) manual fixes related #2084 --- tests/.eslintrc.json | 1 - tests/morebits.batchOperation.js | 4 +-- tests/morebits.date.js | 56 ++++++++++++++++---------------- tests/morebits.quickForm.js | 4 +-- tests/morebits.taskManager.js | 6 ++-- tests/morebits.unbinder.js | 10 +++--- tests/morebits.wikitext.js | 8 ++--- 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json index 9ad47d2d9..e2d17abda 100644 --- a/tests/.eslintrc.json +++ b/tests/.eslintrc.json @@ -13,7 +13,6 @@ "object-curly-spacing": "off", "space-in-parens": "off", - "new-cap": "warn", "no-undef": "warn", "no-useless-escape": "warn" } diff --git a/tests/morebits.batchOperation.js b/tests/morebits.batchOperation.js index 06aed974a..9fa045008 100644 --- a/tests/morebits.batchOperation.js +++ b/tests/morebits.batchOperation.js @@ -2,9 +2,9 @@ describe('Morebits.batchOperation', () => { test('Contruction', () => { - assert.true(new Morebits.batchOperation() instanceof Morebits.batchOperation, 'Correct instance'); + assert.true(new Morebits.BatchOperation() instanceof Morebits.batchOperation, 'Correct instance'); }); - const batch = new Morebits.batchOperation(); + const batch = new Morebits.BatchOperation(); const pageList = ['Macbeth', 'Hamlet', 'Romeo and Juliet', 'Much Ado About Nothing', 'Tempest']; batch.setPageList(pageList); const chunkLength = 2; diff --git a/tests/morebits.date.js b/tests/morebits.date.js index b9d535948..13f419ed3 100644 --- a/tests/morebits.date.js +++ b/tests/morebits.date.js @@ -6,21 +6,21 @@ describe('Morebits.date', () => { test('Construction', () => { // getTime and toISOString imply testing of inherited methods // Allow off-by-one values in milliseconds for not-quite-simultaneous date contructions - expect(Math.abs(new Morebits.date().getTime() - Date.now())).toBeLessThanOrEqual(1); + expect(Math.abs(new Morebits.Date().getTime() - Date.now())).toBeLessThanOrEqual(1); - assert.strictEqual(new Morebits.date(now).getTime(), new Date(now).getTime(), 'Constructor from timestring'); - assert.strictEqual(new Morebits.date(2020, 11, 7, 16, 26).getTime(), new Date(2020, 11, 7, 16, 26).getTime(), 'Constructor from parts'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).toISOString(), timestampIso, 'enWiki timestamp format'); - assert.strictEqual(new Morebits.date(naive).toISOString(), timestampIso, 'MediaWiki 14-digit number'); - assert.strictEqual(new Morebits.date(naive.toString()).toISOString(), timestampIso, 'MediaWiki 14-digit string'); - assert.strictEqual(new Morebits.date(parseInt(naive / 10, 10)).toISOString(), new Date(parseInt(naive / 10, 10)).toISOString(), 'native 13 digit'); - assert.strictEqual(new Morebits.date(naive * 10).toISOString(), new Date(naive * 10).toISOString(), 'native 15 digit'); + assert.strictEqual(new Morebits.Date(now).getTime(), new Date(now).getTime(), 'Constructor from timestring'); + assert.strictEqual(new Morebits.Date(2020, 11, 7, 16, 26).getTime(), new Date(2020, 11, 7, 16, 26).getTime(), 'Constructor from parts'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).toISOString(), timestampIso, 'enWiki timestamp format'); + assert.strictEqual(new Morebits.Date(naive).toISOString(), timestampIso, 'MediaWiki 14-digit number'); + assert.strictEqual(new Morebits.Date(naive.toString()).toISOString(), timestampIso, 'MediaWiki 14-digit string'); + assert.strictEqual(new Morebits.Date(parseInt(naive / 10, 10)).toISOString(), new Date(parseInt(naive / 10, 10)).toISOString(), 'native 13 digit'); + assert.strictEqual(new Morebits.Date(naive * 10).toISOString(), new Date(naive * 10).toISOString(), 'native 15 digit'); }); - const date = new Morebits.date(timestampMediaWiki); + const date = new Morebits.Date(timestampMediaWiki); test('Methods', () => { assert.true(date.isValid(), 'Valid'); // Logs a message; not a failure, but annoying - assert.false(new Morebits.date('no').isValid(), 'Invalid'); + assert.false(new Morebits.Date('no').isValid(), 'Invalid'); // Ideally we would test the differences between UTC and non-UTC dates assert.strictEqual(date.getUTCDayName(), 'Saturday', 'getUTCDayName'); @@ -28,7 +28,7 @@ describe('Morebits.date', () => { assert.strictEqual(date.getUTCMonthName(), 'November', 'getUTCMonthName'); assert.strictEqual(date.getUTCMonthNameAbbrev(), 'Nov', 'getUTCMonthNameAbbrev'); - assert.true(new Morebits.date(now).isAfter(date), 'isAfter'); + assert.true(new Morebits.Date(now).isAfter(date), 'isAfter'); assert.true(date.isBefore(new Date(now)), 'isBefore'); }); test('RegEx headers', () => { @@ -43,25 +43,25 @@ describe('Morebits.date', () => { assert.false(date.monthHeaderRegex().test('==December 2020=='), 'Wrong month'); }); test('add/subtract', () => { - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string"); - assert.strictEqual(new Morebits.date(timestampMediaWiki).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').subtract(2, 'weeks').toISOString(), timestampIso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string"); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(2, 'weeks').subtract(2, 'weeks').toISOString(), timestampIso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year'); - assert.throws(() => new Morebits.date(timestampMediaWiki).add('forty-two'), 'throws: non-number provided'); - assert.throws(() => new Morebits.date(timestampMediaWiki).add(1), 'throws: no unit'); - assert.throws(() => new Morebits.date(timestampMediaWiki).subtract(1, 'dayo'), 'throws: bad unit'); + assert.throws(() => new Morebits.Date(timestampMediaWiki).add('forty-two'), 'throws: non-number provided'); + assert.throws(() => new Morebits.Date(timestampMediaWiki).add(1), 'throws: no unit'); + assert.throws(() => new Morebits.Date(timestampMediaWiki).subtract(1, 'dayo'), 'throws: bad unit'); }); test('Formats', () => { - assert.strictEqual(new Morebits.date(now).format('YYYY-MM-DDTHH:mm:ss.SSSZ', 'utc'), new Date(now).toISOString(), 'ISO format'); + assert.strictEqual(new Morebits.Date(now).format('YYYY-MM-DDTHH:mm:ss.SSSZ', 'utc'), new Date(now).toISOString(), 'ISO format'); assert.strictEqual(date.format('dddd D MMMM YY h:mA', 'utc'), 'Saturday 7 November 20 4:26PM', 'Some weirder stuff'); assert.strictEqual(date.format('MMt[h month], [d]a[y] D, h [o\'clock] A', 'utc'), '11th month, day 7, 4 o\'clock PM', 'Format escapes'); assert.strictEqual(date.format('dddd D MMMM YY h:mA', 600), 'Sunday 8 November 20 2:26AM', 'non-UTC formatting'); @@ -70,7 +70,7 @@ describe('Morebits.date', () => { test('Calendar', () => { assert.strictEqual(date.calendar('utc'), '2020-11-07', 'Old calendar'); assert.strictEqual(date.calendar(600), '2020-11-08', 'Old non-UTC'); - assert.strictEqual(new Morebits.date(now).calendar('utc'), 'Today at ' + new Morebits.date(now).format('h:mm A', 'utc'), 'New calendar'); - assert.strictEqual(new Morebits.date(now).subtract(1, 'day').calendar('utc'), 'Yesterday at ' + new Morebits.date(now).format('h:mm A', 'utc'), 'Close calendar'); + assert.strictEqual(new Morebits.Date(now).calendar('utc'), 'Today at ' + new Morebits.Date(now).format('h:mm A', 'utc'), 'New calendar'); + assert.strictEqual(new Morebits.Date(now).subtract(1, 'day').calendar('utc'), 'Yesterday at ' + new Morebits.Date(now).format('h:mm A', 'utc'), 'Close calendar'); }); }); diff --git a/tests/morebits.quickForm.js b/tests/morebits.quickForm.js index de48acb10..c3f2d5e4e 100644 --- a/tests/morebits.quickForm.js +++ b/tests/morebits.quickForm.js @@ -6,7 +6,7 @@ * @param data */ function renderElement(data) { - return new Morebits.quickForm.element(data).render(); + return new Morebits.QuickForm.Element(data).render(); } describe('quickform', () => { @@ -77,7 +77,7 @@ describe('quickform', () => { }; const getRenderedForm = () => { - const form = new Morebits.quickForm(() => {}); + const form = new Morebits.QuickForm(() => {}); form.append(inputConfig); form.append(checkboxesConfig); form.append(checkboxListConfig); diff --git a/tests/morebits.taskManager.js b/tests/morebits.taskManager.js index 7d5ea5f00..bcd03db49 100644 --- a/tests/morebits.taskManager.js +++ b/tests/morebits.taskManager.js @@ -2,7 +2,7 @@ describe('Morebits.taskManager', () => { test('Contruction', () => { - const tm = new Morebits.taskManager(); + const tm = new Morebits.TaskManager(); assert.true(tm instanceof Morebits.taskManager, 'Correct instance'); }); @@ -21,7 +21,7 @@ describe('Morebits.taskManager', () => { test('Simple', () => { generateFuncs(); - const simple = new Morebits.taskManager(); + const simple = new Morebits.TaskManager(); simple.add(data.one, []); simple.add(data.two, [data.one]); simple.add(data.three, [data.two]); @@ -32,7 +32,7 @@ describe('Morebits.taskManager', () => { }); test('Complex', () => { generateFuncs(); - const complex = new Morebits.taskManager(); + const complex = new Morebits.TaskManager(); complex.add(data.one, [data.two]); complex.add(data.two, [data.three, data.four]); complex.add(data.three, []); diff --git a/tests/morebits.unbinder.js b/tests/morebits.unbinder.js index 98e7362ec..4c4cd6644 100644 --- a/tests/morebits.unbinder.js +++ b/tests/morebits.unbinder.js @@ -2,20 +2,20 @@ describe('Morebits.unbinder', () => { test('Construction', () => { - assert.throws(() => new Morebits.unbinder(), 'throws: no string'); - assert.throws(() => new Morebits.unbinder([42]), 'throws: not a string'); - const u = new Morebits.unbinder('Hello world'); + assert.throws(() => new Morebits.Unbinder(), 'throws: no string'); + assert.throws(() => new Morebits.Unbinder([42]), 'throws: not a string'); + const u = new Morebits.Unbinder('Hello world'); assert.true(u instanceof Morebits.unbinder, 'Correct instance'); assert.throws(() => u.unbind(), 'throws: Missing prefix'); assert.throws(() => u.unbind('w'), 'throws: Missing postfix'); }); test('Run', () => { - let u = new Morebits.unbinder('Hello world world'); + let u = new Morebits.Unbinder('Hello world world'); u.unbind(''); u.content = u.content.replace(/world/g, 'earth'); assert.strictEqual(u.rebind(), 'Hello earth earth', 'Simple replace'); - u = new Morebits.unbinder('Hello world world [link link] [[link|link]]'); + u = new Morebits.Unbinder('Hello world world [link link] [[link|link]]'); assert.true(u instanceof Morebits.unbinder, 'Correct instance'); u.unbind(''); u.unbind('\\[\\[', '\\]\\]'); diff --git a/tests/morebits.wikitext.js b/tests/morebits.wikitext.js index 6d7a8b5e1..a6e5a3b45 100644 --- a/tests/morebits.wikitext.js +++ b/tests/morebits.wikitext.js @@ -83,13 +83,13 @@ describe('Morebits.wikitext', () => { test('Morebits.wikitext.page', () => { const text = '{{short description}}{{about}}[[File:Fee.svg]]O, [[Juliet|she]] doth {{plural|teach}} the torches to burn bright!'; - const page = new Morebits.wikitext.page(text); + const page = new Morebits.wikitext.Page(text); assert.true(page instanceof Morebits.wikitext.page, 'Correct instance'); assert.strictEqual(page.getText(), text, 'Got text'); // Throws - assert.throws(() => new Morebits.wikitext.page(text).insertAfterTemplates(), 'throws: no tag'); - assert.throws(() => new Morebits.wikitext.page(text).insertAfterTemplates('tag'), 'throws: no regex'); + assert.throws(() => new Morebits.wikitext.Page(text).insertAfterTemplates(), 'throws: no tag'); + assert.throws(() => new Morebits.wikitext.Page(text).insertAfterTemplates('tag'), 'throws: no regex'); // Define all the tests individually, with the appropriate method, // input, expected output, and (spreaded) parameters. @@ -356,7 +356,7 @@ describe('Morebits.wikitext', () => { ]; tests.forEach((test) => { - const page = new Morebits.wikitext.page(test.input); + const page = new Morebits.wikitext.Page(test.input); assert.strictEqual(page[test.method](...test.params).getText(), test.expected, test.method + ' - ' + test.name); }); }); From 2a38b76589b757a9233e49641218016ed6eaa95c Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:33:54 -0800 Subject: [PATCH 7/8] eslint: fix no-undef in tests (#2130) manual fixes basically just hard-code all the existing globals into the "globals" section of .eslintrc.json --- tests/.eslintrc.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json index e2d17abda..df1feabfb 100644 --- a/tests/.eslintrc.json +++ b/tests/.eslintrc.json @@ -5,6 +5,15 @@ "env": { "jest": true }, + "globals": { + "assert": "readonly", + "document": "readonly", + "jQuery": "readonly", + "Morebits": "readonly", + "mw": "readonly", + "Twinkle": "readonly", + "window": "readonly" + }, "root": true, "rules": { "array-bracket-spacing": "off", @@ -13,7 +22,6 @@ "object-curly-spacing": "off", "space-in-parens": "off", - "no-undef": "warn", "no-useless-escape": "warn" } } From 58828bd80341d54e1e2c35a9624d4f078bc2f945 Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:42:44 -0800 Subject: [PATCH 8/8] eslint: fix no-useless-escape in tests (#2131) * eslint: fix no-useless-escape in tests manual fixes * comma --- tests/.eslintrc.json | 4 +--- tests/morebits.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json index df1feabfb..3e27609f3 100644 --- a/tests/.eslintrc.json +++ b/tests/.eslintrc.json @@ -20,8 +20,6 @@ "computed-property-spacing": "off", "no-shadow": "off", "object-curly-spacing": "off", - "space-in-parens": "off", - - "no-useless-escape": "warn" + "space-in-parens": "off" } } diff --git a/tests/morebits.js b/tests/morebits.js index 13083740c..eb03a660f 100644 --- a/tests/morebits.js +++ b/tests/morebits.js @@ -20,7 +20,7 @@ describe('methods', () => { assert.strictEqual(Morebits.pageNameRegex(''), '', 'Empty'); assert.strictEqual(Morebits.pageNameRegex('a'), '[Aa]', 'Single character'); assert.strictEqual(Morebits.pageNameRegex('#'), '#', 'Single same-case'); - assert.strictEqual(Morebits.pageNameRegex('*$, \{}(a) |.?+-^ [ ]'), '\\*\\$,[_ ]\\{\\}\\(a\\)[_ ]\\|\\.\\?\\+\\-\\^\[_ ]\\[[_ ]\\]', 'Special characters'); + assert.strictEqual(Morebits.pageNameRegex('*$, {}(a) |.?+-^ [ ]'), '\\*\\$,[_ ]\\{\\}\\(a\\)[_ ]\\|\\.\\?\\+\\-\\^[_ ]\\[[_ ]\\]', 'Special characters'); }); test('namespaceRegex', () => { assert.strictEqual(Morebits.namespaceRegex([6]), '(?:[Ff][Ii][Ll][Ee]|[Ii][Mm][Aa][Gg][Ee])', 'Files');