diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index e99b547ffc..0000000000 --- a/.eslintrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "root": true, - "extends": [ - "habitrpg/lib/node" - ], - "rules": { - 'no-param-reassign': ['error', { - props: false, - }], - } -} diff --git a/gulp/gulp-tests.js b/gulp/gulp-tests.js index 00fa172bb9..47eec297ec 100644 --- a/gulp/gulp-tests.js +++ b/gulp/gulp-tests.js @@ -29,8 +29,8 @@ const testCount = (stdout, regexp) => { const testBin = (string, additionalEnvVariables = '') => { if (os.platform() === 'win32') { if (additionalEnvVariables !== '') { - additionalEnvVariables = additionalEnvVariables.split(' ').join('&&set '); - additionalEnvVariables = `set ${additionalEnvVariables}&&`; + additionalEnvVariables = additionalEnvVariables.split(' ').join('&&set '); // eslint-disable-line no-param-reassign + additionalEnvVariables = `set ${additionalEnvVariables}&&`; // eslint-disable-line no-param-reassign } return `set NODE_ENV=test&&${additionalEnvVariables}${string}`; } @@ -46,9 +46,9 @@ gulp.task('test:nodemon', gulp.series(done => { gulp.task('test:prepare:mongo', cb => { mongoose.connect(TEST_DB_URI, err => { if (err) return cb(`Unable to connect to mongo database. Are you sure it's running? \n\n${err}`); - mongoose.connection.dropDatabase(err2 => { + return mongoose.connection.dropDatabase(err2 => { if (err2) return cb(err2); - mongoose.connection.close(cb); + return mongoose.connection.close(cb); }); }); }); diff --git a/gulp/gulp-transifex-test.js b/gulp/gulp-transifex-test.js index b90f9d441e..5ecb013e2d 100644 --- a/gulp/gulp-transifex-test.js +++ b/gulp/gulp-transifex-test.js @@ -44,7 +44,7 @@ function eachTranslationFile (languages, cb) { const englishFile = fs.readFileSync(ENGLISH_LOCALE + filename); const parsedEnglishFile = JSON.parse(englishFile); - cb(null, lang, filename, parsedEnglishFile, parsedTranslationFile); + return cb(null, lang, filename, parsedEnglishFile, parsedTranslationFile); }); }); } diff --git a/migrations/.eslintrc b/migrations/.eslintrc deleted file mode 100644 index 6509e9ee6b..0000000000 --- a/migrations/.eslintrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "root": false, - "rules": { - "no-console": 0, - "no-use-before-define": ["error", { "functions": false }] - } -} diff --git a/migrations/challenges/sync-all-challenges.js b/migrations/challenges/sync-all-challenges.js index 519865e267..22d34b6f35 100644 --- a/migrations/challenges/sync-all-challenges.js +++ b/migrations/challenges/sync-all-challenges.js @@ -18,7 +18,7 @@ async function syncChallengeToMembers (challenges) { return Promise.all(promises); }); - return await Promise.all(challengSyncPromises); + return Promise.all(challengSyncPromises); } async function syncChallenges (lastChallengeDate) { diff --git a/migrations/command-line/cancelSubscription.js b/migrations/command-line/cancelSubscription.js index 682568239e..a59a0a4c7f 100644 --- a/migrations/command-line/cancelSubscription.js +++ b/migrations/command-line/cancelSubscription.js @@ -1,6 +1,7 @@ // mongo habitrpg ./node_modules/moment/moment.js ./migrations/cancelSubscription.js -// For some reason people often to contact me to cancel their sub, rather than do it online. Even when I point them to +// For some reason people often to contact me to cancel their sub, +// rather than do it online. Even when I point them to // the FAQ (http://goo.gl/1uoPGQ) they insist... db.users.update( diff --git a/migrations/command-line/contribs_plan.js b/migrations/command-line/contribs_plan.js index a08b8acc0b..3a6d66359e 100644 --- a/migrations/command-line/contribs_plan.js +++ b/migrations/command-line/contribs_plan.js @@ -1,6 +1,5 @@ // Give contrib.level 7+ free subscription for life db.users.update( - { 'contributor.level': { $gte: 7 }, 'purchased.plan.customerId': null, diff --git a/migrations/command-line/duplicatedTasksFindAndRemove.js b/migrations/command-line/duplicatedTasksFindAndRemove.js index 6fa6d3d1fb..d96b22356e 100644 --- a/migrations/command-line/duplicatedTasksFindAndRemove.js +++ b/migrations/command-line/duplicatedTasksFindAndRemove.js @@ -84,7 +84,7 @@ db.users.aggregate([ ]).forEach(data => { // print( "\n" ); printjson(data); data.troublesomeIds.forEach(taskid => { - print(`non-unique task: ${taskid}`); + print(`non-unique task: ${taskid}`); // eslint-disable-line no-restricted-globals db.users.update({ _id: uuid, todos: { $elemMatch: { id: taskid } }, diff --git a/migrations/command-line/facebook_to_local.js b/migrations/command-line/facebook_to_local.js index 04fd254965..fb9c65d324 100644 --- a/migrations/command-line/facebook_to_local.js +++ b/migrations/command-line/facebook_to_local.js @@ -4,6 +4,7 @@ const newUser = db.users.findOne({ _id: newId }); db.users.update({ _id: oldId }, { $set: { auth: newUser.auth } }); -// remove the auth on the new user (which is a template account). The account will be preened automatically later, +// remove the auth on the new user (which is a template account). +// The account will be preened automatically later, // this allows us to keep the account around a few days in case there was a mistake db.users.update({ _id: newId }, { $unset: { auth: 1 } }); diff --git a/migrations/command-line/freeMonth.js b/migrations/command-line/freeMonth.js index 377e28b726..eccf3f7cc4 100644 --- a/migrations/command-line/freeMonth.js +++ b/migrations/command-line/freeMonth.js @@ -15,20 +15,20 @@ db.users.update( // db.users.update( // {_id:''}, // {$set:{'purchased.plan':{ -// planId: 'basic_'+m+'mo', -// paymentMethod: 'Paypal', -// customerId: 'Gift', -// dateCreated: new Date(), -// dateTerminated: moment().add('month',m).toDate(), -// dateUpdated: new Date(), -// extraMonths: 0, -// gemsBought: 0, -// mysteryItems: [], -// consecutive: { -// count: 0, -// offset: m, -// gemCapExtra: m/3*5, -// trinkets: m/3 -// } +// planId: 'basic_'+m+'mo', +// paymentMethod: 'Paypal', +// customerId: 'Gift', +// dateCreated: new Date(), +// dateTerminated: moment().add('month',m).toDate(), +// dateUpdated: new Date(), +// extraMonths: 0, +// gemsBought: 0, +// mysteryItems: [], +// consecutive: { +// count: 0, +// offset: m, +// gemCapExtra: m/3*5, +// trinkets: m/3 +// } // }}} // ) diff --git a/migrations/groups/habitrpg-jackalopes.js b/migrations/groups/habitrpg-jackalopes.js index 2eb10a7e93..e38dddaafb 100644 --- a/migrations/groups/habitrpg-jackalopes.js +++ b/migrations/groups/habitrpg-jackalopes.js @@ -1,7 +1,8 @@ /* let migrationName = 'Jackalopes for Unlimited Subscribers'; */ /* - * This migration will find users with unlimited subscriptions who are also eligible for Jackalope mounts, and award them + * This migration will find users with unlimited subscriptions who are also eligible + * for Jackalope mounts, and award them */ import { model as Group } from '../../website/server/models/group'; @@ -35,7 +36,7 @@ async function handOutJackalopes () { cursor.on('close', async () => { console.log('done'); - return await Promise.all(promises); + return Promise.all(promises); }); } diff --git a/migrations/groups/migrate-chat.js b/migrations/groups/migrate-chat.js index 8b341952cd..a2dad3b755 100644 --- a/migrations/groups/migrate-chat.js +++ b/migrations/groups/migrate-chat.js @@ -8,7 +8,7 @@ */ import { model as Group } from '../../website/server/models/group'; -import { model as Chat } from '../../website/server/models/chat'; +import { chatModel as Chat } from '../../website/server/models/message'; async function moveGroupChatToModel (skip = 0) { const groups = await Group.find({}) @@ -40,7 +40,7 @@ async function moveGroupChatToModel (skip = 0) { const reducedPromises = promises.reduce((acc, curr) => { - acc = acc.concat(curr); + acc = acc.concat(curr); // eslint-disable-line no-param-reassign return acc; }, []); diff --git a/migrations/groups/reconcile-group-plan-members.js b/migrations/groups/reconcile-group-plan-members.js index 05407ac16c..17d4e8937b 100644 --- a/migrations/groups/reconcile-group-plan-members.js +++ b/migrations/groups/reconcile-group-plan-members.js @@ -1,4 +1,4 @@ -import monk from 'monk'; +import monk from 'monk'; // eslint-disable-line import/no-extraneous-dependencies import nconf from 'nconf'; import stripePayments from '../../website/server/libs/payments/stripe'; @@ -43,7 +43,7 @@ async function fixGroupPlanMembers () { }, ).each(async (group, { close, pause, resume }) => { // eslint-disable-line no-unused-vars pause(); - groupPlanCount++; + groupPlanCount += 1; const canonicalMemberCount = await dbUsers.count( { @@ -78,7 +78,7 @@ async function fixGroupPlanMembers () { if (!groupUpdate) return; - fixedGroupCount++; + fixedGroupCount += 1; if (group.purchased.plan.paymentMethod === 'Stripe') { await stripePayments.chargeForAdditionalGroupMember(group); await dbGroups.update( diff --git a/migrations/groups/update-groups-with-group-plans.js b/migrations/groups/update-groups-with-group-plans.js index ac369609fa..2e6597edce 100644 --- a/migrations/groups/update-groups-with-group-plans.js +++ b/migrations/groups/update-groups-with-group-plans.js @@ -5,12 +5,12 @@ let authorUuid = ''; // ... own data is done */ /* - * This migrations will iterate through all groups with a group plan a subscription and resync the free - * subscription to all members + * This migrations will iterate through all groups with a group plan + * a subscription and resync the free subscription to all members */ import { model as Group } from '../../website/server/models/group'; -import * as payments from '../../website/server/libs/payments'; +import payments from '../../website/server/libs/payments/payments'; async function updateGroupsWithGroupPlans () { const cursor = Group.find({ @@ -25,7 +25,7 @@ async function updateGroupsWithGroupPlans () { promises.push(group.save()); }); - cursor.on('close', async () => await Promise.all(promises)); + cursor.on('close', async () => Promise.all(promises)); } module.exports = updateGroupsWithGroupPlans; diff --git a/migrations/migration-runner.js b/migrations/migration-runner.js index 0b502c155b..b78cfeb1f9 100644 --- a/migrations/migration-runner.js +++ b/migrations/migration-runner.js @@ -1,4 +1,4 @@ -require('babel-register'); +require('@babel/register'); // eslint-disable-line import/no-extraneous-dependencies // This file must use ES5, everything required can be in ES6 @@ -17,7 +17,7 @@ function setUpServer () { setUpServer(); // Replace this with your migration -const processUsers = require(''); +const processUsers = () => {}; // require(''); processUsers() .then(() => { diff --git a/migrations/new_stuff.js b/migrations/new_stuff.js index b367500d87..3bde550ec0 100644 --- a/migrations/new_stuff.js +++ b/migrations/new_stuff.js @@ -6,7 +6,7 @@ const authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is do * set the newStuff flag in all user accounts so they see a Bailey message */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE const dbUsers = monk(connectionString).get('users', { castIds: false }); @@ -26,7 +26,9 @@ function processUsers (lastId) { dbUsers.find(query, { sort: { _id: 1 }, limit: 250, - fields: [], // specify fields we are interested in to limit retrieved data (empty if we're not reading data): + // specify fields we are interested in to limit retrieved data + // (empty if we're not reading data): + fields: [], }) .then(updateUsers) .catch(err => { @@ -42,7 +44,7 @@ function updateUsers (users) { if (!users || users.length === 0) { console.warn('All appropriate users found and modified.'); displayData(); - return; + return null; } const userPromises = users.map(updateUser); @@ -55,7 +57,7 @@ function updateUsers (users) { } function updateUser (user) { - count++; + count += 1; const set = { 'flags.newStuff': true }; @@ -71,9 +73,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/restock_armoire.js b/migrations/restock_armoire.js index 7e6471118f..1449b54bb0 100644 --- a/migrations/restock_armoire.js +++ b/migrations/restock_armoire.js @@ -6,7 +6,7 @@ const authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is do * Remove flag stating that the Enchanted Armoire is empty, for when new equipment is added */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE const dbUsers = monk(connectionString).get('users', { castIds: false }); @@ -26,7 +26,9 @@ function processUsers (lastId) { dbUsers.find(query, { sort: { _id: 1 }, limit: 250, - fields: [], // specify fields we are interested in to limit retrieved data (empty if we're not reading data): + // specify fields we are interested in to limit retrieved data + // (empty if we're not reading data): + fields: [], }) .then(updateUsers) .catch(err => { @@ -42,7 +44,7 @@ function updateUsers (users) { if (!users || users.length === 0) { console.warn('All appropriate users found and modified.'); displayData(); - return; + return null; } const userPromises = users.map(updateUser); @@ -55,7 +57,7 @@ function updateUsers (users) { } function updateUser (user) { - count++; + count += 1; const set = { migration: migrationName, 'flags.armoireEmpty': false }; @@ -71,9 +73,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/restock_armoire_for_users_that_need_it.js b/migrations/restock_armoire_for_users_that_need_it.js index 46dbeeeea1..2fbfd3a07e 100644 --- a/migrations/restock_armoire_for_users_that_need_it.js +++ b/migrations/restock_armoire_for_users_that_need_it.js @@ -20,7 +20,7 @@ const authorUuid = '3e595299-3d8a-4a10-bfe0-88f555e4aa0c'; // ... own data is do const connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const dbUsers = monk(connectionString).get('users', { castIds: false }); @@ -47,10 +47,12 @@ function processUsers (lastId) { dbUsers.find(query, { sort: { _id: 1 }, limit: 250, + // specify fields we are interested in to limit retrieved data + // (empty if we're not reading data): fields: { 'flags.armoireEmpty': 1, 'items.gear.owned': 1, - }, // specify fields we are interested in to limit retrieved data (empty if we're not reading data): + }, }) .then(updateUsers) .catch(err => { @@ -66,7 +68,7 @@ function updateUsers (users) { if (!users || users.length === 0) { console.warn('All appropriate users found and modified.'); displayData(); - return; + return null; } const userPromises = users.map(updateUser); @@ -79,14 +81,64 @@ function updateUsers (users) { } function updateUser (user) { - count++; + count += 1; const set = { migration: migrationName, 'flags.armoireEmpty': false }; if (user.flags.armoireEmpty) { // this user believes their armoire has no more items in it - if (user.items.gear.owned.weapon_armoire_barristerGavel && user.items.gear.owned.armor_armoire_barristerRobes && user.items.gear.owned.head_armoire_jesterCap && user.items.gear.owned.armor_armoire_jesterCostume && user.items.gear.owned.head_armoire_barristerWig && user.items.gear.owned.weapon_armoire_jesterBaton && user.items.gear.owned.weapon_armoire_lunarSceptre && user.items.gear.owned.armor_armoire_gladiatorArmor && user.items.gear.owned.weapon_armoire_basicCrossbow && user.items.gear.owned.head_armoire_gladiatorHelm && user.items.gear.owned.armor_armoire_lunarArmor && user.items.gear.owned.head_armoire_redHairbow && user.items.gear.owned.head_armoire_violetFloppyHat && user.items.gear.owned.head_armoire_rancherHat && user.items.gear.owned.shield_armoire_gladiatorShield && user.items.gear.owned.head_armoire_blueHairbow && user.items.gear.owned.weapon_armoire_mythmakerSword && user.items.gear.owned.head_armoire_royalCrown && user.items.gear.owned.head_armoire_hornedIronHelm && user.items.gear.owned.weapon_armoire_rancherLasso && user.items.gear.owned.armor_armoire_rancherRobes && user.items.gear.owned.armor_armoire_hornedIronArmor && user.items.gear.owned.armor_armoire_goldenToga && user.items.gear.owned.weapon_armoire_ironCrook && user.items.gear.owned.head_armoire_goldenLaurels && user.items.gear.owned.head_armoire_redFloppyHat && user.items.gear.owned.armor_armoire_plagueDoctorOvercoat && user.items.gear.owned.head_armoire_plagueDoctorHat && user.items.gear.owned.weapon_armoire_goldWingStaff && user.items.gear.owned.head_armoire_yellowHairbow && user.items.gear.owned.eyewear_armoire_plagueDoctorMask && user.items.gear.owned.head_armoire_blackCat && user.items.gear.owned.weapon_armoire_batWand && user.items.gear.owned.head_armoire_orangeCat && user.items.gear.owned.shield_armoire_midnightShield && user.items.gear.owned.armor_armoire_royalRobes && user.items.gear.owned.head_armoire_blueFloppyHat && user.items.gear.owned.shield_armoire_royalCane && user.items.gear.owned.weapon_armoire_shepherdsCrook && user.items.gear.owned.armor_armoire_shepherdRobes && user.items.gear.owned.head_armoire_shepherdHeaddress && user.items.gear.owned.weapon_armoire_blueLongbow && user.items.gear.owned.weapon_armoire_crystalCrescentStaff && user.items.gear.owned.head_armoire_crystalCrescentHat && user.items.gear.owned.armor_armoire_dragonTamerArmor && user.items.gear.owned.head_armoire_dragonTamerHelm && user.items.gear.owned.armor_armoire_crystalCrescentRobes && user.items.gear.owned.shield_armoire_dragonTamerShield && user.items.gear.owned.weapon_armoire_glowingSpear) { + if ( + user.items.gear.owned.weapon_armoire_barristerGavel + && user.items.gear.owned.armor_armoire_barristerRobes + && user.items.gear.owned.head_armoire_jesterCap + && user.items.gear.owned.armor_armoire_jesterCostume + && user.items.gear.owned.head_armoire_barristerWig + && user.items.gear.owned.weapon_armoire_jesterBaton + && user.items.gear.owned.weapon_armoire_lunarSceptre + && user.items.gear.owned.armor_armoire_gladiatorArmor + && user.items.gear.owned.weapon_armoire_basicCrossbow + && user.items.gear.owned.head_armoire_gladiatorHelm + && user.items.gear.owned.armor_armoire_lunarArmor + && user.items.gear.owned.head_armoire_redHairbow + && user.items.gear.owned.head_armoire_violetFloppyHat + && user.items.gear.owned.head_armoire_rancherHat + && user.items.gear.owned.shield_armoire_gladiatorShield + && user.items.gear.owned.head_armoire_blueHairbow + && user.items.gear.owned.weapon_armoire_mythmakerSword + && user.items.gear.owned.head_armoire_royalCrown + && user.items.gear.owned.head_armoire_hornedIronHelm + && user.items.gear.owned.weapon_armoire_rancherLasso + && user.items.gear.owned.armor_armoire_rancherRobes + && user.items.gear.owned.armor_armoire_hornedIronArmor + && user.items.gear.owned.armor_armoire_goldenToga + && user.items.gear.owned.weapon_armoire_ironCrook + && user.items.gear.owned.head_armoire_goldenLaurels + && user.items.gear.owned.head_armoire_redFloppyHat + && user.items.gear.owned.armor_armoire_plagueDoctorOvercoat + && user.items.gear.owned.head_armoire_plagueDoctorHat + && user.items.gear.owned.weapon_armoire_goldWingStaff + && user.items.gear.owned.head_armoire_yellowHairbow + && user.items.gear.owned.eyewear_armoire_plagueDoctorMask + && user.items.gear.owned.head_armoire_blackCat + && user.items.gear.owned.weapon_armoire_batWand + && user.items.gear.owned.head_armoire_orangeCat + && user.items.gear.owned.shield_armoire_midnightShield + && user.items.gear.owned.armor_armoire_royalRobes + && user.items.gear.owned.head_armoire_blueFloppyHat + && user.items.gear.owned.shield_armoire_royalCane + && user.items.gear.owned.weapon_armoire_shepherdsCrook + && user.items.gear.owned.armor_armoire_shepherdRobes + && user.items.gear.owned.head_armoire_shepherdHeaddress + && user.items.gear.owned.weapon_armoire_blueLongbow + && user.items.gear.owned.weapon_armoire_crystalCrescentStaff + && user.items.gear.owned.head_armoire_crystalCrescentHat + && user.items.gear.owned.armor_armoire_dragonTamerArmor + && user.items.gear.owned.head_armoire_dragonTamerHelm + && user.items.gear.owned.armor_armoire_crystalCrescentRobes + && user.items.gear.owned.shield_armoire_dragonTamerShield + && user.items.gear.owned.weapon_armoire_glowingSpear + ) { // this user does have all the armoire items so we don't change the flag // console.log("don't change: " + user._id); // FOR TESTING } else { @@ -109,9 +161,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/restore-profile-data.js b/migrations/restore-profile-data.js index ae9254031b..9b3d0d438f 100644 --- a/migrations/restore-profile-data.js +++ b/migrations/restore-profile-data.js @@ -6,12 +6,12 @@ const authorUuid = ''; // ... own data is done * Check if users have empty profile data in new database and update it with old database info */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const connectionString = ''; // FOR TEST DATABASE const dbUsers = monk(connectionString).get('users', { castIds: false }); -const monk2 = require('monk'); +const monk2 = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const oldDbConnectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE const olDbUsers = monk2(oldDbConnectionString).get('users', { castIds: false }); @@ -49,7 +49,7 @@ function updateUsers (users) { if (!users || users.length === 0) { console.warn('All appropriate users found and modified.'); setTimeout(displayData, 300000); - return; + return null; } const userPaymentPromises = users.map(updateUser); @@ -60,16 +60,16 @@ function updateUsers (users) { } function updateUser (user) { - count++; + count += 1; if (!user.profile.name || user.profile.name === 'profile name not found' || !user.profile.imageUrl || !user.profile.blurb) { return olDbUsers.findOne({ _id: user._id }, '_id profile') .then(oldUserData => { - if (!oldUserData) return; + if (!oldUserData) return null; // specify user data to change: const set = {}; - if (oldUserData.profile.name === 'profile name not found') return; + if (oldUserData.profile.name === 'profile name not found') return null; const userNeedsProfileName = !user.profile.name || user.profile.name === 'profile name not found'; if (userNeedsProfileName && oldUserData.profile.name) { @@ -88,11 +88,15 @@ function updateUser (user) { console.log(set); return dbUsers.update({ _id: user._id }, { $set: set }); } + + return null; }); } if (count % progressCount === 0) console.warn(`${count} ${user._id}`); if (user._id === authorUuid) console.warn(`${authorName} processed`); + + return null; } function displayData () { @@ -101,9 +105,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/s3-upload.js b/migrations/s3-upload.js index 612da82cbc..848029b304 100644 --- a/migrations/s3-upload.js +++ b/migrations/s3-upload.js @@ -46,7 +46,7 @@ function getFileFromUrl (url) { request.get(url).end((err, res) => { if (err) return reject(err); const file = res.body; - resolve(file); + return resolve(file); }); }); } @@ -70,7 +70,7 @@ function uploadToS3 (start, end, filesUrls) { .then(buffer => uploadFile(buffer, getFileName(fullUrl)))); console.log(promises.length); - return Promise.all(promises) + Promise.all(promises) .then(() => { currentIndex += 50; uploadToS3(currentIndex, currentIndex + 50, filesUrls); diff --git a/migrations/tasks/habits-one-history-entry-per-day-challenges.js b/migrations/tasks/habits-one-history-entry-per-day-challenges.js index 410c34e44d..e7218556a7 100644 --- a/migrations/tasks/habits-one-history-entry-per-day-challenges.js +++ b/migrations/tasks/habits-one-history-entry-per-day-challenges.js @@ -3,10 +3,10 @@ // const authorUuid = 'ed4c688c-6652-4a92-9d03-a5a79844174a'; // ... own data is done /* - * Iterates over all habits and condense multiple history entries for the same day into a single entry + * Iterates over all habits and condense multiple history entries for the same day into a single one */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const _ = require('lodash'); const moment = require('moment'); @@ -44,7 +44,7 @@ function updateChallengeHabits (habits) { if (!habits || habits.length === 0) { console.warn('All appropriate challenge habits found and modified.'); displayData(); - return; + return null; } const habitsPromises = habits.map(updateChallengeHabit); @@ -55,7 +55,7 @@ function updateChallengeHabits (habits) { } function updateChallengeHabit (habit) { - count++; + count += 1; if (habit && habit.history && habit.history.length > 0) { // First remove missing entries @@ -75,8 +75,8 @@ function updateChallengeHabit (habit) { entry.scoreDirection = entry.value > previousValue ? 'up' : 'down'; } }) - .groupBy(entry => // group entries by aggregateBy - moment(entry.date).format('YYYYMMDD')) + // group entries by aggregateBy + .groupBy(entry => moment(entry.date).format('YYYYMMDD')) .toPairs() // [key, entry] .sortBy(([key]) => key) // sort by date .map(keyEntryPair => { @@ -111,6 +111,7 @@ function updateChallengeHabit (habit) { } if (count % progressCount === 0) console.warn(`${count} habits processed`); + return null; } function displayData () { @@ -119,9 +120,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/tasks/habits-one-history-entry-per-day-users.js b/migrations/tasks/habits-one-history-entry-per-day-users.js index 3405dee55a..96ec9f2b74 100644 --- a/migrations/tasks/habits-one-history-entry-per-day-users.js +++ b/migrations/tasks/habits-one-history-entry-per-day-users.js @@ -3,10 +3,10 @@ const authorName = 'paglias'; // in case script author needs to know when their const authorUuid = 'ed4c688c-6652-4a92-9d03-a5a79844174a'; // ... own data is done /* - * Iterates over all habits and condense multiple history entries for the same day into a single entry + * Iterates over all habits and condense multiple history entries for the same day into a single one */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const _ = require('lodash'); const moment = require('moment'); @@ -44,7 +44,7 @@ function updateUsers (users) { if (!users || users.length === 0) { console.warn('All appropriate users and their tasks found and modified.'); displayData(); - return; + return null; } const usersPromises = users.map(updateUser); @@ -110,10 +110,12 @@ function updateHabit (habit, timezoneOffset, dayStart) { $set: { history: habit.history }, }); } + + return null; } function updateUser (user) { - count++; + count += 1; const { timezoneOffset } = user.preferences; const { dayStart } = user.preferences; @@ -141,9 +143,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/tasks/tasks-set-everyX.js b/migrations/tasks/tasks-set-everyX.js index 899d847bf7..e700354727 100644 --- a/migrations/tasks/tasks-set-everyX.js +++ b/migrations/tasks/tasks-set-everyX.js @@ -3,10 +3,11 @@ const authorName = 'Sabe'; // in case script author needs to know when their ... const authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done /* - * Iterates over all tasks and sets invalid everyX values (less than 0 or more than 9999 or not an int) field to 0 + * Iterates over all tasks and sets invalid everyX values + * (less than 0 or more than 9999 or not an int) field to 0 */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; const dbTasks = monk(connectionString).get('tasks', { castIds: false }); @@ -49,7 +50,7 @@ function updateTasks (tasks) { if (!tasks || tasks.length === 0) { console.warn('All appropriate tasks found and modified.'); displayData(); - return; + return null; } const taskPromises = tasks.map(updatetask); @@ -60,7 +61,7 @@ function updateTasks (tasks) { } function updatetask (task) { - count++; + count += 1; const set = { everyX: 0 }; dbTasks.update({ _id: task._id }, { $set: set }); @@ -75,9 +76,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/tasks/tasks-set-yesterdailies.js b/migrations/tasks/tasks-set-yesterdailies.js index 214ac15f9f..9bc2529bb1 100644 --- a/migrations/tasks/tasks-set-yesterdailies.js +++ b/migrations/tasks/tasks-set-yesterdailies.js @@ -5,7 +5,7 @@ * Iterates over all tasks and sets the yseterDaily field to True */ -import monk from 'monk'; +import monk from 'monk'; // eslint-disable-line import/no-extraneous-dependencies const authorName = 'TheHollidayInn'; // in case script author needs to know when their ... const authorUuid = ''; @@ -17,9 +17,10 @@ const progressCount = 1000; let count = 0; function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { @@ -37,7 +38,7 @@ function displayData () { } function updatetask (task) { - count++; + count += 1; const set = { yesterDaily: true }; dbTasks.update({ _id: task._id }, { $set: set }); @@ -50,15 +51,14 @@ function updateTasks (tasks) { if (!tasks || tasks.length === 0) { console.warn('All appropriate tasks found and modified.'); displayData(); - return; + return null; } const taskPromises = tasks.map(updatetask); const lasttask = tasks[tasks.length - 1]; return Promise.all(taskPromises) - .then(() => processTasks(lasttask._id), // eslint-disable-line no-use-before-define - ); + .then(() => processTasks(lasttask._id)); // eslint-disable-line no-use-before-define } function processTasks (lastId) { @@ -76,7 +76,9 @@ function processTasks (lastId) { dbTasks.find(query, { sort: { _id: 1 }, limit: 250, - fields: [ // specify fields we are interested in to limit retrieved data (empty if we're not reading data): + // specify fields we are interested in to limit retrieved data + // (empty if we're not reading data): + fields: [ ], }) .then(updateTasks) diff --git a/migrations/users/account-transfer.js b/migrations/users/account-transfer.js index b4f1d270c8..10ee822b63 100644 --- a/migrations/users/account-transfer.js +++ b/migrations/users/account-transfer.js @@ -8,7 +8,7 @@ let authorUuid = ''; // ... own data is done * This migraition will copy user data from prod to test */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const connectionString = ''; const Users = monk(connectionString).get('users', { castIds: false }); diff --git a/migrations/users/achievement-restore.js b/migrations/users/achievement-restore.js index dfe4d9b9db..7a790a7e28 100644 --- a/migrations/users/achievement-restore.js +++ b/migrations/users/achievement-restore.js @@ -8,7 +8,7 @@ const authorUuid = ''; // ... own data is done * This migraition will copy user data from prod to test */ -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const connectionString = 'mongodb://localhost/new-habit'; const Users = monk(connectionString).get('users', { castIds: false }); @@ -26,9 +26,11 @@ function getAchievementUpdate (newUser, oldUser) { if (!achievementsUpdate.ultimateGearSets && oldAchievements.ultimateGearSets) { achievementsUpdate.ultimateGearSets = oldAchievements.ultimateGearSets; } else if (oldAchievements.ultimateGearSets) { - for (const index in oldAchievements.ultimateGearSets) { - if (oldAchievements.ultimateGearSets[index]) achievementsUpdate.ultimateGearSets[index] = true; - } + Object.keys(oldAchievements.ultimateGearSets).forEach(index => { + if (oldAchievements.ultimateGearSets[index]) { + achievementsUpdate.ultimateGearSets[index] = true; + } + }); } // challenges @@ -38,35 +40,37 @@ function getAchievementUpdate (newUser, oldUser) { // Quests if (!achievementsUpdate.quests) achievementsUpdate.quests = {}; - for (const index in oldAchievements.quests) { + Object.keys(oldAchievements.quests).forEach(index => { if (!achievementsUpdate.quests[index]) { achievementsUpdate.quests[index] = oldAchievements.quests[index]; } else { achievementsUpdate.quests[index] += oldAchievements.quests[index]; } - } + }); // Rebirth level if (achievementsUpdate.rebirthLevel) { - achievementsUpdate.rebirthLevel = Math.max(achievementsUpdate.rebirthLevel, oldAchievements.rebirthLevel); + achievementsUpdate.rebirthLevel = Math.max( + achievementsUpdate.rebirthLevel, oldAchievements.rebirthLevel, + ); } else if (oldAchievements.rebirthLevel) { achievementsUpdate.rebirthLevel = oldAchievements.rebirthLevel; } // All others const indexsToIgnore = ['ultimateGearSets', 'challenges', 'quests', 'rebirthLevel']; - for (const index in oldAchievements) { - if (indexsToIgnore.indexOf(index) !== -1) continue; // eslint-disable-line no-continue + Object.keys(oldAchievements).forEach(index => { + if (indexsToIgnore.indexOf(index) !== -1) return; if (!achievementsUpdate[index]) { achievementsUpdate[index] = oldAchievements[index]; - continue; // eslint-disable-line no-continue + return; } if (Number.isInteger(oldAchievements[index])) { achievementsUpdate[index] += oldAchievements[index]; } else if (oldAchievements[index] === true) achievementsUpdate[index] = true; - } + }); return achievementsUpdate; } @@ -75,9 +79,7 @@ module.exports = async function achievementRestore () { const userIds = [ ]; - /* eslint-disable no-await-in-loop */ - for (const index in userIds) { - const userId = userIds[index]; + Promise.all(userIds.map(userId => (async () => { const oldUser = await UsersOld.findOne({ _id: userId }, 'achievements'); const newUser = await Users.findOne({ _id: userId }, 'achievements'); const achievementUpdate = getAchievementUpdate(newUser, oldUser); @@ -90,6 +92,5 @@ module.exports = async function achievementRestore () { }, ); console.log(`Updated ${userId}`); - /* eslint-enable no-await-in-loop */ - } + })())); }; diff --git a/migrations/users/bulk-email.js b/migrations/users/bulk-email.js index 55a0bcc06c..28a25a8d55 100644 --- a/migrations/users/bulk-email.js +++ b/migrations/users/bulk-email.js @@ -12,7 +12,7 @@ const progressCount = 1000; let count = 0; async function updateUser (user) { - count++; + count += 1; if (count % progressCount === 0) console.warn(`${count} ${user._id}`); @@ -22,7 +22,7 @@ async function updateUser (user) { [{ name: 'BASE_URL', content: BASE_URL }], // Add variables from template ); - return await User.update({ _id: user._id }, { $set: { migration: MIGRATION_NAME } }).exec(); + return User.update({ _id: user._id }, { $set: { migration: MIGRATION_NAME } }).exec(); } module.exports = async function processUsers () { diff --git a/migrations/users/full-stable.js b/migrations/users/full-stable.js index 17df7002f5..ffb781b04e 100644 --- a/migrations/users/full-stable.js +++ b/migrations/users/full-stable.js @@ -15,7 +15,7 @@ let count = 0; */ async function updateUser (user) { - count++; + count += 1; const set = {}; @@ -48,7 +48,7 @@ async function updateUser (user) { if (count % progressCount === 0) console.warn(`${count} ${user._id}`); - return await User.update({ _id: user._id }, { $set: set }).exec(); + return User.update({ _id: user._id }, { $set: set }).exec(); } module.exports = async function processUsers () { diff --git a/migrations/users/mystery-items.js b/migrations/users/mystery-items.js index f0b3ad5e96..b1871663d7 100644 --- a/migrations/users/mystery-items.js +++ b/migrations/users/mystery-items.js @@ -9,7 +9,7 @@ const progressCount = 1000; let count = 0; async function updateUser (user) { - count++; + count += 1; const addToSet = { 'purchased.plan.mysteryItems': { @@ -30,7 +30,7 @@ async function updateUser (user) { if (count % progressCount === 0) console.warn(`${count} ${user._id}`); - return await User.update({ _id: user._id }, { $set: set, $push: push, $addToSet: addToSet }).exec(); + return User.update({ _id: user._id }, { $set: set, $push: push, $addToSet: addToSet }).exec(); } module.exports = async function processUsers () { diff --git a/migrations/users/pi-day.js b/migrations/users/pi-day.js index 3586194eab..a0eaae86e0 100644 --- a/migrations/users/pi-day.js +++ b/migrations/users/pi-day.js @@ -9,7 +9,7 @@ const progressCount = 1000; let count = 0; async function updateUser (user) { - count++; + count *= 1; const inc = { 'items.food.Pie_Skeleton': 1, @@ -36,7 +36,9 @@ async function updateUser (user) { if (count % progressCount === 0) console.warn(`${count} ${user._id}`); - return await User.update({ _id: user._id }, { $inc: inc, $set: set, $push: { pinnedItems: { $each: push } } }).exec(); + return User + .update({ _id: user._id }, { $inc: inc, $set: set, $push: { pinnedItems: { $each: push } } }) + .exec(); } module.exports = async function processUsers () { diff --git a/migrations/users/remove-social-users-extra-data.js b/migrations/users/remove-social-users-extra-data.js index 2e63da3d30..534fa224fa 100644 --- a/migrations/users/remove-social-users-extra-data.js +++ b/migrations/users/remove-social-users-extra-data.js @@ -7,7 +7,7 @@ const authorUuid = 'ed4c688c-6652-4a92-9d03-a5a79844174a'; // ... own data is do */ const connectionString = 'mongodb://localhost:27017/habitrpg?auto_reconnect=true'; // FOR TEST DATABASE -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const dbUsers = monk(connectionString).get('users', { castIds: false }); @@ -45,7 +45,7 @@ function updateUsers (users) { if (!users || users.length === 0) { console.warn('All appropriate users found and modified.'); displayData(); - return; + return null; } const userPromises = users.map(updateUser); @@ -58,7 +58,7 @@ function updateUsers (users) { } function updateUser (user) { - count++; + count *= 1; const isFacebook = user.auth.facebook && user.auth.facebook.id; const isGoogle = user.auth.google && user.auth.google.id; @@ -93,9 +93,10 @@ function displayData () { } function exiting (code, msg) { - code = code || 0; // 0 = success + // 0 = success + code = code || 0; // eslint-disable-line no-param-reassign if (code && !msg) { - msg = 'ERROR!'; + msg = 'ERROR!'; // eslint-disable-line no-param-reassign } if (msg) { if (code) { diff --git a/migrations/users/take-this.js b/migrations/users/take-this.js index 96a067d0be..7dbce2c6cd 100644 --- a/migrations/users/take-this.js +++ b/migrations/users/take-this.js @@ -9,7 +9,7 @@ const progressCount = 1000; let count = 0; async function updateUser (user) { - count++; + count += 1; const set = {}; let push; @@ -41,9 +41,9 @@ async function updateUser (user) { if (count % progressCount === 0) console.warn(`${count} ${user._id}`); if (push) { - return await User.update({ _id: user._id }, { $set: set, $push: push }).exec(); + return User.update({ _id: user._id }, { $set: set, $push: push }).exec(); } - return await User.update({ _id: user._id }, { $set: set }).exec(); + return User.update({ _id: user._id }, { $set: set }).exec(); } module.exports = async function processUsers () { diff --git a/migrations/users/users-to-test.js b/migrations/users/users-to-test.js index edb23e03db..91d165bcb5 100644 --- a/migrations/users/users-to-test.js +++ b/migrations/users/users-to-test.js @@ -10,7 +10,7 @@ let authorUuid = ''; // ... own data is done import uniq from 'lodash/uniq'; -const monk = require('monk'); +const monk = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const testConnectionSting = ''; // FOR TEST DATABASE const usersTest = monk(testConnectionSting).get('users', { castIds: false }); @@ -18,7 +18,7 @@ const groupsTest = monk(testConnectionSting).get('groups', { castIds: false }); const challengesTest = monk(testConnectionSting).get('challenges', { castIds: false }); const tasksTest = monk(testConnectionSting).get('tasks', { castIds: false }); -const monk2 = require('monk'); +const monk2 = require('monk'); // eslint-disable-line import/no-extraneous-dependencies const liveConnectString = ''; // FOR TEST DATABASE const userLive = monk2(liveConnectString).get('users', { castIds: false }); diff --git a/migrations/utils/connect.js b/migrations/utils/connect.js index dfdcc84c08..a49dfeace2 100644 --- a/migrations/utils/connect.js +++ b/migrations/utils/connect.js @@ -1,5 +1,4 @@ - -const { MongoClient } = require('mongodb'); +const { MongoClient } = require('mongodb'); // eslint-disable-line import/no-extraneous-dependencies const logger = require('./logger'); let dbConnection; @@ -16,7 +15,7 @@ function connectToDb (dbUri) { logger.success(`Connected to ${dbUri}`); - resolve(database); + return resolve(database); }); }); } diff --git a/migrations/utils/logger.js b/migrations/utils/logger.js index d93d78612b..36d57861c7 100644 --- a/migrations/utils/logger.js +++ b/migrations/utils/logger.js @@ -1,9 +1,10 @@ - -const chalk = require('chalk'); +const chalk = require('chalk'); // eslint-disable-line import/no-extraneous-dependencies function loggerGenerator (type, color) { return function logger () { - const args = Array.from(arguments).map(arg => chalk[color](arg)); + const args = Array + .from(arguments) // eslint-disable-line prefer-rest-params + .map(arg => chalk[color](arg)); console[type].apply(null, args); }; } diff --git a/migrations/utils/timer.js b/migrations/utils/timer.js index b378ce060e..148e2e0768 100644 --- a/migrations/utils/timer.js +++ b/migrations/utils/timer.js @@ -1,9 +1,7 @@ - const logger = require('./logger'); class Timer { - constructor (options) { - options = options || {}; + constructor (options = {}) { const warningThreshold = options.minutesWarningThreshold || 10; this.count = 0; @@ -14,7 +12,7 @@ class Timer { start () { this._internalTimer = setInterval(() => { - this.count++; + this.count *= 1; const shouldWarn = this._minutesWarningThreshold < this.count; const logStyle = shouldWarn ? 'error' : 'warn'; diff --git a/migrations/utils/unique.js b/migrations/utils/unique.js index df9052e698..346c61404b 100644 --- a/migrations/utils/unique.js +++ b/migrations/utils/unique.js @@ -1,4 +1,3 @@ - function unique (array) { return Array.from(new Set(array)); } diff --git a/package.json b/package.json index bdb0af63a1..29125158e5 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "npm": "^6" }, "scripts": { - "lint": "eslint --ext .js ./website/common --fix", + "lint": "eslint --ext .js ./migrations --fix", "test": "npm run lint && gulp test && gulp apidoc", "test:build": "gulp test:prepare:build", "test:api-v3": "gulp test:api-v3", diff --git a/test/.eslintrc b/test/.eslintrc index 465e06424b..10397df6d7 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,11 +1,7 @@ { "extends": [ - "habitrpg/mocha", - "habitrpg/esnext" + "habitrpg/lib/mocha", ], - "env": { - "node": true, - }, "globals": { "_": true, } diff --git a/test/client/.eslintrc b/test/client/.eslintrc deleted file mode 100644 index e2df933c00..0000000000 --- a/test/client/.eslintrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "env": { - "node": true, - "browser": true, - }, - "extends": [ - "habitrpg/browser", - "habitrpg/mocha", - "habitrpg/esnext", - ], -}