diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-05-05 15:07:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 15:07:46 +0200 |
commit | 020aea5797eb9f858b44dc6157f4b018234df50a (patch) | |
tree | ef0578b9cf94aa99b22cce7af1e3a1322a6ca526 | |
parent | 30a56fbd804882f0acc9d251f237b6c50ef91672 (diff) | |
download | pylint-git-020aea5797eb9f858b44dc6157f4b018234df50a.tar.gz |
Fix the loading of unrelated tools options (#6356)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
9 files changed, 55 insertions, 3 deletions
diff --git a/pylint/config/config_file_parser.py b/pylint/config/config_file_parser.py index 7f89b290a..0bb042bf8 100644 --- a/pylint/config/config_file_parser.py +++ b/pylint/config/config_file_parser.py @@ -9,6 +9,7 @@ from __future__ import annotations import configparser import os import sys +import warnings from pathlib import Path from typing import TYPE_CHECKING @@ -42,6 +43,17 @@ class _ConfigurationFileParser: config_content: dict[str, str] = {} options: list[str] = [] for section in parser.sections(): + if "setup.cfg" in str(file_path) and not section.startswith("pylint"): + if section.lower() == "master": + # TODO: 3.0: Remove deprecated handling of master, only allow 'pylint.' sections + warnings.warn( + "The use of 'MASTER' or 'master' as configuration section for pylint " + "has been deprecated, as it's bad practice to not start sections titles with the " + "tool name. Please use 'pylint.main' instead.", + UserWarning, + ) + else: + continue for opt, value in parser[section].items(): value = value.replace("\n", "") config_content[opt] = value diff --git a/tests/config/functional/setup_cfg/deprecate_master/setup.cfg b/tests/config/functional/setup_cfg/deprecate_master/setup.cfg new file mode 100644 index 000000000..fd6381646 --- /dev/null +++ b/tests/config/functional/setup_cfg/deprecate_master/setup.cfg @@ -0,0 +1,3 @@ +# Test the deprecation of MASTER +[MASTER] +persistent=no diff --git a/tests/config/functional/setup_cfg/deprecate_master/setup.result.json b/tests/config/functional/setup_cfg/deprecate_master/setup.result.json new file mode 100644 index 000000000..b66b78598 --- /dev/null +++ b/tests/config/functional/setup_cfg/deprecate_master/setup.result.json @@ -0,0 +1,3 @@ +{ + "persistent": false +} diff --git a/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.2.out b/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.2.out new file mode 100644 index 000000000..ddb88ed15 --- /dev/null +++ b/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.2.out @@ -0,0 +1,2 @@ +************* Module {abspath} +{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message useless-supression. (bad-option-value) diff --git a/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.cfg b/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.cfg new file mode 100644 index 000000000..b12db80e0 --- /dev/null +++ b/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.cfg @@ -0,0 +1,10 @@ +[myothertool] +ignore = allthefiles + +[pylint.MESSAGES CONTROL] +extension-pkg-whitelist=pygame +enable= + useless-supression, + +disable= + missing-docstring, diff --git a/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.result.json b/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.result.json new file mode 100644 index 000000000..78e3df360 --- /dev/null +++ b/tests/config/functional/setup_cfg/do_not_read_other_tools_configuration/setup.result.json @@ -0,0 +1,10 @@ +{ + "functional_append": { + "disable": [ + "missing-class-docstring", + "missing-function-docstring", + "missing-module-docstring" + ] + }, + "extension_pkg_whitelist": ["pygame"] +} diff --git a/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.cfg b/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.cfg new file mode 100644 index 000000000..df4ec3926 --- /dev/null +++ b/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.cfg @@ -0,0 +1,6 @@ +# Test for the behavior of https://github.com/PyCQA/pylint/issues/4371 +[pylint.MASTER] +persistent=no +ignore = migrations +[flake8] +ignore = D107,D400,D401 diff --git a/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.result.json b/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.result.json new file mode 100644 index 000000000..d515c15b5 --- /dev/null +++ b/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.result.json @@ -0,0 +1 @@ +{ "persistent": false, "ignore": ["migrations"], "black_list": ["migrations"] } diff --git a/tests/config/test_functional_config_loading.py b/tests/config/test_functional_config_loading.py index e4ed15051..64227df79 100644 --- a/tests/config/test_functional_config_loading.py +++ b/tests/config/test_functional_config_loading.py @@ -19,6 +19,7 @@ and ``"functional_remove":``. Check the existing code for examples. # pylint: disable=redefined-outer-name import logging +import warnings from pathlib import Path import pytest @@ -78,9 +79,13 @@ def test_functional_config_loading( expected_loaded_configuration = get_expected_configuration( configuration_path, default_configuration ) - mock_exit, _, runner = run_using_a_configuration_file( - configuration_path, file_to_lint_path - ) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", message="The use of 'MASTER'.*", category=UserWarning + ) + mock_exit, _, runner = run_using_a_configuration_file( + configuration_path, file_to_lint_path + ) mock_exit.assert_called_once_with(expected_code) out, err = capsys.readouterr() # 'rstrip()' applied, so we can have a final newline in the expected test file |