Skip to content
Browse files
check-webkit-style: more strict upper case enum exceptions

Reviewed by Darin Adler.

Added a new list of common abbreviations which are allowed to be
used as all uppercase enum values.

* Tools/Scripts/webkitpy/style/checkers/
(_EnumState.process_clean_line.is_case_error): Extracted common
logic for inline and multiline enum declarations.
* Tools/Scripts/webkitpy/style/checkers/

Canonical link:
git-svn-id: 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
yury-s committed May 20, 2022
1 parent 76dea20 commit 622f5bf389dec8cff2e4bf744b1e17a15c751edd
Showing 2 changed files with 33 additions and 12 deletions.
@@ -1353,18 +1353,27 @@ def process_clean_line(self, line):
# FIXME: The regular expressions for expr_all_uppercase and expr_enum_end only accept integers
# and identifiers for the value of the enumerator, but do not accept any other constant
# expressions. However, this is sufficient for now (11/27/2012).
expr_all_uppercase = r'\s*[A-Z0-9_]+\s*(?:=\s*[a-zA-Z0-9]+\s*)?,?\s*$'
expr_all_uppercase = r'\s*(?P<value>[A-Z0-9_]+)\s*(?:=\s*[a-zA-Z0-9]+\s*)?,?\s*$'
expr_starts_lowercase = r'\s*[a-jl-z]'
expr_enum_end = r'}\s*(?:[a-zA-Z0-9]+\s*(?:=\s*[a-zA-Z0-9]+)?)?\s*;\s*'
expr_enum_start = r'\s*(?:enum(?:\s+class)?(?:\s+(?P<identifier>[a-zA-Z0-9]+))?)(?:\s*:\s*[a-zA-Z0-9_]+?)?\s*\{?\s*'

def is_case_error(enum_name, value_declaration):
all_uppercase = match(expr_all_uppercase, value_declaration)
if all_uppercase:
if self.is_webidl_enum:
return False
if enum_name in _ALLOW_ALL_UPPERCASE_ENUM:
return False
return match(expr_starts_lowercase, value_declaration)

if self.in_enum_decl:
if match(r'\s*' + expr_enum_end + r'$', line):
self.in_enum_decl = False
self.is_webidl_enum = False
return True
elif match(expr_all_uppercase, line):
return self.is_webidl_enum or self.enum_decl_name in _ALLOW_ALL_UPPERCASE_ENUM
elif match(expr_starts_lowercase, line):
elif is_case_error(self.enum_decl_name, line):
return False
matched = match(expr_enum_start + r'$', line)
if matched:
@@ -1374,14 +1383,9 @@ def process_clean_line(self, line):
matched = match(expr_enum_start + r'(?P<members>[^{]*)' + expr_enum_end + r'$', line)
if matched:
members ='members').split(',')
allow_all_uppercase ='identifier') in _ALLOW_ALL_UPPERCASE_ENUM
found_invalid_member = False
enum_name ='identifier')
for member in members:
if match(expr_all_uppercase, member):
found_invalid_member = not self.is_webidl_enum and not allow_all_uppercase
if match(expr_starts_lowercase, member):
found_invalid_member = True
if found_invalid_member:
if is_case_error(enum_name, member):
self.is_webidl_enum = False
return False
return True
@@ -2546,8 +2550,10 @@ def check_namespace_indentation(clean_lines, line_number, file_extension, file_s

# Enum declaration allowlist
_ALLOW_ALL_UPPERCASE_ENUM = ['JSTokenType', 'Meridiem', 'NSType', 'Requester']

# Enum value allowlist

def check_enum_casing(clean_lines, line_number, enum_state, error):
"""Looks for incorrectly named enum values.
@@ -4333,6 +4333,21 @@ def test_enum_casing(self):
enum class Requester { Main, XHR };''',

'''enum class CommonAbbreviations { AM, CF, PM, URL, XHR };''',

enum class CommonAbbreviationsMultiline {

enum Foo {

0 comments on commit 622f5bf

Please sign in to comment.