Repository: eslint/eslint
File: lib/cli.js (JavaScript)

Code before:

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const mkdir = promisify(fs.mkdir);
const stat = promisify(fs.stat);
const writeFile = promisify(fs.writeFile);

/**
 * Loads plugins with the specified names.
 * @param {{ "import": (name: string) => Promise<any> }} importer An object with an `import` method called once for each plugin.
 * @param {string[]} pluginNames The names of the plugins to be loaded, with or without the "eslint-plugin-" prefix.
 * @returns {Promise<Record<string, Plugin>>} A mapping of plugin short names to implementations.
 */
async function loadPlugins(importer, pluginNames) {
    const plugins = {};

    await Promise.all(pluginNames.map(async pluginName => {

        const shortName = naming.getShorthandName(pluginName, "eslint-plugin");
        const longName = naming.normalizePackageName(pluginName, "eslint-plugin");
        const module = await importer.import(longName);

        if (!("default" in module)) {
            throw Error(`"${longName}" cannot be imported because it does not provide a default export`);
        }
        plugins[shortName] = module.default;
    }));

    return plugins;
}

/**
 * Predicate function for whether or not to apply fixes in quiet mode.
 * If a message is a warning, do not apply a fix.
 * @param {LintMessage} message The lint result.
 * @returns {boolean} True if the lint message is an error (and thus should be
 * autofixed), false otherwise.
 */
function quietFixPredicate(message) {
    return message.severity === 2;
}

/**
 * Predicate function for whether or not to run a rule in quiet mode.
 * If a rule is set to warning, do not run it.
 * @param {{ ruleId: string; severity: number; }} rule The rule id and severity.
 * @returns {boolean} True if the lint rule should run, false otherwise.
 */
function quietRuleFilter(rule) {

Review comment (suggestion):
[Question] Elsewhere outside of `.md` files and `tests/`, it's always `throw new Error` - not `throw Error`. I.e. [`no-throw-literal`](https://eslint.org/docs/latest/rules/no-throw-literal) has been adhered to. Is it intentional that this doesn't?

```suggestion
            throw new Error(`"${longName}" cannot be imported because it does not provide a default export`);
```

Code after:

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const mkdir = promisify(fs.mkdir);
const stat = promisify(fs.stat);
const writeFile = promisify(fs.writeFile);

/**
 * Loads plugins with the specified names.
 * @param {{ "import": (name: string) => Promise<any> }} importer An object with an `import` method called once for each plugin.
 * @param {string[]} pluginNames The names of the plugins to be loaded, with or without the "eslint-plugin-" prefix.
 * @returns {Promise<Record<string, Plugin>>} A mapping of plugin short names to implementations.
 */
async function loadPlugins(importer, pluginNames) {
    const plugins = {};

    await Promise.all(pluginNames.map(async pluginName => {

        const longName = naming.normalizePackageName(pluginName, "eslint-plugin");
        const module = await importer.import(longName);

        if (!("default" in module)) {
            throw new Error(`"${longName}" cannot be used with the \`--plugin\` option because its default module does not provide a \`default\` export`);
        }

        const shortName = naming.getShorthandName(pluginName, "eslint-plugin");

        plugins[shortName] = module.default;
    }));

    return plugins;
}

/**
 * Predicate function for whether or not to apply fixes in quiet mode.
 * If a message is a warning, do not apply a fix.
 * @param {LintMessage} message The lint result.
 * @returns {boolean} True if the lint message is an error (and thus should be
 * autofixed), false otherwise.
 */
function quietFixPredicate(message) {
    return message.severity === 2;
}

/**
 * Predicate function for whether or not to run a rule in quiet mode.
 * If a rule is set to warning, do not run it.
 * @param {{ ruleId: string; severity: number; }} rule The rule id and severity.
 * @returns {boolean} True if the lint rule should run, false otherwise.