eslint
Advanced tools
Comparing version 8.22.0 to 8.23.0
@@ -12,5 +12,2 @@ #!/usr/bin/env node | ||
// to use V8's code cache to speed up instantiation time | ||
require("v8-compile-cache"); | ||
// must do this initialization *before* other requires in order to work | ||
@@ -141,4 +138,5 @@ if (process.argv.includes("--debug")) { | ||
process.argv, | ||
process.argv.includes("--stdin") ? await readStdin() : null | ||
process.argv.includes("--stdin") ? await readStdin() : null, | ||
true | ||
); | ||
}()).catch(onFatalError); |
@@ -127,3 +127,7 @@ /** | ||
const es2023 = { | ||
...es2022 | ||
}; | ||
//----------------------------------------------------------------------------- | ||
@@ -144,3 +148,4 @@ // Exports | ||
es2021, | ||
es2022 | ||
es2022, | ||
es2023 | ||
}; |
152
lib/cli.js
@@ -9,3 +9,3 @@ /** | ||
/* | ||
* The CLI object should *not* call process.exit() directly. It should only return | ||
* NOTE: The CLI object should *not* call process.exit() directly. It should only return | ||
* exit codes. This allows other programs to use the CLI object and still control | ||
@@ -23,5 +23,10 @@ * when the program exits. | ||
{ ESLint } = require("./eslint"), | ||
CLIOptions = require("./options"), | ||
{ FlatESLint } = require("./eslint/flat-eslint"), | ||
createCLIOptions = require("./options"), | ||
log = require("./shared/logging"), | ||
RuntimeInfo = require("./shared/runtime-info"); | ||
const { Legacy: { naming } } = require("@eslint/eslintrc"); | ||
const { findFlatConfigFile } = require("./eslint/flat-eslint"); | ||
const { gitignoreToMinimatch } = require("@humanwhocodes/gitignore-to-minimatch"); | ||
const { ModuleImporter } = require("@humanwhocodes/module-importer"); | ||
@@ -59,8 +64,10 @@ const debug = require("debug")("eslint:cli"); | ||
/** | ||
* Translates the CLI options into the options expected by the CLIEngine. | ||
* Translates the CLI options into the options expected by the ESLint constructor. | ||
* @param {ParsedCLIOptions} cliOptions The CLI options to translate. | ||
* @returns {ESLintOptions} The options object for the CLIEngine. | ||
* @param {"flat"|"eslintrc"} [configType="eslintrc"] The format of the | ||
* config to generate. | ||
* @returns {Promise<ESLintOptions>} The options object for the ESLint constructor. | ||
* @private | ||
*/ | ||
function translateOptions({ | ||
async function translateOptions({ | ||
cache, | ||
@@ -71,2 +78,3 @@ cacheFile, | ||
config, | ||
configLookup, | ||
env, | ||
@@ -92,15 +100,62 @@ errorOnUnmatchedPattern, | ||
rulesdir | ||
}) { | ||
return { | ||
allowInlineConfig: inlineConfig, | ||
cache, | ||
cacheLocation: cacheLocation || cacheFile, | ||
cacheStrategy, | ||
errorOnUnmatchedPattern, | ||
extensions: ext, | ||
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true), | ||
fixTypes: fixType, | ||
ignore, | ||
ignorePath, | ||
overrideConfig: { | ||
}, configType) { | ||
let overrideConfig, overrideConfigFile; | ||
const importer = new ModuleImporter(); | ||
if (configType === "flat") { | ||
overrideConfigFile = (typeof config === "string") ? config : !configLookup; | ||
if (overrideConfigFile === false) { | ||
overrideConfigFile = void 0; | ||
} | ||
let globals = {}; | ||
if (global) { | ||
globals = global.reduce((obj, name) => { | ||
if (name.endsWith(":true")) { | ||
obj[name.slice(0, -5)] = "writable"; | ||
} else { | ||
obj[name] = "readonly"; | ||
} | ||
return obj; | ||
}, globals); | ||
} | ||
overrideConfig = [{ | ||
languageOptions: { | ||
globals, | ||
parserOptions: parserOptions || {} | ||
}, | ||
rules: rule ? rule : {} | ||
}]; | ||
if (parser) { | ||
overrideConfig[0].languageOptions.parser = await importer.import(parser); | ||
} | ||
if (plugin) { | ||
const plugins = {}; | ||
for (const pluginName of plugin) { | ||
const shortName = naming.getShorthandName(pluginName, "eslint-plugin"); | ||
const longName = naming.normalizePackageName(pluginName, "eslint-plugin"); | ||
plugins[shortName] = await importer.import(longName); | ||
} | ||
overrideConfig[0].plugins = plugins; | ||
} | ||
if (ignorePattern) { | ||
overrideConfig.push({ | ||
ignores: ignorePattern.map(gitignoreToMinimatch) | ||
}); | ||
} | ||
} else { | ||
overrideConfigFile = config; | ||
overrideConfig = { | ||
env: env && env.reduce((obj, name) => { | ||
@@ -123,9 +178,28 @@ obj[name] = true; | ||
rules: rule | ||
}, | ||
overrideConfigFile: config, | ||
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0, | ||
resolvePluginsRelativeTo, | ||
rulePaths: rulesdir, | ||
useEslintrc: eslintrc | ||
}; | ||
} | ||
const options = { | ||
allowInlineConfig: inlineConfig, | ||
cache, | ||
cacheLocation: cacheLocation || cacheFile, | ||
cacheStrategy, | ||
errorOnUnmatchedPattern, | ||
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true), | ||
fixTypes: fixType, | ||
ignore, | ||
ignorePath, | ||
overrideConfig, | ||
overrideConfigFile, | ||
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0 | ||
}; | ||
if (configType !== "flat") { | ||
options.resolvePluginsRelativeTo = resolvePluginsRelativeTo; | ||
options.rulePaths = rulesdir; | ||
options.useEslintrc = eslintrc; | ||
options.extensions = ext; | ||
} | ||
return options; | ||
} | ||
@@ -227,5 +301,6 @@ | ||
* @param {string} [text] The text to lint (used for TTY). | ||
* @param {boolean} [allowFlatConfig] Whether or not to allow flat config. | ||
* @returns {Promise<number>} The exit code for the operation. | ||
*/ | ||
async execute(args, text) { | ||
async execute(args, text, allowFlatConfig) { | ||
if (Array.isArray(args)) { | ||
@@ -235,2 +310,15 @@ debug("CLI args: %o", args.slice(2)); | ||
/* | ||
* Before doing anything, we need to see if we are using a | ||
* flat config file. If so, then we need to change the way command | ||
* line args are parsed. This is temporary, and when we fully | ||
* switch to flat config we can remove this logic. | ||
*/ | ||
const usingFlatConfig = allowFlatConfig && !!(await findFlatConfigFile(process.cwd())); | ||
debug("Using flat config?", usingFlatConfig); | ||
const CLIOptions = createCLIOptions(usingFlatConfig); | ||
/** @type {ParsedCLIOptions} */ | ||
@@ -242,2 +330,3 @@ let options; | ||
} catch (error) { | ||
debug("Error parsing CLI options:", error.message); | ||
log.error(error.message); | ||
@@ -263,2 +352,3 @@ return 2; | ||
} catch (err) { | ||
debug("Error retrieving environment info"); | ||
log.error(err.message); | ||
@@ -279,3 +369,5 @@ return 2; | ||
const engine = new ESLint(translateOptions(options)); | ||
const engine = usingFlatConfig | ||
? new FlatESLint(await translateOptions(options, "flat")) | ||
: new ESLint(await translateOptions(options)); | ||
const fileConfig = | ||
@@ -303,3 +395,5 @@ await engine.calculateConfigForFile(options.printConfig); | ||
const engine = new ESLint(translateOptions(options)); | ||
const ActiveESLint = usingFlatConfig ? FlatESLint : ESLint; | ||
const engine = new ActiveESLint(await translateOptions(options, usingFlatConfig ? "flat" : "eslintrc")); | ||
let results; | ||
@@ -318,3 +412,3 @@ | ||
debug("Fix mode enabled - applying fixes"); | ||
await ESLint.outputFixes(results); | ||
await ActiveESLint.outputFixes(results); | ||
} | ||
@@ -326,3 +420,3 @@ | ||
debug("Quiet mode enabled - filtering out warnings"); | ||
resultsToPrint = ESLint.getErrorResults(resultsToPrint); | ||
resultsToPrint = ActiveESLint.getErrorResults(resultsToPrint); | ||
} | ||
@@ -329,0 +423,0 @@ |
@@ -107,2 +107,4 @@ /** | ||
* @param {FlatConfigArray} args.configs The configs for the current run. | ||
* @param {boolean} args.errorOnUnmatchedPattern Determines if an unmatched pattern | ||
* should throw an error. | ||
* @returns {Promise<Array<string>>} The fully resolved file paths. | ||
@@ -116,3 +118,4 @@ * @throws {AllFilesIgnoredError} If there are no results due to an ignore pattern. | ||
cwd, | ||
configs | ||
configs, | ||
errorOnUnmatchedPattern | ||
}) { | ||
@@ -227,3 +230,5 @@ | ||
// no files were found | ||
throw new NoFilesFoundError(globbyPattern, globInputPaths); | ||
if (errorOnUnmatchedPattern) { | ||
throw new NoFilesFoundError(globbyPattern, globInputPaths); | ||
} | ||
} | ||
@@ -235,3 +240,3 @@ /* eslint-enable no-unreachable-loop -- Go back to normal. */ | ||
// there were patterns that didn't match anything, tell the user | ||
if (missingPatterns.length) { | ||
if (errorOnUnmatchedPattern && missingPatterns.length) { | ||
throw new NoFilesFoundError(missingPatterns[0], globInputPaths); | ||
@@ -329,2 +334,3 @@ } | ||
], | ||
suppressedMessages: [], | ||
errorCount: 0, | ||
@@ -386,3 +392,2 @@ warningCount: 1, | ||
errorOnUnmatchedPattern = true, | ||
extensions = null, // ← should be null by default because if it's an array then it suppresses RFC20 feature. | ||
fix = false, | ||
@@ -414,2 +419,5 @@ fixTypes = null, // ← should be null by default because if it's an array then it suppresses rules that don't have the `meta.type` property. | ||
} | ||
if (unknownOptionKeys.includes("extensions")) { | ||
errors.push("'extensions' has been removed."); | ||
} | ||
if (unknownOptionKeys.includes("resolvePluginsRelativeTo")) { | ||
@@ -461,5 +469,2 @@ errors.push("'resolvePluginsRelativeTo' has been removed."); | ||
} | ||
if (!isArrayOfNonEmptyString(extensions) && extensions !== null) { | ||
errors.push("'extensions' must be an array of non-empty strings or null."); | ||
} | ||
if (typeof fix !== "boolean" && typeof fix !== "function") { | ||
@@ -518,3 +523,2 @@ errors.push("'fix' must be a boolean or a function."); | ||
errorOnUnmatchedPattern, | ||
extensions, | ||
fix, | ||
@@ -521,0 +525,0 @@ fixTypes, |
@@ -76,3 +76,2 @@ /** | ||
* @property {boolean} [errorOnUnmatchedPattern] If `false` then `ESLint#lintFiles()` doesn't throw even if no target files found. Defaults to `true`. | ||
* @property {string[]} [extensions] An array of file extensions to check. | ||
* @property {boolean|Function} [fix] Execute in autofix mode. If a function, should return a boolean. | ||
@@ -325,4 +324,3 @@ * @property {string[]} [fixTypes] Array of rule types to apply fixes for. | ||
ignorePath, | ||
ignorePatterns, | ||
extensions | ||
ignorePatterns | ||
}) { | ||
@@ -370,9 +368,2 @@ | ||
// if there are any extensions, create configs for them for easier matching | ||
if (extensions && extensions.length) { | ||
configs.push({ | ||
files: extensions.map(ext => `**/*${ext}`) | ||
}); | ||
} | ||
let allIgnorePatterns = []; | ||
@@ -521,2 +512,3 @@ let ignoreFilePath; | ||
messages, | ||
suppressedMessages: linter.getSuppressedMessages(), | ||
...calculateStatsPerFile(messages) | ||
@@ -696,2 +688,3 @@ }; | ||
const filteredMessages = result.messages.filter(isErrorMessage); | ||
const filteredSuppressedMessages = result.suppressedMessages.filter(isErrorMessage); | ||
@@ -702,2 +695,3 @@ if (filteredMessages.length > 0) { | ||
messages: filteredMessages, | ||
suppressedMessages: filteredSuppressedMessages, | ||
errorCount: filteredMessages.length, | ||
@@ -755,7 +749,8 @@ warningCount: 0, | ||
const config = configs.getConfig(filePath); | ||
const allMessages = result.messages.concat(result.suppressedMessages); | ||
for (const { ruleId } of result.messages) { | ||
for (const { ruleId } of allMessages) { | ||
const rule = getRuleFromConfig(ruleId, config); | ||
// ensure the rule exists exists | ||
// ensure the rule exists | ||
if (!rule) { | ||
@@ -796,4 +791,4 @@ throw new TypeError(`Could not find the rule "${ruleId}".`); | ||
reportUnusedDisableDirectives, | ||
extensions, | ||
globInputPaths | ||
globInputPaths, | ||
errorOnUnmatchedPattern | ||
} = eslintOptions; | ||
@@ -823,5 +818,5 @@ const startTime = Date.now(); | ||
cwd, | ||
extensions, | ||
globInputPaths, | ||
configs | ||
configs, | ||
errorOnUnmatchedPattern | ||
}); | ||
@@ -1139,2 +1134,3 @@ | ||
return formatter(results, { | ||
cwd, | ||
get rulesMeta() { | ||
@@ -1188,3 +1184,4 @@ if (!rulesMeta) { | ||
module.exports = { | ||
FlatESLint | ||
FlatESLint, | ||
findFlatConfigFile | ||
}; |
@@ -134,4 +134,3 @@ /** | ||
// Collapse whitespace around commas | ||
string.replace(/\s*,\s*/gu, ",").split(/,+/u).forEach(name => { | ||
string.split(",").forEach(name => { | ||
const trimmedName = name.trim(); | ||
@@ -138,0 +137,0 @@ |
@@ -66,13 +66,21 @@ /** | ||
// exports "parse(args)", "generateHelp()", and "generateHelpForOption(optionName)" | ||
module.exports = optionator({ | ||
prepend: "eslint [options] file.js [file.js] [dir]", | ||
defaults: { | ||
concatRepeatedArrays: true, | ||
mergeRepeatedObjects: true | ||
}, | ||
options: [ | ||
{ | ||
heading: "Basic configuration" | ||
}, | ||
{ | ||
/** | ||
* Creates the CLI options for ESLint. | ||
* @param {boolean} usingFlatConfig Indicates if flat config is being used. | ||
* @returns {Object} The opinionator instance. | ||
*/ | ||
module.exports = function(usingFlatConfig) { | ||
let lookupFlag; | ||
if (usingFlatConfig) { | ||
lookupFlag = { | ||
option: "config-lookup", | ||
type: "Boolean", | ||
default: "true", | ||
description: "Disable look up for eslint.config.js" | ||
}; | ||
} else { | ||
lookupFlag = { | ||
option: "eslintrc", | ||
@@ -82,244 +90,284 @@ type: "Boolean", | ||
description: "Disable use of configuration from .eslintrc.*" | ||
}, | ||
{ | ||
option: "config", | ||
alias: "c", | ||
type: "path::String", | ||
description: "Use this configuration, overriding .eslintrc.* config options if present" | ||
}, | ||
{ | ||
}; | ||
} | ||
let envFlag; | ||
if (!usingFlatConfig) { | ||
envFlag = { | ||
option: "env", | ||
type: "[String]", | ||
description: "Specify environments" | ||
}, | ||
{ | ||
}; | ||
} | ||
let extFlag; | ||
if (!usingFlatConfig) { | ||
extFlag = { | ||
option: "ext", | ||
type: "[String]", | ||
description: "Specify JavaScript file extensions" | ||
}, | ||
{ | ||
option: "global", | ||
type: "[String]", | ||
description: "Define global variables" | ||
}, | ||
{ | ||
option: "parser", | ||
type: "String", | ||
description: "Specify the parser to be used" | ||
}, | ||
{ | ||
option: "parser-options", | ||
type: "Object", | ||
description: "Specify parser options" | ||
}, | ||
{ | ||
}; | ||
} | ||
let resolvePluginsFlag; | ||
if (!usingFlatConfig) { | ||
resolvePluginsFlag = { | ||
option: "resolve-plugins-relative-to", | ||
type: "path::String", | ||
description: "A folder where plugins should be resolved from, CWD by default" | ||
}, | ||
{ | ||
heading: "Specifying rules and plugins" | ||
}, | ||
{ | ||
option: "plugin", | ||
type: "[String]", | ||
description: "Specify plugins" | ||
}, | ||
{ | ||
option: "rule", | ||
type: "Object", | ||
description: "Specify rules" | ||
}, | ||
{ | ||
}; | ||
} | ||
let rulesDirFlag; | ||
if (!usingFlatConfig) { | ||
rulesDirFlag = { | ||
option: "rulesdir", | ||
type: "[path::String]", | ||
description: "Load additional rules from this directory. Deprecated: Use rules from plugins" | ||
}; | ||
} | ||
return optionator({ | ||
prepend: "eslint [options] file.js [file.js] [dir]", | ||
defaults: { | ||
concatRepeatedArrays: true, | ||
mergeRepeatedObjects: true | ||
}, | ||
{ | ||
heading: "Fixing problems" | ||
}, | ||
{ | ||
option: "fix", | ||
type: "Boolean", | ||
default: false, | ||
description: "Automatically fix problems" | ||
}, | ||
{ | ||
option: "fix-dry-run", | ||
type: "Boolean", | ||
default: false, | ||
description: "Automatically fix problems without saving the changes to the file system" | ||
}, | ||
{ | ||
option: "fix-type", | ||
type: "Array", | ||
description: "Specify the types of fixes to apply (directive, problem, suggestion, layout)" | ||
}, | ||
{ | ||
heading: "Ignoring files" | ||
}, | ||
{ | ||
option: "ignore-path", | ||
type: "path::String", | ||
description: "Specify path of ignore file" | ||
}, | ||
{ | ||
option: "ignore", | ||
type: "Boolean", | ||
default: "true", | ||
description: "Disable use of ignore files and patterns" | ||
}, | ||
{ | ||
option: "ignore-pattern", | ||
type: "[String]", | ||
description: "Pattern of files to ignore (in addition to those in .eslintignore)", | ||
concatRepeatedArrays: [true, { | ||
oneValuePerFlag: true | ||
}] | ||
}, | ||
{ | ||
heading: "Using stdin" | ||
}, | ||
{ | ||
option: "stdin", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Lint code provided on <STDIN>" | ||
}, | ||
{ | ||
option: "stdin-filename", | ||
type: "String", | ||
description: "Specify filename to process STDIN as" | ||
}, | ||
{ | ||
heading: "Handling warnings" | ||
}, | ||
{ | ||
option: "quiet", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Report errors only" | ||
}, | ||
{ | ||
option: "max-warnings", | ||
type: "Int", | ||
default: "-1", | ||
description: "Number of warnings to trigger nonzero exit code" | ||
}, | ||
{ | ||
heading: "Output" | ||
}, | ||
{ | ||
option: "output-file", | ||
alias: "o", | ||
type: "path::String", | ||
description: "Specify file to write report to" | ||
}, | ||
{ | ||
option: "format", | ||
alias: "f", | ||
type: "String", | ||
default: "stylish", | ||
description: "Use a specific output format" | ||
}, | ||
{ | ||
option: "color", | ||
type: "Boolean", | ||
alias: "no-color", | ||
description: "Force enabling/disabling of color" | ||
}, | ||
{ | ||
heading: "Inline configuration comments" | ||
}, | ||
{ | ||
option: "inline-config", | ||
type: "Boolean", | ||
default: "true", | ||
description: "Prevent comments from changing config or rules" | ||
}, | ||
{ | ||
option: "report-unused-disable-directives", | ||
type: "Boolean", | ||
default: void 0, | ||
description: "Adds reported errors for unused eslint-disable directives" | ||
}, | ||
{ | ||
heading: "Caching" | ||
}, | ||
{ | ||
option: "cache", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Only check changed files" | ||
}, | ||
{ | ||
option: "cache-file", | ||
type: "path::String", | ||
default: ".eslintcache", | ||
description: "Path to the cache file. Deprecated: use --cache-location" | ||
}, | ||
{ | ||
option: "cache-location", | ||
type: "path::String", | ||
description: "Path to the cache file or directory" | ||
}, | ||
{ | ||
option: "cache-strategy", | ||
dependsOn: ["cache"], | ||
type: "String", | ||
default: "metadata", | ||
enum: ["metadata", "content"], | ||
description: "Strategy to use for detecting changed files in the cache" | ||
}, | ||
{ | ||
heading: "Miscellaneous" | ||
}, | ||
{ | ||
option: "init", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Run config initialization wizard" | ||
}, | ||
{ | ||
option: "env-info", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Output execution environment information" | ||
}, | ||
{ | ||
option: "error-on-unmatched-pattern", | ||
type: "Boolean", | ||
default: "true", | ||
description: "Prevent errors when pattern is unmatched" | ||
}, | ||
{ | ||
option: "exit-on-fatal-error", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Exit with exit code 2 in case of fatal error" | ||
}, | ||
{ | ||
option: "debug", | ||
type: "Boolean", | ||
default: false, | ||
description: "Output debugging information" | ||
}, | ||
{ | ||
option: "help", | ||
alias: "h", | ||
type: "Boolean", | ||
description: "Show help" | ||
}, | ||
{ | ||
option: "version", | ||
alias: "v", | ||
type: "Boolean", | ||
description: "Output the version number" | ||
}, | ||
{ | ||
option: "print-config", | ||
type: "path::String", | ||
description: "Print the configuration for the given file" | ||
} | ||
] | ||
}); | ||
options: [ | ||
{ | ||
heading: "Basic configuration" | ||
}, | ||
lookupFlag, | ||
{ | ||
option: "config", | ||
alias: "c", | ||
type: "path::String", | ||
description: usingFlatConfig | ||
? "Use this configuration instead of eslint.config.js" | ||
: "Use this configuration, overriding .eslintrc.* config options if present" | ||
}, | ||
envFlag, | ||
extFlag, | ||
{ | ||
option: "global", | ||
type: "[String]", | ||
description: "Define global variables" | ||
}, | ||
{ | ||
option: "parser", | ||
type: "String", | ||
description: "Specify the parser to be used" | ||
}, | ||
{ | ||
option: "parser-options", | ||
type: "Object", | ||
description: "Specify parser options" | ||
}, | ||
resolvePluginsFlag, | ||
{ | ||
heading: "Specifying rules and plugins" | ||
}, | ||
{ | ||
option: "plugin", | ||
type: "[String]", | ||
description: "Specify plugins" | ||
}, | ||
{ | ||
option: "rule", | ||
type: "Object", | ||
description: "Specify rules" | ||
}, | ||
rulesDirFlag, | ||
{ | ||
heading: "Fixing problems" | ||
}, | ||
{ | ||
option: "fix", | ||
type: "Boolean", | ||
default: false, | ||
description: "Automatically fix problems" | ||
}, | ||
{ | ||
option: "fix-dry-run", | ||
type: "Boolean", | ||
default: false, | ||
description: "Automatically fix problems without saving the changes to the file system" | ||
}, | ||
{ | ||
option: "fix-type", | ||
type: "Array", | ||
description: "Specify the types of fixes to apply (directive, problem, suggestion, layout)" | ||
}, | ||
{ | ||
heading: "Ignoring files" | ||
}, | ||
{ | ||
option: "ignore-path", | ||
type: "path::String", | ||
description: "Specify path of ignore file" | ||
}, | ||
{ | ||
option: "ignore", | ||
type: "Boolean", | ||
default: "true", | ||
description: "Disable use of ignore files and patterns" | ||
}, | ||
{ | ||
option: "ignore-pattern", | ||
type: "[String]", | ||
description: "Pattern of files to ignore (in addition to those in .eslintignore)", | ||
concatRepeatedArrays: [true, { | ||
oneValuePerFlag: true | ||
}] | ||
}, | ||
{ | ||
heading: "Using stdin" | ||
}, | ||
{ | ||
option: "stdin", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Lint code provided on <STDIN>" | ||
}, | ||
{ | ||
option: "stdin-filename", | ||
type: "String", | ||
description: "Specify filename to process STDIN as" | ||
}, | ||
{ | ||
heading: "Handling warnings" | ||
}, | ||
{ | ||
option: "quiet", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Report errors only" | ||
}, | ||
{ | ||
option: "max-warnings", | ||
type: "Int", | ||
default: "-1", | ||
description: "Number of warnings to trigger nonzero exit code" | ||
}, | ||
{ | ||
heading: "Output" | ||
}, | ||
{ | ||
option: "output-file", | ||
alias: "o", | ||
type: "path::String", | ||
description: "Specify file to write report to" | ||
}, | ||
{ | ||
option: "format", | ||
alias: "f", | ||
type: "String", | ||
default: "stylish", | ||
description: "Use a specific output format" | ||
}, | ||
{ | ||
option: "color", | ||
type: "Boolean", | ||
alias: "no-color", | ||
description: "Force enabling/disabling of color" | ||
}, | ||
{ | ||
heading: "Inline configuration comments" | ||
}, | ||
{ | ||
option: "inline-config", | ||
type: "Boolean", | ||
default: "true", | ||
description: "Prevent comments from changing config or rules" | ||
}, | ||
{ | ||
option: "report-unused-disable-directives", | ||
type: "Boolean", | ||
default: void 0, | ||
description: "Adds reported errors for unused eslint-disable directives" | ||
}, | ||
{ | ||
heading: "Caching" | ||
}, | ||
{ | ||
option: "cache", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Only check changed files" | ||
}, | ||
{ | ||
option: "cache-file", | ||
type: "path::String", | ||
default: ".eslintcache", | ||
description: "Path to the cache file. Deprecated: use --cache-location" | ||
}, | ||
{ | ||
option: "cache-location", | ||
type: "path::String", | ||
description: "Path to the cache file or directory" | ||
}, | ||
{ | ||
option: "cache-strategy", | ||
dependsOn: ["cache"], | ||
type: "String", | ||
default: "metadata", | ||
enum: ["metadata", "content"], | ||
description: "Strategy to use for detecting changed files in the cache" | ||
}, | ||
{ | ||
heading: "Miscellaneous" | ||
}, | ||
{ | ||
option: "init", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Run config initialization wizard" | ||
}, | ||
{ | ||
option: "env-info", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Output execution environment information" | ||
}, | ||
{ | ||
option: "error-on-unmatched-pattern", | ||
type: "Boolean", | ||
default: "true", | ||
description: "Prevent errors when pattern is unmatched" | ||
}, | ||
{ | ||
option: "exit-on-fatal-error", | ||
type: "Boolean", | ||
default: "false", | ||
description: "Exit with exit code 2 in case of fatal error" | ||
}, | ||
{ | ||
option: "debug", | ||
type: "Boolean", | ||
default: false, | ||
description: "Output debugging information" | ||
}, | ||
{ | ||
option: "help", | ||
alias: "h", | ||
type: "Boolean", | ||
description: "Show help" | ||
}, | ||
{ | ||
option: "version", | ||
alias: "v", | ||
type: "Boolean", | ||
description: "Output the version number" | ||
}, | ||
{ | ||
option: "print-config", | ||
type: "path::String", | ||
description: "Print the configuration for the given file" | ||
} | ||
].filter(value => !!value) | ||
}); | ||
}; |
@@ -7,3 +7,3 @@ /** | ||
/* eslint-env mocha -- Mocha/Jest wrapper */ | ||
/* globals describe, it -- Mocha globals */ | ||
@@ -10,0 +10,0 @@ //------------------------------------------------------------------------------ |
@@ -7,3 +7,3 @@ /** | ||
/* eslint-env mocha -- Mocha wrapper */ | ||
/* globals describe, it -- Mocha globals */ | ||
@@ -10,0 +10,0 @@ /* |
@@ -79,2 +79,6 @@ /** | ||
default: "" | ||
}, | ||
allowEmptyCase: { | ||
type: "boolean", | ||
default: false | ||
} | ||
@@ -95,2 +99,3 @@ }, | ||
const sourceCode = context.getSourceCode(); | ||
const allowEmptyCase = options.allowEmptyCase || false; | ||
@@ -109,3 +114,2 @@ /* | ||
} | ||
return { | ||
@@ -125,3 +129,4 @@ onCodePathStart(codePath) { | ||
*/ | ||
if (fallthroughCase && !hasFallthroughComment(fallthroughCase, node, context, fallthroughCommentPattern)) { | ||
if (fallthroughCase && (!hasFallthroughComment(fallthroughCase, node, context, fallthroughCommentPattern))) { | ||
context.report({ | ||
@@ -144,3 +149,3 @@ messageId: node.test ? "case" : "default", | ||
if (currentCodePath.currentSegments.some(isReachable) && | ||
(node.consequent.length > 0 || hasBlankLinesBetween(node, nextToken)) && | ||
(node.consequent.length > 0 || (!allowEmptyCase && hasBlankLinesBetween(node, nextToken))) && | ||
node.parent.cases[node.parent.cases.length - 1] !== node) { | ||
@@ -147,0 +152,0 @@ fallthroughCase = node; |
@@ -94,3 +94,3 @@ /** | ||
// ES6: report blocks without block-level bindings, or that's only child of another block | ||
if (context.parserOptions.ecmaVersion >= 6) { | ||
if (context.languageOptions.ecmaVersion >= 2015) { | ||
ruleDef = { | ||
@@ -97,0 +97,0 @@ BlockStatement(node) { |
@@ -40,2 +40,11 @@ /** | ||
enum: ["start", "anywhere"] | ||
}, | ||
decoration: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
pattern: "^\\S$" | ||
}, | ||
minItems: 1, | ||
uniqueItems: true | ||
} | ||
@@ -57,2 +66,3 @@ }, | ||
location = configuration.location || "start", | ||
decoration = [...configuration.decoration || []].join(""), | ||
selfConfigRegEx = /\bno-warning-comments\b/u; | ||
@@ -69,2 +79,3 @@ | ||
const escaped = escapeRegExp(term); | ||
const escapedDecoration = escapeRegExp(decoration); | ||
@@ -80,7 +91,12 @@ /* | ||
* e.g. terms ["TODO"] matches `// something TODO` | ||
* \s* handles optional leading spaces (for "start" location only) | ||
* e.g. terms ["TODO"] matches `// TODO something` | ||
* \b handles terms preceded/followed by word boundary | ||
* e.g. terms: ["!FIX", "FIX!"] matches `// FIX!something` or `// something!FIX` | ||
* terms: ["FIX"] matches `// FIX!` or `// !FIX`, but not `// fixed or affix` | ||
* | ||
* For location start: | ||
* [\s]* handles optional leading spaces | ||
* e.g. terms ["TODO"] matches `// TODO something` | ||
* [\s\*]* (where "\*" is the escaped string of decoration) | ||
* handles optional leading spaces or decoration characters (for "start" location only) | ||
* e.g. terms ["TODO"] matches `/**** TODO something ... ` | ||
*/ | ||
@@ -92,3 +108,3 @@ const wordBoundary = "\\b"; | ||
if (location === "start") { | ||
prefix = "^\\s*"; | ||
prefix = `^[\\s${escapedDecoration}]*`; | ||
} else if (/^\w/u.test(term)) { | ||
@@ -103,3 +119,6 @@ prefix = wordBoundary; | ||
* For location "start", the typical regex is: | ||
* /^\s*ESCAPED_TERM\b/iu. | ||
* /^[\s]*ESCAPED_TERM\b/iu. | ||
* Or if decoration characters are specified (e.g. "*"), then any of | ||
* those characters may appear in any order at the start: | ||
* /^[\s\*]*ESCAPED_TERM\b/iu. | ||
* | ||
@@ -109,3 +128,3 @@ * For location "anywhere" the typical regex is | ||
* | ||
* If it starts or ends with non-word character, the prefix and suffix empty, respectively. | ||
* If it starts or ends with non-word character, the prefix and suffix are empty, respectively. | ||
*/ | ||
@@ -112,0 +131,0 @@ return new RegExp(`${prefix}${escaped}${suffix}`, flags); |
@@ -24,3 +24,3 @@ /** | ||
* @property {EcmaFeatures} [ecmaFeatures] The optional features. | ||
* @property {3|5|6|7|8|9|10|11|12|13|2015|2016|2017|2018|2019|2020|2021|2022} [ecmaVersion] The ECMAScript version (or revision number). | ||
* @property {3|5|6|7|8|9|10|11|12|13|14|2015|2016|2017|2018|2019|2020|2021|2022|2023} [ecmaVersion] The ECMAScript version (or revision number). | ||
* @property {"script"|"module"} [sourceType] The source code type. | ||
@@ -27,0 +27,0 @@ * @property {boolean} [allowReserved] Allowing the use of reserved words as identifiers in ES3. |
{ | ||
"name": "eslint", | ||
"version": "8.22.0", | ||
"version": "8.23.0", | ||
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>", | ||
@@ -58,5 +58,6 @@ "description": "An AST-based pattern checker for JavaScript.", | ||
"dependencies": { | ||
"@eslint/eslintrc": "^1.3.0", | ||
"@eslint/eslintrc": "^1.3.1", | ||
"@humanwhocodes/config-array": "^0.10.4", | ||
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2", | ||
"@humanwhocodes/module-importer": "^1.0.1", | ||
"ajv": "^6.10.0", | ||
@@ -71,3 +72,3 @@ "chalk": "^4.0.0", | ||
"eslint-visitor-keys": "^3.3.0", | ||
"espree": "^9.3.3", | ||
"espree": "^9.4.0", | ||
"esquery": "^1.4.0", | ||
@@ -97,4 +98,3 @@ "esutils": "^2.0.2", | ||
"strip-json-comments": "^3.1.0", | ||
"text-table": "^0.2.0", | ||
"v8-compile-cache": "^2.0.3" | ||
"text-table": "^0.2.0" | ||
}, | ||
@@ -101,0 +101,0 @@ "devDependencies": { |
Sorry, the diff of this file is too big to display
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
2803896
66636
14
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
- Removedv8-compile-cache@^2.0.3
- Removedv8-compile-cache@2.4.0(transitive)
Updated@eslint/eslintrc@^1.3.1
Updatedespree@^9.4.0