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
fix: Add missing warning for regular expression with [\\/] #2154
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,18 +144,13 @@ def check(self, dct: Dict[str, Any]) -> None: | |
f"regex, not a glob -- matching '/*' probably isn't what you " | ||
f'want here', | ||
) | ||
if r'[\/]' in dct.get(self.key, ''): | ||
logger.warning( | ||
fr'pre-commit normalizes slashes in the {self.key!r} field ' | ||
fr'in hook {dct.get("id")!r} to forward slashes, so you ' | ||
fr'can use / instead of [\/]', | ||
) | ||
if r'[/\\]' in dct.get(self.key, ''): | ||
logger.warning( | ||
fr'pre-commit normalizes slashes in the {self.key!r} field ' | ||
fr'in hook {dct.get("id")!r} to forward slashes, so you ' | ||
fr'can use / instead of [/\\]', | ||
) | ||
for fwd_slash_re in [r'[\\/]', r'[\/]', r'[/\\]']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also: should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something I expected you to comment on, and I'm glad for that. Since this was accepted in the previous pull request regarding these regexes, without any comments on the subject, I felt like confirming if this is meant to be a style guideline? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, and thanks for working on this. Yes, you’re right that pre-commit could warn about I understand that this could be quite a nit pick, and that grouping all the regexes under the same message would be equally acceptable, although a little less precise with regards to semantics. @asottile any thoughts about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah so admittedly the original task was a mistake on my part since the flip |
||
if fwd_slash_re in dct.get(self.key, ''): | ||
logger.warning( | ||
fr'pre-commit normalizes slashes in the {self.key!r} ' | ||
fr'field in hook {dct.get("id")!r} to forward slashes, ' | ||
fr'so you can use / instead of {fwd_slash_re}', | ||
) | ||
|
||
|
||
class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault): | ||
|
@@ -167,18 +162,13 @@ def check(self, dct: Dict[str, Any]) -> None: | |
f'The top-level {self.key!r} field is a regex, not a glob -- ' | ||
f"matching '/*' probably isn't what you want here", | ||
) | ||
if r'[\/]' in dct.get(self.key, ''): | ||
logger.warning( | ||
fr'pre-commit normalizes the slashes in the top-level ' | ||
fr'{self.key!r} field to forward slashes, so you can use / ' | ||
fr'instead of [\/]', | ||
) | ||
if r'[/\\]' in dct.get(self.key, ''): | ||
logger.warning( | ||
fr'pre-commit normalizes the slashes in the top-level ' | ||
fr'{self.key!r} field to forward slashes, so you can use / ' | ||
fr'instead of [/\\]', | ||
) | ||
for fwd_slash_re in [r'[\\/]', r'[\/]', r'[/\\]']: | ||
if fwd_slash_re in dct.get(self.key, ''): | ||
logger.warning( | ||
fr'pre-commit normalizes the slashes in the top-level ' | ||
fr'{self.key!r} field to forward slashes, so you ' | ||
fr'can use / instead of {fwd_slash_re}', | ||
) | ||
|
||
|
||
class MigrateShaToRev: | ||
|
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.
this should be a tuple
while the code was originally written as separate if statements to make sure everything is covered, this is fine I guess
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.
Fixed the first, and making excuses for the second:
Figured I'd remove some duplication, but if requested, I will revert it back to if statements.