Skip to content

Commit d7051cf

Browse files
ZviBaratzclaude
andauthored
fix(ego-lint): add replacement-pattern to R-VER rules for version-compat suppression (#84)
## Summary - Add file-level `replacement-pattern` to 4 version-compat rules (R-VER44-02, R-VER46-04, R-VER49-08, R-VER49-11) to suppress findings when the replacement API is present in the same file - Skip 3 rules where the replacement API is too common for file-level suppression (R-VER46-01, R-VER46-02, R-VER46-07) - Add test fixture `ver-replacement-compat@test` with 4 assertions verifying suppression ### Rules updated | Rule | Deprecated API | replacement-pattern | Rationale | |------|---|---|---| | R-VER44-02 | `Meta.later_remove` | `get_laters` | New API path `get_laters().removeLater()` | | R-VER46-04 | `Gio.UnixInputStream` | `GioUnix` | New module name | | R-VER49-08 | `maximize(MaximizeFlags)` | `set_maximize_flags` | New API for flag setting | | R-VER49-11 | `unmaximize(MaximizeFlags)` | `set_maximize_flags` | Same new API | ### Rules skipped (replacement API too common) | Rule | Why | |------|-----| | R-VER46-01 `.add_actor()` | `add_child` ubiquitous in extensions | | R-VER46-02 `.remove_actor()` | `remove_child` ubiquitous in extensions | | R-VER46-07 `Clutter.Container` | No specific replacement; `Clutter.Actor` everywhere | ## Test plan - [x] `bash tests/run-tests.sh` — 607 passed, 0 failed - [x] New `ver-replacement-compat@test` fixture verifies all 4 rules suppressed when replacement API present - [x] Existing `gnome46-compat`, `gnome48-compat`, `gnome49-compat` fixtures still FAIL correctly (no replacement APIs in those files) Closes #74 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0d2df8d commit d7051cf

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

rules/patterns.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@
812812
category: version-compat
813813
fix: "Use global.compositor.get_laters().addLater(Meta.LaterType.BEFORE_REDRAW, callback)"
814814
min-version: 44
815+
replacement-pattern: "get_laters"
815816

816817
- id: R-VER44-02
817818
pattern: "\\bMeta\\.later_remove\\b"
@@ -823,6 +824,7 @@
823824
min-version: 44
824825
guard-pattern: "if\\s*\\(\\s*global\\.compositor\\s*\\)"
825826
guard-window: 7
827+
replacement-pattern: "get_laters"
826828

827829
- id: R-VER46-01
828830
pattern: "\\.add_actor\\s*\\("
@@ -862,6 +864,7 @@
862864
fix: "Import GioUnix from 'gi://GioUnix' and use GioUnix.InputStream"
863865
min-version: 46
864866
guard-pattern: "\\bGioUnix\\b"
867+
replacement-pattern: "GioUnix"
865868

866869
- id: R-VER46-05
867870
pattern: "\\bExtensionState\\.(ENABLED|DISABLED|INITIALIZED|DEACTIVATING|ACTIVATING)\\b"
@@ -1065,6 +1068,7 @@
10651068
min-version: 49
10661069
guard-pattern: "get_maximized\\s*\\?"
10671070
guard-window: 1
1071+
replacement-pattern: "set_maximize_flags"
10681072

10691073
- id: R-VER49-09
10701074
pattern: "\\bAppMenuButton\\b"
@@ -1094,6 +1098,7 @@
10941098
fix: "Call unmaximize() without the MaximizeFlags parameter"
10951099
guard-pattern: "get_maximized\\s*\\?"
10961100
guard-window: 1
1101+
replacement-pattern: "set_maximize_flags"
10971102

10981103
# --- GNOME 50 migration (version-gated) ---
10991104
# GNOME 50 removed X11 support and associated APIs.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SPDX-License-Identifier: GPL-2.0-or-later
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
2+
import Meta from 'gi://Meta';
3+
import Gio from 'gi://Gio';
4+
5+
let GioUnix;
6+
try {
7+
GioUnix = (await import('gi://GioUnix')).default;
8+
} catch {
9+
// fallback for GNOME < 46
10+
}
11+
12+
export default class VersionReplacementCompat extends Extension {
13+
enable() {
14+
// R-VER44-01: old API (suppressed — file contains "get_laters")
15+
this._laterId = Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {});
16+
17+
// R-VER44-02: old API (suppressed — file contains "get_laters")
18+
Meta.later_remove(this._laterId);
19+
20+
// R-VER46-04: old API (suppressed — file contains "GioUnix")
21+
this._stream = new Gio.UnixInputStream({fd: 0});
22+
23+
// R-VER49-08: old API (suppressed — file contains "set_maximize_flags")
24+
this._win.maximize(Meta.MaximizeFlags.BOTH);
25+
26+
// R-VER49-11: old API (suppressed — file contains "set_maximize_flags")
27+
this._win.unmaximize(Meta.MaximizeFlags.BOTH);
28+
}
29+
30+
_newApi() {
31+
// Replacement APIs present in file for version-compat
32+
const laters = global.compositor.get_laters();
33+
laters.removeLater(this._laterId);
34+
this._win.set_maximize_flags(Meta.MaximizeFlags.BOTH);
35+
this._win.maximize();
36+
}
37+
38+
disable() {
39+
this._stream = null;
40+
this._win = null;
41+
}
42+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uuid": "ver-replacement-compat@test",
3+
"name": "Version Replacement Compat Test",
4+
"description": "Tests replacement-pattern suppression for version-compat code",
5+
"shell-version": ["49"],
6+
"url": ""
7+
}

tests/run-tests.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,16 @@ assert_output_not_contains "no R-VER49-08 with ternary guard" "\[FAIL\].*R-VER49
453453
assert_output_not_contains "no R-VER49-11 with ternary guard" "\[FAIL\].*R-VER49-11"
454454
echo ""
455455

456+
# --- ver-replacement-compat ---
457+
echo "=== ver-replacement-compat ==="
458+
run_lint "ver-replacement-compat@test"
459+
assert_output_not_contains "no R-VER44-01 with replacement-pattern" "\[FAIL\].*R-VER44-01"
460+
assert_output_not_contains "no R-VER44-02 with replacement-pattern" "\[FAIL\].*R-VER44-02"
461+
assert_output_not_contains "no R-VER46-04 with replacement-pattern" "\[FAIL\].*R-VER46-04"
462+
assert_output_not_contains "no R-VER49-08 with replacement-pattern" "\[FAIL\].*R-VER49-08"
463+
assert_output_not_contains "no R-VER49-11 with replacement-pattern" "\[FAIL\].*R-VER49-11"
464+
echo ""
465+
456466
# --- gnome46-extras ---
457467
echo "=== gnome46-extras ==="
458468
run_lint "gnome46-extras@test"

0 commit comments

Comments
 (0)