diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-11-15 23:22:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-15 23:22:25 +0100 |
commit | 8a653aab1580d65f30d3575c7a482665598f5016 (patch) | |
tree | 9c286a9bb2c390de93ef43b68f1bdf0a3fff9826 | |
parent | 8f5d4d569fc164792a2328e7ed47b43e33775f6f (diff) | |
download | pylint-git-8a653aab1580d65f30d3575c7a482665598f5016.tar.gz |
Add ``enable-all-extensions`` option (#5315)
* Add ``enable-all-extensions`` option
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | doc/whatsnew/2.12.rst | 3 | ||||
-rw-r--r-- | pylint/lint/run.py | 24 | ||||
-rw-r--r-- | tests/test_self.py | 24 |
4 files changed, 53 insertions, 1 deletions
@@ -70,6 +70,9 @@ Release date: TBA Closes #3688 +* Added the ``--enable-all-extensions`` command line option. It will load all available extensions + which can be listed by running ``--list-extensions`` + * Fix bug with importing namespace packages with relative imports Closes #2967 and #5131 diff --git a/doc/whatsnew/2.12.rst b/doc/whatsnew/2.12.rst index 97957d7c5..f39c3f56f 100644 --- a/doc/whatsnew/2.12.rst +++ b/doc/whatsnew/2.12.rst @@ -191,3 +191,6 @@ Other Changes Closes #5171 Follow-up in #5065 + +* Added the ``--enable-all-extensions`` command line option. It will load all available extensions + which can be listed by running ``--list-extensions`` diff --git a/pylint/lint/run.py b/pylint/lint/run.py index 46710dc2b..ff2e6a243 100644 --- a/pylint/lint/run.py +++ b/pylint/lint/run.py @@ -93,6 +93,7 @@ group are mutually exclusive.", "init-hook": (cb_init_hook, True), "rcfile": (self.cb_set_rcfile, True), "load-plugins": (self.cb_add_plugins, True), + "enable-all-extensions": (self.cb_enable_all_extensions, False), "verbose": (self.cb_verbose_mode, False), "output": (self.cb_set_output, True), }, @@ -258,6 +259,15 @@ group are mutually exclusive.", "will be displayed.", }, ), + ( + "enable-all-extensions", + { + "action": "callback", + "callback": self.cb_enable_all_extensions, + "help": "Load and enable all available extensions. " + "Use --list-extensions to see a list all available extensions.", + }, + ), ), option_groups=self.option_groups, pylintrc=self._rcfile, @@ -475,3 +485,17 @@ to search for configuration file. def cb_verbose_mode(self, *args, **kwargs): self.verbose = True + + def cb_enable_all_extensions(self, option_name: str, value: None) -> None: + """Callback to load and enable all available extensions""" + for filename in os.listdir(os.path.dirname(extensions.__file__)): + # pylint: disable=fixme + # TODO: Remove the check for deprecated check_docs after the extension has been removed + if ( + filename.endswith(".py") + and not filename.startswith("_") + and not filename.startswith("check_docs") + ): + extension_name = f"pylint.extensions.{filename[:-3]}" + if extension_name not in self._plugins: + self._plugins.append(extension_name) diff --git a/tests/test_self.py b/tests/test_self.py index a4a3ac794..8441a5acb 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -58,7 +58,7 @@ from unittest.mock import patch import pytest from py._path.local import LocalPath # type: ignore -from pylint import modify_sys_path +from pylint import extensions, modify_sys_path from pylint.constants import MAIN_CHECKER_NAME, MSG_TYPES_STATUS from pylint.lint import Run from pylint.lint.pylinter import PyLinter @@ -1237,3 +1237,25 @@ class TestRunTC: output_file, expected_output=expected, ) + + @staticmethod + def test_enable_all_extensions() -> None: + """Test to see if --enable-all-extensions does indeed load all extensions""" + # Record all extensions + plugins = [] + for filename in os.listdir(os.path.dirname(extensions.__file__)): + # pylint: disable=fixme + # TODO: Remove the check for deprecated check_docs after the extension has been removed + if ( + filename.endswith(".py") + and not filename.startswith("_") + and not filename.startswith("check_docs") + ): + plugins.append(f"pylint.extensions.{filename[:-3]}") + + # Check if they are loaded + runner = Run( + ["--enable-all-extensions", join(HERE, "regrtest_data", "empty.py")], + exit=False, + ) + assert sorted(plugins) == sorted(runner.linter._dynamic_plugins) |