lint: require const field names to be in ALL_CAPS

GitOrigin-RevId: 8b6c20e6d978f2756bdbf946ff860ce5cc48e3ce
This commit is contained in:
Colin McMillen 2020-02-25 20:34:19 -05:00
parent 5549f15029
commit 6b95a66859

View File

@ -32,14 +32,20 @@ def lint_csharp(filename):
if len(line) > MAX_LINE_LENGTH: if len(line) > MAX_LINE_LENGTH:
if not re.match(r'\s*// https?:', line): if not re.match(r'\s*// https?:', line):
emit_error(filename, line_num, 'line too long') emit_error(filename, line_num, 'line too long')
if re.match(r'\s*//\S', line):
emit_error(filename, line_num, 'no space between // and comment')
match = re.match(r'\s*const.* (\w+) =', line)
if match:
identifier = match.group(1)
if not re.fullmatch(r'[A-Z_]+', identifier):
emit_error(filename, line_num,
'const field %s should be in ALL_CAPS' % identifier)
if re.search(r'\t', line): if re.search(r'\t', line):
emit_error(filename, line_num, 'illegal \\t character') emit_error(filename, line_num, 'illegal \\t character')
if re.search(r'\r', line): if re.search(r'\r', line):
emit_error(filename, line_num, 'illegal \\r character') emit_error(filename, line_num, 'illegal \\r character')
if re.search(r'\s+$', line): if re.search(r'\s+$', line):
emit_error(filename, line_num, 'trailing whitespace') emit_error(filename, line_num, 'trailing whitespace')
if re.match(r'\s*//\S', line):
emit_error(filename, line_num, 'no space between // and comment')
def main(args): def main(args):