Skip to content

Commit

Permalink
Bump xo to 0.38.1 and move to devDependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 22, 2021
1 parent 3b0c91f commit 3f51315
Show file tree
Hide file tree
Showing 12 changed files with 11,017 additions and 8,272 deletions.
6 changes: 5 additions & 1 deletion .xo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"unicorn/no-fn-reference-in-iterator": "off",
"prefer-spread": "off",
"default-param-last": "off",
"unicorn/explicit-length-check": "off"
"unicorn/explicit-length-check": "off",
"unicorn/no-this-assignment": "off",
"unicorn/no-array-for-each": "off",
"unicorn/no-array-callback-reference": "off"

}
}

2 changes: 1 addition & 1 deletion lib/actions/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fs.renderTemplates = function (templates, templateData = this._templateData()) {
);
};

templates.forEach((template) => renderEachTemplate(template));
for (const template of templates) renderEachTemplate(template);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/actions/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ help.help = function () {

// Build options
if (Object.keys(this._options).length > 0) {
out = out.concat(['Options:', this.optionsHelp(), '']);
out = [...out, 'Options:', this.optionsHelp(), ''];
}

// Build arguments
if (this._arguments.length > 0) {
out = out.concat(['Arguments:', this.argumentsHelp(), '']);
out = [...out, 'Arguments:', this.argumentsHelp(), ''];
}

// Append USAGE file is any
Expand Down
5 changes: 4 additions & 1 deletion lib/actions/install.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
/* eslint-disable unicorn/prefer-spread */
const assert = require('assert');
const _ = require('lodash');
const dargs = require('dargs');
Expand Down Expand Up @@ -43,7 +44,7 @@ install.scheduleInstallTask = function (

// Only for npm, use a minimum cache of one day
if (installer === 'npm') {
args = args.concat(['--cache-min', 24 * 60 * 60]);
args = [...args, '--cache-min', 24 * 60 * 60];
}

// Return early if we're skipping installation
Expand Down Expand Up @@ -220,3 +221,5 @@ install.npmInstall = function (pkgs, options, spawnOptions) {
install.yarnInstall = function (pkgs, options, spawnOptions) {
this.scheduleInstallTask('yarn', pkgs, options, spawnOptions);
};

/* eslint-enable unicorn/prefer-spread */
58 changes: 26 additions & 32 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ENV_VER_WITH_VER_API = '2.9.0';

const mixins = [require('./actions/package-json')];

// eslint-disable-next-line unicorn/no-reduce
// eslint-disable-next-line unicorn/no-array-reduce
const Base = mixins.reduce((a, b) => b(a), EventEmitter);

// Ensure a prototype method is a candidate run by default
Expand Down Expand Up @@ -249,9 +249,9 @@ class Generator extends Base {
this._queues = {};

// Add original queues.
Generator.queues.forEach((queue) => {
for (const queue of Generator.queues) {
this._queues[queue] = {priorityName: queue, queueName: queue};
});
}

// Add custom queues
if (Array.isArray(this.options.customPriorities)) {
Expand Down Expand Up @@ -337,22 +337,22 @@ class Generator extends Base {
});

// Add queue to runLoop
customPriorities.forEach((customQueue) => {
for (const customQueue of customPriorities) {
customQueue.queueName =
customQueue.queueName ||
`${this.options.namespace}#${customQueue.priorityName}`;
debug(`Registering custom queue ${customQueue.queueName}`);
this._queues[customQueue.priorityName] = customQueue;

if (this.env.runLoop.queueNames.includes(customQueue.queueName)) {
return;
continue;
}

const beforeQueue = customQueue.before
? this._queues[customQueue.before].queueName
: undefined;
this.env.runLoop.addSubQueue(customQueue.queueName, beforeQueue);
});
}
}

checkEnvironmentVersion(packageDependency, version) {
Expand Down Expand Up @@ -433,7 +433,7 @@ class Generator extends Base {
return String;
};

questions.forEach((q) => {
for (const q of questions) {
const question = {...q};
if (q.exportOption) {
const option =
Expand All @@ -448,7 +448,7 @@ class Generator extends Base {
}

this._prompts.push(question);
});
}
}

/**
Expand Down Expand Up @@ -507,11 +507,11 @@ class Generator extends Base {
}

// Shows the prompt even if the answer already exists.
questions.forEach((question) => {
for (const question of questions) {
if (question.askAnswered === undefined) {
question.askAnswered = this.options.askAnswered === true;
}
});
}

// Pre-fill answers with storage values.
const answers = {};
Expand Down Expand Up @@ -567,9 +567,10 @@ class Generator extends Base {
*/
option(name, config) {
if (Array.isArray(name)) {
name.forEach((option) => {
for (const option of name) {
this.option(option);
});
}

return;
}

Expand All @@ -596,7 +597,7 @@ class Generator extends Base {

// Check whether boolean option is invalid (starts with no-)
const boolOptionRegex = /^no-/;
if (config.type === Boolean && name.match(boolOptionRegex)) {
if (config.type === Boolean && boolOptionRegex.test(name)) {
const simpleName = name.replace(boolOptionRegex, '');
throw new Error(
[
Expand Down Expand Up @@ -725,15 +726,15 @@ class Generator extends Base {
});

// Parse positional arguments to valid options
this._arguments.forEach((config, index) => {
for (const [index, config] of this._arguments.entries()) {
let value;
if (index >= parsedOptions._.length) {
if (config.name in this._initOptions) {
value = this._initOptions[config.name];
} else if ('default' in config) {
value = config.default;
} else {
return;
continue;
}
} else if (config.type === Array) {
value = parsedOptions._.slice(index, parsedOptions._.length);
Expand All @@ -742,7 +743,7 @@ class Generator extends Base {
}

parsedOptions[config.name] = value;
});
}

// Make the parsed options available to the instance
Object.assign(this.options, parsedOptions);
Expand All @@ -765,15 +766,15 @@ class Generator extends Base {
return;
}

this._arguments.forEach((config, position) => {
for (const [position, config] of this._arguments.entries()) {
// If the help option was not provided, check whether the argument was
// required, and whether a value was provided.
if (config.required && position >= this.args.length) {
throw new Error(
`Did not provide required argument ${chalk.bold(config.name)}!`
);
}
});
}
}

/**
Expand Down Expand Up @@ -820,12 +821,11 @@ class Generator extends Base {
* @param {TaskOptions} [taskOptions]: options.
*/
queueTaskGroup(taskGroup, taskOptions) {
const self = this;
// Run each queue items
_.each(taskGroup, (newMethod, newMethodName) => {
if (!_.isFunction(newMethod) || !methodIsValid(newMethodName)) return;

self.queueTask({
this.queueTask({
...taskOptions,
method: newMethod,
taskName: newMethodName
Expand Down Expand Up @@ -909,9 +909,8 @@ class Generator extends Base {
}
}

validMethods.forEach((methodName) =>
this.queueOwnTask(methodName, taskOptions)
);
for (const methodName of validMethods)
this.queueOwnTask(methodName, taskOptions);
}

/**
Expand Down Expand Up @@ -960,7 +959,7 @@ class Generator extends Base {
self.runningState = {namespace, queueName, methodName};
return method.apply(self, self.args);
})()
.then(function () {
.then(() => {
delete self.runningState;
const eventName = `done$${
namespace || 'unknownnamespace'
Expand Down Expand Up @@ -1062,9 +1061,8 @@ class Generator extends Base {
`Queueing generator ${this.options.namespace} with generator version ${this.yoGeneratorVersion}`
);
this.queueOwnTasks();
this._composedWith.forEach((generator) =>
this.env.queueGenerator(generator, false)
);
for (const generator of this._composedWith)
this.env.queueGenerator(generator, false);
this._composedWith = [];
}

Expand All @@ -1091,11 +1089,7 @@ class Generator extends Base {
args = options.arguments || options.args || [];
}

if (typeof options === 'boolean') {
options = {};
} else {
options = options || {};
}
options = typeof options === 'boolean' ? {} : options || {};

let instantiatedGenerator;

Expand Down
Loading

0 comments on commit 3f51315

Please sign in to comment.