Skip to content
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

Add check for illegal Widnows names #590

Conversation

ericfrederich
Copy link
Contributor

Fixes #589

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, crazy idea -- I think we can replace this entire hook with a fail hook without needing to write any code:

-   id: check-illegal-windows-names
    name: check illegal windows names
    entry: Illegal windows filenames detected
    language: fail
    files: '(?i)(^|/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|/|$)'

from typing import Sequence
from typing import Set

from pre_commit_hooks.util import added_files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should just filter all files, instead of using added_files here

Comment on lines +45 to +46
while '.' in root:
root, _ = os.path.splitext(root)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be better written as root, _, _ = root.partition('.')



# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
ILLEGAL_NAMES = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frozenset((

while '.' in root:
root, _ = os.path.splitext(root)
if root.lower() in lower_set(ILLEGAL_NAMES):
print(f'Illegal name {filename}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Illegal windows filename: {filename}

'filenames', nargs='*',
help='Filenames pre-commit believes are changed.',
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this newline


args = parser.parse_args(argv)

return find_illegal_windows_names(args.filenames)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can probably be inlined or underscored -- I don't think having a separate function improves anything here (especially once you remove the added_files bit)

Comment on lines +12 to +15
skip_win32 = pytest.mark.skipif(
sys.platform == 'win32',
reason='case conflicts between directories and files',
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think once you remove added_files as a constraint you won't need to skip anything (you won't even need to have any disk state either!)

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

Successfully merging this pull request may close these issues.

Add check for illegal Windows filenames
2 participants