Skip to content

Commit 8a653aa

Browse files
authored
Add enable-all-extensions option (#5315)
* Add ``enable-all-extensions`` option
1 parent 8f5d4d5 commit 8a653aa

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

ChangeLog

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Release date: TBA
7070

7171
Closes #3688
7272

73+
* Added the ``--enable-all-extensions`` command line option. It will load all available extensions
74+
which can be listed by running ``--list-extensions``
75+
7376
* Fix bug with importing namespace packages with relative imports
7477

7578
Closes #2967 and #5131

doc/whatsnew/2.12.rst

+3
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,6 @@ Other Changes
191191

192192
Closes #5171
193193
Follow-up in #5065
194+
195+
* Added the ``--enable-all-extensions`` command line option. It will load all available extensions
196+
which can be listed by running ``--list-extensions``

pylint/lint/run.py

+24
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(
9393
"init-hook": (cb_init_hook, True),
9494
"rcfile": (self.cb_set_rcfile, True),
9595
"load-plugins": (self.cb_add_plugins, True),
96+
"enable-all-extensions": (self.cb_enable_all_extensions, False),
9697
"verbose": (self.cb_verbose_mode, False),
9798
"output": (self.cb_set_output, True),
9899
},
@@ -258,6 +259,15 @@ def __init__(
258259
"will be displayed.",
259260
},
260261
),
262+
(
263+
"enable-all-extensions",
264+
{
265+
"action": "callback",
266+
"callback": self.cb_enable_all_extensions,
267+
"help": "Load and enable all available extensions. "
268+
"Use --list-extensions to see a list all available extensions.",
269+
},
270+
),
261271
),
262272
option_groups=self.option_groups,
263273
pylintrc=self._rcfile,
@@ -475,3 +485,17 @@ def cb_list_groups(self, *args, **kwargs):
475485

476486
def cb_verbose_mode(self, *args, **kwargs):
477487
self.verbose = True
488+
489+
def cb_enable_all_extensions(self, option_name: str, value: None) -> None:
490+
"""Callback to load and enable all available extensions"""
491+
for filename in os.listdir(os.path.dirname(extensions.__file__)):
492+
# pylint: disable=fixme
493+
# TODO: Remove the check for deprecated check_docs after the extension has been removed
494+
if (
495+
filename.endswith(".py")
496+
and not filename.startswith("_")
497+
and not filename.startswith("check_docs")
498+
):
499+
extension_name = f"pylint.extensions.{filename[:-3]}"
500+
if extension_name not in self._plugins:
501+
self._plugins.append(extension_name)

tests/test_self.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
import pytest
5959
from py._path.local import LocalPath # type: ignore
6060

61-
from pylint import modify_sys_path
61+
from pylint import extensions, modify_sys_path
6262
from pylint.constants import MAIN_CHECKER_NAME, MSG_TYPES_STATUS
6363
from pylint.lint import Run
6464
from pylint.lint.pylinter import PyLinter
@@ -1237,3 +1237,25 @@ def test_output_file_specified_in_rcfile(self, tmpdir: LocalPath) -> None:
12371237
output_file,
12381238
expected_output=expected,
12391239
)
1240+
1241+
@staticmethod
1242+
def test_enable_all_extensions() -> None:
1243+
"""Test to see if --enable-all-extensions does indeed load all extensions"""
1244+
# Record all extensions
1245+
plugins = []
1246+
for filename in os.listdir(os.path.dirname(extensions.__file__)):
1247+
# pylint: disable=fixme
1248+
# TODO: Remove the check for deprecated check_docs after the extension has been removed
1249+
if (
1250+
filename.endswith(".py")
1251+
and not filename.startswith("_")
1252+
and not filename.startswith("check_docs")
1253+
):
1254+
plugins.append(f"pylint.extensions.{filename[:-3]}")
1255+
1256+
# Check if they are loaded
1257+
runner = Run(
1258+
["--enable-all-extensions", join(HERE, "regrtest_data", "empty.py")],
1259+
exit=False,
1260+
)
1261+
assert sorted(plugins) == sorted(runner.linter._dynamic_plugins)

0 commit comments

Comments
 (0)