--- name: fix-xml-globals description: | Fix XML view/fragment issues that UI5 linter reports but cannot auto-fix. Use this skill when linter outputs these rules: - `no-globals` - For ALL global variable access in XML views — sap.*, jQuery.*, AND app-namespace globals (e.g., com.example.app.utils.Handler.onPress, my.app.formatter.method) - `no-ambiguous-event-handler` - For event handlers without dot prefix or local name - `no-deprecated-api` - For legacy template:require syntax (space-separated) Trigger on XML view/fragment files with errors about global variables, event handlers, formatters, type references in bindings, factory functions, or template:require. Automatically adds core:require declarations, fixes event handler prefixes, and handles .bind($control) for functions that use 'this'. IMPORTANT: The linter reports app-namespace globals in XML under `no-globals` — these MUST be fixed by this skill, NOT deferred to fix-linter-blind-spots. For native HTML or SVG in XML views, use the fix-xml-native-html skill instead. --- # Fix XML Views/Fragments Global Access This skill fixes XML view and fragment issues that the UI5 linter detects but cannot auto-fix because they require understanding of module paths and handler locations. ## Linter Rules Handled | Rule ID | Message Pattern | This Skill's Action | |---------|-----------------|---------------------| | `no-globals` | Access of global variable '...' (...) | Add `core:require` and use local name | | `no-ambiguous-event-handler` | Event handler '...' must be prefixed by a dot '.' or refer to a local name | Add `.` prefix for controller methods or add `core:require` for modules | | `no-deprecated-api` | Usage of space-separated list '...' in template:require | Convert to object notation | ## When to Use Apply this skill when you see linter output like: ``` Main.view.xml:15:5 error Access of global variable 'formatter' (my.app.model.formatter) no-globals Main.view.xml:20:5 warning Event handler 'onPress' must be prefixed by a dot '.' or refer to a local name no-ambiguous-event-handler Main.view.xml:25:5 error Usage of space-separated list 'formatter helper' in template:require no-deprecated-api ``` ## Fix Strategy ### 1. `no-globals` - Fix Global Variable Access with core:require When a formatter, type, or utility function is accessed via global namespace (e.g., `my.app.formatter.formatDate`), add a `core:require` declaration and use the local name. **Step 1: Add xmlns:core namespace if not present** ```xml ``` **Step 2: Add core:require on the nearest control that uses the module** Place `core:require` on the **control that uses the global reference**. If multiple controls use the same module, place it on their **nearest common ancestor**. See the "core:require Placement Rules" section below for details. ```xml ``` ```xml ``` **Step 3: Update references to use local name** ```xml ``` **Step 4: Add `.bind($control)` for formatters that use `this`** If a formatter function accesses `this` internally, add `.bind($control)` to preserve the control context. This applies **only to formatters** — never add `.bind($control)` to event handlers or factory functions. ```xml ``` ### 2. `no-ambiguous-event-handler` - Fix Event Handlers Event handlers must either: - Start with a dot (`.`) to indicate controller method - Use a locally required module name **Controller method (add dot prefix):** ```xml