Skip to content

Commit 614883e

Browse files
ZviBaratzSolomonclaude
authored
fix(ego-lint): suppress R-VER46-01/02 for ShellVersion-guarded else branches (#151)
## Problem `R-VER46-01` (`add_actor`) and `R-VER46-02` (`remove_actor`) fire as false positives when the deprecated API is called inside an `else {}` branch guarded by a `ShellVersion` version check: \`\`\`js const ShellVersion = parseFloat(Config.PACKAGE_VERSION); if (ShellVersion >= 46) { parent.remove_child(actor); // modern path } else { parent.remove_actor(actor); // ← R-VER46-02 was firing here (FP) } \`\`\` This pattern is used by caffeine (`extension.js:721, 829`) and hara-hachi-bu, and is entirely correct — `remove_actor()` only runs on GNOME < 46 where it still exists. ## Root Cause The existing `guard-pattern` for both rules only matched feature-check guards like `if (obj.remove_actor)`, not `ShellVersion`-based version conditionals. ## Fix Extend the `guard-pattern` regex for R-VER46-01 and R-VER46-02 with `|\\bShellVersion\\b` and set `guard-window: 5`. This causes the backward-scan to skip the match when `ShellVersion` appears within the preceding 5 lines — covering all typical 3–4 line if/else version guards. The existing guard for feature-check patterns is preserved (regex alternation). ## Tests - New fixture `version-guard-remove-actor@test`: verifies both R-VER46-01 and R-VER46-02 produce no FAIL or WARN on ShellVersion-guarded else branches - Existing `gnome46-compat@test`: unchanged — unguarded `add_actor`/`remove_actor` still produces FAIL (true positives preserved) - Net change: +4 passing assertions, 0 regressions (567→571 pass, 125 fail unchanged) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Solomon <sol@nanoclaw.dev> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fc10806 commit 614883e

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

rules/patterns.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@
854854
category: version-compat
855855
fix: "Replace .add_actor(child) with .add_child(child)"
856856
min-version: 46
857-
guard-pattern: "\\bif\\s*\\(.*\\.add_actor\\b"
857+
guard-pattern: "\\bif\\s*\\(.*\\.add_actor\\b|\\bShellVersion\\b"
858+
guard-window: 5
858859
compat-downgrade: true
859860

860861
- id: R-VER46-02
@@ -865,7 +866,8 @@
865866
category: version-compat
866867
fix: "Replace .remove_actor(child) with .remove_child(child)"
867868
min-version: 46
868-
guard-pattern: "\\bif\\s*\\(.*\\.remove_actor\\b"
869+
guard-pattern: "\\bif\\s*\\(.*\\.remove_actor\\b|\\bShellVersion\\b"
870+
guard-window: 5
869871
compat-downgrade: true
870872

871873
- id: R-VER46-03
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
2+
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
3+
4+
const ShellVersion = parseFloat(Config.PACKAGE_VERSION);
5+
6+
export default class VersionGuardExtension extends Extension {
7+
enable() {
8+
this._addActor();
9+
}
10+
11+
_addActor() {
12+
// Version-guarded compat code: add_actor() only runs on GNOME < 46
13+
if (ShellVersion >= 46) {
14+
this._box.add_child(this._actor);
15+
} else {
16+
this._box.add_actor(this._actor);
17+
}
18+
}
19+
20+
_removeActor() {
21+
// Version-guarded compat code: remove_actor() only runs on GNOME < 46
22+
if (ShellVersion >= 46) {
23+
this._box.remove_child(this._actor);
24+
} else {
25+
this._box.remove_actor(this._actor);
26+
}
27+
}
28+
29+
disable() {
30+
this._removeActor();
31+
this._box = null;
32+
this._actor = null;
33+
}
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uuid": "version-guard-remove-actor@test",
3+
"name": "Version Guard Remove Actor Test",
4+
"description": "Tests that add_actor/remove_actor inside ShellVersion else-branches are not flagged",
5+
"shell-version": ["45", "46"],
6+
"url": "https://github.com/test/version-guard-remove-actor"
7+
}

tests/run-tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,15 @@ assert_output_contains "fails on add_actor" "\[FAIL\].*R-VER46-01"
474474
assert_output_contains "fails on remove_actor" "\[FAIL\].*R-VER46-02"
475475
echo ""
476476

477+
# --- version-guard-remove-actor ---
478+
echo "=== version-guard-remove-actor ==="
479+
run_lint "version-guard-remove-actor@test"
480+
assert_output_not_contains "no R-VER46-01 on ShellVersion-guarded add_actor" "\[FAIL\].*R-VER46-01"
481+
assert_output_not_contains "no R-VER46-01 warn on ShellVersion-guarded add_actor" "\[WARN\].*R-VER46-01"
482+
assert_output_not_contains "no R-VER46-02 on ShellVersion-guarded remove_actor" "\[FAIL\].*R-VER46-02"
483+
assert_output_not_contains "no R-VER46-02 warn on ShellVersion-guarded remove_actor" "\[WARN\].*R-VER46-02"
484+
echo ""
485+
477486
# --- gnome47-compat ---
478487
echo "=== gnome47-compat ==="
479488
run_lint "gnome47-compat@test"

0 commit comments

Comments
 (0)