question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug - glob exceptions from base config do not get overwritten by more specific local ones

See original GitHub issue

I have a base config with has an exception with globs to activate specific flake8 plugins for test files only and deactivate other rules:

...
[tool.flakeheaven.exceptions."**/test_*.py"]
flake8-aaa = ["+*"]
flake8-bandit = ["-S101"]

source

In a project I set this file as base and add another exception which is specific to a single file:

[tool.flakeheaven.exceptions."tests/test_rstcheck.py"]
flake8-aaa = ["-AAA01"]

But I still get multiple errors from this file like this:

tests/test_rstcheck.py:503:5: AAA01 no Act block found in test [flake8-aaa]

EDIT: I use the latest release version. EDIT2: On master this is also the case. 6138285ed808c334c9cb175e2a1f97dfb3cb679a

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

5reactions
orsiniumcommented, May 9, 2022

I looked a bit more into it and found when it was changed: https://github.com/life4/flakehell/pull/104

So, yeah, my initial guess is correct. I implemented it to return the first match and then there was merging logic added which basically inverted the priorities. Now you can either revert the change or reverse the whole logic inside. Namely:

  1. The reverse=True should be dropped, so longer exceptions go last (I tried to do it nginx-style for regular rules).
  2. The globs should go before paths.

Shame on me for bad test coverage. Flakehell was my first experiment on “deliver fast, test later if people start using it”. TBH, in flake8-ruler I just dropped exceptions logic, “keep it simple”.

1reaction
Cielquancommented, May 8, 2022

Then IMO this should be changed. Lets make an experiment:

Setup

Lets assume we have the following file structure.

File tree:

root
└─ dir_1
   └─ dir_1_1
      └─ file_1.py
   └─ dir_1_2
      └─ file_2.py

This means we have two files:

  • root/dir_1/dir_1_1/file_1.py
  • root/dir_1/dir_1_2/file_2.py

Example prefix

When we have the following exceptions:

[tool.flakeheaven.exceptions."root/dir_1"]
flake8-aaa = ["+AAA01"]

[tool.flakeheaven.exceptions."root/dir_1/dir_1_2"]
flake8-aaa = ["-AAA01"]

This would result in +AAA01 for both files, because the upper exception has a shorter prefix. If I would see this config without knowledge I would assume that file_2.py has -AAA01 and file_1.py has +AAA01, would you not?

Example glob

When we have the following exceptions:

[tool.flakeheaven.exceptions."*/dir1"]
flake8-aaa = ["+AAA01"]

[tool.flakeheaven.exceptions."*/dir_1/dir_1_2"]
flake8-aaa = ["-AAA01"]

This would again result in +AAA01 for both files, because the upper exception has a shorter glob. If I would see this config without knowledge I would again assume that file_2.py has -AAA01 and file_1.py has +AAA01, would you not?

Example prefix vs glob

When we have the following exceptions:

[tool.flakeheaven.exceptions."*/dir1"]
flake8-aaa = ["+AAA01"]

[tool.flakeheaven.exceptions."root/dir_1/dir_1/dir_1_2"]
flake8-aaa = ["-AAA01"]

This would again result in +AAA01 for both files, because the upper exception has is a glob even so it matches less good for file_2.py. If I would see this config without knowledge I would again assume that file_2.py has -AAA01 and file_1.py has +AAA01, would you not?

Conclusion

So in all three cases the result is against intuition.

I think it would be better to take the longest matching prefix/glob instead of the shortest, because elsewise you cannot overwrite deeper nested exceptions.

I also think it is no good to let globs take precedence over prefixes by default.

If I have an error in my thought experiment please tell me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration Files - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Your local changes to the following files would be overwritten ...
Your error appears when you have modified a file and the branch that you are switching to has changes for this file ...
Read more >
git-config Documentation - Git
A list of all available configuration variables can be obtained using the git help --config command. OPTIONS. --replace-all. Default behavior is to replace...
Read more >
Configuration — Kedro 0.18.4 documentation - Read the Docs
Kedro-specific configuration (e.g., DataCatalog configuration for IO) is loaded ... keys from conf/base will be overwritten by the ones from conf/local .
Read more >
Configuration options | Yarn - Package Manager
List of all the configuration option for Yarn (yarnrc files)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found