# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html # For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Functions that creates the basic options for the Run and PyLinter classes.""" from __future__ import annotations import re import sys from typing import TYPE_CHECKING from pylint import constants, interfaces from pylint.config.callback_actions import ( _DisableAction, _DoNothingAction, _EnableAction, _ErrorsOnlyModeAction, _FullDocumentationAction, _GenerateConfigFileAction, _GenerateRCFileAction, _ListCheckGroupsAction, _ListConfidenceLevelsAction, _ListExtensionsAction, _ListMessagesAction, _ListMessagesEnabledAction, _LongHelpAction, _MessageHelpAction, _OutputFormatAction, ) from pylint.typing import Options if TYPE_CHECKING: from pylint.lint import PyLinter, Run def _make_linter_options(linter: PyLinter) -> Options: """Return the options used in a PyLinter class.""" return ( ( "ignore", { "type": "csv", "metavar": "[,...]", "dest": "black_list", "kwargs": {"old_names": ["black_list"]}, "default": constants.DEFAULT_IGNORE_LIST, "help": "Files or directories to be skipped. " "They should be base names, not paths.", }, ), ( "ignore-patterns", { "type": "regexp_csv", "metavar": "[,...]", "dest": "black_list_re", "default": (re.compile(r"^\.#"),), "help": "Files or directories matching the regular expression patterns are" " skipped. The regex matches against base names, not paths. The default value " "ignores Emacs file locks", }, ), ( "ignore-paths", { "type": "regexp_paths_csv", "metavar": "[,...]", "default": [], "help": "Add files or directories matching the regular expressions patterns to the " "ignore-list. The regex matches against paths and can be in " "Posix or Windows format. Because '\\\\' represents the directory delimiter " "on Windows systems, it can't be used as an escape character.", }, ), ( "persistent", { "default": True, "type": "yn", "metavar": "", "help": "Pickle collected data for later comparisons.", }, ), ( "load-plugins", { "type": "csv", "metavar": "", "default": (), "help": "List of plugins (as comma separated values of " "python module names) to load, usually to register " "additional checkers.", }, ), ( "output-format", { "default": "text", "action": _OutputFormatAction, "callback": lambda x: x, "metavar": "", "short": "f", "group": "Reports", "help": "Set the output format. Available formats are text," " parseable, colorized, json and msvs (visual studio)." " You can also give a reporter class, e.g. mypackage.mymodule." "MyReporterClass.", "kwargs": {"linter": linter}, }, ), ( "reports", { "default": False, "type": "yn", "metavar": "", "short": "r", "group": "Reports", "help": "Tells whether to display a full report or only the " "messages.", }, ), ( "evaluation", { "type": "string", "metavar": "", "group": "Reports", "default": "max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + " "convention) / statement) * 10))", "help": "Python expression which should return a score less " "than or equal to 10. You have access to the variables 'fatal', " "'error', 'warning', 'refactor', 'convention', and 'info' which " "contain the number of messages in each category, as well as " "'statement' which is the total number of statements " "analyzed. This score is used by the global " "evaluation report (RP0004).", }, ), ( "score", { "default": True, "type": "yn", "metavar": "", "short": "s", "group": "Reports", "help": "Activate the evaluation score.", }, ), ( "fail-under", { "default": 10, "type": "float", "metavar": "", "help": "Specify a score threshold under which the program will exit with error.", }, ), ( "fail-on", { "default": "", "type": "csv", "metavar": "", "help": "Return non-zero exit code if any of these messages/categories are detected," " even if score is above --fail-under value. Syntax same as enable." " Messages specified are enabled, while categories only check already-enabled messages.", }, ), ( "confidence", { "type": "confidence", "metavar": "", "default": interfaces.CONFIDENCE_LEVEL_NAMES, "group": "Messages control", "help": "Only show warnings with the listed confidence levels." f" Leave empty to show all. Valid levels: {', '.join(interfaces.CONFIDENCE_LEVEL_NAMES)}.", }, ), ( "enable", { "action": _EnableAction, "callback": lambda x1, x2, x3, x4: x1, "default": (), "metavar": "", "short": "e", "group": "Messages control", "help": "Enable the message, report, category or checker with the " "given id(s). You can either give multiple identifier " "separated by comma (,) or put this option multiple time " "(only on the command line, not in the configuration file " "where it should appear only once). " 'See also the "--disable" option for examples.', "kwargs": {"linter": linter}, }, ), ( "disable", { "action": _DisableAction, "callback": lambda x1, x2, x3, x4: x1, "metavar": "", "default": (), "short": "d", "group": "Messages control", "help": "Disable the message, report, category or checker " "with the given id(s). You can either give multiple identifiers " "separated by comma (,) or put this option multiple times " "(only on the command line, not in the configuration file " "where it should appear only once). " 'You can also use "--disable=all" to disable everything first ' "and then re-enable specific checks. For example, if you want " "to run only the similarities checker, you can use " '"--disable=all --enable=similarities". ' "If you want to run only the classes checker, but have no " "Warning level messages displayed, use " '"--disable=all --enable=classes --disable=W".', "kwargs": {"linter": linter}, }, ), ( "msg-template", { "type": "string", "default": "", "metavar": "