From 23f212a4c0aca967f08f8bba06d06ebf49d1c7ac Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 6 Feb 2021 14:10:15 -0700 Subject: [PATCH] chore: eslint prefer-destructuring --- .eslintrc | 11 +++++------ Gruntfile.js | 4 ++-- loader.js | 2 +- src/admin/search.js | 2 +- src/api/helpers.js | 2 +- src/api/topics.js | 2 +- src/api/users.js | 2 +- src/categories/delete.js | 2 +- src/categories/topics.js | 4 ++-- src/categories/update.js | 2 +- src/cli/colors.js | 2 +- src/cli/index.js | 2 +- src/cli/manage.js | 2 +- src/cli/upgrade.js | 4 ++-- src/controllers/accounts/helpers.js | 14 +++++++------- src/controllers/accounts/posts.js | 2 +- src/controllers/admin/cache.js | 2 +- src/controllers/admin/groups.js | 2 +- src/controllers/admin/info.js | 2 +- src/controllers/admin/users.js | 2 +- src/controllers/authentication.js | 6 +++--- src/controllers/composer.js | 2 +- src/controllers/helpers.js | 6 ++---- src/controllers/home.js | 2 +- src/controllers/mods.js | 2 +- src/controllers/recent.js | 2 +- src/controllers/unread.js | 2 +- src/controllers/users.js | 2 +- src/controllers/write/users.js | 2 +- src/database/postgres.js | 2 +- src/database/postgres/connection.js | 2 +- src/database/postgres/main.js | 2 +- src/database/postgres/sorted.js | 2 +- src/database/postgres/sorted/intersect.js | 2 +- src/database/postgres/sorted/union.js | 2 +- src/database/redis/pubsub.js | 2 +- src/database/redis/sorted/intersect.js | 2 +- src/groups/cover.js | 2 +- src/languages.js | 2 +- src/logger.js | 2 +- src/meta/debugFork.js | 2 +- src/meta/js.js | 6 +++--- src/meta/languages.js | 4 ++-- src/meta/minifier.js | 2 +- src/middleware/admin.js | 2 +- src/middleware/header.js | 2 +- src/middleware/render.js | 4 ++-- src/plugins/index.js | 4 ++-- src/posts/create.js | 4 ++-- src/posts/edit.js | 2 +- src/privileges/posts.js | 4 ++-- src/privileges/topics.js | 4 ++-- src/routes/accounts.js | 2 +- src/routes/authentication.js | 2 +- src/routes/debug.js | 2 +- src/routes/feeds.js | 4 ++-- src/routes/index.js | 2 +- src/routes/write/admin.js | 2 +- src/routes/write/categories.js | 2 +- src/routes/write/files.js | 2 +- src/routes/write/groups.js | 2 +- src/routes/write/index.js | 2 +- src/routes/write/posts.js | 2 +- src/routes/write/topics.js | 2 +- src/routes/write/users.js | 2 +- src/routes/write/utilities.js | 2 +- src/socket.io/admin/digest.js | 2 +- src/socket.io/helpers.js | 10 +++++----- src/socket.io/index.js | 2 +- src/socket.io/uploads.js | 2 +- src/socket.io/user/picture.js | 2 +- src/socket.io/user/profile.js | 2 +- src/topics/create.js | 10 +++++----- src/topics/follow.js | 2 +- src/topics/sorted.js | 4 ++-- src/topics/tags.js | 2 +- src/topics/teaser.js | 2 +- src/topics/unread.js | 2 +- src/upgrades/1.0.0/user_best_posts.js | 2 +- .../1.1.0/assign_topic_read_privilege.js | 4 ++-- src/upgrades/1.1.0/separate_upvote_downvote.js | 2 +- .../1.10.0/hash_recent_ip_addresses.js | 2 +- src/upgrades/1.10.2/event_filters.js | 2 +- src/upgrades/1.10.2/fix_category_post_zsets.js | 2 +- .../1.10.2/fix_category_topic_zsets.js | 2 +- src/upgrades/1.10.2/upgrade_bans_to_hashes.js | 2 +- src/upgrades/1.10.2/username_email_history.js | 2 +- .../1.11.1/remove_ignored_cids_per_user.js | 2 +- src/upgrades/1.12.0/category_watch_state.js | 2 +- .../1.12.1/clear_username_email_history.js | 2 +- .../1.12.1/moderation_notes_refactor.js | 2 +- src/upgrades/1.12.1/post_upload_sizes.js | 2 +- src/upgrades/1.12.3/user_pid_sets.js | 2 +- src/upgrades/1.13.0/clean_flag_byCid.js | 2 +- src/upgrades/1.13.0/clean_post_topic_hash.js | 2 +- .../1.13.0/cleanup_old_notifications.js | 2 +- src/upgrades/1.13.3/fix_users_sorted_sets.js | 2 +- .../1.14.1/readd_deleted_recent_topics.js | 2 +- src/upgrades/1.15.0/add_target_uid_to_flags.js | 4 ++-- src/upgrades/1.15.0/consolidate_flags.js | 2 +- src/upgrades/1.15.0/fullname_search_set.js | 2 +- .../1.15.0/remove_flag_reporters_zset.js | 2 +- src/upgrades/1.15.0/topic_poster_count.js | 2 +- src/upgrades/1.15.0/verified_users_group.js | 2 +- src/upgrades/1.15.4/clear_purged_replies.js | 2 +- src/upgrades/1.16.0/category_tags.js | 4 ++-- src/upgrades/1.16.0/migrate_thumbs.js | 2 +- src/upgrades/1.17.0/banned_users_group.js | 2 +- src/upgrades/1.17.0/category_name_zset.js | 2 +- src/upgrades/1.17.0/subcategories_per_page.js | 2 +- src/upgrades/1.17.0/topic_thumb_count.js | 2 +- .../edit_delete_deletetopic_privileges.js | 4 ++-- src/upgrades/1.3.0/favourites_to_bookmarks.js | 2 +- .../1.3.0/sorted_sets_for_post_replies.js | 2 +- src/upgrades/1.4.6/delete_sessions.js | 2 +- src/upgrades/1.5.0/flags_refactor.js | 2 +- .../1.5.0/moderation_history_refactor.js | 2 +- src/upgrades/1.5.0/post_votes_zset.js | 2 +- .../remove_relative_uploaded_profile_cover.js | 2 +- src/upgrades/1.5.1/rename_mods_group.js | 2 +- src/upgrades/1.5.2/rss_token_wipe.js | 2 +- src/upgrades/1.5.2/tags_privilege.js | 2 +- src/upgrades/1.6.2/topics_lastposttime_zset.js | 2 +- src/upgrades/1.7.1/notification-settings.js | 2 +- src/upgrades/1.7.3/key_value_schema_change.js | 4 ++-- src/upgrades/1.7.3/topic_votes.js | 2 +- src/upgrades/1.7.4/fix_moved_topics_byvotes.js | 2 +- .../1.7.4/fix_user_topics_per_category.js | 2 +- src/upgrades/1.8.1/diffs_zset_to_listhash.js | 2 +- .../1.9.0/refresh_post_upload_associations.js | 2 +- src/user/approval.js | 2 +- src/user/bans.js | 2 +- src/user/create.js | 2 +- src/user/digest.js | 2 +- src/user/jobs.js | 2 +- src/user/notifications.js | 2 +- src/widgets/index.js | 2 +- test/api.js | 2 +- test/emailer.js | 2 +- test/plugins.js | 2 +- test/topics.js | 18 +++++++++--------- test/translator.js | 2 +- test/utils.js | 6 +++--- 143 files changed, 192 insertions(+), 195 deletions(-) diff --git a/.eslintrc b/.eslintrc index dffb62726f..7bd5900a39 100644 --- a/.eslintrc +++ b/.eslintrc @@ -59,12 +59,11 @@ "function-paren-newline": ["error", "consistent"], // only require const if all parts of destructuring can be const "prefer-const": ["error", { "destructuring": "all" }], - // don't require destructuring when assigning - // "prefer-destructuring": ["error", { - // "VariableDeclarator": { "array": true, "object": true }, - // "AssignmentExpression": { "array": false, "object": false } - // }], - "prefer-destructuring": "off", + // don't require destructuring for arrays or assignment + "prefer-destructuring": ["error", { + "VariableDeclarator": { "array": false, "object": true }, + "AssignmentExpression": { "array": false, "object": false } + }], // identical to airbnb rule, except for allowing for..of, because we want to use it // "no-restricted-syntax": [ // "error", diff --git a/Gruntfile.js b/Gruntfile.js index 6ee95b186e..d95d14f7fd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,9 +7,9 @@ nconf.argv().env({ separator: '__', }); const winston = require('winston'); -const fork = require('child_process').fork; +const { fork } = require('child_process'); -const env = process.env; +const { env } = process; let worker; env.NODE_ENV = env.NODE_ENV || 'development'; diff --git a/loader.js b/loader.js index b7302b28ba..a4e9ddf626 100644 --- a/loader.js +++ b/loader.js @@ -4,7 +4,7 @@ const nconf = require('nconf'); const fs = require('fs'); const url = require('url'); const path = require('path'); -const fork = require('child_process').fork; +const { fork } = require('child_process'); const async = require('async'); const logrotate = require('logrotate-stream'); const mkdirp = require('mkdirp'); diff --git a/src/admin/search.js b/src/admin/search.js index 143f535e67..be20c1594b 100644 --- a/src/admin/search.js +++ b/src/admin/search.js @@ -7,7 +7,7 @@ const nconf = require('nconf'); const winston = require('winston'); const file = require('../file'); -const Translator = require('../translator').Translator; +const { Translator } = require('../translator'); function filterDirectories(directories) { return directories.map( diff --git a/src/api/helpers.js b/src/api/helpers.js index dc2ee14852..618a0f034b 100644 --- a/src/api/helpers.js +++ b/src/api/helpers.js @@ -15,7 +15,7 @@ exports.buildReqObject = (req, payload) => { req = req || {}; const headers = req.headers || {}; const encrypted = req.connection ? !!req.connection.encrypted : false; - let host = headers.host; + let { host } = headers; const referer = headers.referer || ''; if (!host) { diff --git a/src/api/topics.js b/src/api/topics.js index 521c3f77d7..b6678ccfa8 100644 --- a/src/api/topics.js +++ b/src/api/topics.js @@ -8,7 +8,7 @@ const privileges = require('../privileges'); const apiHelpers = require('./helpers'); -const doTopicAction = apiHelpers.doTopicAction; +const { doTopicAction } = apiHelpers; const websockets = require('../socket.io'); const socketHelpers = require('../socket.io/helpers'); diff --git a/src/api/users.js b/src/api/users.js index 73717e5bb1..2a4c5100d6 100644 --- a/src/api/users.js +++ b/src/api/users.js @@ -229,7 +229,7 @@ usersAPI.unban = async function (caller, data) { }; async function isPrivilegedOrSelfAndPasswordMatch(caller, data) { - const uid = caller.uid; + const { uid } = caller; const isSelf = parseInt(uid, 10) === parseInt(data.uid, 10); const [isAdmin, isTargetAdmin, isGlobalMod] = await Promise.all([ diff --git a/src/categories/delete.js b/src/categories/delete.js index 89f3228d44..d2a19e6270 100644 --- a/src/categories/delete.js +++ b/src/categories/delete.js @@ -27,7 +27,7 @@ module.exports = function (Categories) { }; async function purgeCategory(categoryData) { - const cid = categoryData.cid; + const { cid } = categoryData; await db.sortedSetRemoveBulk([ ['categories:cid', cid], ['categories:name', `${categoryData.name.substr(0, 200).toLowerCase()}:${cid}`], diff --git a/src/categories/topics.js b/src/categories/topics.js index c2253491f2..b24bc6c757 100644 --- a/src/categories/topics.js +++ b/src/categories/topics.js @@ -55,7 +55,7 @@ module.exports = function (Categories) { return result && result.tids; } - let start = data.start; + let { start } = data; if (start > 0 && totalPinnedCount) { start -= totalPinnedCount - pinnedCountOnPage; } @@ -91,7 +91,7 @@ module.exports = function (Categories) { }; Categories.buildTopicsSortedSet = async function (data) { - const cid = data.cid; + const { cid } = data; let set = `cid:${cid}:tids`; const sort = data.sort || (data.settings && data.settings.categoryTopicSort) || meta.config.categoryTopicSort || 'newest_to_oldest'; diff --git a/src/categories/update.js b/src/categories/update.js index f54655b9fe..438e833639 100644 --- a/src/categories/update.js +++ b/src/categories/update.js @@ -29,7 +29,7 @@ module.exports = function (Categories) { } const result = await plugins.hooks.fire('filter:category.update', { cid: cid, category: modifiedFields }); - const category = result.category; + const { category } = result; const fields = Object.keys(category); // move parent to front, so its updated first const parentCidIndex = fields.indexOf('parentCid'); diff --git a/src/cli/colors.js b/src/cli/colors.js index 1de89873d8..bb4ea2887e 100644 --- a/src/cli/colors.js +++ b/src/cli/colors.js @@ -5,7 +5,7 @@ // to include color styling in the output // so the CLI looks nice -const Command = require('commander').Command; +const { Command } = require('commander'); const commandColor = 'yellow'; const optionColor = 'cyan'; diff --git a/src/cli/index.js b/src/cli/index.js index f4c137b3bd..8e1fa90339 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -41,7 +41,7 @@ try { const defaultPackage = require('../../install/package.json'); const checkVersion = function (packageName) { - const version = JSON.parse(fs.readFileSync(path.join(paths.nodeModules, packageName, 'package.json'), 'utf8')).version; + const { version } = JSON.parse(fs.readFileSync(path.join(paths.nodeModules, packageName, 'package.json'), 'utf8')); if (!semver.satisfies(version, defaultPackage.dependencies[packageName])) { const e = new TypeError(`Incorrect dependency version: ${packageName}`); e.code = 'DEP_WRONG_VERSION'; diff --git a/src/cli/manage.js b/src/cli/manage.js index cb12f6aa10..898ddac4dd 100644 --- a/src/cli/manage.js +++ b/src/cli/manage.js @@ -94,7 +94,7 @@ async function listEvents(count) { async function info() { console.log(''); - const version = require('../../package.json').version; + const { version } = require('../../package.json'); console.log(` version: ${version}`); console.log(` Node ver: ${process.version}`); diff --git a/src/cli/upgrade.js b/src/cli/upgrade.js index fc2d993707..9c1beab4f0 100644 --- a/src/cli/upgrade.js +++ b/src/cli/upgrade.js @@ -7,7 +7,7 @@ const packageInstall = require('./package-install'); const upgrade = require('../upgrade'); const build = require('../meta/build'); const db = require('../database'); -const upgradePlugins = require('./upgrade-plugins').upgradePlugins; +const { upgradePlugins } = require('./upgrade-plugins'); const steps = { package: { @@ -69,7 +69,7 @@ function runSteps(tasks) { const message = 'NodeBB Upgrade Complete!'; // some consoles will return undefined/zero columns, so just use 2 spaces in upgrade script if we can't get our column count - const columns = process.stdout.columns; + const { columns } = process.stdout; const spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' '; console.log(`\n\n${spaces}${message.green.bold}${'\n'.reset}`); diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js index f94b73095a..a6b1d45872 100644 --- a/src/controllers/accounts/helpers.js +++ b/src/controllers/accounts/helpers.js @@ -28,12 +28,12 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID) { } await parseAboutMe(results.userData); - const userData = results.userData; - const userSettings = results.userSettings; - const isAdmin = results.isAdmin; - const isGlobalModerator = results.isGlobalModerator; - const isModerator = results.isModerator; - const canViewInfo = results.canViewInfo; + const { userData } = results; + const { userSettings } = results; + const { isAdmin } = results; + const { isGlobalModerator } = results; + const { isModerator } = results; + const { canViewInfo } = results; const isSelf = parseInt(callerUID, 10) === parseInt(userData.uid, 10); userData.age = Math.max(0, userData.birthday ? Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000) : 0); @@ -140,7 +140,7 @@ async function getAllData(uid, callerUID) { } async function getCounts(userData, callerUID) { - const uid = userData.uid; + const { uid } = userData; const cids = await categories.getCidsByPrivilege('categories:cid', callerUID, 'topics:read'); const promises = { posts: db.sortedSetsCardSum(cids.map(c => `cid:${c}:uid:${uid}:pids`)), diff --git a/src/controllers/accounts/posts.js b/src/controllers/accounts/posts.js index b8a1cbc1d0..0d52621a9b 100644 --- a/src/controllers/accounts/posts.js +++ b/src/controllers/accounts/posts.js @@ -62,7 +62,7 @@ const templateToData = { return `uid:${userData.uid}:followed_tids`; }, getTopics: async function (set, req, start, stop) { - const sort = req.query.sort; + const { sort } = req.query; const map = { votes: 'topics:votes', posts: 'topics:posts', diff --git a/src/controllers/admin/cache.js b/src/controllers/admin/cache.js index 15d8ffb91a..430cc28b8a 100644 --- a/src/controllers/admin/cache.js +++ b/src/controllers/admin/cache.js @@ -7,7 +7,7 @@ const utils = require('../../utils'); cacheController.get = function (req, res) { const postCache = require('../../posts/cache'); const groupCache = require('../../groups').cache; - const objectCache = require('../../database').objectCache; + const { objectCache } = require('../../database'); const localCache = require('../../cache'); function getInfo(cache) { diff --git a/src/controllers/admin/groups.js b/src/controllers/admin/groups.js index e3171fe3d2..e4da58a650 100644 --- a/src/controllers/admin/groups.js +++ b/src/controllers/admin/groups.js @@ -69,7 +69,7 @@ async function getGroupNames() { } groupsController.getCSV = async function (req, res) { - const referer = req.headers.referer; + const { referer } = req.headers; if (!referer || !referer.replace(nconf.get('url'), '').startsWith('/admin/manage/groups')) { return res.status(403).send('[[error:invalid-origin]]'); diff --git a/src/controllers/admin/info.js b/src/controllers/admin/info.js index 0d924225eb..60558f2ad6 100644 --- a/src/controllers/admin/info.js +++ b/src/controllers/admin/info.js @@ -3,7 +3,7 @@ const os = require('os'); const winston = require('winston'); const nconf = require('nconf'); -const exec = require('child_process').exec; +const { exec } = require('child_process'); const pubsub = require('../../pubsub'); const rooms = require('../../socket.io/admin/rooms'); diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js index 3dfa5927a9..ae26338dab 100644 --- a/src/controllers/admin/users.js +++ b/src/controllers/admin/users.js @@ -227,7 +227,7 @@ async function getInvites() { async function render(req, res, data) { data.pagination = pagination.create(data.page, data.pageCount, req.query); - const registrationType = meta.config.registrationType; + const { registrationType } = meta.config; data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only'; data.adminInviteOnly = registrationType === 'admin-invite-only'; diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index fcd38f3314..9f1322ef99 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -183,7 +183,7 @@ authenticationController.registerComplete = function (req, res, next) { } else { // Update user hash, clear registration data in session const payload = req.session.registration; - const uid = payload.uid; + const { uid } = payload; delete payload.uid; delete payload.returnTo; @@ -418,8 +418,8 @@ authenticationController.logout = async function (req, res, next) { res.clearCookie(nconf.get('sessionKey'), meta.configs.cookie.get()); return res.status(200).send('not-logged-in'); } - const uid = req.uid; - const sessionID = req.sessionID; + const { uid } = req; + const { sessionID } = req; try { await user.auth.revokeSession(sessionID, uid); diff --git a/src/controllers/composer.js b/src/controllers/composer.js index df20ecee37..d82214fb91 100644 --- a/src/controllers/composer.js +++ b/src/controllers/composer.js @@ -40,7 +40,7 @@ exports.get = async function (req, res, callback) { }; exports.post = async function (req, res) { - const body = req.body; + const { body } = req; const data = { uid: req.uid, req: req, diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index 236b06720c..0eb47fb904 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -282,10 +282,8 @@ async function getCategoryData(cids, uid, selectedCid, states, privilege) { } helpers.getVisibleCategories = async function (params) { - const cids = params.cids; - const uid = params.uid; + const { cids, uid, privilege } = params; const states = params.states || [categories.watchStates.watching, categories.watchStates.notwatching]; - const privilege = params.privilege; const showLinks = !!params.showLinks; let [allowed, watchState, categoriesData, isAdmin, isModerator] = await Promise.all([ @@ -434,7 +432,7 @@ helpers.formatApiResponse = async (statusCode, res, payload) => { response: payload || {}, }); } else if (payload instanceof Error) { - const message = payload.message; + const { message } = payload; const response = {}; // Update status code based on some common error codes diff --git a/src/controllers/home.js b/src/controllers/home.js index cd9886883c..ea596f972f 100644 --- a/src/controllers/home.js +++ b/src/controllers/home.js @@ -37,7 +37,7 @@ async function rewrite(req, res, next) { return next(err); } - const pathname = parsedUrl.pathname; + const { pathname } = parsedUrl; const hook = `action:homepage.get:${pathname}`; if (!plugins.hooks.hasListeners(hook)) { req.url = req.path + (!req.path.endsWith('/') ? '/' : '') + pathname; diff --git a/src/controllers/mods.js b/src/controllers/mods.js index 7907cc243e..acffd4f545 100644 --- a/src/controllers/mods.js +++ b/src/controllers/mods.js @@ -153,7 +153,7 @@ modsController.postQueue = async function (req, res, next) { if (!isPrivileged) { return next(); } - const cid = req.query.cid; + const { cid } = req.query; const page = parseInt(req.query.page, 10) || 1; const postsPerPage = 20; diff --git a/src/controllers/recent.js b/src/controllers/recent.js index 0f003f4576..c5fc8cb832 100644 --- a/src/controllers/recent.js +++ b/src/controllers/recent.js @@ -24,7 +24,7 @@ recentController.get = async function (req, res, next) { recentController.getData = async function (req, url, sort) { const page = parseInt(req.query.page, 10) || 1; let term = helpers.terms[req.query.term]; - const cid = req.query.cid; + const { cid } = req.query; const filter = req.query.filter || ''; if (!term && req.query.term) { diff --git a/src/controllers/unread.js b/src/controllers/unread.js index 6d2792e83a..55d0d7c008 100644 --- a/src/controllers/unread.js +++ b/src/controllers/unread.js @@ -13,7 +13,7 @@ const helpers = require('./helpers'); const unreadController = module.exports; unreadController.get = async function (req, res) { - const cid = req.query.cid; + const { cid } = req.query; const filter = req.query.filter || ''; const [categoryData, userSettings, isPrivileged] = await Promise.all([ diff --git a/src/controllers/users.js b/src/controllers/users.js index 147841cf21..818cb86123 100644 --- a/src/controllers/users.js +++ b/src/controllers/users.js @@ -165,7 +165,7 @@ usersController.getUsersAndCount = async function (set, uid, start, stop) { }; async function render(req, res, data) { - const registrationType = meta.config.registrationType; + const { registrationType } = meta.config; data.maximumInvites = meta.config.maximumInvites; data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only'; diff --git a/src/controllers/write/users.js b/src/controllers/write/users.js index efa048f5aa..fc58c4484d 100644 --- a/src/controllers/write/users.js +++ b/src/controllers/write/users.js @@ -182,7 +182,7 @@ Users.invite = async (req, res) => { return helpers.formatApiResponse(403, res, new Error('[[error:no-privileges]]')); } - const registrationType = meta.config.registrationType; + const { registrationType } = meta.config; const isAdmin = await user.isAdministrator(req.uid); if (registrationType === 'admin-invite-only' && !isAdmin) { return helpers.formatApiResponse(403, res, new Error('[[error:no-privileges]]')); diff --git a/src/database/postgres.js b/src/database/postgres.js index d4c0e00af4..f51f440184 100644 --- a/src/database/postgres.js +++ b/src/database/postgres.js @@ -46,7 +46,7 @@ postgresModule.questions = [ ]; postgresModule.init = async function () { - const Pool = require('pg').Pool; + const { Pool } = require('pg'); const connOptions = connection.getConnectionOptions(); const pool = new Pool(connOptions); postgresModule.pool = pool; diff --git a/src/database/postgres/connection.js b/src/database/postgres/connection.js index 8877882904..54cdc5ebee 100644 --- a/src/database/postgres/connection.js +++ b/src/database/postgres/connection.js @@ -34,7 +34,7 @@ connection.getConnectionOptions = function (postgres) { }; connection.connect = async function (options) { - const Pool = require('pg').Pool; + const { Pool } = require('pg'); const connOptions = connection.getConnectionOptions(options); const db = new Pool(connOptions); await db.connect(); diff --git a/src/database/postgres/main.js b/src/database/postgres/main.js index 313f8a4f5b..5e6ba43e61 100644 --- a/src/database/postgres/main.js +++ b/src/database/postgres/main.js @@ -41,7 +41,7 @@ module.exports = function (module) { }; module.scan = async function (params) { - let match = params.match; + let { match } = params; if (match.startsWith('*')) { match = `%${match.substring(1)}`; } diff --git a/src/database/postgres/sorted.js b/src/database/postgres/sorted.js index 211b0608cb..23066a82a5 100644 --- a/src/database/postgres/sorted.js +++ b/src/database/postgres/sorted.js @@ -606,7 +606,7 @@ DELETE FROM "legacy_zset" z } module.getSortedSetScan = async function (params) { - let match = params.match; + let { match } = params; if (match.startsWith('*')) { match = `%${match.substring(1)}`; } diff --git a/src/database/postgres/sorted/intersect.js b/src/database/postgres/sorted/intersect.js index e201d2e077..e6cd894f19 100644 --- a/src/database/postgres/sorted/intersect.js +++ b/src/database/postgres/sorted/intersect.js @@ -37,7 +37,7 @@ SELECT COUNT(*) c }; async function getSortedSetIntersect(params) { - const sets = params.sets; + const { sets } = params; const start = params.hasOwnProperty('start') ? params.start : 0; const stop = params.hasOwnProperty('stop') ? params.stop : -1; let weights = params.weights || []; diff --git a/src/database/postgres/sorted/union.js b/src/database/postgres/sorted/union.js index 5daf8d112c..a8fcbd0d0d 100644 --- a/src/database/postgres/sorted/union.js +++ b/src/database/postgres/sorted/union.js @@ -31,7 +31,7 @@ SELECT COUNT(DISTINCT z."value") c }; async function getSortedSetUnion(params) { - const sets = params.sets; + const { sets } = params; const start = params.hasOwnProperty('start') ? params.start : 0; const stop = params.hasOwnProperty('stop') ? params.stop : -1; let weights = params.weights || []; diff --git a/src/database/redis/pubsub.js b/src/database/redis/pubsub.js index 9938e0a974..b61b266d67 100644 --- a/src/database/redis/pubsub.js +++ b/src/database/redis/pubsub.js @@ -3,7 +3,7 @@ const nconf = require('nconf'); const util = require('util'); const winston = require('winston'); -const EventEmitter = require('events').EventEmitter; +const { EventEmitter } = require('events'); const connection = require('./connection'); let channelName; diff --git a/src/database/redis/sorted/intersect.js b/src/database/redis/sorted/intersect.js index b23f09869f..2b2ed1fe90 100644 --- a/src/database/redis/sorted/intersect.js +++ b/src/database/redis/sorted/intersect.js @@ -30,7 +30,7 @@ module.exports = function (module) { }; async function getSortedSetRevIntersect(params) { - const sets = params.sets; + const { sets } = params; const start = params.hasOwnProperty('start') ? params.start : 0; const stop = params.hasOwnProperty('stop') ? params.stop : -1; const weights = params.weights || []; diff --git a/src/groups/cover.js b/src/groups/cover.js index 6d40691f4f..6d20b47ac3 100644 --- a/src/groups/cover.js +++ b/src/groups/cover.js @@ -37,7 +37,7 @@ module.exports = function (Groups) { uid: uid, name: 'groupCover', }); - const url = uploadData.url; + const { url } = uploadData; await Groups.setGroupField(data.groupName, 'cover:url', url); await image.resizeImage({ diff --git a/src/languages.js b/src/languages.js index 577db5e254..d19f5798fb 100644 --- a/src/languages.js +++ b/src/languages.js @@ -3,7 +3,7 @@ const fs = require('fs'); const path = require('path'); const utils = require('./utils'); -const paths = require('./constants').paths; +const { paths } = require('./constants'); const Languages = module.exports; const languagesPath = path.join(__dirname, '../build/public/language'); diff --git a/src/logger.js b/src/logger.js index 734651cd9a..566cea2667 100644 --- a/src/logger.js +++ b/src/logger.js @@ -207,7 +207,7 @@ Logger.io_one = function (socket, uid) { if (socket && meta.config.loggerIOStatus > 0) { // courtesy of: http://stackoverflow.com/a/9674248 socket.oEmit = socket.emit; - const emit = socket.emit; + const { emit } = socket; socket.emit = override(emit, 'emit', 'Logger.io_one: emit.apply: Failed'); socket.$onvent = socket.onevent; diff --git a/src/meta/debugFork.js b/src/meta/debugFork.js index 44b2ab3e99..2e61972e33 100644 --- a/src/meta/debugFork.js +++ b/src/meta/debugFork.js @@ -1,6 +1,6 @@ 'use strict'; -const fork = require('child_process').fork; +const { fork } = require('child_process'); let debugArg = process.execArgv.find(arg => /^--(debug|inspect)/.test(arg)); const debugging = !!debugArg; diff --git a/src/meta/js.js b/src/meta/js.js index eaabb77b98..b7d3021c03 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -143,7 +143,7 @@ async function minifyModules(modules, fork) { } async function linkModules() { - const modules = JS.scripts.modules; + const { modules } = JS.scripts; await Promise.all(Object.keys(modules).map(async (relPath) => { const srcPath = path.join(__dirname, '../../', modules[relPath]); @@ -179,8 +179,8 @@ async function getModuleList() { const moduleFiles = []; await Promise.all(modules.map(async (module) => { - const srcPath = module.srcPath; - const destPath = module.destPath; + const { srcPath } = module; + const { destPath } = module; const stats = await fs.promises.stat(srcPath); if (!stats.isDirectory()) { diff --git a/src/meta/languages.js b/src/meta/languages.js index 72bcf866a5..36611f1b9a 100644 --- a/src/meta/languages.js +++ b/src/meta/languages.js @@ -71,8 +71,8 @@ async function writeLanguageFile(language, namespace, translations) { // run through core and all plugins to generate // a full translation hash async function buildTranslations(ref) { - const namespaces = ref.namespaces; - const languages = ref.languages; + const { namespaces } = ref; + const { languages } = ref; const plugins = _.values(Plugins.pluginsData).filter(plugin => typeof plugin.languages === 'string'); const promises = []; diff --git a/src/meta/minifier.js b/src/meta/minifier.js index 00363aad76..4c1af4bab7 100644 --- a/src/meta/minifier.js +++ b/src/meta/minifier.js @@ -104,7 +104,7 @@ const actions = {}; if (process.env.minifier_child) { process.on('message', (message) => { if (message.type === 'action') { - const action = message.action; + const { action } = message; if (typeof actions[action.act] !== 'function') { process.send({ type: 'error', diff --git a/src/middleware/admin.js b/src/middleware/admin.js index e8c9a77cf3..5952f35d9b 100644 --- a/src/middleware/admin.js +++ b/src/middleware/admin.js @@ -42,7 +42,7 @@ middleware.renderHeader = async (req, res, data) => { privileges: privileges.admin.get(req.uid), }); - const userData = results.userData; + const { userData } = results; userData.uid = req.uid; userData['email:confirmed'] = userData['email:confirmed'] === 1; userData.privileges = results.privileges; diff --git a/src/middleware/header.js b/src/middleware/header.js index 677cd11eb0..17b9987752 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -190,7 +190,7 @@ async function appendUnreadCounts({ uid, navigation, unreadData }) { } }); - const tidsByFilter = results.unreadData.tidsByFilter; + const { tidsByFilter } = results.unreadData; navigation = navigation.map((item) => { function modifyNavItem(item, route, filter, content) { if (item && item.originalRoute === route) { diff --git a/src/middleware/render.js b/src/middleware/render.js index ace5e9f256..08f574dc5e 100644 --- a/src/middleware/render.js +++ b/src/middleware/render.js @@ -16,10 +16,10 @@ const relative_path = nconf.get('relative_path'); module.exports = function (middleware) { middleware.processRender = function processRender(req, res, next) { // res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687 - const render = res.render; + const { render } = res; res.render = async function renderOverride(template, options, fn) { const self = this; - const req = this.req; + const { req } = this; options = options || {}; if (typeof options === 'function') { diff --git a/src/plugins/index.js b/src/plugins/index.js index 3775de3620..fbb27eadb2 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -176,7 +176,7 @@ Plugins.list = async function (matching) { if (matching === undefined) { matching = true; } - const version = require(paths.currentPackage).version; + const { version } = require(paths.currentPackage); const url = `${nconf.get('registry') || 'https://packages.nodebb.org'}/api/v1/plugins${matching !== false ? `?version=${version}` : ''}`; try { const body = await request(url, { @@ -198,7 +198,7 @@ Plugins.listTrending = async () => { Plugins.normalise = async function (apiReturn) { const pluginMap = {}; - const dependencies = require(paths.currentPackage).dependencies; + const { dependencies } = require(paths.currentPackage); apiReturn = Array.isArray(apiReturn) ? apiReturn : []; apiReturn.forEach((packageData) => { packageData.id = packageData.name; diff --git a/src/posts/create.js b/src/posts/create.js index 34079e9168..c95ba3535e 100644 --- a/src/posts/create.js +++ b/src/posts/create.js @@ -14,8 +14,8 @@ const utils = require('../utils'); module.exports = function (Posts) { Posts.create = async function (data) { // This is an internal method, consider using Topics.reply instead - const uid = data.uid; - const tid = data.tid; + const { uid } = data; + const { tid } = data; const content = data.content.toString(); const timestamp = data.timestamp || Date.now(); const isMain = data.isMain || false; diff --git a/src/posts/edit.js b/src/posts/edit.js index 8d8c1bc3df..d32b25aaa0 100644 --- a/src/posts/edit.js +++ b/src/posts/edit.js @@ -94,7 +94,7 @@ module.exports = function (Posts) { }; async function editMainPost(data, postData) { - const tid = postData.tid; + const { tid } = postData; const title = data.title ? data.title.trim() : ''; const [topicData, isMain] = await Promise.all([ diff --git a/src/privileges/posts.js b/src/privileges/posts.js index e6610a8278..b6120f15f2 100644 --- a/src/privileges/posts.js +++ b/src/privileges/posts.js @@ -162,11 +162,11 @@ module.exports = function (privileges) { return { flag: false, message: '[[error:topic-locked]]' }; } - const postDeleteDuration = meta.config.postDeleteDuration; + const { postDeleteDuration } = meta.config; if (!results.isMod && postDeleteDuration && (Date.now() - postData.timestamp > postDeleteDuration * 1000)) { return { flag: false, message: `[[error:post-delete-duration-expired, ${meta.config.postDeleteDuration}]]` }; } - const deleterUid = postData.deleterUid; + const { deleterUid } = postData; const flag = results['posts:delete'] && ((results.isOwner && (deleterUid === 0 || deleterUid === postData.uid)) || results.isMod); return { flag: flag, message: '[[error:no-privileges]]' }; }; diff --git a/src/privileges/topics.js b/src/privileges/topics.js index 00945d8977..c3e53136e1 100644 --- a/src/privileges/topics.js +++ b/src/privileges/topics.js @@ -126,7 +126,7 @@ module.exports = function (privileges) { return true; } - const preventTopicDeleteAfterReplies = meta.config.preventTopicDeleteAfterReplies; + const { preventTopicDeleteAfterReplies } = meta.config; if (!isModerator && preventTopicDeleteAfterReplies && (topicData.postcount - 1) >= preventTopicDeleteAfterReplies) { const langKey = preventTopicDeleteAfterReplies > 1 ? `[[error:cant-delete-topic-has-replies, ${meta.config.preventTopicDeleteAfterReplies}]]` : @@ -134,7 +134,7 @@ module.exports = function (privileges) { throw new Error(langKey); } - const deleterUid = topicData.deleterUid; + const { deleterUid } = topicData; return allowedTo[0] && ((isOwner && (deleterUid === 0 || deleterUid === topicData.uid)) || isModerator); }; diff --git a/src/routes/accounts.js b/src/routes/accounts.js index b1d4b61049..60ce207cf5 100644 --- a/src/routes/accounts.js +++ b/src/routes/accounts.js @@ -5,7 +5,7 @@ const nconf = require('nconf'); const helpers = require('./helpers'); -const setupPageRoute = helpers.setupPageRoute; +const { setupPageRoute } = helpers; module.exports = function (app, middleware, controllers) { const middlewares = [middleware.exposeUid, middleware.canViewUsers]; diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 8c0238330c..1bd03f2f75 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -76,7 +76,7 @@ Auth.verifyToken = async function (token, done) { Auth.reloadRoutes = async function (params) { loginStrategies.length = 0; - const router = params.router; + const { router } = params; // Local Logins if (plugins.hooks.hasListeners('action:auth.overrideLogin')) { diff --git a/src/routes/debug.js b/src/routes/debug.js index 6358a95609..fad5e60625 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -16,7 +16,7 @@ module.exports = function (app) { // Redoc router.get('/spec/:type', async (req, res, next) => { const types = ['read', 'write']; - const type = req.params.type; + const { type } = req.params; if (!types.includes(type)) { return next(); } diff --git a/src/routes/feeds.js b/src/routes/feeds.js index af0099c15f..0869636695 100644 --- a/src/routes/feeds.js +++ b/src/routes/feeds.js @@ -39,7 +39,7 @@ module.exports = function (app, middleware) { async function validateTokenIfRequiresLogin(requiresLogin, cid, req, res) { const uid = parseInt(req.query.uid, 10) || 0; - const token = req.query.token; + const { token } = req.query; if (!requiresLogin) { return true; @@ -379,7 +379,7 @@ async function generateForUserTopics(req, res, next) { return controllers404.send404(req, res); } - const userslug = req.params.userslug; + const { userslug } = req.params; const uid = await user.getUidByUserslug(userslug); if (!uid) { return next(); diff --git a/src/routes/index.js b/src/routes/index.js index a8ef01646c..bff5c65eac 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -18,7 +18,7 @@ const authRoutes = require('./authentication'); const writeRoutes = require('./write'); const helpers = require('./helpers'); -const setupPageRoute = helpers.setupPageRoute; +const { setupPageRoute } = helpers; function mainRoutes(app, middleware, controllers) { const loginRegisterMiddleware = [middleware.redirectToAccountIfLoggedIn]; diff --git a/src/routes/write/admin.js b/src/routes/write/admin.js index c85f616ed6..bfcfc5ca2b 100644 --- a/src/routes/write/admin.js +++ b/src/routes/write/admin.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; module.exports = function () { const middlewares = [middleware.authenticate]; diff --git a/src/routes/write/categories.js b/src/routes/write/categories.js index a87456a657..6e1c584af8 100644 --- a/src/routes/write/categories.js +++ b/src/routes/write/categories.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; module.exports = function () { const middlewares = [middleware.authenticate]; diff --git a/src/routes/write/files.js b/src/routes/write/files.js index c325673df5..f4eb603c35 100644 --- a/src/routes/write/files.js +++ b/src/routes/write/files.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; module.exports = function () { const middlewares = [middleware.authenticate]; diff --git a/src/routes/write/groups.js b/src/routes/write/groups.js index e5adf28a40..676f587f9b 100644 --- a/src/routes/write/groups.js +++ b/src/routes/write/groups.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; module.exports = function () { const middlewares = [middleware.authenticate]; diff --git a/src/routes/write/index.js b/src/routes/write/index.js index fd530cbe56..d4679f7667 100644 --- a/src/routes/write/index.js +++ b/src/routes/write/index.js @@ -10,7 +10,7 @@ const helpers = require('../../controllers/helpers'); const Write = module.exports; Write.reload = async (params) => { - const router = params.router; + const { router } = params; let apiSettings = await meta.settings.get('core.api'); plugins.hooks.register('core', { hook: 'action:settings.set', diff --git a/src/routes/write/posts.js b/src/routes/write/posts.js index 56853bc3de..967d1b6a0f 100644 --- a/src/routes/write/posts.js +++ b/src/routes/write/posts.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; module.exports = function () { const middlewares = [middleware.authenticate]; diff --git a/src/routes/write/topics.js b/src/routes/write/topics.js index 9f415c9e7b..8877b2a535 100644 --- a/src/routes/write/topics.js +++ b/src/routes/write/topics.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; module.exports = function () { const middlewares = [middleware.authenticate]; diff --git a/src/routes/write/users.js b/src/routes/write/users.js index 94345a65ff..0138a9c1da 100644 --- a/src/routes/write/users.js +++ b/src/routes/write/users.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; // eslint-disable-next-line no-unused-vars function guestRoutes() { diff --git a/src/routes/write/utilities.js b/src/routes/write/utilities.js index 085536766c..7f442bbfa2 100644 --- a/src/routes/write/utilities.js +++ b/src/routes/write/utilities.js @@ -5,7 +5,7 @@ const middleware = require('../../middleware'); const controllers = require('../../controllers'); const routeHelpers = require('../helpers'); -const setupApiRoute = routeHelpers.setupApiRoute; +const { setupApiRoute } = routeHelpers; module.exports = function () { // The "ping" routes are mounted at root level, but for organizational purposes, the controllers are in `utilities.js` diff --git a/src/socket.io/admin/digest.js b/src/socket.io/admin/digest.js index b6427aced6..491b639d93 100644 --- a/src/socket.io/admin/digest.js +++ b/src/socket.io/admin/digest.js @@ -6,7 +6,7 @@ const userDigest = require('../../user/digest'); const Digest = module.exports; Digest.resend = async (socket, data) => { - const uid = data.uid; + const { uid } = data; const interval = data.action.startsWith('resend-') ? data.action.slice(7) : await userDigest.getUsersInterval(uid); if (!interval && meta.config.dailyDigestFreq === 'off') { diff --git a/src/socket.io/helpers.js b/src/socket.io/helpers.js index 6801cf91e8..986c99553e 100644 --- a/src/socket.io/helpers.js +++ b/src/socket.io/helpers.js @@ -36,8 +36,8 @@ SocketHelpers.notifyNew = async function (uid, type, result) { async function notifyUids(uid, uids, type, result) { const post = result.posts[0]; - const tid = post.topic.tid; - const cid = post.topic.cid; + const { tid } = post.topic; + const { cid } = post.topic; uids = await privileges.topics.filterUids('topics:read', tid, uids); const watchStateUids = uids; @@ -150,10 +150,10 @@ SocketHelpers.upvote = async function (data, notification) { return; } - const votes = data.post.votes; + const { votes } = data.post; const touid = data.post.uid; - const fromuid = data.fromuid; - const pid = data.post.pid; + const { fromuid } = data; + const { pid } = data.post; const shouldNotify = { all: function () { diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 5e49562360..35e3bf6d26 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -207,7 +207,7 @@ async function validateSession(socket) { const cookieParserAsync = util.promisify((req, callback) => cookieParser(req, {}, err => callback(err))); async function authorize(socket, callback) { - const request = socket.request; + const { request } = socket; if (!request) { return callback(new Error('[[error:not-authorized]]')); diff --git a/src/socket.io/uploads.js b/src/socket.io/uploads.js index cbbb2ca21b..c3fd025e0d 100644 --- a/src/socket.io/uploads.js +++ b/src/socket.io/uploads.js @@ -21,7 +21,7 @@ uploads.upload = async function (socket, data) { inProgress[socket.id] = inProgress[socket.id] || {}; const socketUploads = inProgress[socket.id]; - const method = data.params.method; + const { method } = data.params; socketUploads[method] = socketUploads[method] || { imageData: '' }; socketUploads[method].imageData += data.chunk; diff --git a/src/socket.io/user/picture.js b/src/socket.io/user/picture.js index 5fe4b0ea98..e3cb6e6ba0 100644 --- a/src/socket.io/user/picture.js +++ b/src/socket.io/user/picture.js @@ -17,7 +17,7 @@ module.exports = function (SocketUser) { throw new Error('[[error:invalid-data]]'); } - const type = data.type; + const { type } = data; let picture = ''; await user.isAdminOrGlobalModOrSelf(socket.uid, data.uid); if (type === 'default') { diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 3ffd45feda..42f78abc25 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -54,7 +54,7 @@ module.exports = function (SocketUser) { }; async function isPrivilegedOrSelfAndPasswordMatch(socket, data) { - const uid = socket.uid; + const { uid } = socket; const isSelf = parseInt(uid, 10) === parseInt(data.uid, 10); const [isAdmin, isTargetAdmin, isGlobalMod] = await Promise.all([ diff --git a/src/topics/create.js b/src/topics/create.js index 44cebbe872..cafa04a70b 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -62,7 +62,7 @@ module.exports = function (Topics) { }; Topics.post = async function (data) { - const uid = data.uid; + const { uid } = data; data.title = String(data.title).trim(); data.tags = data.tags || []; if (data.content) { @@ -133,8 +133,8 @@ module.exports = function (Topics) { }; Topics.reply = async function (data) { - const tid = data.tid; - const uid = data.uid; + const { tid } = data; + const { uid } = data; const topicData = await Topics.getTopicData(tid); if (!topicData) { @@ -199,8 +199,8 @@ module.exports = function (Topics) { }; async function onNewPost(postData, data) { - const tid = postData.tid; - const uid = postData.uid; + const { tid } = postData; + const { uid } = postData; await Topics.markAsUnreadForAll(tid); await Topics.markAsRead([tid], uid); const [ diff --git a/src/topics/follow.js b/src/topics/follow.js index f53f50c671..e9d895fc31 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -157,7 +157,7 @@ module.exports = function (Topics) { return; } - let title = postData.topic.title; + let { title } = postData.topic; if (title) { title = utils.decodeHTMLEntities(title); } diff --git a/src/topics/sorted.js b/src/topics/sorted.js index 53bf8dee5b..c69e4c2585 100644 --- a/src/topics/sorted.js +++ b/src/topics/sorted.js @@ -121,8 +121,8 @@ module.exports = function (Topics) { } async function filterTids(tids, params) { - const filter = params.filter; - const uid = params.uid; + const { filter } = params; + const { uid } = params; if (filter === 'new') { tids = await Topics.filterNewTids(tids, uid); diff --git a/src/topics/tags.js b/src/topics/tags.js index 0051818c6a..eb8eec50de 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -411,7 +411,7 @@ module.exports = function (Topics) { } async function findMatches(data) { - let query = data.query; + let { query } = data; let tagWhitelist = []; if (parseInt(data.cid, 10)) { tagWhitelist = await categories.getTagWhitelist([data.cid]); diff --git a/src/topics/teaser.js b/src/topics/teaser.js index d72f1ec921..0583818662 100644 --- a/src/topics/teaser.js +++ b/src/topics/teaser.js @@ -17,7 +17,7 @@ module.exports = function (Topics) { return []; } let uid = options; - let teaserPost = meta.config.teaserPost; + let { teaserPost } = meta.config; if (typeof options === 'object') { uid = options.uid; teaserPost = options.teaserPost || meta.config.teaserPost; diff --git a/src/topics/unread.js b/src/topics/unread.js index 1e97484655..82a68d1af6 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -218,7 +218,7 @@ module.exports = function (Topics) { } async function doesTidHaveUnblockedUnreadPosts(tid, params) { - const userLastReadTimestamp = params.userLastReadTimestamp; + const { userLastReadTimestamp } = params; if (!userLastReadTimestamp) { return true; } diff --git a/src/upgrades/1.0.0/user_best_posts.js b/src/upgrades/1.0.0/user_best_posts.js index 51dd55492f..b391e625fd 100644 --- a/src/upgrades/1.0.0/user_best_posts.js +++ b/src/upgrades/1.0.0/user_best_posts.js @@ -10,7 +10,7 @@ module.exports = { timestamp: Date.UTC(2016, 0, 14), method: function (callback) { const batch = require('../../batch'); - const progress = this.progress; + const { progress } = this; batch.processSortedSet('posts:pid', (ids, next) => { async.eachSeries(ids, (id, next) => { diff --git a/src/upgrades/1.1.0/assign_topic_read_privilege.js b/src/upgrades/1.1.0/assign_topic_read_privilege.js index 1232afdacb..2b11904773 100644 --- a/src/upgrades/1.1.0/assign_topic_read_privilege.js +++ b/src/upgrades/1.1.0/assign_topic_read_privilege.js @@ -23,8 +23,8 @@ module.exports = { return next(err); } - const groups = data.groups; - const users = data.users; + const { groups } = data; + const { users } = data; async.waterfall([ function (next) { diff --git a/src/upgrades/1.1.0/separate_upvote_downvote.js b/src/upgrades/1.1.0/separate_upvote_downvote.js index 876adb0e40..db6cf878d4 100644 --- a/src/upgrades/1.1.0/separate_upvote_downvote.js +++ b/src/upgrades/1.1.0/separate_upvote_downvote.js @@ -12,7 +12,7 @@ module.exports = { const batch = require('../../batch'); const posts = require('../../posts'); let count = 0; - const progress = this.progress; + const { progress } = this; batch.processSortedSet('posts:pid', (pids, next) => { winston.verbose(`upgraded ${count} posts`); diff --git a/src/upgrades/1.10.0/hash_recent_ip_addresses.js b/src/upgrades/1.10.0/hash_recent_ip_addresses.js index ac165d7fe4..af210fe326 100644 --- a/src/upgrades/1.10.0/hash_recent_ip_addresses.js +++ b/src/upgrades/1.10.0/hash_recent_ip_addresses.js @@ -11,7 +11,7 @@ module.exports = { name: 'Hash all IP addresses stored in Recent IPs zset', timestamp: Date.UTC(2018, 5, 22), method: function (callback) { - const progress = this.progress; + const { progress } = this; const hashed = /[a-f0-9]{32}/; let hash; diff --git a/src/upgrades/1.10.2/event_filters.js b/src/upgrades/1.10.2/event_filters.js index 46a81a970e..d87a526d5e 100644 --- a/src/upgrades/1.10.2/event_filters.js +++ b/src/upgrades/1.10.2/event_filters.js @@ -9,7 +9,7 @@ module.exports = { name: 'add filters to events', timestamp: Date.UTC(2018, 9, 4), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('events:time', (eids, next) => { async.eachSeries(eids, (eid, next) => { diff --git a/src/upgrades/1.10.2/fix_category_post_zsets.js b/src/upgrades/1.10.2/fix_category_post_zsets.js index d45f2024ac..1411f894c4 100644 --- a/src/upgrades/1.10.2/fix_category_post_zsets.js +++ b/src/upgrades/1.10.2/fix_category_post_zsets.js @@ -9,7 +9,7 @@ module.exports = { name: 'Fix category post zsets', timestamp: Date.UTC(2018, 9, 10), method: function (callback) { - const progress = this.progress; + const { progress } = this; db.getSortedSetRange('categories:cid', 0, -1, (err, cids) => { if (err) { diff --git a/src/upgrades/1.10.2/fix_category_topic_zsets.js b/src/upgrades/1.10.2/fix_category_topic_zsets.js index b81a73211f..692d35af18 100644 --- a/src/upgrades/1.10.2/fix_category_topic_zsets.js +++ b/src/upgrades/1.10.2/fix_category_topic_zsets.js @@ -9,7 +9,7 @@ module.exports = { name: 'Fix category topic zsets', timestamp: Date.UTC(2018, 9, 11), method: function (callback) { - const progress = this.progress; + const { progress } = this; const topics = require('../../topics'); batch.processSortedSet('topics:tid', (tids, next) => { diff --git a/src/upgrades/1.10.2/upgrade_bans_to_hashes.js b/src/upgrades/1.10.2/upgrade_bans_to_hashes.js index bb916ca826..0234915c63 100644 --- a/src/upgrades/1.10.2/upgrade_bans_to_hashes.js +++ b/src/upgrades/1.10.2/upgrade_bans_to_hashes.js @@ -10,7 +10,7 @@ module.exports = { name: 'Upgrade bans to hashes', timestamp: Date.UTC(2018, 8, 24), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (uids, next) => { async.eachSeries(uids, (uid, next) => { diff --git a/src/upgrades/1.10.2/username_email_history.js b/src/upgrades/1.10.2/username_email_history.js index d07bdff0ca..69bae687d3 100644 --- a/src/upgrades/1.10.2/username_email_history.js +++ b/src/upgrades/1.10.2/username_email_history.js @@ -10,7 +10,7 @@ module.exports = { name: 'Record first entry in username/email history', timestamp: Date.UTC(2018, 7, 28), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (ids, next) => { async.each(ids, (uid, next) => { diff --git a/src/upgrades/1.11.1/remove_ignored_cids_per_user.js b/src/upgrades/1.11.1/remove_ignored_cids_per_user.js index 528e236b7f..e94b692a37 100644 --- a/src/upgrades/1.11.1/remove_ignored_cids_per_user.js +++ b/src/upgrades/1.11.1/remove_ignored_cids_per_user.js @@ -8,7 +8,7 @@ module.exports = { name: 'Remove uid::ignored:cids', timestamp: Date.UTC(2018, 11, 11), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (uids, next) => { progress.incr(uids.length); diff --git a/src/upgrades/1.12.0/category_watch_state.js b/src/upgrades/1.12.0/category_watch_state.js index 95c55c3906..71e430bedb 100644 --- a/src/upgrades/1.12.0/category_watch_state.js +++ b/src/upgrades/1.12.0/category_watch_state.js @@ -10,7 +10,7 @@ module.exports = { name: 'Update category watch data', timestamp: Date.UTC(2018, 11, 13), method: function (callback) { - const progress = this.progress; + const { progress } = this; let keys; async.waterfall([ function (next) { diff --git a/src/upgrades/1.12.1/clear_username_email_history.js b/src/upgrades/1.12.1/clear_username_email_history.js index a2925826bd..822b500884 100644 --- a/src/upgrades/1.12.1/clear_username_email_history.js +++ b/src/upgrades/1.12.1/clear_username_email_history.js @@ -8,7 +8,7 @@ module.exports = { name: 'Delete username email history for deleted users', timestamp: Date.UTC(2019, 2, 25), method: function (callback) { - const progress = this.progress; + const { progress } = this; let currentUid = 1; db.getObjectField('global', 'nextUid', (err, nextUid) => { if (err) { diff --git a/src/upgrades/1.12.1/moderation_notes_refactor.js b/src/upgrades/1.12.1/moderation_notes_refactor.js index ad6ab17720..59ea6e6b38 100644 --- a/src/upgrades/1.12.1/moderation_notes_refactor.js +++ b/src/upgrades/1.12.1/moderation_notes_refactor.js @@ -9,7 +9,7 @@ module.exports = { name: 'Update moderation notes to hashes', timestamp: Date.UTC(2019, 3, 5), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (ids, next) => { async.each(ids, (uid, next) => { diff --git a/src/upgrades/1.12.1/post_upload_sizes.js b/src/upgrades/1.12.1/post_upload_sizes.js index bd1e5c4b43..1f91a16a79 100644 --- a/src/upgrades/1.12.1/post_upload_sizes.js +++ b/src/upgrades/1.12.1/post_upload_sizes.js @@ -9,7 +9,7 @@ module.exports = { name: 'Calculate image sizes of all uploaded images', timestamp: Date.UTC(2019, 2, 16), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('posts:pid', (postData, next) => { async.eachSeries(postData, async (pid) => { diff --git a/src/upgrades/1.12.3/user_pid_sets.js b/src/upgrades/1.12.3/user_pid_sets.js index a9692d6d4c..d98b4f9aab 100644 --- a/src/upgrades/1.12.3/user_pid_sets.js +++ b/src/upgrades/1.12.3/user_pid_sets.js @@ -11,7 +11,7 @@ module.exports = { name: 'Create zsets for user posts per category', timestamp: Date.UTC(2019, 5, 23), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('posts:pid', (pids, next) => { progress.incr(pids.length); diff --git a/src/upgrades/1.13.0/clean_flag_byCid.js b/src/upgrades/1.13.0/clean_flag_byCid.js index c0968e2535..5e0cc70132 100644 --- a/src/upgrades/1.13.0/clean_flag_byCid.js +++ b/src/upgrades/1.13.0/clean_flag_byCid.js @@ -7,7 +7,7 @@ module.exports = { name: 'Clean flag byCid zsets', timestamp: Date.UTC(2019, 8, 24), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('flags:datetime', async (flagIds) => { progress.incr(flagIds.length); diff --git a/src/upgrades/1.13.0/clean_post_topic_hash.js b/src/upgrades/1.13.0/clean_post_topic_hash.js index e797b576b5..caa6dbd8f6 100644 --- a/src/upgrades/1.13.0/clean_post_topic_hash.js +++ b/src/upgrades/1.13.0/clean_post_topic_hash.js @@ -7,7 +7,7 @@ module.exports = { name: 'Clean up post hash data', timestamp: Date.UTC(2019, 9, 7), method: async function () { - const progress = this.progress; + const { progress } = this; await cleanPost(progress); await cleanTopic(progress); }, diff --git a/src/upgrades/1.13.0/cleanup_old_notifications.js b/src/upgrades/1.13.0/cleanup_old_notifications.js index bf4cdb9c89..591c0392cc 100644 --- a/src/upgrades/1.13.0/cleanup_old_notifications.js +++ b/src/upgrades/1.13.0/cleanup_old_notifications.js @@ -8,7 +8,7 @@ module.exports = { name: 'Clean up old notifications and hash data', timestamp: Date.UTC(2019, 9, 7), method: async function () { - const progress = this.progress; + const { progress } = this; const week = 604800000; const cutoffTime = Date.now() - week; await batch.processSortedSet('users:joindate', async (uids) => { diff --git a/src/upgrades/1.13.3/fix_users_sorted_sets.js b/src/upgrades/1.13.3/fix_users_sorted_sets.js index f977c09847..a23955a8da 100644 --- a/src/upgrades/1.13.3/fix_users_sorted_sets.js +++ b/src/upgrades/1.13.3/fix_users_sorted_sets.js @@ -7,7 +7,7 @@ module.exports = { name: 'Fix user sorted sets', timestamp: Date.UTC(2020, 4, 2), method: async function () { - const progress = this.progress; + const { progress } = this; const nextUid = await db.getObjectField('global', 'nextUid'); const allUids = []; for (let i = 1; i <= nextUid; i++) { diff --git a/src/upgrades/1.14.1/readd_deleted_recent_topics.js b/src/upgrades/1.14.1/readd_deleted_recent_topics.js index 75a088a8c1..eabd23cc77 100644 --- a/src/upgrades/1.14.1/readd_deleted_recent_topics.js +++ b/src/upgrades/1.14.1/readd_deleted_recent_topics.js @@ -8,7 +8,7 @@ module.exports = { name: 'Re-add deleted topics to topics:recent', timestamp: Date.UTC(2018, 9, 11), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('topics:tid', async (tids) => { progress.incr(tids.length); diff --git a/src/upgrades/1.15.0/add_target_uid_to_flags.js b/src/upgrades/1.15.0/add_target_uid_to_flags.js index f76cdc4b09..0f9d9cfa83 100644 --- a/src/upgrades/1.15.0/add_target_uid_to_flags.js +++ b/src/upgrades/1.15.0/add_target_uid_to_flags.js @@ -8,7 +8,7 @@ module.exports = { name: 'Add target uid to flag objects', timestamp: Date.UTC(2020, 7, 22), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('flags:datetime', async (flagIds) => { progress.incr(flagIds.length); @@ -16,7 +16,7 @@ module.exports = { for (const flagObj of flagData) { /* eslint-disable no-await-in-loop */ if (flagObj) { - const targetId = flagObj.targetId; + const { targetId } = flagObj; if (targetId) { if (flagObj.type === 'post') { const targetUid = await posts.getPostField(targetId, 'uid'); diff --git a/src/upgrades/1.15.0/consolidate_flags.js b/src/upgrades/1.15.0/consolidate_flags.js index 01aa94e7ae..b6b4adb88a 100644 --- a/src/upgrades/1.15.0/consolidate_flags.js +++ b/src/upgrades/1.15.0/consolidate_flags.js @@ -9,7 +9,7 @@ module.exports = { name: 'Consolidate multiple flags reports, going forward', timestamp: Date.UTC(2020, 6, 16), method: async function () { - const progress = this.progress; + const { progress } = this; let flags = await db.getSortedSetRange('flags:datetime', 0, -1); flags = flags.map(flagId => `flag:${flagId}`); diff --git a/src/upgrades/1.15.0/fullname_search_set.js b/src/upgrades/1.15.0/fullname_search_set.js index 42e8476dff..28b79803d6 100644 --- a/src/upgrades/1.15.0/fullname_search_set.js +++ b/src/upgrades/1.15.0/fullname_search_set.js @@ -9,7 +9,7 @@ module.exports = { name: 'Create fullname search set', timestamp: Date.UTC(2020, 8, 11), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('users:joindate', async (uids) => { progress.incr(uids.length); diff --git a/src/upgrades/1.15.0/remove_flag_reporters_zset.js b/src/upgrades/1.15.0/remove_flag_reporters_zset.js index 3b3724da7e..6ea79e64dd 100644 --- a/src/upgrades/1.15.0/remove_flag_reporters_zset.js +++ b/src/upgrades/1.15.0/remove_flag_reporters_zset.js @@ -7,7 +7,7 @@ module.exports = { name: 'Remove flag reporters sorted set', timestamp: Date.UTC(2020, 6, 31), method: async function () { - const progress = this.progress; + const { progress } = this; progress.total = await db.sortedSetCard('flags:datetime'); await batch.processSortedSet('flags:datetime', async (flagIds) => { diff --git a/src/upgrades/1.15.0/topic_poster_count.js b/src/upgrades/1.15.0/topic_poster_count.js index 3ac1bf44e0..dbb2a6edd8 100644 --- a/src/upgrades/1.15.0/topic_poster_count.js +++ b/src/upgrades/1.15.0/topic_poster_count.js @@ -8,7 +8,7 @@ module.exports = { name: 'Store poster count in topic hash', timestamp: Date.UTC(2020, 9, 24), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('topics:tid', async (tids) => { progress.incr(tids.length); diff --git a/src/upgrades/1.15.0/verified_users_group.js b/src/upgrades/1.15.0/verified_users_group.js index 66c4ccd92f..0aabdb3224 100644 --- a/src/upgrades/1.15.0/verified_users_group.js +++ b/src/upgrades/1.15.0/verified_users_group.js @@ -13,7 +13,7 @@ module.exports = { name: 'Create verified/unverified user groups', timestamp: Date.UTC(2020, 9, 13), method: async function () { - const progress = this.progress; + const { progress } = this; const maxGroupLength = meta.config.maximumGroupNameLength; meta.config.maximumGroupNameLength = 30; diff --git a/src/upgrades/1.15.4/clear_purged_replies.js b/src/upgrades/1.15.4/clear_purged_replies.js index 2077965e45..8b32db239c 100644 --- a/src/upgrades/1.15.4/clear_purged_replies.js +++ b/src/upgrades/1.15.4/clear_purged_replies.js @@ -9,7 +9,7 @@ module.exports = { name: 'Clear purged replies and toPid', timestamp: Date.UTC(2020, 10, 26), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('posts:pid', async (pids) => { progress.incr(pids.length); diff --git a/src/upgrades/1.16.0/category_tags.js b/src/upgrades/1.16.0/category_tags.js index 8cd1c2c1e1..4d770b3b94 100644 --- a/src/upgrades/1.16.0/category_tags.js +++ b/src/upgrades/1.16.0/category_tags.js @@ -9,7 +9,7 @@ module.exports = { name: 'Create category tags sorted sets', timestamp: Date.UTC(2020, 10, 23), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('topics:tid', async (tids) => { await async.eachSeries(tids, async (tid) => { @@ -19,7 +19,7 @@ module.exports = { ]); if (tags.length) { - const cid = topicData.cid; + const { cid } = topicData; await async.eachSeries(tags, async (tag) => { await db.sortedSetAdd(`cid:${cid}:tag:${tag}:topics`, topicData.timestamp, tid); const count = await db.sortedSetCard(`cid:${cid}:tag:${tag}:topics`); diff --git a/src/upgrades/1.16.0/migrate_thumbs.js b/src/upgrades/1.16.0/migrate_thumbs.js index c791ed9ae6..0686af71c1 100644 --- a/src/upgrades/1.16.0/migrate_thumbs.js +++ b/src/upgrades/1.16.0/migrate_thumbs.js @@ -11,7 +11,7 @@ module.exports = { name: 'Migrate existing topic thumbnails to new format', timestamp: Date.UTC(2020, 11, 11), method: async function () { - const progress = this.progress; + const { progress } = this; const current = await meta.configs.get('topicThumbSize'); if (parseInt(current, 10) === 120) { diff --git a/src/upgrades/1.17.0/banned_users_group.js b/src/upgrades/1.17.0/banned_users_group.js index 27ebc3b340..623725a9ec 100644 --- a/src/upgrades/1.17.0/banned_users_group.js +++ b/src/upgrades/1.17.0/banned_users_group.js @@ -10,7 +10,7 @@ module.exports = { name: 'Move banned users to banned-users group', timestamp: Date.UTC(2020, 11, 13), method: async function () { - const progress = this.progress; + const { progress } = this; const timestamp = await db.getObjectField('group:administrators', 'timestamp'); const bannedExists = await groups.exists('banned-users'); if (!bannedExists) { diff --git a/src/upgrades/1.17.0/category_name_zset.js b/src/upgrades/1.17.0/category_name_zset.js index 1ace788d24..01f0370427 100644 --- a/src/upgrades/1.17.0/category_name_zset.js +++ b/src/upgrades/1.17.0/category_name_zset.js @@ -7,7 +7,7 @@ module.exports = { name: 'Create category name sorted set', timestamp: Date.UTC(2021, 0, 27), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('categories:cid', async (cids) => { const keys = cids.map(cid => `category:${cid}`); diff --git a/src/upgrades/1.17.0/subcategories_per_page.js b/src/upgrades/1.17.0/subcategories_per_page.js index c6b667d5c5..8323ac0525 100644 --- a/src/upgrades/1.17.0/subcategories_per_page.js +++ b/src/upgrades/1.17.0/subcategories_per_page.js @@ -7,7 +7,7 @@ module.exports = { name: 'Create subCategoriesPerPage property for categories', timestamp: Date.UTC(2021, 0, 31), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('categories:cid', async (cids) => { const keys = cids.map(cid => `category:${cid}`); diff --git a/src/upgrades/1.17.0/topic_thumb_count.js b/src/upgrades/1.17.0/topic_thumb_count.js index f5ccd134b2..a5239101d0 100644 --- a/src/upgrades/1.17.0/topic_thumb_count.js +++ b/src/upgrades/1.17.0/topic_thumb_count.js @@ -8,7 +8,7 @@ module.exports = { name: 'Store number of thumbs a topic has in the topic object', timestamp: Date.UTC(2021, 1, 7), method: async function () { - const progress = this.progress; + const { progress } = this; await batch.processSortedSet('topics:tid', async (tids) => { const keys = tids.map(tid => `topic:${tid}:thumbs`); diff --git a/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js b/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js index b5d28f4a56..0ebfd4b274 100644 --- a/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js +++ b/src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js @@ -23,8 +23,8 @@ module.exports = { return next(err); } - const groups = data.groups; - const users = data.users; + const { groups } = data; + const { users } = data; async.waterfall([ function (next) { diff --git a/src/upgrades/1.3.0/favourites_to_bookmarks.js b/src/upgrades/1.3.0/favourites_to_bookmarks.js index a61bbf3cce..782b4774db 100644 --- a/src/upgrades/1.3.0/favourites_to_bookmarks.js +++ b/src/upgrades/1.3.0/favourites_to_bookmarks.js @@ -8,7 +8,7 @@ module.exports = { name: 'Favourites to Bookmarks', timestamp: Date.UTC(2016, 9, 8), method: function (callback) { - const progress = this.progress; + const { progress } = this; function upgradePosts(next) { const batch = require('../../batch'); diff --git a/src/upgrades/1.3.0/sorted_sets_for_post_replies.js b/src/upgrades/1.3.0/sorted_sets_for_post_replies.js index d34f30a60d..630757b9d9 100644 --- a/src/upgrades/1.3.0/sorted_sets_for_post_replies.js +++ b/src/upgrades/1.3.0/sorted_sets_for_post_replies.js @@ -11,7 +11,7 @@ module.exports = { method: function (callback) { const posts = require('../../posts'); const batch = require('../../batch'); - const progress = this.progress; + const { progress } = this; batch.processSortedSet('posts:pid', (ids, next) => { posts.getPostsFields(ids, ['pid', 'toPid', 'timestamp'], (err, data) => { diff --git a/src/upgrades/1.4.6/delete_sessions.js b/src/upgrades/1.4.6/delete_sessions.js index aadf00b0ba..a257da1725 100644 --- a/src/upgrades/1.4.6/delete_sessions.js +++ b/src/upgrades/1.4.6/delete_sessions.js @@ -18,7 +18,7 @@ module.exports = { } const isRedisSessionStore = configJSON.hasOwnProperty('redis'); - const progress = this.progress; + const { progress } = this; async.waterfall([ function (next) { diff --git a/src/upgrades/1.5.0/flags_refactor.js b/src/upgrades/1.5.0/flags_refactor.js index 55a2553882..f16d9a5224 100644 --- a/src/upgrades/1.5.0/flags_refactor.js +++ b/src/upgrades/1.5.0/flags_refactor.js @@ -11,7 +11,7 @@ module.exports = { const batch = require('../../batch'); const posts = require('../../posts'); const flags = require('../../flags'); - const progress = this.progress; + const { progress } = this; batch.processSortedSet('posts:pid', (ids, next) => { posts.getPostsByPids(ids, 1, (err, posts) => { diff --git a/src/upgrades/1.5.0/moderation_history_refactor.js b/src/upgrades/1.5.0/moderation_history_refactor.js index e06b3318b4..8a98830acf 100644 --- a/src/upgrades/1.5.0/moderation_history_refactor.js +++ b/src/upgrades/1.5.0/moderation_history_refactor.js @@ -9,7 +9,7 @@ module.exports = { name: 'Update moderation notes to zset', timestamp: Date.UTC(2017, 2, 22), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (ids, next) => { async.each(ids, (uid, next) => { diff --git a/src/upgrades/1.5.0/post_votes_zset.js b/src/upgrades/1.5.0/post_votes_zset.js index 9a84bfddaa..810a1886b1 100644 --- a/src/upgrades/1.5.0/post_votes_zset.js +++ b/src/upgrades/1.5.0/post_votes_zset.js @@ -8,7 +8,7 @@ module.exports = { name: 'New sorted set posts:votes', timestamp: Date.UTC(2017, 1, 27), method: function (callback) { - const progress = this.progress; + const { progress } = this; require('../../batch').processSortedSet('posts:pid', (pids, next) => { async.each(pids, (pid, next) => { diff --git a/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js b/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js index 5cbe49996b..9cb34c5986 100644 --- a/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js +++ b/src/upgrades/1.5.0/remove_relative_uploaded_profile_cover.js @@ -9,7 +9,7 @@ module.exports = { name: 'Remove relative_path from uploaded profile cover urls', timestamp: Date.UTC(2017, 3, 26), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (ids, done) => { async.each(ids, (uid, cb) => { diff --git a/src/upgrades/1.5.1/rename_mods_group.js b/src/upgrades/1.5.1/rename_mods_group.js index 5bdaa45c91..5e64dc0a53 100644 --- a/src/upgrades/1.5.1/rename_mods_group.js +++ b/src/upgrades/1.5.1/rename_mods_group.js @@ -11,7 +11,7 @@ module.exports = { name: 'rename user mod privileges group', timestamp: Date.UTC(2017, 4, 26), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('categories:cid', (cids, next) => { async.eachSeries(cids, (cid, next) => { const groupName = `cid:${cid}:privileges:mods`; diff --git a/src/upgrades/1.5.2/rss_token_wipe.js b/src/upgrades/1.5.2/rss_token_wipe.js index e8b992dd33..a2097dcc25 100644 --- a/src/upgrades/1.5.2/rss_token_wipe.js +++ b/src/upgrades/1.5.2/rss_token_wipe.js @@ -8,7 +8,7 @@ module.exports = { name: 'Wipe all existing RSS tokens', timestamp: Date.UTC(2017, 6, 5), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (uids, next) => { async.eachLimit(uids, 500, (uid, next) => { diff --git a/src/upgrades/1.5.2/tags_privilege.js b/src/upgrades/1.5.2/tags_privilege.js index 44217acbc8..72b9b730b8 100644 --- a/src/upgrades/1.5.2/tags_privilege.js +++ b/src/upgrades/1.5.2/tags_privilege.js @@ -8,7 +8,7 @@ module.exports = { name: 'Give tag privilege to registered-users on all categories', timestamp: Date.UTC(2017, 5, 16), method: function (callback) { - const progress = this.progress; + const { progress } = this; const privileges = require('../../privileges'); batch.processSortedSet('categories:cid', (cids, next) => { async.eachSeries(cids, (cid, next) => { diff --git a/src/upgrades/1.6.2/topics_lastposttime_zset.js b/src/upgrades/1.6.2/topics_lastposttime_zset.js index 071901199a..1dee9feb1a 100644 --- a/src/upgrades/1.6.2/topics_lastposttime_zset.js +++ b/src/upgrades/1.6.2/topics_lastposttime_zset.js @@ -8,7 +8,7 @@ module.exports = { name: 'New sorted set cid::tids:lastposttime', timestamp: Date.UTC(2017, 9, 30), method: function (callback) { - const progress = this.progress; + const { progress } = this; require('../../batch').processSortedSet('topics:tid', (tids, next) => { async.eachSeries(tids, (tid, next) => { diff --git a/src/upgrades/1.7.1/notification-settings.js b/src/upgrades/1.7.1/notification-settings.js index 7ee78f244e..e7a455feb9 100644 --- a/src/upgrades/1.7.1/notification-settings.js +++ b/src/upgrades/1.7.1/notification-settings.js @@ -8,7 +8,7 @@ module.exports = { name: 'Convert old notification digest settings', timestamp: Date.UTC(2017, 10, 15), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('users:joindate', (uids, next) => { async.eachLimit(uids, 500, (uid, next) => { diff --git a/src/upgrades/1.7.3/key_value_schema_change.js b/src/upgrades/1.7.3/key_value_schema_change.js index 1904baf917..997db02551 100644 --- a/src/upgrades/1.7.3/key_value_schema_change.js +++ b/src/upgrades/1.7.3/key_value_schema_change.js @@ -15,11 +15,11 @@ module.exports = { configJSON = { [process.env.database]: true, database: process.env.database }; } const isMongo = configJSON.hasOwnProperty('mongo') && configJSON.database === 'mongo'; - const progress = this.progress; + const { progress } = this; if (!isMongo) { return callback(); } - const client = db.client; + const { client } = db; let cursor; async.waterfall([ function (next) { diff --git a/src/upgrades/1.7.3/topic_votes.js b/src/upgrades/1.7.3/topic_votes.js index e28f0a8b27..f7c5d0c122 100644 --- a/src/upgrades/1.7.3/topic_votes.js +++ b/src/upgrades/1.7.3/topic_votes.js @@ -8,7 +8,7 @@ module.exports = { name: 'Add votes to topics', timestamp: Date.UTC(2017, 11, 8), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('topics:tid', (tids, next) => { async.eachLimit(tids, 500, (tid, _next) => { diff --git a/src/upgrades/1.7.4/fix_moved_topics_byvotes.js b/src/upgrades/1.7.4/fix_moved_topics_byvotes.js index 4d607c386a..bb183557ef 100644 --- a/src/upgrades/1.7.4/fix_moved_topics_byvotes.js +++ b/src/upgrades/1.7.4/fix_moved_topics_byvotes.js @@ -8,7 +8,7 @@ module.exports = { name: 'Fix sort by votes for moved topics', timestamp: Date.UTC(2018, 0, 8), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('topics:tid', (tids, next) => { async.eachLimit(tids, 500, (tid, _next) => { diff --git a/src/upgrades/1.7.4/fix_user_topics_per_category.js b/src/upgrades/1.7.4/fix_user_topics_per_category.js index 0be8d81692..73b6671864 100644 --- a/src/upgrades/1.7.4/fix_user_topics_per_category.js +++ b/src/upgrades/1.7.4/fix_user_topics_per_category.js @@ -8,7 +8,7 @@ module.exports = { name: 'Fix topics in categories per user if they were moved', timestamp: Date.UTC(2018, 0, 22), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('topics:tid', (tids, next) => { async.eachLimit(tids, 500, (tid, _next) => { diff --git a/src/upgrades/1.8.1/diffs_zset_to_listhash.js b/src/upgrades/1.8.1/diffs_zset_to_listhash.js index b69252acd6..370242fba1 100644 --- a/src/upgrades/1.8.1/diffs_zset_to_listhash.js +++ b/src/upgrades/1.8.1/diffs_zset_to_listhash.js @@ -9,7 +9,7 @@ module.exports = { name: 'Reformatting post diffs to be stored in lists and hash instead of single zset', timestamp: Date.UTC(2018, 2, 15), method: function (callback) { - const progress = this.progress; + const { progress } = this; batch.processSortedSet('posts:pid', (pids, next) => { async.each(pids, (pid, next) => { diff --git a/src/upgrades/1.9.0/refresh_post_upload_associations.js b/src/upgrades/1.9.0/refresh_post_upload_associations.js index 3c44431a0f..44acfc079f 100644 --- a/src/upgrades/1.9.0/refresh_post_upload_associations.js +++ b/src/upgrades/1.9.0/refresh_post_upload_associations.js @@ -7,7 +7,7 @@ module.exports = { name: 'Refresh post-upload associations', timestamp: Date.UTC(2018, 3, 16), method: function (callback) { - const progress = this.progress; + const { progress } = this; require('../../batch').processSortedSet('posts:pid', (pids, next) => { async.each(pids, (pid, next) => { diff --git a/src/user/approval.js b/src/user/approval.js index 04974b8470..639315f00d 100644 --- a/src/user/approval.js +++ b/src/user/approval.js @@ -106,7 +106,7 @@ module.exports = function (User) { } User.shouldQueueUser = async function (ip) { - const registrationApprovalType = meta.config.registrationApprovalType; + const { registrationApprovalType } = meta.config; if (registrationApprovalType === 'admin-approval') { return true; } else if (registrationApprovalType === 'admin-approval-ip') { diff --git a/src/user/bans.js b/src/user/bans.js index eb443080d9..8a7352d29e 100644 --- a/src/user/bans.js +++ b/src/user/bans.js @@ -93,7 +93,7 @@ module.exports = function (User) { User.bans.canLoginIfBanned = async function (uid) { let canLogin = true; - const banned = (await User.bans.unbanIfExpired([uid]))[0].banned; + const { banned } = (await User.bans.unbanIfExpired([uid]))[0]; // Group privilege overshadows individual one if (banned) { canLogin = await privileges.global.canGroup('local:login', groups.BANNED_USERS); diff --git a/src/user/create.js b/src/user/create.js index 6f66812603..adb9f6e478 100644 --- a/src/user/create.js +++ b/src/user/create.js @@ -186,7 +186,7 @@ module.exports = function (User) { User.uniqueUsername = async function (userData) { let numTries = 0; - let username = userData.username; + let { username } = userData; while (true) { /* eslint-disable no-await-in-loop */ const exists = await meta.userOrGroupExists(username); diff --git a/src/user/digest.js b/src/user/digest.js index 5889883f09..8bd247bc0b 100644 --- a/src/user/digest.js +++ b/src/user/digest.js @@ -21,7 +21,7 @@ Digest.execute = async function (payload) { winston.info(`[user/jobs] Did not send digests (${payload.interval}) because subscription system is disabled.`); return; } - let subscribers = payload.subscribers; + let { subscribers } = payload; if (!subscribers) { subscribers = await Digest.getSubscribers(payload.interval); } diff --git a/src/user/jobs.js b/src/user/jobs.js index 9090d6b51e..ce5808ac26 100644 --- a/src/user/jobs.js +++ b/src/user/jobs.js @@ -12,7 +12,7 @@ module.exports = function (User) { winston.verbose('[user/jobs] (Re-)starting jobs...'); let started = 0; - let digestHour = meta.config.digestHour; + let { digestHour } = meta.config; // Fix digest hour if invalid if (isNaN(digestHour)) { diff --git a/src/user/notifications.js b/src/user/notifications.js index dcfa29f421..ad9175cab0 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -171,7 +171,7 @@ UserNotifications.sendTopicNotificationToFollowers = async function (uid, topicD if (!followers.length) { return; } - let title = topicData.title; + let { title } = topicData; if (title) { title = utils.decodeHTMLEntities(title); title = title.replace(/,/g, '\\,'); diff --git a/src/widgets/index.js b/src/widgets/index.js index 54cecfac07..d169876b85 100644 --- a/src/widgets/index.js +++ b/src/widgets/index.js @@ -75,7 +75,7 @@ async function renderWidget(widget, uid, options) { return; } - let html = data.html; + let { html } = data; if (widget.data.container && widget.data.container.match('{body}')) { html = await Benchpress.compileRender(widget.data.container, { diff --git a/test/api.js b/test/api.js index af21409775..fb32d5f998 100644 --- a/test/api.js +++ b/test/api.js @@ -315,7 +315,7 @@ describe('API', async () => { }); it('should have examples when parameters are present', () => { - let parameters = context[method].parameters; + let { parameters } = context[method]; let testPath = path; if (parameters) { diff --git a/test/emailer.js b/test/emailer.js index 2cb1b52896..17e639f0b9 100644 --- a/test/emailer.js +++ b/test/emailer.js @@ -1,6 +1,6 @@ 'use strict'; -const SMTPServer = require('smtp-server').SMTPServer; +const { SMTPServer } = require('smtp-server'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); diff --git a/test/plugins.js b/test/plugins.js index df90b982ed..05fa025969 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -176,7 +176,7 @@ describe('Plugins', () => { }); it('should show installed plugins', (done) => { - const nodeModulesPath = plugins.nodeModulesPath; + const { nodeModulesPath } = plugins; plugins.nodeModulesPath = path.join(__dirname, './mocks/plugin_modules'); plugins.showInstalled((err, pluginsData) => { diff --git a/test/topics.js b/test/topics.js index 6d84fee933..ae3899af5f 100644 --- a/test/topics.js +++ b/test/topics.js @@ -887,7 +887,7 @@ describe('Topic\'s', () => { topics.getUnreadTopics({ cid: 0, uid: uid, start: 0, stop: -1, filter: '' }, done); }, function (results, done) { - const topics = results.topics; + const { topics } = results; const tids = topics.map(topic => topic.tid); assert.equal(tids.indexOf(newTid), -1, 'The topic appeared in the unread list.'); done(); @@ -909,7 +909,7 @@ describe('Topic\'s', () => { }, done); }, function (results, done) { - const topics = results.topics; + const { topics } = results; let topic; let i; for (i = 0; i < topics.length; i += 1) { @@ -936,7 +936,7 @@ describe('Topic\'s', () => { topics.getUnreadTopics({ cid: 0, uid: uid, start: 0, stop: -1, filter: '' }, done); }, function (results, done) { - const topics = results.topics; + const { topics } = results; const tids = topics.map(topic => topic.tid); assert.notEqual(tids.indexOf(newTid), -1, 'The topic did not appear in the unread list.'); done(); @@ -956,7 +956,7 @@ describe('Topic\'s', () => { topics.getUnreadTopics({ cid: 0, uid: uid, start: 0, stop: -1, filter: '' }, done); }, function (results, done) { - const topics = results.topics; + const { topics } = results; const tids = topics.map(topic => topic.tid); assert.notEqual(tids.indexOf(newTid), -1, 'The topic did not appear in the unread list.'); done(); @@ -1941,7 +1941,7 @@ describe('Topic\'s', () => { it('should delete category tag as well', async () => { const category = await categories.create({ name: 'delete category' }); - const cid = category.cid; + const { cid } = category; await topics.post({ uid: adminUid, tags: ['willbedeleted', 'notthis'], title: 'tag topic', content: 'topic 1 content', cid: cid }); let categoryTags = await topics.getCategoryTags(cid, 0, -1); assert(categoryTags.includes('willbedeleted')); @@ -1954,9 +1954,9 @@ describe('Topic\'s', () => { it('should add and remove tags from topics properly', async () => { const category = await categories.create({ name: 'add/remove category' }); - const cid = category.cid; + const { cid } = category; const result = await topics.post({ uid: adminUid, tags: ['tag4', 'tag2', 'tag1', 'tag3'], title: 'tag topic', content: 'topic 1 content', cid: cid }); - const tid = result.topicData.tid; + const { tid } = result.topicData; let tags = await topics.getTopicTags(tid); let categoryTags = await topics.getCategoryTags(cid, 0, -1); @@ -2030,7 +2030,7 @@ describe('Topic\'s', () => { it('should create and delete category tags properly', async () => { const category = await categories.create({ name: 'tag category 2' }); - const cid = category.cid; + const { cid } = category; const title = 'test title'; const postResult = await topics.post({ uid: adminUid, tags: ['cattag1', 'cattag2', 'cattag3'], title: title, content: 'topic 1 content', cid: cid }); await topics.post({ uid: adminUid, tags: ['cattag1', 'cattag2'], title: title, content: 'topic 1 content', cid: cid }); @@ -2353,7 +2353,7 @@ describe('Topic\'s', () => { it('should fail to edit if user does not have tag privilege', (done) => { topics.post({ uid: uid, cid: cid, title: 'topic with tags', content: 'some content here' }, (err, result) => { assert.ifError(err); - const pid = result.postData.pid; + const { pid } = result.postData; posts.edit({ pid: pid, uid: uid, content: 'edited content', tags: ['tag2'] }, (err) => { assert.equal(err.message, '[[error:no-privileges]]'); done(); diff --git a/test/translator.js b/test/translator.js index b3c80eedad..962a1ba41b 100644 --- a/test/translator.js +++ b/test/translator.js @@ -4,7 +4,7 @@ const assert = require('assert'); const shim = require('../public/src/modules/translator.js'); -const Translator = shim.Translator; +const { Translator } = shim; const db = require('./mocks/databasemock'); describe('Translator shim', () => { diff --git a/test/utils.js b/test/utils.js index d765c15e8a..cb764c214b 100644 --- a/test/utils.js +++ b/test/utils.js @@ -2,7 +2,7 @@ const assert = require('assert'); -const JSDOM = require('jsdom').JSDOM; +const { JSDOM } = require('jsdom'); const utils = require('../public/src/utils.js'); const slugify = require('../src/slugify'); const db = require('./mocks/databasemock'); @@ -11,11 +11,11 @@ describe('Utility Methods', () => { // https://gist.github.com/robballou/9ee108758dc5e0e2d028 // create some jsdom magic to allow jQuery to work const dom = new JSDOM(''); - const window = dom.window; + const { window } = dom; global.window = window; global.jQuery = require('jquery'); global.$ = global.jQuery; - const $ = global.$; + const { $ } = global; require('jquery-deserialize'); require('jquery-serializeobject');