Skip to content

Commit e1394a6

Browse files
author
abacus_fixer
committed
fix(code_quality): do not deduct for public members in struct bodies
The public_member_variable rule previously applied uniformly to both class and struct bodies, treating any public data member as a code-quality finding regardless of the enclosing type. In C++ a struct has public access by default and public data members are the idiomatic shape for POD aggregates, value types, configuration data, and mixin tags; penalising them charges the author for writing legitimate, intended C++. Gate the finding in analyze_class_blocks on kind == 'class'. struct bodies — including struct members that appear inside an explicit 'public:' access block — no longer produce public_member_variable findings. class bodies keep the existing behaviour: public data members in a class continue to be deducted because the author of a class is expected to encapsulate state. Update the inline comment to explain the rationale so future readers understand why struct and class are treated differently. Reproducer: struct A { int counter; double value; }; used to report 2 findings (counter, value); now 0. class B { public: int counter; double value; }; still reports 2 findings.
1 parent 7f237b2 commit e1394a6

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

tools/03_code_analysis/code_quality_score.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,13 @@ def analyze_class_blocks(
13901390
# multi-line declaration are skipped regardless of how they
13911391
# look in isolation — e.g. ` = std::vector<int>;` after a
13921392
# two-line `using value_type` alias must not count as a member.
1393+
# Only `class` bodies are penalised: in C++ a `struct` has
1394+
# public access by default and public data members are a
1395+
# legitimate, intended usage (POD aggregate, value types,
1396+
# mixin tags). Treating them as a code-quality issue would
1397+
# penalise perfectly idiomatic C++.
13931398
if prev_depth == 1 and access_per_line[idx] == "public" \
1399+
and kind == "class" \
13941400
and idx not in continued_idxs:
13951401
if is_public_member_var(line):
13961402
pub_findings.append(Finding(

0 commit comments

Comments
 (0)