BUG: `pycodestyle` in `pyproject.toml` even though the plugin is disabled through the config
See original GitHub issueChecklist
- Same issue occurs when reproducing the MWE below: new virtualenv, clean folder, minimal additional libs, etc.
- Same issue occurs when running without cache (eg by setting the env var
FLAKEHEAVEN_CACHE_TIMEOUT=0
)
Bug Description
Disabling pycodestyle
warnings for pyproject.toml
does not work when adding the file as an argument in the cli. Enabling pytest-mypy-plugins
to lint toml files is therefore not possible. If I understand this correctly, according to the docs it should be possible to enable/disable plugins for specific files/paths.
Add this config to pyproject.toml
to not lint pycodestyle on this file:
[tool.flakeheaven.exceptions."pyproject.toml"]
pycodestyle = ["-*"]
Executing flakeheaven lint pyproject.toml
show this warning:
pyproject.toml
3: 2 E999 SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='? [pycodestyle]
Expected behavior
No pycodestyle
warnings should show up.
Bug Repro
In short (if you have hatch installed):
- execute
hatch new test-flakeheaven test-flakeheaven
- add
flakeheaven
topyproject.toml
underdependencies
- add config to ignore
pycodestyle
inpyproject.toml
(see below) - execute
hatch run flakeheaven lint pyproject.toml
- Ubuntu 22.04
python --version
: 3.10.6pyproject.toml
(and / or all other config files that apply, eg.pylintrc
, stc)
[tool.flakeheaven]
exclude = [".git", "__pycache__", "venv/", "temp/"]
format = "grouped"
[tool.flakeheaven.exceptions."pyproject.toml"]
# or [tool.flakeheaven.exceptions."**/pyproject.toml"]
pycodestyle = ["-*"]
flakeheaven plugins
: pycodestyle and pyflakes (disabled)- Contents of any additional files (eg sample
.py
file(s) to be linted): just a normal toml file - [If available] contents of
flakeheaven config -vvv
Steps to reproduce the behavior:
- run
flakeheaven lint pyproject.toml
My suspicion is that there’s something wrong with the file/path matcher. If there’s tool.flakeheaven.exceptions
like so **/foo.py
, it will only match files in subdirectories, not at the first/root level.
This was an error on my side. Please ignore.
Additional test case:
Add a file foo.py
to root and a subdirectory with the content a = 'bar'
(single quotes!). Add an exception to pyproject.toml:
[tool.flakeheaven.exceptions."**/foo.py"]
flake8-black = ["-*"]
flakeheaven
will still report:
foo.py
1: 5 BLK100 Black would make changes. [flake8-black]
But nothing on subdir/foo.py
.
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top GitHub Comments
There’s a difference in flakeheaven between actually running the plugin and running it but not report some exceptions.
two errors are targeted to be always reported, so even if excluded (specifically or glob) they will be produced: https://github.com/flakeheaven/flakeheaven/blob/a981c8cd5617bc4691009c998e54f5aa3a4bbbd0/flakeheaven/_logic/_plugin.py#L100
we could skip processing the file altogether with specific plugin. For example, when deciding whether to process a file: https://github.com/flakeheaven/flakeheaven/blob/a981c8cd5617bc4691009c998e54f5aa3a4bbbd0/flakeheaven/_patched/_checkers.py#L119 we’re comparing the rules like this
set(rules) == {'-*'}
(which is debatable, to say the least).Instead, we could do
if '-*' in rules
. In this case, enabling a plugin globally in the plugins section (egpycodestyle = ['+*']
), and then disabling its execution explicitly in the exceptions withpycodestyle = ['-*']
would avoid even processing the fileIm checking to understand whats going on.
The additional test case works as expected:
then, after commenting out the
flake8-black
exception: