check_code_comments treats a leading dereference as a block comment #961

Closed
opened 2026-08-06 20:10:13 +00:00 by coilyco-ops · 0 comments
Member

Symptom

The code-comments catalog hook reports a comment violation on a line that contains no comment:

FAIL: crates/factory_sim/src/player.rs:578: comment line is 100 chars, over the 90-char cap. Move durable detail to docs/.

Line 578 is ordinary Rust:

*self.warehouse_stock.entry(item).or_default() += self.trucks[truck_index].cargo_quantity;

Cause

is_comment_line in agentic_os/pre_commit/check_code_comments.py classifies a line as a block-comment continuation when the stripped text starts with *:

if suffix in BLOCK_COMMENT_EXTS:
    return (
        stripped.startswith("/*")
        or stripped.startswith("*")
        or stripped.startswith("*/")
    )

A leading * is also the dereference operator. The heuristic has no block-comment state, so it cannot tell a continuation line from a deref statement. Confirmed against the shipped module:

.rs   True   *self.stock.entry(item).or_default() += n;
.c    True   *ptr = 5;
.go   True   *count += 1;

BLOCK_COMMENT_EXTS covers .c, .cc, .cpp, .cs, .go, .h, .hpp, .java, .rs, and more, so this reaches every pointer-bearing language in the fleet. Both checks misfire: a long deref trips the char cap, and three consecutive derefs trip the contiguous-block cap.

Why it matters

The false positive is silent until a formatter produces the shape. In coilyco-gaming/factory-game-v3 the repo's own ward exec cargo-fmt joins that statement onto one 100-char line, so running the repo's declared format verb makes the repo's declared test gate fail. Neither tool is wrong on its own terms. That repo's half is tracked separately in coilyco-gaming/factory-game-v3#82.

Suggested shape

Track block-comment open and close state across the scan rather than guessing per line, so * continuation is only recognized between /* and */. A cheaper interim narrowing is to accept a leading * only when followed by whitespace or end of line, which rejects *self, *ptr, and *count while keeping real continuations. State tracking is the correct fix.

Acceptance

  • A leading dereference in .rs, .c, and .go is not counted as a comment, for both the char cap and the contiguous-block cap.
  • Genuine /* ... */ continuation lines are still counted.
  • Regression tests in tests/test_check_code_comments.py cover deref and real continuation for at least one block-comment language.
  • pre-commit run --all-files passes in this repo.
## Symptom The `code-comments` catalog hook reports a comment violation on a line that contains no comment: ``` FAIL: crates/factory_sim/src/player.rs:578: comment line is 100 chars, over the 90-char cap. Move durable detail to docs/. ``` Line 578 is ordinary Rust: ```rust *self.warehouse_stock.entry(item).or_default() += self.trucks[truck_index].cargo_quantity; ``` ## Cause `is_comment_line` in `agentic_os/pre_commit/check_code_comments.py` classifies a line as a block-comment continuation when the stripped text starts with `*`: ```python if suffix in BLOCK_COMMENT_EXTS: return ( stripped.startswith("/*") or stripped.startswith("*") or stripped.startswith("*/") ) ``` A leading `*` is also the dereference operator. The heuristic has no block-comment state, so it cannot tell a continuation line from a deref statement. Confirmed against the shipped module: ``` .rs True *self.stock.entry(item).or_default() += n; .c True *ptr = 5; .go True *count += 1; ``` `BLOCK_COMMENT_EXTS` covers `.c`, `.cc`, `.cpp`, `.cs`, `.go`, `.h`, `.hpp`, `.java`, `.rs`, and more, so this reaches every pointer-bearing language in the fleet. Both checks misfire: a long deref trips the char cap, and three consecutive derefs trip the contiguous-block cap. ## Why it matters The false positive is silent until a formatter produces the shape. In `coilyco-gaming/factory-game-v3` the repo's own `ward exec cargo-fmt` joins that statement onto one 100-char line, so running the repo's declared format verb makes the repo's declared test gate fail. Neither tool is wrong on its own terms. That repo's half is tracked separately in `coilyco-gaming/factory-game-v3#82`. ## Suggested shape Track block-comment open and close state across the scan rather than guessing per line, so `*` continuation is only recognized between `/*` and `*/`. A cheaper interim narrowing is to accept a leading `*` only when followed by whitespace or end of line, which rejects `*self`, `*ptr`, and `*count` while keeping real continuations. State tracking is the correct fix. ## Acceptance - A leading dereference in `.rs`, `.c`, and `.go` is not counted as a comment, for both the char cap and the contiguous-block cap. - Genuine `/* ... */` continuation lines are still counted. - Regression tests in `tests/test_check_code_comments.py` cover deref and real continuation for at least one block-comment language. - `pre-commit run --all-files` passes in this repo.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
coilyco-flight-deck/agentic-os#961
No description provided.