From e742b9ed52385df2e3b811b20775cfcd63b9ba2b Mon Sep 17 00:00:00 2001 From: nicolassanchez02 <98576999+nicolassanchez02@users.noreply.github.com> Date: Fri, 29 May 2026 19:48:22 -0500 Subject: [PATCH] codecompliance: check spaces around compound/comparison operators cppstyle.py already flags a few C++ spacing slips but not missing spaces around the compound-assignment and comparison operators (+=, ==, <=, and friends), which #837 asks for. Add a check for them. The operators overlap, so a naive scan false-matches: >= sits inside >>=, <= inside <<= and the C++20 <=> spaceship. The regex uses lookbehind/lookahead to only match the standalone forms. Comments and string literals are blanked before checking, and operator-overload declarations (operator==, etc.) are skipped, so things like `// a==b`, `"x==y"` and `bool operator==(...)` don't trip it. The existing tree already passes the new check (zero hits across libopenage), so this is purely additive. Closes #837. --- buildsystem/codecompliance/cppstyle.py | 45 ++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/buildsystem/codecompliance/cppstyle.py b/buildsystem/codecompliance/cppstyle.py index c05021e223..43a3a17af7 100644 --- a/buildsystem/codecompliance/cppstyle.py +++ b/buildsystem/codecompliance/cppstyle.py @@ -1,4 +1,4 @@ -# Copyright 2015-2017 the openage authors. See copying.md for legal info. +# Copyright 2015-2026 the openage authors. See copying.md for legal info. """ Checks some code style rules for cpp files. @@ -47,6 +47,33 @@ r")" ) +# Compound-assignment and comparison operators that must be surrounded by spaces. +# Ordered longest-first; < and >-based ops use lookbehind/lookahead to avoid +# matching the shorter pattern inside a longer one (e.g. >= inside >>=, +# <= inside <<= or the C++20 <=> spaceship operator). +_SPACED_OPS_ALT = ( + r'<<=|>>=|' + r'\+=|-=|\*=|%=|\^=|\|=|&=|~=|' + r'(?)|(?)>=|' + r'==|!=' +) + +OPERATOR_SPACING_RE = re.compile( + r'(?