Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

More consistent Usage of ES6+ Code #5056

Merged
merged 13 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/modules/core/helpers/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ export function Apps(optionHash) {
// Check that shopType matches showForShopType if option is present
if (item.showForShopTypes &&
Array.isArray(item.showForShopTypes) &&
item.showForShopTypes.indexOf(shopType) === -1) {
!item.showForShopTypes.includes(shopType)) {
return false;
}

// Check that shopType does not match hideForShopType if option is present
if (item.hideForShopTypes &&
Array.isArray(item.hideForShopTypes) &&
item.hideForShopTypes.indexOf(shopType) !== -1) {
item.hideForShopTypes.includes(shopType)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ export default function hasPermission(user, permissions, roleGroup) {
const checkRoles = permissions.slice(0);

// This should always return true for owners
if (checkRoles.indexOf("owner") === -1) checkRoles.push("owner");
if (!checkRoles.includes("owner")) checkRoles.push("owner");

const { roles } = user;

// always check GLOBAL_GROUP
const globalRoles = roles[GLOBAL_GROUP];
if (Array.isArray(globalRoles) && checkRoles.some((role) => globalRoles.indexOf(role) !== -1)) return true;
if (Array.isArray(globalRoles) && checkRoles.some((role) => globalRoles.includes(role))) return true;

if (roleGroup) {
// convert any periods to underscores for MongoDB compatibility
const group = roleGroup.replace(/\./g, "_");

const groupRoles = roles[group];
if (Array.isArray(groupRoles) && checkRoles.some((role) => groupRoles.indexOf(role) !== -1)) return true;
if (Array.isArray(groupRoles) && checkRoles.some((role) => groupRoles.includes(role))) return true;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function viewer(_, __, context, info) {

// Classic Meteor UI creates dummy accounts for "anonymous" user. We should ignore those.
const user = await context.collections.users.findOne({ _id: context.userId });
if (!user || !user.roles || !Array.isArray(user.roles[Object.keys(user.roles)[0]]) || user.roles[Object.keys(user.roles)[0]].indexOf("anonymous") !== -1) {
if (!user || !user.roles || !Array.isArray(user.roles[Object.keys(user.roles)[0]]) || user.roles[Object.keys(user.roles)[0]].includes("anonymous")) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default async function reconcileCarts(context, input) {
// Don't use `userHasPermission` for this check because that always returns true if there
// is "owner" role. We want to know explicitly whether they have the "anonymous" role.
const roles = (user.roles && user.roles[shopId]) || [];
if (roles.indexOf("anonymous") !== -1) {
if (roles.includes("anonymous")) {
Logger.warn("reconcileCarts called by an anonymous user. Check client code.");
throw new ReactionError("access-denied", "Access Denied");
}
Expand Down
2 changes: 1 addition & 1 deletion imports/plugins/core/core/server/Reaction/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ export default {
}

if (enabledPackages && Array.isArray(enabledPackages)) {
if (enabledPackages.indexOf(pkg.name) === -1) {
if (!enabledPackages.includes(pkg.name)) {
pkg.enabled = false;
} else if (pkg.settings && pkg.settings[packageName]) { // Enable "soft switch" for package.
pkg.settings[packageName].enabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Template.coreOrderShippingTracking.helpers({

const orderItems = order.shipping.reduce((list, group) => [...list, ...group.items], []);
return orderItems.every((item) => {
if (fulfillment.itemIds.indexOf(item._id) === -1) {
if (!fulfillment.itemIds.includes(item._id)) {
// The item is not in this shipment so we don't care
return true;
}
Expand All @@ -147,7 +147,7 @@ Template.coreOrderShippingTracking.helpers({

const orderItems = order.shipping.reduce((list, group) => [...list, ...group.items], []);
return orderItems.every((item) => {
if (fulfillment.itemIds.indexOf(item._id) === -1) {
if (!fulfillment.itemIds.includes(item._id)) {
// The item is not in this shipment so we don't care
return true;
}
Expand All @@ -164,7 +164,7 @@ Template.coreOrderShippingTracking.helpers({

const orderItems = order.shipping.reduce((list, group) => [...list, ...group.items], []);
return orderItems.every((item) => {
if (fulfillment.itemIds.indexOf(item._id) === -1) {
if (!fulfillment.itemIds.includes(item._id)) {
// The item is not in this shipment so we don't care
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/shipping/server/no-meteor/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ReactionError from "@reactioncommerce/reaction-error";
* @returns {Object|null} The group or null if no viable group
*/
function determineInitialGroupForItem(currentGroups, supportedFulfillmentTypes, shopId) {
const compatibleGroup = currentGroups.find((group) => supportedFulfillmentTypes.indexOf(group.type) !== -1 &&
const compatibleGroup = currentGroups.find((group) => supportedFulfillmentTypes.includes(group.type) &&
shopId === group.shopId);
return compatibleGroup || null;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function startup({ appEvents, collections }) {
// If there is a compatible group but it has no items array, add one with just this item in it
didModifyGroups = true;
group.itemIds = [item._id];
} else if (group.itemIds.indexOf(item._id) === -1) {
} else if (!group.itemIds.includes(item._id)) {
// If there is a compatible group with an items array but it is missing this item, add this item ID to the array
didModifyGroups = true;
group.itemIds.push(item._id);
Expand Down
2 changes: 1 addition & 1 deletion lib/api/account-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const validationMethods = {
// Valid
if (optional === true && processedEmail.length === 0) {
return true;
} else if (processedEmail.indexOf("@") !== -1) {
} else if (processedEmail.includes("@")) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ ReactionProduct.getProductsByTag = function (tag) {
while (relatedTags.length) {
newRelatedTags = [];
for (relatedTag of relatedTags) {
if (hashtags.indexOf(relatedTag._id) === -1) {
if (!hashtags.includes(relatedTag._id)) {
hashtags.push(relatedTag._id);
}
}
Expand Down