Upgrade lodash to v4 and lint more files (#8495)

* common: import lodash modules separately

* remove test/content from .eslintignore, fix with eslint --fix content/index

* lint test/content

* lint content/index except for lodash methods

* upgrade server/models

* upgrade server/middlewares and server/libs

* port server/controllers/top-level

* port server/controllers/api-v3

* port views and tests

* client old port lodash and _(, missing _.

* upgrade client-old

* port common/script (root level files only)

* port common/script/fns

* port common/libs

* port common/script/ops

* port common/script/content and common/script/libs/shops.js

* misc fixes

* misc fixes

* misc fixes

* more tests fixes

* fix payments test stubbing, down to 2 failing tests

* remove more instances of lodash wrapping

* fix bug where toObject does not clone object

* fix tests

* upgrade migration or add lodash 4 note

* update shrinkwrap

* fix linting

* upgrade eslint-config-habitrpg

* update shrinkwrap

* recompile shrinkwrap
This commit is contained in:
Matteo Pagliazzi
2017-03-01 17:10:48 +01:00
committed by GitHub
parent ef02e59590
commit 98c019a0b6
150 changed files with 4996 additions and 1533 deletions

View File

@@ -1,4 +1,4 @@
import { each } from 'lodash';
import each from 'lodash/each';
let achievementsData = {};

View File

@@ -1,4 +1,4 @@
import {forOwn} from 'lodash';
import forOwn from 'lodash/forOwn';
import t from '../translation';
/* eslint-disable camelcase */

View File

@@ -4,7 +4,8 @@ import skins from './skin.js';
import sizes from './size.js';
import backgrounds from './backgrounds.js';
import chairs from './chair.js';
import {forOwn, clone} from 'lodash';
import forOwn from 'lodash/forOwn';
import clone from 'lodash/clone';
let reorderedBgs = {};

View File

@@ -1,4 +1,4 @@
import {forOwn} from 'lodash';
import forOwn from 'lodash/forOwn';
module.exports = function prefillAppearances (obj) {
forOwn(obj, function prefillAppearance (value, key) {

View File

@@ -1,8 +1,6 @@
import {
assign,
defaults,
each,
} from 'lodash';
import assign from 'lodash/assign';
import defaults from 'lodash/defaults';
import each from 'lodash/each';
import t from './translation';
function applyEggDefaults (set, config) {

View File

@@ -1,4 +1,4 @@
import { isBoolean } from 'lodash';
import isBoolean from 'lodash/isBoolean';
export function ownsItem (item) {
return (user) => {

View File

@@ -1,4 +1,5 @@
import {each, defaults} from 'lodash';
import each from 'lodash/each';
import defaults from 'lodash/defaults';
import moment from 'moment';
import {

View File

@@ -1,4 +1,4 @@
import {cloneDeep} from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import {shield as baseShield} from './sets/base';

View File

@@ -1,8 +1,6 @@
import {
assign,
defaults,
each,
} from 'lodash';
import assign from 'lodash/assign';
import defaults from 'lodash/defaults';
import each from 'lodash/each';
import t from './translation';
let drops = {

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,8 @@
import _ from 'lodash';
import range from 'lodash/range';
import { MAX_INCENTIVES } from '../constants';
// NOTE do not import this file alone but only access it through common.content
// so that it's already compiled
module.exports = function getLoginIncentives (api) {
let loginIncentives = {
1: {
@@ -228,7 +230,7 @@ module.exports = function getLoginIncentives (api) {
// We could also, use a list, but then we would be cloning each of the rewards.
// Create a new array if we want the loginIncentives to be immutable in the future
let nextRewardKey;
_.range(MAX_INCENTIVES + 1).reverse().forEach(function addNextRewardLink (index) {
range(MAX_INCENTIVES + 1).reverse().forEach(function addNextRewardLink (index) {
if (loginIncentives[index] && loginIncentives[index].rewardKey) {
loginIncentives[index].nextRewardAt = nextRewardKey;
nextRewardKey = index;
@@ -242,7 +244,7 @@ module.exports = function getLoginIncentives (api) {
});
let prevRewardKey;
_.range(MAX_INCENTIVES + 1).forEach(function addPrevRewardLink (index) {
range(MAX_INCENTIVES + 1).forEach(function addPrevRewardLink (index) {
loginIncentives[index].prevRewardKey = prevRewardKey;
if (loginIncentives[index].rewardKey) prevRewardKey = index;
});

View File

@@ -1,4 +1,4 @@
import { each } from 'lodash';
import each from 'lodash/each';
import t from './translation';
let mysterySets = {

View File

@@ -1,5 +1,5 @@
import t from './translation';
import _ from 'lodash';
import each from 'lodash/each';
import { NotAuthorized } from '../libs/errors';
/*
---------------------------------------------------------------
@@ -56,7 +56,7 @@ spells.wizard = {
target: 'party',
notes: t('spellWizardMPHealNotes'),
cast (user, target) {
_.each(target, (member) => {
each(target, (member) => {
let bonus = user._statsComputed.int;
if (user._id !== member._id) {
member.stats.mp += Math.ceil(diminishingReturns(bonus, 25, 125));
@@ -71,7 +71,7 @@ spells.wizard = {
target: 'party',
notes: t('spellWizardEarthNotes'),
cast (user, target) {
_.each(target, (member) => {
each(target, (member) => {
let bonus = user._statsComputed.int - user.stats.buffs.int;
if (!member.stats.buffs.int) member.stats.buffs.int = 0;
member.stats.buffs.int += Math.ceil(diminishingReturns(bonus, 30, 200));
@@ -123,7 +123,7 @@ spells.warrior = {
target: 'party',
notes: t('spellWarriorValorousPresenceNotes'),
cast (user, target) {
_.each(target, (member) => {
each(target, (member) => {
let bonus = user._statsComputed.str - user.stats.buffs.str;
if (!member.stats.buffs.str) member.stats.buffs.str = 0;
member.stats.buffs.str += Math.ceil(diminishingReturns(bonus, 20, 200));
@@ -137,7 +137,7 @@ spells.warrior = {
target: 'party',
notes: t('spellWarriorIntimidateNotes'),
cast (user, target) {
_.each(target, (member) => {
each(target, (member) => {
let bonus = user._statsComputed.con - user.stats.buffs.con;
if (!member.stats.buffs.con) member.stats.buffs.con = 0;
member.stats.buffs.con += Math.ceil(diminishingReturns(bonus, 24, 200));
@@ -179,7 +179,7 @@ spells.rogue = {
target: 'party',
notes: t('spellRogueToolsOfTradeNotes'),
cast (user, target) {
_.each(target, (member) => {
each(target, (member) => {
let bonus = user._statsComputed.per - user.stats.buffs.per;
if (!member.stats.buffs.per) member.stats.buffs.per = 0;
member.stats.buffs.per += Math.ceil(diminishingReturns(bonus, 100, 50));
@@ -218,7 +218,7 @@ spells.healer = {
target: 'tasks',
notes: t('spellHealerBrightnessNotes'),
cast (user, tasks) {
_.each(tasks, (task) => {
each(tasks, (task) => {
if (task.type !== 'reward') {
task.value += 4 * (user._statsComputed.int / (user._statsComputed.int + 40));
}
@@ -232,7 +232,7 @@ spells.healer = {
target: 'party',
notes: t('spellHealerProtectAuraNotes'),
cast (user, target) {
_.each(target, (member) => {
each(target, (member) => {
let bonus = user._statsComputed.con - user.stats.buffs.con;
if (!member.stats.buffs.con) member.stats.buffs.con = 0;
member.stats.buffs.con += Math.ceil(diminishingReturns(bonus, 200, 200));
@@ -246,7 +246,7 @@ spells.healer = {
target: 'party',
notes: t('spellHealerHealAllNotes'),
cast (user, target) {
_.each(target, (member) => {
each(target, (member) => {
member.stats.hp += (user._statsComputed.con + user._statsComputed.int + 5) * 0.04;
if (member.stats.hp > 50) member.stats.hp = 50;
});
@@ -388,7 +388,7 @@ spells.special = {
if (!user.achievements.nye) user.achievements.nye = 0;
user.achievements.nye++;
} else {
_.each([user, target], (u) => {
each([user, target], (u) => {
if (!u.achievements.nye) u.achievements.nye = 0;
u.achievements.nye++;
});
@@ -416,7 +416,7 @@ spells.special = {
if (!user.achievements.valentine) user.achievements.valentine = 0;
user.achievements.valentine++;
} else {
_.each([user, target], (u) => {
each([user, target], (u) => {
if (!u.achievements.valentine) u.achievements.valentine = 0;
u.achievements.valentine++;
});
@@ -443,7 +443,7 @@ spells.special = {
if (user === target) {
user.achievements.greeting++;
} else {
_.each([user, target], (u) => {
each([user, target], (u) => {
if (!u.achievements.greeting) u.achievements.greeting = 0;
u.achievements.greeting++;
});
@@ -471,7 +471,7 @@ spells.special = {
if (!user.achievements.thankyou) user.achievements.thankyou = 0;
user.achievements.thankyou++;
} else {
_.each([user, target], (u) => {
each([user, target], (u) => {
if (!u.achievements.thankyou) u.achievements.thankyou = 0;
u.achievements.thankyou++;
});
@@ -499,7 +499,7 @@ spells.special = {
if (!user.achievements.birthday) user.achievements.birthday = 0;
user.achievements.birthday++;
} else {
_.each([user, target], (u) => {
each([user, target], (u) => {
if (!u.achievements.birthday) u.achievements.birthday = 0;
u.achievements.birthday++;
});
@@ -516,8 +516,8 @@ spells.special = {
},
};
_.each(spells, (spellClass) => {
_.each(spellClass, (spell, key) => {
each(spells, (spellClass) => {
each(spellClass, (spell, key) => {
spell.key = key;
let _cast = spell.cast;
spell.cast = function castSpell (user, target, req) {

View File

@@ -1,6 +1,4 @@
import {
each,
} from 'lodash';
import each from 'lodash/each';
import {
drops as dropEggs,
quests as questEggs,

View File

@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import _ from 'lodash';
import each from 'lodash/each';
let subscriptionBlocks = {
basic_earned: {
@@ -32,7 +32,7 @@ let subscriptionBlocks = {
},
};
_.each(subscriptionBlocks, function createKeys (b, k) {
each(subscriptionBlocks, function createKeys (b, k) {
return b.key = k;
});

View File

@@ -1,11 +1,16 @@
import _ from 'lodash';
import each from 'lodash/each';
import filter from 'lodash/filter';
import keys from 'lodash/keys';
import union from 'lodash/union';
import reduce from 'lodash/reduce';
import mysterySets from './mystery-sets';
import gear from './gear';
let mystery = mysterySets;
_.each(mystery, (v, k) => {
return v.items = _.where(gear.flat, {
each(mystery, (v, k) => {
return v.items = filter(gear.flat, {
mystery: k,
});
});
@@ -13,10 +18,11 @@ _.each(mystery, (v, k) => {
let timeTravelerStore = (user) => {
let ownedKeys;
let owned = user.items.gear.owned;
let unopenedGifts = user.purchased.plan.mysteryItems;
ownedKeys = _.keys((typeof owned.toObject === 'function' ? owned.toObject() : undefined) || owned);
ownedKeys = _.union(ownedKeys, unopenedGifts);
return _.reduce(mystery, (m, v, k) => {
let mysteryItems = user.purchased.plan.mysteryItems;
let unopenedGifts = typeof mysteryItems.toObject === 'function' ? mysteryItems.toObject() : mysteryItems;
ownedKeys = keys(typeof owned.toObject === 'function' ? owned.toObject() : owned);
ownedKeys = union(ownedKeys, unopenedGifts);
return reduce(mystery, (m, v, k) => {
if (k === 'wondercon' || ownedKeys.indexOf(v.items[0].key) !== -1) {
return m;
}