Pull.
J'ai juste update le cutie.js, CONNARD Ah oui, j'ai aussi add le info.js, qui est merdique d'ailleurs
This commit is contained in:
328
node_modules/eslint/lib/cli.js
generated
vendored
328
node_modules/eslint/lib/cli.js
generated
vendored
@@ -16,8 +16,9 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const fs = require("node:fs"),
|
||||
{ mkdir, stat, writeFile } = require("node:fs/promises"),
|
||||
path = require("node:path"),
|
||||
{ promisify } = require("node:util"),
|
||||
{ pathToFileURL } = require("node:url"),
|
||||
{ LegacyESLint } = require("./eslint"),
|
||||
{
|
||||
ESLint,
|
||||
@@ -27,282 +28,23 @@ const fs = require("node:fs"),
|
||||
createCLIOptions = require("./options"),
|
||||
log = require("./shared/logging"),
|
||||
RuntimeInfo = require("./shared/runtime-info"),
|
||||
{ normalizeSeverityToString } = require("./shared/severity");
|
||||
const { ModuleImporter } = require("@humanwhocodes/module-importer");
|
||||
translateOptions = require("./shared/translate-cli-options");
|
||||
const { getCacheFile } = require("./eslint/eslint-helpers");
|
||||
const { SuppressionsService } = require("./services/suppressions-service");
|
||||
const debug = require("debug")("eslint:cli");
|
||||
const {
|
||||
normalizePackageName,
|
||||
getShorthandName,
|
||||
} = require("./shared/naming.js");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @import { ESLintOptions } from "./eslint/eslint.js" */
|
||||
|
||||
/** @typedef {import("./options").ParsedCLIOptions} ParsedCLIOptions */
|
||||
/** @typedef {import("./types").Linter.LintMessage} LintMessage */
|
||||
/** @typedef {import("./types").ESLint.LintResult} LintResult */
|
||||
/** @typedef {import("./types").ESLint.Plugin} Plugin */
|
||||
/** @typedef {import("./types").ESLint.ResultsMeta} ResultsMeta */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// 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 = 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 = 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.
|
||||
*/
|
||||
function quietRuleFilter(rule) {
|
||||
return rule.severity === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the CLI options into the options expected by the ESLint constructor.
|
||||
* @param {ParsedCLIOptions} cliOptions The CLI options to translate.
|
||||
* @param {"flat"|"eslintrc"} [configType="eslintrc"] The format of the
|
||||
* config to generate.
|
||||
* @returns {Promise<ESLintOptions>} The options object for the ESLint constructor.
|
||||
* @private
|
||||
*/
|
||||
async function translateOptions(
|
||||
{
|
||||
cache,
|
||||
cacheFile,
|
||||
cacheLocation,
|
||||
cacheStrategy,
|
||||
config,
|
||||
configLookup,
|
||||
env,
|
||||
errorOnUnmatchedPattern,
|
||||
eslintrc,
|
||||
ext,
|
||||
fix,
|
||||
fixDryRun,
|
||||
fixType,
|
||||
flag,
|
||||
global,
|
||||
ignore,
|
||||
ignorePath,
|
||||
ignorePattern,
|
||||
inlineConfig,
|
||||
parser,
|
||||
parserOptions,
|
||||
plugin,
|
||||
quiet,
|
||||
reportUnusedDisableDirectives,
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
reportUnusedInlineConfigs,
|
||||
resolvePluginsRelativeTo,
|
||||
rule,
|
||||
rulesdir,
|
||||
stats,
|
||||
warnIgnored,
|
||||
passOnNoPatterns,
|
||||
maxWarnings,
|
||||
},
|
||||
configType,
|
||||
) {
|
||||
let overrideConfig, overrideConfigFile;
|
||||
const importer = new ModuleImporter();
|
||||
|
||||
if (configType === "flat") {
|
||||
overrideConfigFile =
|
||||
typeof config === "string" ? config : !configLookup;
|
||||
if (overrideConfigFile === false) {
|
||||
overrideConfigFile = void 0;
|
||||
}
|
||||
|
||||
const languageOptions = {};
|
||||
|
||||
if (global) {
|
||||
languageOptions.globals = global.reduce((obj, name) => {
|
||||
if (name.endsWith(":true")) {
|
||||
obj[name.slice(0, -5)] = "writable";
|
||||
} else {
|
||||
obj[name] = "readonly";
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (parserOptions) {
|
||||
languageOptions.parserOptions = parserOptions;
|
||||
}
|
||||
|
||||
if (parser) {
|
||||
languageOptions.parser = await importer.import(parser);
|
||||
}
|
||||
|
||||
overrideConfig = [
|
||||
{
|
||||
...(Object.keys(languageOptions).length > 0
|
||||
? { languageOptions }
|
||||
: {}),
|
||||
rules: rule ? rule : {},
|
||||
},
|
||||
];
|
||||
|
||||
if (
|
||||
reportUnusedDisableDirectives ||
|
||||
reportUnusedDisableDirectivesSeverity !== void 0
|
||||
) {
|
||||
overrideConfig[0].linterOptions = {
|
||||
reportUnusedDisableDirectives: reportUnusedDisableDirectives
|
||||
? "error"
|
||||
: normalizeSeverityToString(
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (reportUnusedInlineConfigs !== void 0) {
|
||||
overrideConfig[0].linterOptions = {
|
||||
...overrideConfig[0].linterOptions,
|
||||
reportUnusedInlineConfigs: normalizeSeverityToString(
|
||||
reportUnusedInlineConfigs,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (plugin) {
|
||||
overrideConfig[0].plugins = await loadPlugins(importer, plugin);
|
||||
}
|
||||
|
||||
if (ext) {
|
||||
overrideConfig.push({
|
||||
files: ext.map(
|
||||
extension =>
|
||||
`**/*${extension.startsWith(".") ? "" : "."}${extension}`,
|
||||
),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
overrideConfigFile = config;
|
||||
|
||||
overrideConfig = {
|
||||
env:
|
||||
env &&
|
||||
env.reduce((obj, name) => {
|
||||
obj[name] = true;
|
||||
return obj;
|
||||
}, {}),
|
||||
globals:
|
||||
global &&
|
||||
global.reduce((obj, name) => {
|
||||
if (name.endsWith(":true")) {
|
||||
obj[name.slice(0, -5)] = "writable";
|
||||
} else {
|
||||
obj[name] = "readonly";
|
||||
}
|
||||
return obj;
|
||||
}, {}),
|
||||
ignorePatterns: ignorePattern,
|
||||
parser,
|
||||
parserOptions,
|
||||
plugins: plugin,
|
||||
rules: rule,
|
||||
};
|
||||
}
|
||||
|
||||
const options = {
|
||||
allowInlineConfig: inlineConfig,
|
||||
cache,
|
||||
cacheLocation: cacheLocation || cacheFile,
|
||||
cacheStrategy,
|
||||
errorOnUnmatchedPattern,
|
||||
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
|
||||
fixTypes: fixType,
|
||||
ignore,
|
||||
overrideConfig,
|
||||
overrideConfigFile,
|
||||
passOnNoPatterns,
|
||||
};
|
||||
|
||||
if (configType === "flat") {
|
||||
options.ignorePatterns = ignorePattern;
|
||||
options.stats = stats;
|
||||
options.warnIgnored = warnIgnored;
|
||||
options.flags = flag;
|
||||
|
||||
/*
|
||||
* For performance reasons rules not marked as 'error' are filtered out in quiet mode. As maxWarnings
|
||||
* requires rules set to 'warn' to be run, we only filter out 'warn' rules if maxWarnings is not specified.
|
||||
*/
|
||||
options.ruleFilter =
|
||||
quiet && maxWarnings === -1 ? quietRuleFilter : () => true;
|
||||
} else {
|
||||
options.resolvePluginsRelativeTo = resolvePluginsRelativeTo;
|
||||
options.rulePaths = rulesdir;
|
||||
options.useEslintrc = eslintrc;
|
||||
options.extensions = ext;
|
||||
options.ignorePath = ignorePath;
|
||||
if (
|
||||
reportUnusedDisableDirectives ||
|
||||
reportUnusedDisableDirectivesSeverity !== void 0
|
||||
) {
|
||||
options.reportUnusedDisableDirectives =
|
||||
reportUnusedDisableDirectives
|
||||
? "error"
|
||||
: normalizeSeverityToString(
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count error messages.
|
||||
* @param {LintResult[]} results The lint results.
|
||||
@@ -322,6 +64,26 @@ function countErrors(results) {
|
||||
return { errorCount, fatalErrorCount, warningCount };
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an options module from the provided CLI options and encodes it as a data URL.
|
||||
* @param {ParsedCLIOptions} options The CLI options.
|
||||
* @returns {URL} The URL of the options module.
|
||||
*/
|
||||
function createOptionsModule(options) {
|
||||
const translateOptionsFileURL = new URL(
|
||||
"./shared/translate-cli-options.js",
|
||||
pathToFileURL(__filename),
|
||||
).href;
|
||||
const optionsSrc =
|
||||
`import translateOptions from ${JSON.stringify(translateOptionsFileURL)};\n` +
|
||||
`export default await translateOptions(${JSON.stringify(options)}, "flat");\n`;
|
||||
|
||||
// Base64 encoding is typically shorter than URL encoding
|
||||
return new URL(
|
||||
`data:text/javascript;base64,${Buffer.from(optionsSrc).toString("base64")}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given file path is a directory or not.
|
||||
* @param {string} filePath The path to a file to check.
|
||||
@@ -385,6 +147,30 @@ async function printResults(engine, results, format, outputFile, resultsMeta) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the `--concurrency` flag value.
|
||||
* @param {string} concurrency The `--concurrency` flag value to validate.
|
||||
* @returns {void}
|
||||
* @throws {Error} If the `--concurrency` flag value is invalid.
|
||||
*/
|
||||
function validateConcurrency(concurrency) {
|
||||
if (
|
||||
concurrency === void 0 ||
|
||||
concurrency === "auto" ||
|
||||
concurrency === "off"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const concurrencyValue = Number(concurrency);
|
||||
|
||||
if (!Number.isInteger(concurrencyValue) || concurrencyValue < 1) {
|
||||
throw new Error(
|
||||
`Option concurrency: '${concurrency}' is not a positive integer, 'auto' or 'off'.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -445,6 +231,7 @@ const cli = {
|
||||
|
||||
try {
|
||||
options = CLIOptions.parse(args);
|
||||
validateConcurrency(options.concurrency);
|
||||
} catch (error) {
|
||||
debug("Error parsing CLI options:", error.message);
|
||||
|
||||
@@ -614,11 +401,20 @@ const cli = {
|
||||
}
|
||||
|
||||
const ActiveESLint = usingFlatConfig ? ESLint : LegacyESLint;
|
||||
const eslintOptions = await translateOptions(
|
||||
options,
|
||||
usingFlatConfig ? "flat" : "eslintrc",
|
||||
);
|
||||
const engine = new ActiveESLint(eslintOptions);
|
||||
|
||||
/** @type {ESLint|LegacyESLint} */
|
||||
let engine;
|
||||
|
||||
if (options.concurrency && options.concurrency !== "off") {
|
||||
const optionsURL = createOptionsModule(options);
|
||||
engine = await ESLint.fromOptionsModule(optionsURL);
|
||||
} else {
|
||||
const eslintOptions = await translateOptions(
|
||||
options,
|
||||
usingFlatConfig ? "flat" : "eslintrc",
|
||||
);
|
||||
engine = new ActiveESLint(eslintOptions);
|
||||
}
|
||||
let results;
|
||||
|
||||
if (useStdin) {
|
||||
|
||||
Reference in New Issue
Block a user