flake8-simplify icon indicating copy to clipboard operation
flake8-simplify copied to clipboard

[New Rule] Unnecessary use of backslash escaping

Open rpdelaney opened this issue 1 year ago • 0 comments

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 avatar Nov 09 '22 17:11 rpdelaney