-
-
Notifications
You must be signed in to change notification settings - Fork 747
Add check for illegal Widnows names #1031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
asottile
merged 1 commit into
pre-commit:main
from
ericfrederich:check-illegal-windows-names
Apr 14, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import annotations | ||
|
||
import os.path | ||
import re | ||
|
||
import pytest | ||
|
||
from pre_commit_hooks.check_yaml import yaml | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def hook_re(): | ||
here = os.path.dirname(__file__) | ||
with open(os.path.join(here, '..', '.pre-commit-hooks.yaml')) as f: | ||
hook_defs = yaml.load(f) | ||
hook, = ( | ||
hook | ||
for hook in hook_defs | ||
if hook['id'] == 'check-illegal-windows-names' | ||
) | ||
yield re.compile(hook['files']) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
's', | ||
( | ||
pytest.param('aux.txt', id='with ext'), | ||
pytest.param('aux', id='without ext'), | ||
pytest.param('AuX.tXt', id='capitals'), | ||
pytest.param('com7.dat', id='com with digit'), | ||
), | ||
) | ||
def test_check_illegal_windows_names_matches(hook_re, s): | ||
assert hook_re.search(s) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
's', | ||
( | ||
pytest.param('README.md', id='standard file'), | ||
pytest.param('foo.aux', id='as ext'), | ||
pytest.param('com.dat', id='com without digit'), | ||
), | ||
) | ||
def test_check_illegal_windows_names_does_not_match(hook_re, s): | ||
assert hook_re.search(s) is None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a quick little test which loads this regex from the configuration and runs it against a few expected values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asottile @ericfrederich I recommend checking for the
:
character as well (see my comment in #589 regarding :Zone.Identifier files).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jleclanche looks like this got merged without code checking for the
:
but no release has been made yet.I just checked and it's definitely a problem on Windows. I created a file
foo:bar
on linux, commited, pushed, then pulled down the repo from Windows and got greeted witherror: invalid path 'foo:bar'
I'll add a test for it and a new PR