| |
| |
| |
| |
| |
| |
| "use strict"; |
|
|
| |
| |
| |
|
|
| const { normalizeSeverityToString } = require("./severity"); |
| const { getShorthandName, normalizePackageName } = require("./naming"); |
| const { ModuleImporter } = require("@humanwhocodes/module-importer"); |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| 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; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function quietFixPredicate(message) { |
| return message.severity === 2; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function quietRuleFilter(rule) { |
| return rule.severity === 2; |
| } |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| async function translateOptions({ |
| cache, |
| cacheFile, |
| cacheLocation, |
| cacheStrategy, |
| concurrency, |
| config, |
| configLookup, |
| errorOnUnmatchedPattern, |
| ext, |
| fix, |
| fixDryRun, |
| fixType, |
| flag, |
| global, |
| ignore, |
| ignorePattern, |
| inlineConfig, |
| parser, |
| parserOptions, |
| plugin, |
| quiet, |
| reportUnusedDisableDirectives, |
| reportUnusedDisableDirectivesSeverity, |
| reportUnusedInlineConfigs, |
| rule, |
| stats, |
| warnIgnored, |
| passOnNoPatterns, |
| maxWarnings, |
| }) { |
| const importer = new ModuleImporter(); |
|
|
| let 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); |
| } |
|
|
| const 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}`, |
| ), |
| }); |
| } |
|
|
| |
| |
| |
| |
| const ruleFilter = |
| quiet && maxWarnings === -1 ? quietRuleFilter : () => true; |
|
|
| const options = { |
| allowInlineConfig: inlineConfig, |
| cache, |
| cacheLocation: cacheLocation || cacheFile, |
| cacheStrategy, |
| concurrency, |
| errorOnUnmatchedPattern, |
| fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true), |
| fixTypes: fixType, |
| flags: flag, |
| ignore, |
| ignorePatterns: ignorePattern, |
| overrideConfig, |
| overrideConfigFile, |
| passOnNoPatterns, |
| ruleFilter, |
| stats, |
| warnIgnored, |
| }; |
|
|
| return options; |
| } |
|
|
| module.exports = translateOptions; |
|
|