iljapostnovs / VSCodeUI5Plugin

Visual Studio Code Extension for UI5 Development
Apache License 2.0
61 stars 6 forks source link

Bug: bad Linter warning in controller extension #402

Closed bilbon-s closed 7 months ago

bilbon-s commented 7 months ago

Hi and thanks for this usefull extension,

Describe the bug Linter is showing a warning in fiori elements controller extension when calling this.getView() (or any other controller method like this.getOwnerComponent()...)

To Reproduce Create a new fiori elements list report application. Add a controller extension (with guided fiori tools for exemple)

Result is a code like this :

sap.ui.define([
    "sap/m/MessageToast"
], function(MessageToast) {
    'use strict';

    return {
        onCustomAction: function(oEvent) {
            MessageToast.show("Custom handler invoked.");
        }
    };
});

Now add a method call like : this.getView()

Expected behavior No warning from linter as this method call is correct.

Screenshots image

Desktop (please complete the following information):

iljapostnovs commented 7 months ago

Hi, Yes it does and it will. You are returning just an object with no parent or anything else and an error message is precise. The magic which UI5 framework is doing is pretty bad one from OOP perspective. If you want getView and other methods to be present, you should have it defined somewhere. I didn't try it, but maybe this will help: https://ui5.sap.com/#/topic/21515f09c0324218bb705b27407f5d61

bilbon-s commented 7 months ago

Hi, Thanks for the very fast answer ! I agree that this linter result is logic from OOP perspective. We can manage to make it work properly using the Controller extension API, but the code effort / quantity is a bit high compared to just following the simple usual controller extension. I think I'll live with that :)

Thanks again for your answer