diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-16 18:10:29 +0200 |
---|---|---|
committer | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-17 13:48:52 +0200 |
commit | 653e87adae4a0b9c5aa204af259c1286d9e99130 (patch) | |
tree | a1958df954ee81408a0fb2f63b05fd2ea8f92f54 | |
parent | 4405e13488c130c842db9006261e71cf2f578c8a (diff) | |
download | pylint-git-653e87adae4a0b9c5aa204af259c1286d9e99130.tar.gz |
Refactors in preparation of ``pylint-config``
-rw-r--r-- | .pyenchant_pylint_custom_dict.txt | 5 | ||||
-rw-r--r-- | pylint/config/arguments_manager.py | 2 | ||||
-rw-r--r-- | pylint/config/callback_actions.py | 43 | ||||
-rw-r--r-- | pylint/config/config_initialization.py | 8 | ||||
-rw-r--r-- | pylint/extensions/comparetozero.py | 1 | ||||
-rw-r--r-- | pylint/lint/run.py | 5 |
6 files changed, 58 insertions, 6 deletions
diff --git a/.pyenchant_pylint_custom_dict.txt b/.pyenchant_pylint_custom_dict.txt index 933a9e49d..1f8705c70 100644 --- a/.pyenchant_pylint_custom_dict.txt +++ b/.pyenchant_pylint_custom_dict.txt @@ -186,6 +186,7 @@ misdesign misdesigns mixin modname +monkeypatch mro # Used so much that we need the abbreviation msg @@ -217,6 +218,7 @@ numpy ok optdict optik +optionals optiondict optname optparse @@ -229,6 +231,7 @@ params paren parens passthru +positionals png pragma pragma's @@ -283,9 +286,11 @@ stmt str stringified subclasses +subcommands subdicts subgraphs sublists +subparsers subparts subprocess subscriptable diff --git a/pylint/config/arguments_manager.py b/pylint/config/arguments_manager.py index 1efa0de29..e2aa57738 100644 --- a/pylint/config/arguments_manager.py +++ b/pylint/config/arguments_manager.py @@ -71,6 +71,8 @@ class _ArgumentsManager: usage=usage or "%(prog)s [options]", description=description, formatter_class=_HelpFormatter, + # Needed to let 'pylint-config' overwrite the -h command + conflict_handler="resolve", ) """The command line argument parser.""" diff --git a/pylint/config/callback_actions.py b/pylint/config/callback_actions.py index 15bea574a..9dcda7cc9 100644 --- a/pylint/config/callback_actions.py +++ b/pylint/config/callback_actions.py @@ -420,3 +420,46 @@ class _OutputFormatAction(_AccessLinterObjectAction): values[0], str ), "'output-format' should be a comma separated string of reporters" self.linter._load_reporters(values[0]) + + +class _AccessParserAction(_CallbackAction): + """Action that has access to the ArgumentParser object.""" + + def __init__( + self, + option_strings: Sequence[str], + dest: str, + nargs: None = None, + const: None = None, + default: None = None, + type: None = None, + choices: None = None, + required: bool = False, + help: str = "", + metavar: str = "", + **kwargs: argparse.ArgumentParser, + ) -> None: + self.parser = kwargs["parser"] + + super().__init__( + option_strings, + dest, + 0, + const, + default, + type, + choices, + required, + help, + metavar, + ) + + @abc.abstractmethod + def __call__( + self, + parser: argparse.ArgumentParser, + namespace: argparse.Namespace, + values: str | Sequence[Any] | None, + option_string: str | None = None, + ) -> None: + raise NotImplementedError # pragma: no cover diff --git a/pylint/config/config_initialization.py b/pylint/config/config_initialization.py index f688c4cf3..49dfa24fd 100644 --- a/pylint/config/config_initialization.py +++ b/pylint/config/config_initialization.py @@ -91,15 +91,11 @@ def _config_initialization( # load plugin specific configuration. linter.load_plugin_configuration() - # parsed_args_list should now only be a list of files/directories to lint. - # All other options have been removed from the list. - if not parsed_args_list: - print(linter.help()) - sys.exit(32) - # Now that plugins are loaded, get list of all fail_on messages, and enable them linter.enable_fail_on_messages() linter._parse_error_mode() + # parsed_args_list should now only be a list of files/directories to lint. + # All other options have been removed from the list. return parsed_args_list diff --git a/pylint/extensions/comparetozero.py b/pylint/extensions/comparetozero.py index d4332c67a..dd0f1949a 100644 --- a/pylint/extensions/comparetozero.py +++ b/pylint/extensions/comparetozero.py @@ -46,6 +46,7 @@ class CompareToZeroChecker(checkers.BaseChecker): @utils.only_required_for_messages("compare-to-zero") def visit_compare(self, node: nodes.Compare) -> None: + # pylint: disable=duplicate-code _operators = ["!=", "==", "is not", "is"] # note: astroid.Compare has the left most operand in node.left # while the rest are a list of tuples in node.ops diff --git a/pylint/lint/run.py b/pylint/lint/run.py index 778e64441..2948021c7 100644 --- a/pylint/lint/run.py +++ b/pylint/lint/run.py @@ -136,6 +136,11 @@ group are mutually exclusive.", linter, args, reporter, config_file=self._rcfile, verbose_mode=self.verbose ) + # Display help messages if there are no files to lint + if not args: + print(linter.help()) + sys.exit(32) + if linter.config.jobs < 0: print( f"Jobs number ({linter.config.jobs}) should be greater than or equal to 0", |