Skip to content

Commit db9c11c

Browse files
authored
[Infrastructure] O2 linter: Remove prefix exception for constexpr constants (#13518)
1 parent ef81014 commit db9c11c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

.clang-tidy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ CheckOptions:
44
- { key: readability-identifier-naming.ClassMemberPrefix, value: m }
55
- { key: readability-identifier-naming.ConceptCase, value: CamelCase }
66
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
7-
- { key: readability-identifier-naming.ConstexprVariableIgnoredRegexp, value: "^k[A-Z][a-zA-Z0-9]*$" } # Allow "k" prefix.
87
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
98
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
10-
- { key: readability-identifier-naming.EnumConstantIgnoredRegexp, value: "^k?[A-Z][a-zA-Z0-9_]*$" } # Allow "k" prefix and underscores.
9+
- { key: readability-identifier-naming.EnumConstantIgnoredRegexp, value: "^k?[A-Z][a-zA-Z0-9_]*$" } # Allow "k" prefix and non-trailing underscores in PDG names.
1110
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
1211
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
1312
- { key: readability-identifier-naming.MacroDefinitionIgnoredRegexp, value: "^[A-Z][A-Z0-9_]*_$" } # Allow the trailing underscore in header guards.

Scripts/o2_linter.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -988,21 +988,19 @@ class TestNameConstant(TestSpec):
988988
"""Test constexpr constant names."""
989989

990990
name = "name/constexpr-constant"
991-
message = (
992-
'Use UpperCamelCase for names of constexpr constants. Names of special constants may be prefixed with "k".'
993-
)
991+
message = "Use UpperCamelCase for names of constexpr constants."
994992
rationale = rationale_names
995993
references = references_names
996994
suffixes = [".h", ".cxx", ".C"]
997995

998996
def __init__(self) -> None:
999997
super().__init__()
1000998
keyword = r"(.+ )" # e.g. "static "
1001-
type_val = r"([\w:<>+\-*\/, ]+ )" # value type e.g. "std::array<Type, n + 1> "
999+
type_val = r"([\w:<>+\-*\/, ]+ )" # value type e.g. "std::array<Type, n + 1> "
10021000
prefix = r"(\w+::)" # prefix with namespace or class, e.g. "MyClass::"
10031001
name_val = r"(\w+)" # name of the constant
1004-
array = r"(\[.*\])" # array declaration: "[...]"
1005-
assignment = r"( =|\(\d|{)" # value assignment, e.g. " = 2", " = expression", "(2)", "{2}", "{{...}}"
1002+
array = r"(\[.*\])" # array declaration: "[...]"
1003+
assignment = r"( =|\(\d|{)" # value assignment, e.g. " = 2", " = expression", "(2)", "{2}", "{{...}}"
10061004
self.pattern = re.compile(rf"{keyword}?constexpr {type_val}?{prefix}*{name_val}{array}?{assignment}")
10071005

10081006
def test_line(self, line: str) -> bool:
@@ -1013,8 +1011,6 @@ def test_line(self, line: str) -> bool:
10131011
return True
10141012
constant_name = match.group(4)
10151013
# The actual test comes here.
1016-
if constant_name.startswith("k") and len(constant_name) > 1: # exception for special constants
1017-
constant_name = constant_name[1:] # test the name without "k"
10181014
return is_upper_camel_case(constant_name)
10191015

10201016

@@ -1785,7 +1781,9 @@ def main():
17851781
print("Skipping writing in GITHUB_OUTPUT.")
17861782

17871783
# Print tips.
1788-
print("\nTip: You can run the O2 linter locally from the O2Physics directory with: python3 Scripts/o2_linter.py <files>")
1784+
print(
1785+
"\nTip: You can run the O2 linter locally from the O2Physics directory with: python3 Scripts/o2_linter.py <files>"
1786+
)
17891787

17901788
if not passed:
17911789
sys.exit(1)

0 commit comments

Comments
 (0)