Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ CheckOptions:
- { key: readability-identifier-naming.ClassMemberPrefix, value: m }
- { key: readability-identifier-naming.ConceptCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariableIgnoredRegexp, value: "^k[A-Z][a-zA-Z0-9]*$" } # Allow "k" prefix.
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantIgnoredRegexp, value: "^k?[A-Z][a-zA-Z0-9_]*$" } # Allow "k" prefix and underscores.
- { key: readability-identifier-naming.EnumConstantIgnoredRegexp, value: "^k?[A-Z][a-zA-Z0-9_]*$" } # Allow "k" prefix and non-trailing underscores in PDG names.
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
- { key: readability-identifier-naming.MacroDefinitionIgnoredRegexp, value: "^[A-Z][A-Z0-9_]*_$" } # Allow the trailing underscore in header guards.
Expand Down
16 changes: 7 additions & 9 deletions Scripts/o2_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,21 +988,19 @@ class TestNameConstant(TestSpec):
"""Test constexpr constant names."""

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

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

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


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

# Print tips.
print("\nTip: You can run the O2 linter locally from the O2Physics directory with: python3 Scripts/o2_linter.py <files>")
print(
"\nTip: You can run the O2 linter locally from the O2Physics directory with: python3 Scripts/o2_linter.py <files>"
)

if not passed:
sys.exit(1)
Expand Down
Loading