Update bazel to match only extension or whole name#1
Update bazel to match only extension or whole name#1jlebar merged 3 commits intojlebar:masterfrom TheButlah:master
Conversation
The hook was originally matching all files in the repository as long as they had `BUILD` or `BUILD.bazel` in them. This meant that they actually overrode the `files` setting in the user's repository. This commit ensures that, for example, `BUILD.bazel` and `whatever/BUILD.bazel` match, but not `whateverBUILD.bazelasdf`. It also adds support for `whatever.BUILD` files.
|
Duplicated from FelixSeptem/pre-commit-golang#3 |
|
Thank you so much for the PR! I agree the original code is broken (oops), but I'm not 100% sure the new code works as intended either. I may just be misunderstanding, though. Deconstructed this is: I've only really used RE2, which doesn't support backreferences, so I may be misunderstanding how this is supposed to work. But AIUI WDYT, am I missing something? |
|
Yep, I think you're right. Here's an updated regex: https://regex101.com/r/AYsCnu/1/ |
|
I was confused what WDYT of the following; maybe it's slightly easier to parse? |
|
I agree, using How about this as the simplest version: https://regex101.com/r/f0fFhE/2 ^(.*/)?(BUILD\.bazel|BUILD)$|\.BUILD$ |
Eh, you're right, it was a premature optimization. The whole purpose of noncapturing groups is to let the regex engine optimize things that it otherwise couldn't, but it doesn't matter in this case. |
|
LGTM, merging! Thanks again for the PR. |
The hook was originally matching all files in the repository as long as they had
BUILDorBUILD.bazelin them. This commit ensures that, for example,BUILD.bazelandwhatever/BUILD.bazelmatch, but notwhateverBUILD.bazelasdf. It also adds support forwhatever.BUILDfiles.