diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-06-29 12:49:04 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-06-29 15:44:58 +0200 |
commit | 15470d10f74adb8fd3fab599097a8da8c10ec515 (patch) | |
tree | f80ecbfcacca91e76c302f41264e87d39d092d88 | |
parent | e8202000e046e286816375f5887110cacda4d11b (diff) | |
download | pylint-git-15470d10f74adb8fd3fab599097a8da8c10ec515.tar.gz |
Fix recognition of config files named ``setup.cfg`` (#3630) (#6577)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
8 files changed, 47 insertions, 4 deletions
diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst index d0f64f790..34ebdc50c 100644 --- a/doc/whatsnew/2/2.14/full.rst +++ b/doc/whatsnew/2/2.14/full.rst @@ -27,6 +27,12 @@ Release date: TBA Closes #6965 +* Fixed an issue with the recognition of ``setup.cfg`` files. + Only ``.cfg`` files that are exactly named ``setup.cfg`` require section names that + start with ``pylint.``. + + Closes #3630 + * Don't report ``import-private-name`` for relative imports. Closes #7078 diff --git a/pylint/config/config_file_parser.py b/pylint/config/config_file_parser.py index 3d7694956..b6809d984 100644 --- a/pylint/config/config_file_parser.py +++ b/pylint/config/config_file_parser.py @@ -42,7 +42,7 @@ class _ConfigurationFileParser: config_content: dict[str, str] = {} options: list[str] = [] for section in parser.sections(): - if self._ini_file_with_sections(str(file_path)) and not section.startswith( + if self._ini_file_with_sections(file_path) and not section.startswith( "pylint" ): if section.lower() == "master": @@ -61,11 +61,11 @@ class _ConfigurationFileParser: return config_content, options @staticmethod - def _ini_file_with_sections(file_path: str) -> bool: + def _ini_file_with_sections(file_path: Path) -> bool: """Return whether the file uses sections.""" - if "setup.cfg" in file_path: + if "setup.cfg" in file_path.parts: return True - if "tox.ini" in file_path: + if "tox.ini" in file_path.parts: return True return False diff --git a/tests/config/functional/setup_cfg/issue_3630/not_setup.2.out b/tests/config/functional/setup_cfg/issue_3630/not_setup.2.out new file mode 100644 index 000000000..1e104d8f8 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/not_setup.2.out @@ -0,0 +1,3 @@ +I should just print +************* Module Command line or configuration file +Command line or configuration file:1:0: E0013: Plugin 'pylint_flask' is impossible to load, is it installed ? ('No module named 'pylint_flask'') (bad-plugin-value) diff --git a/tests/config/functional/setup_cfg/issue_3630/not_setup.cfg b/tests/config/functional/setup_cfg/issue_3630/not_setup.cfg new file mode 100644 index 000000000..87d19d681 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/not_setup.cfg @@ -0,0 +1,12 @@ +# We load all sections as this is not a file that requires correct section headers +[tool.pylint.MASTER] +init-hook='print("I should just print")' + +# We still load from pylint. +[pylint.MASTER] +load-plugins=pylint_flask + +# We even load from section without pylint in their name +[FORMAT] +max-line-length=220 +max-module-lines=2001 diff --git a/tests/config/functional/setup_cfg/issue_3630/not_setup.result.json b/tests/config/functional/setup_cfg/issue_3630/not_setup.result.json new file mode 100644 index 000000000..799f47e82 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/not_setup.result.json @@ -0,0 +1,5 @@ +{ + "load_plugins": ["pylint_flask"], + "max_line_length": 220, + "max_module_lines": 2001 +} diff --git a/tests/config/functional/setup_cfg/issue_3630/setup.2.out b/tests/config/functional/setup_cfg/issue_3630/setup.2.out new file mode 100644 index 000000000..39887eed3 --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/setup.2.out @@ -0,0 +1,2 @@ +************* Module Command line or configuration file +Command line or configuration file:1:0: E0013: Plugin 'pylint_flask' is impossible to load, is it installed ? ('No module named 'pylint_flask'') (bad-plugin-value) diff --git a/tests/config/functional/setup_cfg/issue_3630/setup.cfg b/tests/config/functional/setup_cfg/issue_3630/setup.cfg new file mode 100644 index 000000000..26ade91ee --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/setup.cfg @@ -0,0 +1,12 @@ +# Don't load from tool.pylint, we only support pylint. +[tool.pylint.MASTER] +init-hook='print("I should NOT print in setup.cfg we only parse 'pylint.'")' + +# We do load from pylint. +[pylint.MASTER] +load-plugins=pylint_flask + +# We don't load options from random sections +[FORMAT] +max-line-length=220 +max-module-lines=2001 diff --git a/tests/config/functional/setup_cfg/issue_3630/setup.result.json b/tests/config/functional/setup_cfg/issue_3630/setup.result.json new file mode 100644 index 000000000..091cf1e7b --- /dev/null +++ b/tests/config/functional/setup_cfg/issue_3630/setup.result.json @@ -0,0 +1,3 @@ +{ + "load_plugins": ["pylint_flask"] +} |