用途:修复 UI5 linter 能检测但无法自动修复的 Control renderer 问题,这些问题需要理解控件的渲染行为与模块依赖。
主要能力:处理 no-deprecated-control-renderer-declaration(缺失 renderer 声明、字符串式 renderer 声明)、no-deprecated-api(缺少 apiVersion: 2、使用 oRm.icon() 未导入 IconPool、覆写已废弃的 rerender)、ui5-class-declaration(renderer 必须为静态属性)。
使用方式:先运行 npx @ui5/linter --details 获取上下文,按规则 ID 与消息定位问题,再按策略修改。缺失声明时,若默认路径存在 <ControlName>Renderer.js 则导入并赋值,否则用 renderer: null 或内联 renderer;字符串声明改为模块导入;缺少 apiVersion 时补 apiVersion: 2 并把 write() 等旧方法改为 openStart/openEnd/text/close 等语义方法;使用 oRm.icon() 时在 sap.ui.define 依赖中加入 sap/ui/core/IconPool;rerender 覆写逻辑迁移到 onBeforeRendering 与 onAfterRendering;ES6 类中 renderer 加 static。修改后重新运行 linter 验证。
适用场景:UI5 项目升级或现代化改造中,控件 renderer 触发上述 linter 规则时。
限制:仅针对资料列出的规则;继承 sap/ui/core/mvc/View、XMLComposite、webc/WebComponent、uxap/BlockBase 的控件无需 renderer 声明;apiVersion: 4 亦有效;IconPool 导入在模块加载时即需存在,即使代码未直接引用变量。相关技能包括 fix-js-globals、fix-pseudo-modules、fix-library-init。