UI5 / UI5/linter

ui5lint --fix should not add AMD dependency on `instanceof` usages

Open
#666 1 comment 1 reaction 1 assignee View on GitHub

@flovogt is already working on this.

Since Aug 10, 2026.

autofix
Dominant language
TypeScript
Stars
79
Forks
13
Avg merge
19h 34m
Merged PRs (30d)
9

Description

Is your feature request related to a problem? Please describe.

Currently, the UI5 linter replaces identified usages of globals with AMD dependencies. In most cases this is the expected behavior. However, when checking whether an object belongs to a UI5 class (e.g. obj instanceof sap.m.Button) it might be desirable to avoid this dependency, either for performance reason, or because the check is a mere probing and must not lead to a dependency. In addition to the impact on the performance or adding an unwanted dependency, this might lead to a dependency cycle which might make successful loading of the module even impossible.

Describe the solution you'd like

Instead of adding an AMD dependency, use sap/ui/base/Object#isObjectA().
Enhances behavior: If there is already another dependency to the class used in instanceof (after applying all the other fixes to the module), keep the instanceof and make use of the dependency.

Describe alternatives you've considered

n/a

Additional context

Sample:

Input to UI5 linter sap.ui.define([], () => { ... const isButton = ctrl instanceof sap.m.Button; ... }; sap.ui.define([], () => { ... const ctrl = new sap.m.Button(); ... const isButton = ctrl instanceof sap.m.Button; ... };
Current --fix result sap.ui.define(["sap/m/Button"], (Button) => { ... const isButton = ctrl instanceof Button; ... }; sap.ui.define(["sap/m/Button"], (Button) => { ... const ctrl = new Button(); ... const isButton = ctrl instanceof Button; ... };
Proposed --fix result sap.ui.define(["sap/ui/base/Object"], (BaseObject) => { ... const isButton = BaseObject.isObjectA(ctrl, "sap.m.Button"); ... }; sap.ui.define(["sap/m/Button"], (Button) => { ... const ctrl = new Button(); ... const isButton = ctrl instanceof Button; ... };

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.