Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint: fix prefer-const #2099

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"no-use-before-define": "warn",
"no-useless-concat": "warn",
"no-var": "warn",
"prefer-const": "warn",
"unicorn/prefer-string-slice": "warn"
}
}
3 changes: 2 additions & 1 deletion modules/twinklebatchprotect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
31 changes: 18 additions & 13 deletions modules/twinkleblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]'));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down
11 changes: 7 additions & 4 deletions modules/twinkleconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/twinkleprotect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '';
Expand Down
11 changes: 5 additions & 6 deletions modules/twinklespeedy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 => [<string> wikitext, <object> 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}}
Expand Down
14 changes: 8 additions & 6 deletions modules/twinkletag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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

/**
Expand Down Expand Up @@ -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');
Expand Down
7 changes: 2 additions & 5 deletions modules/twinklewarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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';
Expand Down
6 changes: 4 additions & 2 deletions morebits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Expand Down
Loading