diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-11-04 08:17:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-04 08:17:52 +0100 |
commit | c532a171fadc9dc06bd97c58d490436456837031 (patch) | |
tree | d7e0b9a3a9376ff6cccd7d7ca618968b849ad980 | |
parent | de307ccf20c69ef1cfba05c000de19ec2407b5cd (diff) | |
download | pylint-git-c532a171fadc9dc06bd97c58d490436456837031.tar.gz |
Add script to generate new message category id (#5248)
-rw-r--r-- | doc/development_guide/contribute.rst | 3 | ||||
-rw-r--r-- | pylint/extensions/__init__.py | 17 | ||||
-rw-r--r-- | script/get_unused_message_id_category.py | 33 |
3 files changed, 53 insertions, 0 deletions
diff --git a/doc/development_guide/contribute.rst b/doc/development_guide/contribute.rst index d846805ac..86cd352fd 100644 --- a/doc/development_guide/contribute.rst +++ b/doc/development_guide/contribute.rst @@ -194,6 +194,9 @@ Tips for Getting Started with Pylint Development message to find where the warning is raised, and therefore where the logic for that code exists. +* When adding a new checker class you can use the :file:`get_unused_message_id_category.py` + script in :file:`./scripts` to get a message id that is not used by + any of the other checkers. Building the documentation ---------------------------- diff --git a/pylint/extensions/__init__.py b/pylint/extensions/__init__.py index e69de29bb..96568077c 100644 --- a/pylint/extensions/__init__.py +++ b/pylint/extensions/__init__.py @@ -0,0 +1,17 @@ +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE + +from typing import TYPE_CHECKING + +from pylint.utils import register_plugins + +if TYPE_CHECKING: + from pylint.lint import PyLinter + + +def initialize(linter: "PyLinter") -> None: + """Initialize linter with checkers in the extensions directory""" + register_plugins(linter, __path__[0]) # type: ignore # Fixed in https://github.com/python/mypy/pull/9454 + + +__all__ = ["initialize"] diff --git a/script/get_unused_message_id_category.py b/script/get_unused_message_id_category.py new file mode 100644 index 000000000..5ddcd0b3c --- /dev/null +++ b/script/get_unused_message_id_category.py @@ -0,0 +1,33 @@ +"""Small script to get a new unused message id category""" +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE + +from typing import List + +from pylint.checkers import initialize as initialize_checkers +from pylint.extensions import initialize as initialize_extensions +from pylint.lint.pylinter import PyLinter + + +def register_all_checkers_and_plugins(linter: "PyLinter") -> None: + """Registers all checkers and plugins""" + linter.cmdline_parser.set_conflict_handler("resolve") + initialize_checkers(linter) + initialize_extensions(linter) + + +def get_next_code_category(message_ids: List[str]) -> int: + categories = sorted({int(i[:2]) for i in message_ids}) + for i in categories: + if i + 1 not in categories: + return i + 1 + return categories[-1] + 1 + + +if __name__ == "__main__": + pylinter = PyLinter() + register_all_checkers_and_plugins(pylinter) + messages = sorted(i.msgid[1:] for i in pylinter.msgs_store.messages) + next_category = get_next_code_category(messages) + print(f"Next free message id category is {next_category:02}") + print(f"Please use {next_category:02}01 for the first message of the new checker") |