]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/options.js
import 8.23.1 source
[pve-eslint.git] / eslint / lib / options.js
1 /**
2 * @fileoverview Options configuration for optionator.
3 * @author George Zahariev
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const optionator = require("optionator");
13
14 //------------------------------------------------------------------------------
15 // Typedefs
16 //------------------------------------------------------------------------------
17
18 /**
19 * The options object parsed by Optionator.
20 * @typedef {Object} ParsedCLIOptions
21 * @property {boolean} cache Only check changed files
22 * @property {string} cacheFile Path to the cache file. Deprecated: use --cache-location
23 * @property {string} [cacheLocation] Path to the cache file or directory
24 * @property {"metadata" | "content"} cacheStrategy Strategy to use for detecting changed files in the cache
25 * @property {boolean} [color] Force enabling/disabling of color
26 * @property {string} [config] Use this configuration, overriding .eslintrc.* config options if present
27 * @property {boolean} debug Output debugging information
28 * @property {string[]} [env] Specify environments
29 * @property {boolean} envInfo Output execution environment information
30 * @property {boolean} errorOnUnmatchedPattern Prevent errors when pattern is unmatched
31 * @property {boolean} eslintrc Disable use of configuration from .eslintrc.*
32 * @property {string[]} [ext] Specify JavaScript file extensions
33 * @property {boolean} fix Automatically fix problems
34 * @property {boolean} fixDryRun Automatically fix problems without saving the changes to the file system
35 * @property {("directive" | "problem" | "suggestion" | "layout")[]} [fixType] Specify the types of fixes to apply (directive, problem, suggestion, layout)
36 * @property {string} format Use a specific output format
37 * @property {string[]} [global] Define global variables
38 * @property {boolean} [help] Show help
39 * @property {boolean} ignore Disable use of ignore files and patterns
40 * @property {string} [ignorePath] Specify path of ignore file
41 * @property {string[]} [ignorePattern] Pattern of files to ignore (in addition to those in .eslintignore)
42 * @property {boolean} init Run config initialization wizard
43 * @property {boolean} inlineConfig Prevent comments from changing config or rules
44 * @property {number} maxWarnings Number of warnings to trigger nonzero exit code
45 * @property {string} [outputFile] Specify file to write report to
46 * @property {string} [parser] Specify the parser to be used
47 * @property {Object} [parserOptions] Specify parser options
48 * @property {string[]} [plugin] Specify plugins
49 * @property {string} [printConfig] Print the configuration for the given file
50 * @property {boolean | undefined} reportUnusedDisableDirectives Adds reported errors for unused eslint-disable directives
51 * @property {string} [resolvePluginsRelativeTo] A folder where plugins should be resolved from, CWD by default
52 * @property {Object} [rule] Specify rules
53 * @property {string[]} [rulesdir] Load additional rules from this directory. Deprecated: Use rules from plugins
54 * @property {boolean} stdin Lint code provided on <STDIN>
55 * @property {string} [stdinFilename] Specify filename to process STDIN as
56 * @property {boolean} quiet Report errors only
57 * @property {boolean} [version] Output the version number
58 * @property {string[]} _ Positional filenames or patterns
59 */
60
61 //------------------------------------------------------------------------------
62 // Initialization and Public Interface
63 //------------------------------------------------------------------------------
64
65 // exports "parse(args)", "generateHelp()", and "generateHelpForOption(optionName)"
66
67 /**
68 * Creates the CLI options for ESLint.
69 * @param {boolean} usingFlatConfig Indicates if flat config is being used.
70 * @returns {Object} The opinionator instance.
71 */
72 module.exports = function(usingFlatConfig) {
73
74 let lookupFlag;
75
76 if (usingFlatConfig) {
77 lookupFlag = {
78 option: "config-lookup",
79 type: "Boolean",
80 default: "true",
81 description: "Disable look up for eslint.config.js"
82 };
83 } else {
84 lookupFlag = {
85 option: "eslintrc",
86 type: "Boolean",
87 default: "true",
88 description: "Disable use of configuration from .eslintrc.*"
89 };
90 }
91
92 let envFlag;
93
94 if (!usingFlatConfig) {
95 envFlag = {
96 option: "env",
97 type: "[String]",
98 description: "Specify environments"
99 };
100 }
101
102 let extFlag;
103
104 if (!usingFlatConfig) {
105 extFlag = {
106 option: "ext",
107 type: "[String]",
108 description: "Specify JavaScript file extensions"
109 };
110 }
111
112 let resolvePluginsFlag;
113
114 if (!usingFlatConfig) {
115 resolvePluginsFlag = {
116 option: "resolve-plugins-relative-to",
117 type: "path::String",
118 description: "A folder where plugins should be resolved from, CWD by default"
119 };
120 }
121
122 let rulesDirFlag;
123
124 if (!usingFlatConfig) {
125 rulesDirFlag = {
126 option: "rulesdir",
127 type: "[path::String]",
128 description: "Load additional rules from this directory. Deprecated: Use rules from plugins"
129 };
130 }
131
132 return optionator({
133 prepend: "eslint [options] file.js [file.js] [dir]",
134 defaults: {
135 concatRepeatedArrays: true,
136 mergeRepeatedObjects: true
137 },
138 options: [
139 {
140 heading: "Basic configuration"
141 },
142 lookupFlag,
143 {
144 option: "config",
145 alias: "c",
146 type: "path::String",
147 description: usingFlatConfig
148 ? "Use this configuration instead of eslint.config.js"
149 : "Use this configuration, overriding .eslintrc.* config options if present"
150 },
151 envFlag,
152 extFlag,
153 {
154 option: "global",
155 type: "[String]",
156 description: "Define global variables"
157 },
158 {
159 option: "parser",
160 type: "String",
161 description: "Specify the parser to be used"
162 },
163 {
164 option: "parser-options",
165 type: "Object",
166 description: "Specify parser options"
167 },
168 resolvePluginsFlag,
169 {
170 heading: "Specifying rules and plugins"
171 },
172 {
173 option: "plugin",
174 type: "[String]",
175 description: "Specify plugins"
176 },
177 {
178 option: "rule",
179 type: "Object",
180 description: "Specify rules"
181 },
182 rulesDirFlag,
183 {
184 heading: "Fixing problems"
185 },
186 {
187 option: "fix",
188 type: "Boolean",
189 default: false,
190 description: "Automatically fix problems"
191 },
192 {
193 option: "fix-dry-run",
194 type: "Boolean",
195 default: false,
196 description: "Automatically fix problems without saving the changes to the file system"
197 },
198 {
199 option: "fix-type",
200 type: "Array",
201 description: "Specify the types of fixes to apply (directive, problem, suggestion, layout)"
202 },
203 {
204 heading: "Ignoring files"
205 },
206 {
207 option: "ignore-path",
208 type: "path::String",
209 description: "Specify path of ignore file"
210 },
211 {
212 option: "ignore",
213 type: "Boolean",
214 default: "true",
215 description: "Disable use of ignore files and patterns"
216 },
217 {
218 option: "ignore-pattern",
219 type: "[String]",
220 description: "Pattern of files to ignore (in addition to those in .eslintignore)",
221 concatRepeatedArrays: [true, {
222 oneValuePerFlag: true
223 }]
224 },
225 {
226 heading: "Using stdin"
227 },
228 {
229 option: "stdin",
230 type: "Boolean",
231 default: "false",
232 description: "Lint code provided on <STDIN>"
233 },
234 {
235 option: "stdin-filename",
236 type: "String",
237 description: "Specify filename to process STDIN as"
238 },
239 {
240 heading: "Handling warnings"
241 },
242 {
243 option: "quiet",
244 type: "Boolean",
245 default: "false",
246 description: "Report errors only"
247 },
248 {
249 option: "max-warnings",
250 type: "Int",
251 default: "-1",
252 description: "Number of warnings to trigger nonzero exit code"
253 },
254 {
255 heading: "Output"
256 },
257 {
258 option: "output-file",
259 alias: "o",
260 type: "path::String",
261 description: "Specify file to write report to"
262 },
263 {
264 option: "format",
265 alias: "f",
266 type: "String",
267 default: "stylish",
268 description: "Use a specific output format"
269 },
270 {
271 option: "color",
272 type: "Boolean",
273 alias: "no-color",
274 description: "Force enabling/disabling of color"
275 },
276 {
277 heading: "Inline configuration comments"
278 },
279 {
280 option: "inline-config",
281 type: "Boolean",
282 default: "true",
283 description: "Prevent comments from changing config or rules"
284 },
285 {
286 option: "report-unused-disable-directives",
287 type: "Boolean",
288 default: void 0,
289 description: "Adds reported errors for unused eslint-disable directives"
290 },
291 {
292 heading: "Caching"
293 },
294 {
295 option: "cache",
296 type: "Boolean",
297 default: "false",
298 description: "Only check changed files"
299 },
300 {
301 option: "cache-file",
302 type: "path::String",
303 default: ".eslintcache",
304 description: "Path to the cache file. Deprecated: use --cache-location"
305 },
306 {
307 option: "cache-location",
308 type: "path::String",
309 description: "Path to the cache file or directory"
310 },
311 {
312 option: "cache-strategy",
313 dependsOn: ["cache"],
314 type: "String",
315 default: "metadata",
316 enum: ["metadata", "content"],
317 description: "Strategy to use for detecting changed files in the cache"
318 },
319 {
320 heading: "Miscellaneous"
321 },
322 {
323 option: "init",
324 type: "Boolean",
325 default: "false",
326 description: "Run config initialization wizard"
327 },
328 {
329 option: "env-info",
330 type: "Boolean",
331 default: "false",
332 description: "Output execution environment information"
333 },
334 {
335 option: "error-on-unmatched-pattern",
336 type: "Boolean",
337 default: "true",
338 description: "Prevent errors when pattern is unmatched"
339 },
340 {
341 option: "exit-on-fatal-error",
342 type: "Boolean",
343 default: "false",
344 description: "Exit with exit code 2 in case of fatal error"
345 },
346 {
347 option: "debug",
348 type: "Boolean",
349 default: false,
350 description: "Output debugging information"
351 },
352 {
353 option: "help",
354 alias: "h",
355 type: "Boolean",
356 description: "Show help"
357 },
358 {
359 option: "version",
360 alias: "v",
361 type: "Boolean",
362 description: "Output the version number"
363 },
364 {
365 option: "print-config",
366 type: "path::String",
367 description: "Print the configuration for the given file"
368 }
369 ].filter(value => !!value)
370 });
371 };