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

[New Rule] Unnecessary use of backslash escaping #162

Open
rpdelaney opened this issue Nov 9, 2022 · 0 comments
Open

[New Rule] Unnecessary use of backslash escaping #162

rpdelaney opened this issue Nov 9, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@rpdelaney
Copy link

Explanation

raw strings are more readable and maintainable for humans in many cases.

Prior art:

Example

# Bad
path = "C:\\Users\\root"

# Good
path = r"C:\Users\root"

# Bad
regex = "\\^\\(\\?P<major>0\\|\\[1\\-9\\]\\\\d\\*\\)\\\\\\.\\(\\?P<minor>0\\|\\[1\\-9\\]\\\\d\\*\\)\\\\\\.\\(\\?P<patch>0\\|\\[1\\-9\\]\\\\d\\*\\)\\(\\?:\\-\\(\\?P<prerelease>\\(\\?:0\\|\\[1\\-9\\]\\\\d\\*\\|\\\\d\\*\\[a\\-zA\\-Z\\-\\]\\[0\\-9a\\-zA\\-Z\\-\\]\\*\\)\\(\\?:\\\\\\.\\(\\?:0\\|\\[1\\-9\\]\\\\d\\*\\|\\\\d\\*\\[a\\-zA\\-Z\\-\\]\\[0\\-9a\\-zA\\-Z\\-\\]\\*\\)\\)\\*\\)\\)\\?\\(\\?:\\\\\\+\\(\\?P<buildmetadata>\\[0\\-9a\\-zA\\-Z\\-\\]\\+\\(\\?:\\\\\\.\\[0\\-9a\\-zA\\-Z\\-\\]\\+\\)\\*\\)\\)\\?\\$"

# Good
regex = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
@rpdelaney rpdelaney added the enhancement New feature or request label Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants