Pre-commit-hook ignores exclude patterns

See original GitHub issue

My team wants to try black as a pre-commit hook on a provisional basis, so we run it only on files in one directory of the project as we develop a new feature.

While configuring this, I discovered that black seems to ignore inclusion/exclusion rules completely if it’s given a path to a file not a folder. Since the input to a pre-commit hook is a list of modified/created filepaths, all or our lovely inclusion/exclusion rules get ignored completely and that makes us sad 😦

I’m not familiar enough with the code to have a good gauge of this, but how much work do you think it would be to add support for this?

Thanks for the cool tool!! P.S. Personally, I’d take the leap and format the whole repo, but I’m not alone in this world 😉

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

59reactions
asottilecommented, Jul 8, 2018

If you’re using pre-commit you can control the inclusion / exclusion by using files / exclude in the pre-commit configuration.

For example:

    -   id: black
        # only in tests
        files: ^tests/
    -   id: black
        # everything but tests
        exclude: ^tests/

(etc. etc.)

55reactions
asottilecommented, Jun 6, 2019

Say you want to exclude both ^foo/ and ^bar/ you can combine them with | (naively: (^foo/|^bar/))

You can also mark your regex as verbose and write a multiline regex:

exclude: |
    (?x)(
        ^foo/|
        ^bar/
    )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exclude some files on running black using pre-commit
pre -commit finds all the python files, then applies pre-commit 's exclusion, and then passes that list of files to the underlying tools...
Read more >
pre-commit
We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements....
Read more >
Can I Exclude Files From Every Precommit Hook Except For One
The behavior we'd like to see is that black's exclude regex would apply even when full Precommithook ignores exclude patterns #395. Coding can...
Read more >
pre-commit-config.yaml - platform/external/python/pybind11
repo: https://github.com/pre-commit/pre-commit-hooks. rev: v3.4.0. hooks: ... By default, this ignores pyi files, though black supports them. types: [text].
Read more >
git-check-ignore Documentation - Git
(Matching an exclude pattern usually means the path is excluded, but if the pattern begins with " ! " then it is a...
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