Spaces:
Sleeping
Sleeping
File size: 11,942 Bytes
443c22e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | /**
* @fileoverview Options configuration for optionator.
* @author George Zahariev
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const optionator = require("optionator");
//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------
/**
* The options object parsed by Optionator.
* @typedef {Object} ParsedCLIOptions
* @property {boolean} cache Only check changed files
* @property {string} cacheFile Path to the cache file. Deprecated: use --cache-location
* @property {string} [cacheLocation] Path to the cache file or directory
* @property {"metadata" | "content"} cacheStrategy Strategy to use for detecting changed files in the cache
* @property {boolean} [color] Force enabling/disabling of color
* @property {number | "auto" | "off"} [concurrency] Number of linting threads, "auto" to choose automatically, "off" for no multithreading
* @property {string} [config] Use this configuration, overriding eslint.config.* config options if present
* @property {boolean} debug Output debugging information
* @property {boolean} envInfo Output execution environment information
* @property {boolean} errorOnUnmatchedPattern Prevent errors when pattern is unmatched
* @property {string[]} [ext] Specify JavaScript file extensions
* @property {string[]} [flag] Feature flags
* @property {boolean} fix Automatically fix problems
* @property {boolean} fixDryRun Automatically fix problems without saving the changes to the file system
* @property {("directive" | "problem" | "suggestion" | "layout")[]} [fixType] Specify the types of fixes to apply (directive, problem, suggestion, layout)
* @property {string} format Use a specific output format
* @property {string[]} [global] Define global variables
* @property {boolean} [help] Show help
* @property {boolean} ignore Disable use of ignore files and patterns
* @property {string[]} [ignorePattern] Patterns of files to ignore
* @property {boolean} init Run config initialization wizard
* @property {boolean} inlineConfig Prevent comments from changing config or rules
* @property {number} maxWarnings Number of warnings to trigger nonzero exit code
* @property {string} [outputFile] Specify file to write report to
* @property {string} [parser] Specify the parser to be used
* @property {Object} [parserOptions] Specify parser options
* @property {boolean} [passOnNoPatterns=false] When set to true, missing patterns cause
* the linting operation to short circuit and not report any failures.
* @property {boolean} [passOnUnprunedSuppressions] Ignore unused suppressions
* @property {string[]} [plugin] Specify plugins
* @property {string} [printConfig] Print the configuration for the given file
* @property {boolean} [pruneSuppressions] Prune unused suppressions
* @property {boolean} quiet Report errors only
* @property {boolean | undefined} reportUnusedDisableDirectives Adds reported errors for unused eslint-disable and eslint-enable directives
* @property {string | undefined} reportUnusedDisableDirectivesSeverity A severity string indicating if and how unused disable and enable directives should be tracked and reported.
* @property {Object} [rule] Specify rules
* @property {boolean} [stats] Report additional statistics
* @property {boolean} stdin Lint code provided on <STDIN>
* @property {string} [stdinFilename] Specify filename to process STDIN as
* @property {boolean} [suppressAll] Suppress all error violations
* @property {string} [suppressionsLocation] Path to the suppressions file or directory
* @property {string[]} [suppressRule] Suppress specific rules
* @property {boolean} [version] Output the version number
* @property {boolean} warnIgnored Show warnings when the file list includes ignored files
* @property {string[]} _ Positional filenames or patterns
*/
//------------------------------------------------------------------------------
// Initialization and Public Interface
//------------------------------------------------------------------------------
// exports "parse(args)", "generateHelp()", and "generateHelpForOption(optionName)"
/**
* Creates the CLI options for ESLint.
* @returns {Object} The optionator instance.
*/
module.exports = function () {
return optionator({
prepend: "eslint [options] file.js [file.js] [dir]",
defaults: {
concatRepeatedArrays: true,
mergeRepeatedObjects: true,
},
options: [
{
heading: "Basic configuration",
},
{
option: "config-lookup",
type: "Boolean",
default: "true",
description: "Disable look up for eslint.config.js",
},
{
option: "config",
alias: "c",
type: "path::String",
description:
"Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs",
},
{
option: "inspect-config",
type: "Boolean",
description:
"Open the config inspector with the current configuration",
},
{
option: "ext",
type: "[String]",
description: "Specify additional file extensions to lint",
},
{
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",
},
{
heading: "Specify Rules and Plugins",
},
{
option: "plugin",
type: "[String]",
description: "Specify plugins",
},
{
option: "rule",
type: "Object",
description: "Specify rules",
},
{
heading: "Fix 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: "Ignore Files",
},
{
option: "ignore",
type: "Boolean",
default: "true",
description: "Disable use of ignore files and patterns",
},
{
option: "ignore-pattern",
type: "[String]",
description: "Patterns of files to ignore",
concatRepeatedArrays: [
true,
{
oneValuePerFlag: true,
},
],
},
{
heading: "Use 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: "Handle 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 and eslint-enable directives",
},
{
option: "report-unused-disable-directives-severity",
type: "String",
default: void 0,
description:
"Chooses severity level for reporting unused eslint-disable and eslint-enable directives",
enum: ["off", "warn", "error", "0", "1", "2"],
},
{
option: "report-unused-inline-configs",
type: "String",
default: void 0,
description:
"Adds reported errors for unused eslint inline config comments",
enum: ["off", "warn", "error", "0", "1", "2"],
},
{
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: "Suppressing Violations",
},
{
option: "suppress-all",
type: "Boolean",
default: "false",
description: "Suppress all violations",
},
{
option: "suppress-rule",
type: "[String]",
description: "Suppress specific rules",
},
{
option: "suppressions-location",
type: "path::String",
description: "Specify the location of the suppressions file",
},
{
option: "prune-suppressions",
type: "Boolean",
default: "false",
description: "Prune unused suppressions",
},
{
option: "pass-on-unpruned-suppressions",
type: "Boolean",
default: "false",
description: "Ignore unused suppressions",
},
{
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: "warn-ignored",
type: "Boolean",
default: "true",
description:
"Suppress warnings when the file list includes ignored files",
},
{
option: "pass-on-no-patterns",
type: "Boolean",
default: false,
description:
"Exit with exit code 0 in case no file patterns are passed",
},
{
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",
},
{
option: "stats",
type: "Boolean",
default: "false",
description: "Add statistics to the lint report",
},
{
option: "flag",
type: "[String]",
description: "Enable a feature flag",
},
{
option: "mcp",
type: "Boolean",
description: "Start the ESLint MCP server",
},
{
option: "concurrency",
type: "Int|String",
default: "off",
description:
"Number of linting threads, auto to choose automatically, off for no multithreading",
},
],
});
};
|