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

chore: replace _.forOwn with Object.entries().forEach #8284

Merged
merged 1 commit into from Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 29 additions & 23 deletions lib/classes/PluginManager.js
Expand Up @@ -362,17 +362,21 @@ class PluginManager {
const currentCommands = stack.pop();
const commands = currentCommands.commands;
const target = currentCommands.target;
_.forOwn(commands, (command, name) => {
if (command.type !== 'entrypoint') {
_.set(target, name, _.omit(command, 'commands'));
if (
Object.values(command.commands).some(childCommand => childCommand.type !== 'entrypoint')
) {
target[name].commands = {};
stack.push({ commands: command.commands, target: target[name].commands });
if (commands) {
Object.entries(commands).forEach(([name, command]) => {
if (command.type !== 'entrypoint') {
_.set(target, name, _.omit(command, 'commands'));
if (
Object.values(command.commands).some(
childCommand => childCommand.type !== 'entrypoint'
)
) {
target[name].commands = {};
stack.push({ commands: command.commands, target: target[name].commands });
}
}
}
});
});
}
}
// Iterate through the existing aliases and add them as commands
_.remove(stack);
Expand All @@ -381,19 +385,21 @@ class PluginManager {
const currentAlias = stack.pop();
const aliases = currentAlias.aliases;
const target = currentAlias.target;
_.forOwn(aliases, (alias, name) => {
if (name === 'command') {
return;
}
if (alias.command) {
const commandPath = alias.command.split(':').join('.commands.');
_.set(target, name, _.get(this.commands, commandPath));
} else {
target[name] = target[name] || {};
target[name].commands = target[name].commands || {};
}
stack.push({ aliases: alias, target: target[name].commands });
});
if (aliases) {
Object.entries(aliases).forEach(([name, alias]) => {
if (name === 'command') {
return;
}
if (alias.command) {
const commandPath = alias.command.split(':').join('.commands.');
_.set(target, name, _.get(this.commands, commandPath));
} else {
target[name] = target[name] || {};
target[name].commands = target[name].commands || {};
}
stack.push({ aliases: alias, target: target[name].commands });
});
}
}
return result;
}
Expand Down
36 changes: 19 additions & 17 deletions lib/plugins/aws/utils/findReferences.js
Expand Up @@ -18,24 +18,26 @@ function findReferences(root, value) {
while (stack.length) {
const property = stack.pop();

_.forOwn(property.propValue, (propValue, key) => {
let propKey;
if (Array.isArray(property.propValue)) {
propKey = `[${key}]`;
} else {
propKey = !property.path ? `${key}` : `.${key}`;
}
if (propValue === value) {
resourcePaths.push(`${property.path}${propKey}`);
} else if (_.isObject(propValue)) {
// Prevent circular references
if (visitedObjects.includes(propValue)) {
return;
if (property.propValue) {
Object.entries(property.propValue).forEach(([key, propValue]) => {
let propKey;
if (Array.isArray(property.propValue)) {
propKey = `[${key}]`;
} else {
propKey = !property.path ? `${key}` : `.${key}`;
}
visitedObjects.push(propValue);
stack.push({ propValue, path: `${property.path}${propKey}` });
}
});
if (propValue === value) {
resourcePaths.push(`${property.path}${propKey}`);
} else if (_.isObject(propValue)) {
// Prevent circular references
if (visitedObjects.includes(propValue)) {
return;
}
visitedObjects.push(propValue);
stack.push({ propValue, path: `${property.path}${propKey}` });
}
});
}
}

return resourcePaths;
Expand Down