diff --git a/.eslintrc.json b/.eslintrc.json index 5f5867080..904444837 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -62,7 +62,6 @@ "no-use-before-define": "warn", "no-useless-concat": "warn", "no-var": "warn", - "prefer-const": "warn", "unicorn/prefer-string-slice": "warn" } } diff --git a/modules/twinklebatchprotect.js b/modules/twinklebatchprotect.js index 6f745f26d..8e7c61486 100644 --- a/modules/twinklebatchprotect.js +++ b/modules/twinklebatchprotect.js @@ -180,7 +180,8 @@ Twinkle.batchprotect.callback = function twinklebatchprotectCallback() { pages.sort(Twinkle.sortByNamespace); pages.forEach((page) => { const metadata = []; - let missing = !!page.missing, editProt; + const missing = !!page.missing; + let editProt; if (missing) { metadata.push('page does not exist'); diff --git a/modules/twinkleblock.js b/modules/twinkleblock.js index 16c39050c..3b085e756 100644 --- a/modules/twinkleblock.js +++ b/modules/twinkleblock.js @@ -2,7 +2,8 @@ (function() { -let api = new mw.Api(), relevantUserName, blockedUserName; +const api = new mw.Api(); +let relevantUserName, blockedUserName; const menuFormattedNamespaces = $.extend({}, mw.config.get('wgFormattedNamespaces')); menuFormattedNamespaces[0] = '(Article)'; @@ -156,8 +157,8 @@ Twinkle.block.fetchedData = {}; // Processes the data from a a query response, separated from // Twinkle.block.fetchUserInfo to allow reprocessing of already-fetched data Twinkle.block.processUserInfo = function twinkleblockProcessUserInfo(data, fn) { - let blockinfo = data.query.blocks[0], - userinfo = data.query.users[0]; + let blockinfo = data.query.blocks[0]; + const userinfo = data.query.users[0]; // If an IP is blocked *and* rangeblocked, the above finds // whichever block is more recent, not necessarily correct. // Three seems... unlikely @@ -296,7 +297,8 @@ Twinkle.block.callback.change_block64 = function twinkleblockCallbackChangeBlock }; Twinkle.block.callback.change_action = function twinkleblockCallbackChangeAction(e) { - let field_preset, field_template_options, field_block_options, $form = $(e.target.form); + let field_preset, field_template_options, field_block_options; + const $form = $(e.target.form); // Make ifs shorter const blockBox = $form.find('[name=actiontype][value=block]').is(':checked'); const templateBox = $form.find('[name=actiontype][value=template]').is(':checked'); @@ -1572,7 +1574,8 @@ Twinkle.block.callback.toggle_ds_reason = function twinkleblockCallbackToggleDSR }; Twinkle.block.callback.update_form = function twinkleblockCallbackUpdateForm(e, data) { - let form = e.target.form, expiry = data.expiry; + const form = e.target.form; + let expiry = data.expiry; // don't override original expiry if useInitialOptions is set if (!data.useInitialOptions) { @@ -1723,11 +1726,11 @@ Twinkle.block.callback.preview = function twinkleblockcallbackPreview(form) { }; Twinkle.block.callback.evaluate = function twinkleblockCallbackEvaluate(e) { - let $form = $(e.target), + const $form = $(e.target), toBlock = $form.find('[name=actiontype][value=block]').is(':checked'), toWarn = $form.find('[name=actiontype][value=template]').is(':checked'), - toPartial = $form.find('[name=actiontype][value=partial]').is(':checked'), - blockoptions = {}, templateoptions = {}; + toPartial = $form.find('[name=actiontype][value=partial]').is(':checked'); + let blockoptions = {}, templateoptions = {}; Twinkle.block.callback.saveFieldset($form.find('[name=field_block_options]')); Twinkle.block.callback.saveFieldset($form.find('[name=field_template_options]')); @@ -1916,7 +1919,8 @@ Twinkle.block.callback.issue_template = function twinkleblockCallbackIssueTempla }; Twinkle.block.callback.getBlockNoticeWikitext = function(params) { - let text = '{{', settings = Twinkle.block.blockPresetsInfo[params.template]; + let text = '{{'; + const settings = Twinkle.block.blockPresetsInfo[params.template]; if (!settings.nonstandard) { text += 'subst:' + params.template; if (params.article && settings.pageParam) { @@ -1990,10 +1994,10 @@ Twinkle.block.callback.getBlockNoticeWikitext = function(params) { }; Twinkle.block.callback.main = function twinkleblockcallbackMain(pageobj) { - let params = pageobj.getCallbackParameters(), + const params = pageobj.getCallbackParameters(), date = new Morebits.Date(pageobj.getLoadTime()), - messageData = params.messageData, - text; + messageData = params.messageData; + let text; params.indefinite = Morebits.string.isInfinity(params.expiry); @@ -2003,7 +2007,8 @@ Twinkle.block.callback.main = function twinkleblockcallbackMain(pageobj) { } else { text = pageobj.getPageText(); - let dateHeaderRegex = date.monthHeaderRegex(), dateHeaderRegexLast, dateHeaderRegexResult; + const dateHeaderRegex = date.monthHeaderRegex(); + let dateHeaderRegexLast, dateHeaderRegexResult; while ((dateHeaderRegexLast = dateHeaderRegex.exec(text)) !== null) { dateHeaderRegexResult = dateHeaderRegexLast; } diff --git a/modules/twinkleconfig.js b/modules/twinkleconfig.js index 6e11c3fb4..124b64832 100644 --- a/modules/twinkleconfig.js +++ b/modules/twinkleconfig.js @@ -1075,7 +1075,8 @@ Twinkle.config.init = function twinkleconfigInit() { } cell = document.createElement('td'); - let label, input, gotPref = Twinkle.getPref(pref.name); + let label, input; + const gotPref = Twinkle.getPref(pref.name); switch (pref.type) { case 'boolean': // create a checkbox @@ -1295,9 +1296,11 @@ Twinkle.config.init = function twinkleconfigInit() { // Styled in twinkle.css box.setAttribute('id', 'twinkle-config-headerbox'); - let link, - scriptPageName = mw.config.get('wgPageName').slice(mw.config.get('wgPageName').lastIndexOf('/') + 1, - mw.config.get('wgPageName').lastIndexOf('.js')); + let link; + const scriptPageName = mw.config.get('wgPageName').slice( + mw.config.get('wgPageName').lastIndexOf('/') + 1, + mw.config.get('wgPageName').lastIndexOf('.js') + ); if (scriptPageName === 'twinkleoptions') { // place "why not try the preference panel" notice diff --git a/modules/twinkleprotect.js b/modules/twinkleprotect.js index e34bb0a8c..3bc6ada64 100644 --- a/modules/twinkleprotect.js +++ b/modules/twinkleprotect.js @@ -173,7 +173,8 @@ Twinkle.protect.fetchProtectionLevel = function twinkleprotectFetchProtectionLev const pageid = protectData[0].query.pageids[0]; const page = protectData[0].query.pages[pageid]; - let current = {}, adminEditDeferred; + const current = {}; + let adminEditDeferred; // Save requested page's watched status for later in case needed when filing request Twinkle.protect.watched = page.watchlistexpiry || page.watched === ''; diff --git a/modules/twinklespeedy.js b/modules/twinklespeedy.js index 1d2a681b1..0c39c65c4 100644 --- a/modules/twinklespeedy.js +++ b/modules/twinklespeedy.js @@ -39,9 +39,8 @@ Twinkle.speedy.hasCSD = !!$('#delete-reason').length; // Prepares the speedy deletion dialog and displays it Twinkle.speedy.initDialog = function twinklespeedyInitDialog(callbackfunc) { - let dialog; Twinkle.speedy.dialog = new Morebits.SimpleWindow(Twinkle.getPref('speedyWindowWidth'), Twinkle.getPref('speedyWindowHeight')); - dialog = Twinkle.speedy.dialog; + const dialog = Twinkle.speedy.dialog; dialog.setTitle('Choose criteria for speedy deletion'); dialog.setScriptName('Twinkle'); dialog.addFooterLink('Speedy deletion policy', 'WP:CSD'); @@ -1140,8 +1139,8 @@ Twinkle.speedy.callbacks = { } if (initialContrib) { - let usertalkpage = new Morebits.wiki.Page('User talk:' + initialContrib, 'Notifying initial contributor (' + initialContrib + ')'), - notifytext, i, editsummary; + const usertalkpage = new Morebits.wiki.Page('User talk:' + initialContrib, 'Notifying initial contributor (' + initialContrib + ')'); + let notifytext, i, editsummary; // special cases: "db" and "db-multiple" if (params.normalizeds.length > 1) { @@ -1367,8 +1366,8 @@ Twinkle.speedy.callbacks = { // given the params, builds the template and also adds the user talk page parameters to the params that were passed in // returns => [ wikitext, utparams] - let buildData = Twinkle.speedy.callbacks.getTemplateCodeAndParams(params), - code = buildData[0]; + const buildData = Twinkle.speedy.callbacks.getTemplateCodeAndParams(params); + let code = buildData[0]; params.utparams = buildData[1]; // Set the correct value for |ts= parameter in {{db-g13}} diff --git a/modules/twinkletag.js b/modules/twinkletag.js index 6421d016f..fb1f5d1b4 100644 --- a/modules/twinkletag.js +++ b/modules/twinkletag.js @@ -351,7 +351,6 @@ Twinkle.tag.callback = function twinkletagCallback() { const evt = document.createEvent('Event'); evt.initEvent('change', true, true); result.sortorder.dispatchEvent(evt); - } else { // Redirects and files: Add a link to each template's description page Morebits.QuickForm.getElements(result, 'tags').forEach(generateLinks); @@ -1589,7 +1588,8 @@ Twinkle.tag.callbacks = { return; } - let tagRe, tagText = '', tags = [], groupableTags = [], groupableExistingTags = []; + let tagRe, tagText = '', tags = []; + const groupableTags = [], groupableExistingTags = []; // Executes first: addition of selected tags /** @@ -1806,10 +1806,12 @@ Twinkle.tag.callbacks = { }, redirect: function redirect(pageobj) { - let params = pageobj.getCallbackParameters(), - pageText = pageobj.getPageText(), - tagRe, tagText = '', summaryText = 'Added', - tags = [], i; + const params = pageobj.getCallbackParameters(), + tags = []; + let pageText = pageobj.getPageText(), + tagRe, tagText = '', + summaryText = 'Added', + i; for (i = 0; i < params.tags.length; i++) { tagRe = new RegExp('(\\{\\{' + params.tags[i] + '(\\||\\}\\}))', 'im'); diff --git a/modules/twinklewarn.js b/modules/twinklewarn.js index cf0724fbd..51ad7d398 100644 --- a/modules/twinklewarn.js +++ b/modules/twinklewarn.js @@ -54,9 +54,8 @@ Twinkle.warn.callback = function twinklewarnCallback() { return; } - let dialog; Twinkle.warn.dialog = new Morebits.SimpleWindow(600, 440); - dialog = Twinkle.warn.dialog; + const dialog = Twinkle.warn.dialog; dialog.setTitle('Warn/notify user'); dialog.setScriptName('Twinkle'); dialog.addFooterLink('Choosing a warning level', 'WP:UWUL#Levels'); @@ -1706,9 +1705,7 @@ Twinkle.warn.callbacks = { // Provided on autolevel, not otherwise templatename = templatename || input.sub_group; const linkedarticle = input.article; - let templatetext; - - templatetext = Twinkle.warn.callbacks.getWarningWikitext(templatename, linkedarticle, + const templatetext = Twinkle.warn.callbacks.getWarningWikitext(templatename, linkedarticle, input.reason, input.main_group === 'custom'); form.previewer.beginRender(templatetext, 'User_talk:' + mw.config.get('wgRelevantUserName')); // Force wikitext/correct username diff --git a/modules/twinklexfd.js b/modules/twinklexfd.js index 59034ac58..964a97c9a 100644 --- a/modules/twinklexfd.js +++ b/modules/twinklexfd.js @@ -424,8 +424,8 @@ Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory label: 'Choose type of action wanted:', name: 'xfdcat', event: function(e) { - let target = e.target, - tfdtarget = target.form.tfdtarget; + const target = e.target; + let tfdtarget = target.form.tfdtarget; // add/remove extra input box if (target.value === 'tfm' && !tfdtarget) { tfdtarget = new Morebits.QuickForm.Element({ @@ -554,9 +554,9 @@ Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory label: 'Choose type of action wanted:', name: 'xfdcat', event: function(e) { - let value = e.target.value, - cfdtarget = e.target.form.cfdtarget, - cfdtarget2 = e.target.form.cfdtarget2; + const value = e.target.value, + cfdtarget = e.target.form.cfdtarget; + let cfdtarget2 = e.target.form.cfdtarget2; // update enabled status cfdtarget.disabled = value === 'cfd' || value === 'sfd-t'; diff --git a/morebits.js b/morebits.js index c015ac77a..11bfe914e 100644 --- a/morebits.js +++ b/morebits.js @@ -266,7 +266,8 @@ Morebits.namespaceRegex = function(namespaces) { if (!Array.isArray(namespaces)) { namespaces = [namespaces]; } - let aliases = [], regex; + const aliases = []; + let regex; $.each(mw.config.get('wgNamespaceIds'), (name, number) => { if (namespaces.indexOf(number) !== -1) { // Namespaces are completely agnostic as to case, @@ -3831,7 +3832,8 @@ Morebits.wiki.page = function(pageName, status) { return; // abort } - let page = response.pages[0], rev; + const page = response.pages[0]; + let rev; ctx.pageExists = !page.missing; if (ctx.pageExists) { rev = page.revisions[0];