Rewrite some strings using raw string syntax.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-04-18 03:37:30 -07:00 committed by Tim Abbott
parent e30b3b094b
commit d68437d5f5
4 changed files with 31 additions and 31 deletions

View file

@ -22,7 +22,7 @@ markdown_whitespace_rules = list([rule for rule in whitespace_rules if rule['pat
{'pattern': r'((?<!\s)\s$)|(\s\s\s+$)|(^\s+$)', {'pattern': r'((?<!\s)\s$)|(\s\s\s+$)|(^\s+$)',
'strip': '\n', 'strip': '\n',
'description': 'Fix trailing whitespace'}, 'description': 'Fix trailing whitespace'},
{'pattern': '^#+[A-Za-z0-9]', {'pattern': r'^#+[A-Za-z0-9]',
'strip': '\n', 'strip': '\n',
'description': 'Missing space after # in heading'}, 'description': 'Missing space after # in heading'},
] # type: Rule ] # type: Rule
@ -35,7 +35,7 @@ python_rules = RuleList(
{'pattern': r"'.*'%\([a-z_].*\)?$", {'pattern': r"'.*'%\([a-z_].*\)?$",
'description': 'Missing space around "%"'}, 'description': 'Missing space around "%"'},
# This rule is constructed with + to avoid triggering on itself # This rule is constructed with + to avoid triggering on itself
{'pattern': " =" + '[^ =>~"]', {'pattern': r" =" + r'[^ =>~"]',
'description': 'Missing whitespace after "="'}, 'description': 'Missing whitespace after "="'},
{'pattern': r'":\w[^"]*$', {'pattern': r'":\w[^"]*$',
'description': 'Missing whitespace after ":"'}, 'description': 'Missing whitespace after ":"'},
@ -44,25 +44,25 @@ python_rules = RuleList(
{'pattern': r"^\s+[#]\w", {'pattern': r"^\s+[#]\w",
'strip': '\n', 'strip': '\n',
'description': 'Missing whitespace after "#"'}, 'description': 'Missing whitespace after "#"'},
{'pattern': "assertEquals[(]", {'pattern': r"assertEquals[(]",
'description': 'Use assertEqual, not assertEquals (which is deprecated).'}, 'description': 'Use assertEqual, not assertEquals (which is deprecated).'},
{'pattern': 'self: Any', {'pattern': r'self: Any',
'description': 'you can omit Any annotation for self', 'description': 'you can omit Any annotation for self',
'good_lines': ['def foo (self):'], 'good_lines': ['def foo (self):'],
'bad_lines': ['def foo(self: Any):']}, 'bad_lines': ['def foo(self: Any):']},
{'pattern': "== None", {'pattern': r"== None",
'description': 'Use `is None` to check whether something is None'}, 'description': 'Use `is None` to check whether something is None'},
{'pattern': "type:[(]", {'pattern': r"type:[(]",
'description': 'Missing whitespace after ":" in type annotation'}, 'description': 'Missing whitespace after ":" in type annotation'},
{'pattern': "# type [(]", {'pattern': r"# type [(]",
'description': 'Missing : after type in type annotation'}, 'description': 'Missing : after type in type annotation'},
{'pattern': "#type", {'pattern': r"#type",
'description': 'Missing whitespace after "#" in type annotation'}, 'description': 'Missing whitespace after "#" in type annotation'},
{'pattern': 'if[(]', {'pattern': r'if[(]',
'description': 'Missing space between if and ('}, 'description': 'Missing space between if and ('},
{'pattern': ", [)]", {'pattern': r", [)]",
'description': 'Unnecessary whitespace between "," and ")"'}, 'description': 'Unnecessary whitespace between "," and ")"'},
{'pattern': "% [(]", {'pattern': r"% [(]",
'description': 'Unnecessary whitespace between "%" and "("'}, 'description': 'Unnecessary whitespace between "%" and "("'},
# This next check could have false positives, but it seems pretty # This next check could have false positives, but it seems pretty
# rare; if we find any, they can be added to the exclude list for # rare; if we find any, they can be added to the exclude list for
@ -71,17 +71,17 @@ python_rules = RuleList(
'description': 'Used % comprehension without a tuple'}, 'description': 'Used % comprehension without a tuple'},
{'pattern': r'.*%s.* % \([a-zA-Z0-9_.]*\)$', {'pattern': r'.*%s.* % \([a-zA-Z0-9_.]*\)$',
'description': 'Used % comprehension without a tuple'}, 'description': 'Used % comprehension without a tuple'},
{'pattern': '__future__', {'pattern': r'__future__',
'include_only': {'zulip_bots/zulip_bots/bots/'}, 'include_only': {'zulip_bots/zulip_bots/bots/'},
'description': 'Bots no longer need __future__ imports.'}, 'description': 'Bots no longer need __future__ imports.'},
{'pattern': '#!/usr/bin/env python$', {'pattern': r'#!/usr/bin/env python$',
'include_only': {'zulip_bots/'}, 'include_only': {'zulip_bots/'},
'description': 'Python shebangs must be python3'}, 'description': 'Python shebangs must be python3'},
{'pattern': r'(^|\s)open\s*\(', {'pattern': r'(^|\s)open\s*\(',
'description': 'open() should not be used in Zulip\'s bots. Use functions' 'description': 'open() should not be used in Zulip\'s bots. Use functions'
' provided by the bots framework to access the filesystem.', ' provided by the bots framework to access the filesystem.',
'include_only': {'zulip_bots/zulip_bots/bots/'}}, 'include_only': {'zulip_bots/zulip_bots/bots/'}},
{'pattern': 'pprint', {'pattern': r'pprint',
'description': 'Used pprint, which is most likely a debugging leftover. For user output, use print().'}, 'description': 'Used pprint, which is most likely a debugging leftover. For user output, use print().'},
{'pattern': r'\(BotTestCase\)', {'pattern': r'\(BotTestCase\)',
'bad_lines': ['class TestSomeBot(BotTestCase):'], 'bad_lines': ['class TestSomeBot(BotTestCase):'],
@ -97,7 +97,7 @@ python_rules = RuleList(
bash_rules = RuleList( bash_rules = RuleList(
langs=['sh'], langs=['sh'],
rules=[ rules=[
{'pattern': '#!.*sh [-xe]', {'pattern': r'#!.*sh [-xe]',
'description': 'Fix shebang line with proper call to /usr/bin/env for Bash path, change -x|-e switches' 'description': 'Fix shebang line with proper call to /usr/bin/env for Bash path, change -x|-e switches'
' to set -x|set -e'}, ' to set -x|set -e'},
] + whitespace_rules[0:1], ] + whitespace_rules[0:1],
@ -117,15 +117,15 @@ json_rules = RuleList(
) )
prose_style_rules = [ prose_style_rules = [
{'pattern': '[^\\/\\#\\-\"]([jJ]avascript)', # exclude usage in hrefs/divs {'pattern': r'[^\/\#\-"]([jJ]avascript)', # exclude usage in hrefs/divs
'description': "javascript should be spelled JavaScript"}, 'description': "javascript should be spelled JavaScript"},
{'pattern': '[^\\/\\-\\.\"\'\\_\\=\\>]([gG]ithub)[^\\.\\-\\_\"\\<]', # exclude usage in hrefs/divs {'pattern': r'''[^\/\-\."'\_\=\>]([gG]ithub)[^\.\-\_"\<]''', # exclude usage in hrefs/divs
'description': "github should be spelled GitHub"}, 'description': "github should be spelled GitHub"},
{'pattern': '[oO]rganisation', # exclude usage in hrefs/divs {'pattern': r'[oO]rganisation', # exclude usage in hrefs/divs
'description': "Organization is spelled with a z"}, 'description': "Organization is spelled with a z"},
{'pattern': '!!! warning', {'pattern': r'!!! warning',
'description': "!!! warning is invalid; it's spelled '!!! warn'"}, 'description': "!!! warning is invalid; it's spelled '!!! warn'"},
{'pattern': '[^-_]botserver(?!rc)|bot server', {'pattern': r'[^-_]botserver(?!rc)|bot server',
'description': "Use Botserver instead of botserver or Botserver."}, 'description': "Use Botserver instead of botserver or Botserver."},
] # type: Rule ] # type: Rule

View file

@ -52,7 +52,7 @@ def process_lines(raw_lines, file_name):
lines = [] lines = []
for line in raw_lines: for line in raw_lines:
# Add any filtering or modification code here # Add any filtering or modification code here
if re.match(".*upstream timed out.*while reading upstream.*", line): if re.match(r".*upstream timed out.*while reading upstream.*", line):
continue continue
lines.append(line) lines.append(line)

View file

@ -338,7 +338,7 @@ def setP4ExecBit(file, mode):
if not isModeExec(mode): if not isModeExec(mode):
p4Type = getP4OpenedType(file) p4Type = getP4OpenedType(file)
p4Type = re.sub('^([cku]?)x(.*)', '\\1\\2', p4Type) p4Type = re.sub(r'^([cku]?)x(.*)', '\\1\\2', p4Type)
p4Type = re.sub(r'(.*?\+.*?)x(.*?)', '\\1\\2', p4Type) p4Type = re.sub(r'(.*?\+.*?)x(.*?)', '\\1\\2', p4Type)
if p4Type[-1] == "+": if p4Type[-1] == "+":
p4Type = p4Type[0:-1] p4Type = p4Type[0:-1]
@ -817,7 +817,7 @@ def wildcard_encode(path):
return path return path
def wildcard_present(path): def wildcard_present(path):
m = re.search("[*#@%]", path) m = re.search(r"[*#@%]", path)
return m is not None return m is not None
class Command: class Command:
@ -1979,7 +1979,7 @@ class P4Sync(Command, P4UserMap):
# Preserve everything in relative path name except leading # Preserve everything in relative path name except leading
# //depot/; just look at first prefix as they all should # //depot/; just look at first prefix as they all should
# be in the same depot. # be in the same depot.
depot = re.sub("^(//[^/]+/).*", r'\1', prefixes[0]) depot = re.sub(r"^(//[^/]+/).*", r'\1', prefixes[0])
if p4PathStartsWith(path, depot): if p4PathStartsWith(path, depot):
path = path[len(depot):] path = path[len(depot):]
@ -3049,7 +3049,7 @@ class P4Rebase(Command):
die("Cannot find upstream branchpoint for rebase") die("Cannot find upstream branchpoint for rebase")
# the branchpoint may be p4/foo~3, so strip off the parent # the branchpoint may be p4/foo~3, so strip off the parent
upstream = re.sub("~[0-9]+$", "", upstream) upstream = re.sub(r"~[0-9]+$", "", upstream)
print("Rebasing the current branch onto %s" % upstream) print("Rebasing the current branch onto %s" % upstream)
oldHead = read_pipe("git rev-parse HEAD").strip() oldHead = read_pipe("git rev-parse HEAD").strip()
@ -3085,8 +3085,8 @@ class P4Clone(P4Sync):
def defaultDestination(self, args): def defaultDestination(self, args):
## TODO: use common prefix of args? ## TODO: use common prefix of args?
depotPath = args[0] depotPath = args[0]
depotDir = re.sub("(@[^@]*)$", "", depotPath) depotDir = re.sub(r"(@[^@]*)$", "", depotPath)
depotDir = re.sub("(#[^#]*)$", "", depotDir) depotDir = re.sub(r"(#[^#]*)$", "", depotDir)
depotDir = re.sub(r"\.\.\.$", "", depotDir) depotDir = re.sub(r"\.\.\.$", "", depotDir)
depotDir = re.sub(r"/$", "", depotDir) depotDir = re.sub(r"/$", "", depotDir)
return os.path.split(depotDir)[1] return os.path.split(depotDir)[1]

View file

@ -32,12 +32,12 @@ class LinkShortenerHandler:
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None: def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
REGEX_STR = ( REGEX_STR = (
'(' r'('
r'(?:http|https):\/\/' # This allows for the HTTP or HTTPS r'(?:http|https):\/\/' # This allows for the HTTP or HTTPS
# protocol. # protocol.
'[^"<>\\{\\}|\\^~[\\]` ]+' # This allows for any character except r'[^"<>\{\}|\^~[\]` ]+' # This allows for any character except
# for certain non-URL-safe ones. # for certain non-URL-safe ones.
')' r')'
) )
HELP_STR = ( HELP_STR = (