Coverage for C:\Repos\ekr-pylint\pylint\lint\base_options.py: 79%
14 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
1# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
5"""Functions that creates the basic options for the Run and PyLinter classes."""
7from __future__ import annotations
9import re
10import sys
11from typing import TYPE_CHECKING
13from pylint import interfaces
14from pylint.config.callback_actions import (
15 _DisableAction,
16 _DoNothingAction,
17 _EnableAction,
18 _ErrorsOnlyModeAction,
19 _FullDocumentationAction,
20 _GenerateConfigFileAction,
21 _GenerateRCFileAction,
22 _ListCheckGroupsAction,
23 _ListConfidenceLevelsAction,
24 _ListExtensionsAction,
25 _ListMessagesAction,
26 _ListMessagesEnabledAction,
27 _LongHelpAction,
28 _MessageHelpAction,
29 _OutputFormatAction,
30)
31from pylint.typing import Options
33if TYPE_CHECKING:
34 from pylint.lint import PyLinter, Run
37def _make_linter_options(linter: PyLinter) -> Options:
38 """Return the options used in a PyLinter class."""
39 return (
40 (
41 "ignore",
42 {
43 "type": "csv",
44 "metavar": "<file>[,<file>...]",
45 "dest": "black_list",
46 "kwargs": {"old_names": ["black_list"]},
47 "default": ("CVS",),
48 "help": "Files or directories to be skipped. "
49 "They should be base names, not paths.",
50 },
51 ),
52 (
53 "ignore-patterns",
54 {
55 "type": "regexp_csv",
56 "metavar": "<pattern>[,<pattern>...]",
57 "dest": "black_list_re",
58 "default": (re.compile(r"^\.#"),),
59 "help": "Files or directories matching the regex patterns are"
60 " skipped. The regex matches against base names, not paths. The default value "
61 "ignores Emacs file locks",
62 },
63 ),
64 (
65 "ignore-paths",
66 {
67 "type": "regexp_paths_csv",
68 "metavar": "<pattern>[,<pattern>...]",
69 "default": [],
70 "help": "Add files or directories matching the regex patterns to the "
71 "ignore-list. The regex matches against paths and can be in "
72 "Posix or Windows format.",
73 },
74 ),
75 (
76 "persistent",
77 {
78 "default": True,
79 "type": "yn",
80 "metavar": "<y or n>",
81 "help": "Pickle collected data for later comparisons.",
82 },
83 ),
84 (
85 "load-plugins",
86 {
87 "type": "csv",
88 "metavar": "<modules>",
89 "default": (),
90 "help": "List of plugins (as comma separated values of "
91 "python module names) to load, usually to register "
92 "additional checkers.",
93 },
94 ),
95 (
96 "output-format",
97 {
98 "default": "text",
99 "action": _OutputFormatAction,
100 "callback": lambda x: x,
101 "metavar": "<format>",
102 "short": "f",
103 "group": "Reports",
104 "help": "Set the output format. Available formats are text,"
105 " parseable, colorized, json and msvs (visual studio)."
106 " You can also give a reporter class, e.g. mypackage.mymodule."
107 "MyReporterClass.",
108 "kwargs": {"linter": linter},
109 },
110 ),
111 (
112 "reports",
113 {
114 "default": False,
115 "type": "yn",
116 "metavar": "<y or n>",
117 "short": "r",
118 "group": "Reports",
119 "help": "Tells whether to display a full report or only the "
120 "messages.",
121 },
122 ),
123 (
124 "evaluation",
125 {
126 "type": "string",
127 "metavar": "<python_expression>",
128 "group": "Reports",
129 "default": "max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + "
130 "convention) / statement) * 10))",
131 "help": "Python expression which should return a score less "
132 "than or equal to 10. You have access to the variables 'fatal', "
133 "'error', 'warning', 'refactor', 'convention', and 'info' which "
134 "contain the number of messages in each category, as well as "
135 "'statement' which is the total number of statements "
136 "analyzed. This score is used by the global "
137 "evaluation report (RP0004).",
138 },
139 ),
140 (
141 "score",
142 {
143 "default": True,
144 "type": "yn",
145 "metavar": "<y or n>",
146 "short": "s",
147 "group": "Reports",
148 "help": "Activate the evaluation score.",
149 },
150 ),
151 (
152 "fail-under",
153 {
154 "default": 10,
155 "type": "float",
156 "metavar": "<score>",
157 "help": "Specify a score threshold to be exceeded before program exits with error.",
158 },
159 ),
160 (
161 "fail-on",
162 {
163 "default": "",
164 "type": "csv",
165 "metavar": "<msg ids>",
166 "help": "Return non-zero exit code if any of these messages/categories are detected,"
167 " even if score is above --fail-under value. Syntax same as enable."
168 " Messages specified are enabled, while categories only check already-enabled messages.",
169 },
170 ),
171 (
172 "confidence",
173 {
174 "type": "confidence",
175 "metavar": "<levels>",
176 "default": interfaces.CONFIDENCE_LEVEL_NAMES,
177 "group": "Messages control",
178 "help": "Only show warnings with the listed confidence levels."
179 f" Leave empty to show all. Valid levels: {', '.join(interfaces.CONFIDENCE_LEVEL_NAMES)}.",
180 },
181 ),
182 (
183 "enable",
184 {
185 "action": _EnableAction,
186 "callback": lambda x1, x2, x3, x4: x1,
187 "default": (),
188 "metavar": "<msg ids>",
189 "short": "e",
190 "group": "Messages control",
191 "help": "Enable the message, report, category or checker with the "
192 "given id(s). You can either give multiple identifier "
193 "separated by comma (,) or put this option multiple time "
194 "(only on the command line, not in the configuration file "
195 "where it should appear only once). "
196 'See also the "--disable" option for examples.',
197 "kwargs": {"linter": linter},
198 },
199 ),
200 (
201 "disable",
202 {
203 "action": _DisableAction,
204 "callback": lambda x1, x2, x3, x4: x1,
205 "metavar": "<msg ids>",
206 "default": (),
207 "short": "d",
208 "group": "Messages control",
209 "help": "Disable the message, report, category or checker "
210 "with the given id(s). You can either give multiple identifiers "
211 "separated by comma (,) or put this option multiple times "
212 "(only on the command line, not in the configuration file "
213 "where it should appear only once). "
214 'You can also use "--disable=all" to disable everything first '
215 "and then re-enable specific checks. For example, if you want "
216 "to run only the similarities checker, you can use "
217 '"--disable=all --enable=similarities". '
218 "If you want to run only the classes checker, but have no "
219 "Warning level messages displayed, use "
220 '"--disable=all --enable=classes --disable=W".',
221 "kwargs": {"linter": linter},
222 },
223 ),
224 (
225 "msg-template",
226 {
227 "type": "string",
228 "default": "",
229 "metavar": "<template>",
230 "group": "Reports",
231 "help": (
232 "Template used to display messages. "
233 "This is a python new-style format string "
234 "used to format the message information. "
235 "See doc for all details."
236 ),
237 },
238 ),
239 (
240 "jobs",
241 {
242 "type": "int",
243 "metavar": "<n-processes>",
244 "short": "j",
245 "default": 1,
246 "help": "Use multiple processes to speed up Pylint. Specifying 0 will "
247 "auto-detect the number of processors available to use.",
248 },
249 ),
250 (
251 "unsafe-load-any-extension",
252 {
253 "type": "yn",
254 "metavar": "<y or n>",
255 "default": False,
256 "hide": True,
257 "help": (
258 "Allow loading of arbitrary C extensions. Extensions"
259 " are imported into the active Python interpreter and"
260 " may run arbitrary code."
261 ),
262 },
263 ),
264 (
265 "limit-inference-results",
266 {
267 "type": "int",
268 "metavar": "<number-of-results>",
269 "default": 100,
270 "help": (
271 "Control the amount of potential inferred values when inferring "
272 "a single object. This can help the performance when dealing with "
273 "large functions or complex, nested conditions."
274 ),
275 },
276 ),
277 (
278 "extension-pkg-allow-list",
279 {
280 "type": "csv",
281 "metavar": "<pkg[,pkg]>",
282 "default": [],
283 "help": (
284 "A comma-separated list of package or module names"
285 " from where C extensions may be loaded. Extensions are"
286 " loading into the active Python interpreter and may run"
287 " arbitrary code."
288 ),
289 },
290 ),
291 (
292 "extension-pkg-whitelist",
293 {
294 "type": "csv",
295 "metavar": "<pkg[,pkg]>",
296 "default": [],
297 "help": (
298 "A comma-separated list of package or module names"
299 " from where C extensions may be loaded. Extensions are"
300 " loading into the active Python interpreter and may run"
301 " arbitrary code. (This is an alternative name to"
302 " extension-pkg-allow-list for backward compatibility.)"
303 ),
304 },
305 ),
306 (
307 "suggestion-mode",
308 {
309 "type": "yn",
310 "metavar": "<y or n>",
311 "default": True,
312 "help": (
313 "When enabled, pylint would attempt to guess common "
314 "misconfiguration and emit user-friendly hints instead "
315 "of false-positive error messages."
316 ),
317 },
318 ),
319 (
320 "exit-zero",
321 {
322 "action": "store_true",
323 "default": False,
324 "metavar": "<flag>",
325 "help": (
326 "Always return a 0 (non-error) status code, even if "
327 "lint errors are found. This is primarily useful in "
328 "continuous integration scripts."
329 ),
330 },
331 ),
332 (
333 "from-stdin",
334 {
335 "action": "store_true",
336 "default": False,
337 "metavar": "<flag>",
338 "help": (
339 "Interpret the stdin as a python script, whose filename "
340 "needs to be passed as the module_or_package argument."
341 ),
342 },
343 ),
344 (
345 "recursive",
346 {
347 "type": "yn",
348 "metavar": "<yn>",
349 "default": False,
350 "help": "Discover python modules and packages in the file system subtree.",
351 },
352 ),
353 (
354 "py-version",
355 {
356 "default": sys.version_info[:2],
357 "type": "py_version",
358 "metavar": "<py_version>",
359 "help": (
360 "Minimum Python version to use for version dependent checks. "
361 "Will default to the version used to run pylint."
362 ),
363 },
364 ),
365 (
366 "ignored-modules",
367 {
368 "default": (),
369 "type": "csv",
370 "metavar": "<module names>",
371 "help": "List of module names for which member attributes "
372 "should not be checked (useful for modules/projects "
373 "where namespaces are manipulated during runtime and "
374 "thus existing member attributes cannot be "
375 "deduced by static analysis). It supports qualified "
376 "module names, as well as Unix pattern matching.",
377 },
378 ),
379 (
380 "analyse-fallback-blocks",
381 {
382 "default": False,
383 "type": "yn",
384 "metavar": "<y or n>",
385 "help": "Analyse import fallback blocks. This can be used to "
386 "support both Python 2 and 3 compatible code, which "
387 "means that the block might have code that exists "
388 "only in one or another interpreter, leading to false "
389 "positives when analysed.",
390 },
391 ),
392 )
395def _make_run_options(self: Run) -> Options:
396 """Return the options used in a Run class."""
397 return (
398 (
399 "rcfile",
400 {
401 "action": _DoNothingAction,
402 "kwargs": {},
403 "group": "Commands",
404 "help": "Specify a configuration file to load.",
405 "hide_from_config_file": True,
406 },
407 ),
408 (
409 "output",
410 {
411 "action": _DoNothingAction,
412 "kwargs": {},
413 "group": "Commands",
414 "help": "Specify an output file.",
415 "hide_from_config_file": True,
416 },
417 ),
418 (
419 "init-hook",
420 {
421 "action": _DoNothingAction,
422 "kwargs": {},
423 "help": "Python code to execute, usually for sys.path "
424 "manipulation such as pygtk.require().",
425 },
426 ),
427 (
428 "help-msg",
429 {
430 "action": _MessageHelpAction,
431 "kwargs": {"Run": self},
432 "group": "Commands",
433 "help": "Display a help message for the given message id and "
434 "exit. The value may be a comma separated list of message ids.",
435 "hide_from_config_file": True,
436 },
437 ),
438 (
439 "list-msgs",
440 {
441 "action": _ListMessagesAction,
442 "kwargs": {"Run": self},
443 "group": "Commands",
444 "help": "Display a list of all pylint's messages divided by whether "
445 "they are emittable with the given interpreter.",
446 "hide_from_config_file": True,
447 },
448 ),
449 (
450 "list-msgs-enabled",
451 {
452 "action": _ListMessagesEnabledAction,
453 "kwargs": {"Run": self},
454 "group": "Commands",
455 "help": "Display a list of what messages are enabled, "
456 "disabled and non-emittable with the given configuration.",
457 "hide_from_config_file": True,
458 },
459 ),
460 (
461 "list-groups",
462 {
463 "action": _ListCheckGroupsAction,
464 "kwargs": {"Run": self},
465 "group": "Commands",
466 "help": "List pylint's message groups.",
467 "hide_from_config_file": True,
468 },
469 ),
470 (
471 "list-conf-levels",
472 {
473 "action": _ListConfidenceLevelsAction,
474 "kwargs": {"Run": self},
475 "group": "Commands",
476 "help": "Generate pylint's confidence levels.",
477 "hide_from_config_file": True,
478 },
479 ),
480 (
481 "list-extensions",
482 {
483 "action": _ListExtensionsAction,
484 "kwargs": {"Run": self},
485 "group": "Commands",
486 "help": "List available extensions.",
487 "hide_from_config_file": True,
488 },
489 ),
490 (
491 "full-documentation",
492 {
493 "action": _FullDocumentationAction,
494 "kwargs": {"Run": self},
495 "group": "Commands",
496 "help": "Generate pylint's full documentation.",
497 "hide_from_config_file": True,
498 },
499 ),
500 (
501 "generate-rcfile",
502 {
503 "action": _GenerateRCFileAction,
504 "kwargs": {"Run": self},
505 "group": "Commands",
506 "help": "Generate a sample configuration file according to "
507 "the current configuration. You can put other options "
508 "before this one to get them in the generated "
509 "configuration.",
510 "hide_from_config_file": True,
511 },
512 ),
513 (
514 "generate-toml-config",
515 {
516 "action": _GenerateConfigFileAction,
517 "kwargs": {"Run": self},
518 "group": "Commands",
519 "help": "Generate a sample configuration file according to "
520 "the current configuration. You can put other options "
521 "before this one to get them in the generated "
522 "configuration. The config is in the .toml format.",
523 "hide_from_config_file": True,
524 },
525 ),
526 (
527 "errors-only",
528 {
529 "action": _ErrorsOnlyModeAction,
530 "kwargs": {"Run": self},
531 "short": "E",
532 "help": "In error mode, checkers without error messages are "
533 "disabled and for others, only the ERROR messages are "
534 "displayed, and no reports are done by default.",
535 "hide_from_config_file": True,
536 },
537 ),
538 (
539 "verbose",
540 {
541 "action": _DoNothingAction,
542 "kwargs": {},
543 "short": "v",
544 "help": "In verbose mode, extra non-checker-related info "
545 "will be displayed.",
546 "hide_from_config_file": True,
547 "metavar": "",
548 },
549 ),
550 (
551 "enable-all-extensions",
552 {
553 "action": _DoNothingAction,
554 "kwargs": {},
555 "help": "Load and enable all available extensions. "
556 "Use --list-extensions to see a list all available extensions.",
557 "hide_from_config_file": True,
558 "metavar": "",
559 },
560 ),
561 (
562 "long-help",
563 {
564 "action": _LongHelpAction,
565 "kwargs": {"Run": self},
566 "help": "Show more verbose help.",
567 "group": "Commands",
568 "hide_from_config_file": True,
569 },
570 ),
571 )