Skip to content

Feature: gitignore support #638

Closed
Closed

Description

@asottile

In GitLab by @notpeter on Jan 12, 2018, 11:29

Hi folks!

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?

Activity

  1. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    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.

  2. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @sigmavirus24 on Oct 20, 2018, 10:15

    closed

  3. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    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.

  4. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @Pequex on Feb 25, 2019, 24:33

    @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)

  5. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    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, 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions