You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'd be great if flake8 could support an optional mode which in addition to the build-in exclude list also supports handling .gitignore files. This is a obviously a non-trivial feature. It would require implementing a parser for gitignore (see codeskyblue/pyignore for inspiration) as well as having code which properly handles both gitignore style (globs, globstar, etc) and existing list of excludes, likely side-by-side.
Something like this could ease adoption of flake8 in existing code bases so that ignored directories (node_modules, etc) don't need to be defined in yet another spot (.gitignore, .dockerignore AND setup.cfg, etc) and enables user-specific ignores with minimal complexity.
In my mind, a minimal implementation of this would need to look for both any global gitignore (git config --get core.excludesfile, usually ~/.gitignore) and .gitignore in any directory arguments provided on the flake8 command-line. For a complete implementation, it should also support sub-directory level .gitignore files, but even supporting only global and top-level gitignore would go a long way to prevent duplicated configs in many environments.
I'm not expecting someone to magically implement this, but more trying to get feedback before I take a stab at it myself. Also to confirm, is flake8 the right place for this or will the underlying quality checkers (pyflakes, pycodestyle, etc) need to be updated as well?
Also, I truly abhor how many places this project already searches out config from. Adding one more is just begging for me to not support any of them to protect my own time.
@sigmavirus24 Mostly out of curiosity... Would a flake8-gitignore extension be feasible? (I do not know if an extension is able to alter the list of collected files)
@Pequex it seems the only apis given to plugins for modifying existing options right now are extend_default_ignore, extend_default_select, and remove_from_default_ignore (nothing to do with exclude currently) -- that isn't to say it wouldn't be possible.
Another option if you want to only run on git managed files is to use something that knows how to do that. For instance pre-commit will only ever pass git-managed files to tools and flake8 is supported directly (pre-commit run flake8 --all-files)
Activity
asottile commentedon Apr 3, 2021
In GitLab by @sigmavirus24 on Oct 20, 2018, 10:15
The behaviour here is definitely way too magical. I can understand the desire, but it's rather too implicit and we strive to be far more explicit.
asottile commentedon Apr 3, 2021
In GitLab by @sigmavirus24 on Oct 20, 2018, 10:15
closed
asottile commentedon Apr 3, 2021
In GitLab by @sigmavirus24 on Oct 20, 2018, 10:16
Also, I truly abhor how many places this project already searches out config from. Adding one more is just begging for me to not support any of them to protect my own time.
asottile commentedon Apr 3, 2021
In GitLab by @Pequex on Feb 25, 2019, 24:33
@sigmavirus24 Mostly out of curiosity... Would a
flake8-gitignoreextension be feasible? (I do not know if an extension is able to alter the list of collected files)asottile commentedon Apr 3, 2021
In GitLab by @asottile on Feb 25, 2019, 08:31
@Pequex it seems the only apis given to plugins for modifying existing options right now are
extend_default_ignore,extend_default_select, andremove_from_default_ignore(nothing to do withexcludecurrently) -- that isn't to say it wouldn't be possible.Another option if you want to only run on
gitmanaged files is to use something that knows how to do that. For instance pre-commit will only ever pass git-managed files to tools and flake8 is supported directly (pre-commit run flake8 --all-files)