Skip to content

Commit 7a3c788

Browse files
Solomonclaude
andcommitted
fix(patterns): suppress R-VER46-01/02 for ShellVersion-guarded else branches
add_actor() and remove_actor() inside `else {}` branches of `if (ShellVersion >= 46) { new_api() } else { old_api() }` guards are correctly version-fenced and should not be flagged. The previous guard-pattern only detected feature-check guards (`if (obj.remove_actor)`), missing the common ShellVersion pattern used by caffeine and hara-hachi-bu. Extend guard-pattern for both rules with `|\\bShellVersion\\b` and set guard-window: 5 so the backward scan covers typical 3-4 line if/else blocks. Add fixture and assertions verifying both rules are suppressed on guarded code and still fire on unguarded code. Fixes: caffeine extension.js:721,829 false positives Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e74c508 commit 7a3c788

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
@@ -856,7 +856,8 @@
856856
category: version-compat
857857
fix: "Replace .add_actor(child) with .add_child(child)"
858858
min-version: 46
859-
guard-pattern: "\\bif\\s*\\(.*\\.add_actor\\b"
859+
guard-pattern: "\\bif\\s*\\(.*\\.add_actor\\b|\\bShellVersion\\b"
860+
guard-window: 5
860861
compat-downgrade: true
861862

862863
- id: R-VER46-02
@@ -867,7 +868,8 @@
867868
category: version-compat
868869
fix: "Replace .remove_actor(child) with .remove_child(child)"
869870
min-version: 46
870-
guard-pattern: "\\bif\\s*\\(.*\\.remove_actor\\b"
871+
guard-pattern: "\\bif\\s*\\(.*\\.remove_actor\\b|\\bShellVersion\\b"
872+
guard-window: 5
871873
compat-downgrade: true
872874

873875
- 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
@@ -473,6 +473,15 @@ assert_output_contains "fails on add_actor" "\[FAIL\].*R-VER46-01"
473473
assert_output_contains "fails on remove_actor" "\[FAIL\].*R-VER46-02"
474474
echo ""
475475

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

0 commit comments

Comments
 (0)