Skip to content

Commit 9d6654a

Browse files
ZviBaratzclaude
andauthored
fix(ego-lint): handle async arrow functions and GObject branch in check-init.py (#55)
## Summary - Update `ARROW_FN_DEF` regex to include optional `async` keyword so `const fn = async () => Main.panel.x` is not flagged - Add `ARROW_FN_DEF` exemption to the `GOBJECT_CONSTRUCTORS` branch so `const make = () => new St.Label()` at module scope is not flagged - Add test fixture cases and assertions for both scenarios Closes #45 ## Test plan - [x] `python3 check-init.py` correctly flags only the true violation (line 5) and exempts all arrow function lines - [x] Full test suite passes (561 assertions) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c6c61be commit 9d6654a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

skills/ego-lint/scripts/check-init.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def is_skip_line(line):
6565
# module scope). Detect `const fn = (...) => expr` patterns.
6666
ARROW_FN_DEF = re.compile(
6767
r'(?:const|let|var)\s+\w+\s*=\s*' # variable assignment
68+
r'(?:async\s+)?' # optional async keyword
6869
r'(?:\([^)]*\)|\w+)' # parameter list or single param
6970
r'\s*=>' # arrow
7071
)
@@ -198,6 +199,10 @@ def check_init_modifications(ext_dir):
198199
continue
199200
violations.append(f"{rel}:{lineno}")
200201
elif GOBJECT_CONSTRUCTORS.search(line):
202+
# Arrow function definitions are lazy — not executed at
203+
# module scope
204+
if ARROW_FN_DEF.search(line):
205+
continue
201206
# GObject.registerClass() returns a class, not an instance
202207
if not REGISTER_CLASS.search(line) and \
203208
not VALUE_TYPES.search(line):

tests/fixtures/init-time-safety@test/extension.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ const primaryIdx = Main.layoutManager.primaryIndex;
77
// OK: arrow function definition is lazy (body not executed at module scope)
88
const getMonitors = () => Main.layoutManager.monitors;
99

10+
// OK: async arrow function definition is lazy
11+
const addItem = async () => Main.panel.addToStatusArea('test', null);
12+
13+
// OK: arrow function wrapping GObject constructor
14+
const makeLabel = () => new St.Label({text: 'hello'});
15+
1016
export default class InitTimeTest extends Extension {
1117
enable() {
1218
// OK: Shell globals inside enable()

tests/run-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ assert_exit_code "exits with 1 (has module-scope violation)" 1
217217
assert_output_contains "fails on module-scope Main access" "\[FAIL\].*init/shell-modification"
218218
assert_output_not_contains "no FP on helper constructor" "init/shell-modification.*helper.js"
219219
assert_output_not_contains "no FP on arrow function definition" "init/shell-modification.*extension.js:8"
220+
assert_output_not_contains "no FP on async arrow function" "init/shell-modification.*extension.js:11"
221+
assert_output_not_contains "no FP on arrow GObject constructor" "init/shell-modification.*extension.js:14"
220222
echo ""
221223

222224
# --- lifecycle-imbalance ---

0 commit comments

Comments
 (0)