Skip to content

ui5lint --fix should not add AMD dependency on instanceof usages #666

@jnsttl

Description

@jnsttl

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; ... };

Metadata

Metadata

Assignees

No one assigned

    Labels

    autofixAn issue related to the autofix capabilities

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions