Skip to content

Commit 7f237b2

Browse files
author
abacus_fixer
committed
fix(code_quality): exclude arrow member access from uppercase constant rule
UPPERCASE_CONST_RE used a (?<![.:]) lookbehind that only excluded the '.' and ':' member-access prefixes. The '->' (arrow) form of member access was missing: 'ptr->UPPER_MEMBER' still matched UPPER_MEMBER even though the semantically equivalent 'obj.MEMBER' and 'Type::MEMBER' were already excluded. This produced different scores for equivalent code depending on whether a pointer or a value/member-access was used. Add '>' to the lookbehind character class so that the character immediately preceding the identifier is now '.' | ':' | '>'. '>' is a literal inside a Python regex character class and requires no escaping. The lookahead (?![.:]) is intentionally left unchanged: the token that follows an arrow member access is usually ';', '(', '=', or whitespace, never '.' or ':', so mirroring the '>' there would be dead weight. This keeps the rule symmetric with how '.' and ':' were already handled (prefix-only exclusion). Reproducer fixed: value = ptr->UPPER_MEMBER; used to match UPPER_MEMBER (1 deduction); now excluded, matching the existing behaviour for obj.MEMBER and Type::MEMBER. Real constants declared on their own line (MY_CONSTANT, GLOBAL_MAX, RED/GREEN/BLUE enum values, #define FOO macros, function-argument constants such as func(MAX_VAL)) are still detected.
1 parent d1fd9fb commit 7f237b2

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tools/03_code_analysis/code_quality_score.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184

185185
CHINESE_RE = re.compile("[\u4e00-\u9fff]")
186186
USING_NS_STD_RE = re.compile(r"\busing\s+namespace\s+std\b")
187-
UPPERCASE_CONST_RE = re.compile(r"(?<![.:])\b[A-Z][A-Z0-9_]{2,}\b(?![.:])")
187+
UPPERCASE_CONST_RE = re.compile(r"(?<![.:>])\b[A-Z][A-Z0-9_]{2,}\b(?![.:])")
188188
ACCESS_RE = re.compile(r"^\s*(public|private|protected)\s*:")
189189
CLASS_OPEN_RE = re.compile(r"\b(class|struct)\s+(\w+)\b")
190190

0 commit comments

Comments
 (0)