mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
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:
@@ -1,5 +1,11 @@
|
||||
import _ from 'lodash';
|
||||
import pickBy from 'lodash.pickby'; // Not available in lodash 3
|
||||
import values from 'lodash/values';
|
||||
import map from 'lodash/map';
|
||||
import keys from 'lodash/keys';
|
||||
import each from 'lodash/each';
|
||||
import eachRight from 'lodash/eachRight';
|
||||
import toArray from 'lodash/toArray';
|
||||
import pickBy from 'lodash/pickBy';
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
|
||||
@@ -22,10 +28,9 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
notes: i18n.t('dropsExplanation', language),
|
||||
};
|
||||
|
||||
eggsCategory.items = _(content.questEggs)
|
||||
.values()
|
||||
eggsCategory.items = sortBy(values(content.questEggs)
|
||||
.filter(egg => egg.canBuy(user))
|
||||
.concat(_.values(content.dropEggs))
|
||||
.concat(values(content.dropEggs))
|
||||
.map(egg => {
|
||||
return {
|
||||
key: egg.key,
|
||||
@@ -37,7 +42,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
currency: 'gems',
|
||||
purchaseType: 'eggs',
|
||||
};
|
||||
}).sortBy('key').value();
|
||||
}), 'key');
|
||||
categories.push(eggsCategory);
|
||||
|
||||
let hatchingPotionsCategory = {
|
||||
@@ -45,8 +50,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
text: i18n.t('hatchingPotions', language),
|
||||
notes: i18n.t('dropsExplanation', language),
|
||||
};
|
||||
hatchingPotionsCategory.items = _(content.hatchingPotions)
|
||||
.values()
|
||||
hatchingPotionsCategory.items = sortBy(values(content.hatchingPotions)
|
||||
.filter(hp => !hp.limited)
|
||||
.map(hatchingPotion => {
|
||||
return {
|
||||
@@ -59,7 +63,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
currency: 'gems',
|
||||
purchaseType: 'hatchingPotions',
|
||||
};
|
||||
}).sortBy('key').value();
|
||||
}), 'key');
|
||||
categories.push(hatchingPotionsCategory);
|
||||
|
||||
let premiumHatchingPotionsCategory = {
|
||||
@@ -67,8 +71,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
text: i18n.t('magicHatchingPotions', language),
|
||||
notes: i18n.t('premiumPotionNoDropExplanation', language),
|
||||
};
|
||||
premiumHatchingPotionsCategory.items = _(content.hatchingPotions)
|
||||
.values()
|
||||
premiumHatchingPotionsCategory.items = sortBy(values(content.hatchingPotions)
|
||||
.filter(hp => hp.limited && hp.canBuy())
|
||||
.map(premiumHatchingPotion => {
|
||||
return {
|
||||
@@ -81,7 +84,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
currency: 'gems',
|
||||
purchaseType: 'hatchingPotions',
|
||||
};
|
||||
}).sortBy('key').value();
|
||||
}), 'key');
|
||||
categories.push(premiumHatchingPotionsCategory);
|
||||
|
||||
let foodCategory = {
|
||||
@@ -89,8 +92,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
text: i18n.t('food', language),
|
||||
notes: i18n.t('dropsExplanation', language),
|
||||
};
|
||||
foodCategory.items = _(content.food)
|
||||
.values()
|
||||
foodCategory.items = sortBy(values(content.food)
|
||||
.filter(food => food.canDrop || food.key === 'Saddle')
|
||||
.map(foodItem => {
|
||||
return {
|
||||
@@ -103,7 +105,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
currency: 'gems',
|
||||
purchaseType: 'food',
|
||||
};
|
||||
}).sortBy('key').value();
|
||||
}), 'key');
|
||||
categories.push(foodCategory);
|
||||
|
||||
return categories;
|
||||
@@ -112,13 +114,13 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
shops.getQuestShopCategories = function getQuestShopCategories (user, language) {
|
||||
let categories = [];
|
||||
|
||||
_.each(content.userCanOwnQuestCategories, type => {
|
||||
each(content.userCanOwnQuestCategories, type => {
|
||||
let category = {
|
||||
identifier: type,
|
||||
text: i18n.t(`${type}Quests`, language),
|
||||
};
|
||||
|
||||
category.items = _(content.questsByLevel)
|
||||
category.items = content.questsByLevel
|
||||
.filter(quest => quest.canBuy(user) && quest.category === type)
|
||||
.map(quest => {
|
||||
let locked = lockQuest(quest, user);
|
||||
@@ -137,7 +139,7 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language)
|
||||
class: locked ? `inventory_quest_scroll_locked inventory_quest_scroll_${quest.key}_locked` : `inventory_quest_scroll inventory_quest_scroll_${quest.key}`,
|
||||
purchaseType: 'quests',
|
||||
};
|
||||
}).value();
|
||||
});
|
||||
|
||||
categories.push(category);
|
||||
});
|
||||
@@ -190,7 +192,7 @@ shops.getTimeTravelersCategories = function getTimeTravelersCategories (user, la
|
||||
purchaseAll: true,
|
||||
};
|
||||
|
||||
category.items = _.map(set.items, item => {
|
||||
category.items = map(set.items, item => {
|
||||
return {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
@@ -228,19 +230,19 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
|
||||
let categories = [];
|
||||
|
||||
let flatGearArray = _.toArray(content.gear.flat);
|
||||
let flatGearArray = toArray(content.gear.flat);
|
||||
|
||||
let spells = pickBy(content.spells.special, (spell, key) => {
|
||||
return _.indexOf(AVAILABLE_SPELLS, key) !== -1;
|
||||
return AVAILABLE_SPELLS.indexOf(key) !== -1;
|
||||
});
|
||||
|
||||
if (_.keys(spells).length > 0) {
|
||||
if (keys(spells).length > 0) {
|
||||
let category = {
|
||||
identifier: 'spells',
|
||||
text: i18n.t('seasonalItems', language),
|
||||
};
|
||||
|
||||
category.items = _.map(spells, (spell, key) => {
|
||||
category.items = map(spells, (spell, key) => {
|
||||
return {
|
||||
key,
|
||||
text: spell.text(language),
|
||||
@@ -258,16 +260,16 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
}
|
||||
|
||||
let quests = pickBy(content.quests, (quest, key) => {
|
||||
return _.indexOf(AVAILABLE_QUESTS, key) !== -1;
|
||||
return AVAILABLE_QUESTS.indexOf(key) !== -1;
|
||||
});
|
||||
|
||||
if (_.keys(quests).length > 0) {
|
||||
if (keys(quests).length > 0) {
|
||||
let category = {
|
||||
identifier: 'quests',
|
||||
text: i18n.t('quests', language),
|
||||
};
|
||||
|
||||
category.items = _.map(quests, (quest, key) => {
|
||||
category.items = map(quests, (quest, key) => {
|
||||
return {
|
||||
key,
|
||||
text: quest.text(language),
|
||||
@@ -294,12 +296,9 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
text: AVAILABLE_SETS[key],
|
||||
};
|
||||
|
||||
category.items = _(flatGearArray).filter((gear) => {
|
||||
if (gear.index !== key) {
|
||||
return false;
|
||||
}
|
||||
return user.items.gear.owned[gear.key] === undefined;
|
||||
}).where({index: key}).map(gear => {
|
||||
category.items = flatGearArray.filter((gear) => {
|
||||
return user.items.gear.owned[gear.key] === undefined && gear.index === key;
|
||||
}).map(gear => {
|
||||
return {
|
||||
key: gear.key,
|
||||
text: gear.text(language),
|
||||
@@ -312,7 +311,8 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
purchaseType: 'gear',
|
||||
class: `shop_${gear.key}`,
|
||||
};
|
||||
}).value();
|
||||
});
|
||||
|
||||
if (category.items.length > 0) {
|
||||
categories.push(category);
|
||||
}
|
||||
@@ -325,23 +325,22 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
shops.getBackgroundShopSets = function getBackgroundShopSets (language) {
|
||||
let sets = [];
|
||||
|
||||
_.eachRight(content.backgrounds, (group, key) => {
|
||||
eachRight(content.backgrounds, (group, key) => {
|
||||
let set = {
|
||||
identifier: key,
|
||||
text: i18n.t(key, language),
|
||||
};
|
||||
|
||||
set.items = _(group)
|
||||
.map((background, bgKey) => {
|
||||
return {
|
||||
key: bgKey,
|
||||
text: background.text(language),
|
||||
notes: background.notes(language),
|
||||
value: background.price,
|
||||
currency: background.currency || 'gems',
|
||||
purchaseType: 'backgrounds',
|
||||
};
|
||||
}).value();
|
||||
set.items = map(group, (background, bgKey) => {
|
||||
return {
|
||||
key: bgKey,
|
||||
text: background.text(language),
|
||||
notes: background.notes(language),
|
||||
value: background.price,
|
||||
currency: background.currency || 'gems',
|
||||
purchaseType: 'backgrounds',
|
||||
};
|
||||
});
|
||||
|
||||
sets.push(set);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user