From 718e997d4ac422bbff27337b5b256b164bd9ea22 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 5 Nov 2022 16:20:16 +0100 Subject: [PATCH 1/2] [test] Enforce the confidence level being set in 'add_message' --- pylint/testutils/lint_module_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index d05f7e481e..8e6d42f3ba 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -256,6 +256,10 @@ def _runTest(self) -> None: ), self.error_msg_for_unequal_messages( actual_messages, expected_messages, actual_output ) + for message in actual_output: + assert ( + message.confidence != "UNDEFINED" + ), f"{message.symbol} use the default 'UNDEFINED' confidence in 'add_message'." self._check_output_text(expected_messages, expected_output, actual_output) def error_msg_for_unequal_messages( From 56ef83ac417e030a0124f486f6f83b0407a9770e Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 4 Dec 2022 17:01:41 +0100 Subject: [PATCH 2/2] wip --- .../m/missing-pylint-confidence/details.rst | 1 + .../m/missing-pylint-confidence/good.py | 1 + .../extensions/pylint_confidence_missing.py | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 doc/data/messages/m/missing-pylint-confidence/details.rst create mode 100644 doc/data/messages/m/missing-pylint-confidence/good.py create mode 100644 pylint/extensions/pylint_confidence_missing.py diff --git a/doc/data/messages/m/missing-pylint-confidence/details.rst b/doc/data/messages/m/missing-pylint-confidence/details.rst new file mode 100644 index 0000000000..ab82045295 --- /dev/null +++ b/doc/data/messages/m/missing-pylint-confidence/details.rst @@ -0,0 +1 @@ +You can help us make the doc better `by contributing `_ ! diff --git a/doc/data/messages/m/missing-pylint-confidence/good.py b/doc/data/messages/m/missing-pylint-confidence/good.py new file mode 100644 index 0000000000..c40beb573f --- /dev/null +++ b/doc/data/messages/m/missing-pylint-confidence/good.py @@ -0,0 +1 @@ +# This is a placeholder for correct code for this message. diff --git a/pylint/extensions/pylint_confidence_missing.py b/pylint/extensions/pylint_confidence_missing.py new file mode 100644 index 0000000000..66777ed6c9 --- /dev/null +++ b/pylint/extensions/pylint_confidence_missing.py @@ -0,0 +1,37 @@ +# 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 +# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt + +"""Check for use of confidence when adding pylint message.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from astroid import nodes + +from pylint.checkers import BaseChecker +from pylint.checkers.utils import only_required_for_messages + +if TYPE_CHECKING: + from pylint.lint import PyLinter + + +class PylintConfidenceChecker(BaseChecker): + + name = "pylint_confidence_missing" + msgs = { + "W3000": ( + "Missing confidence in %s", + "missing-pylint-confidence", + "Check that pylint plugins set the confidence correctly when raising a message.", + ) + } + + @only_required_for_messages("while-used") + def visit_call(self, node: nodes.While) -> None: + self.add_message("while-used", node=node) + + +def register(linter: PyLinter) -> None: + linter.register_checker(PylintConfidenceChecker(linter))