@@ -61,6 +61,15 @@ def is_skip_line(line):
6161 return False
6262
6363
64+ # Arrow function definitions: the body after => is lazy (not executed at
65+ # module scope). Detect `const fn = (...) => expr` patterns.
66+ ARROW_FN_DEF = re .compile (
67+ r'(?:const|let|var)\s+\w+\s*=\s*' # variable assignment
68+ r'(?:\([^)]*\)|\w+)' # parameter list or single param
69+ r'\s*=>' # arrow
70+ )
71+
72+
6473# Shell globals that should only be accessed inside enable()/disable()
6574SHELL_GLOBALS = re .compile (
6675 r'\bMain\.(panel|overview|layoutManager|sessionMode|messageTray|wm|'
@@ -183,6 +192,10 @@ def check_init_modifications(ext_dir):
183192 if is_skip_line (line ):
184193 continue
185194 if SHELL_GLOBALS .search (line ):
195+ # Arrow function definitions are lazy — the body after =>
196+ # is not executed at module scope
197+ if ARROW_FN_DEF .search (line ):
198+ continue
186199 violations .append (f"{ rel } :{ lineno } " )
187200 elif GOBJECT_CONSTRUCTORS .search (line ):
188201 # GObject.registerClass() returns a class, not an instance
@@ -191,17 +204,18 @@ def check_init_modifications(ext_dir):
191204 violations .append (f"{ rel } :{ lineno } " )
192205
193206 # Check constructor() lines
194- # GObject constructors in helper file constructors are runtime-only
195- # (only run when instantiated from enable()), so only flag in extension.js
207+ # Helper file constructors are runtime-only (only run when
208+ # instantiated from enable()), so only flag in extension.js
196209 is_extension_js = os .path .basename (filepath ) == 'extension.js'
197- ctor_lines = extract_constructor_lines (lines )
198- for lineno , line in ctor_lines :
199- if is_skip_line (line ):
200- continue
201- if SHELL_GLOBALS .search (line ):
202- violations .append (f"{ rel } :{ lineno } " )
203- elif is_extension_js and GOBJECT_CONSTRUCTORS .search (line ):
204- violations .append (f"{ rel } :{ lineno } " )
210+ if is_extension_js :
211+ ctor_lines = extract_constructor_lines (lines )
212+ for lineno , line in ctor_lines :
213+ if is_skip_line (line ):
214+ continue
215+ if SHELL_GLOBALS .search (line ):
216+ violations .append (f"{ rel } :{ lineno } " )
217+ elif GOBJECT_CONSTRUCTORS .search (line ):
218+ violations .append (f"{ rel } :{ lineno } " )
205219
206220 if violations :
207221 for loc in violations :
0 commit comments