refactor(autofix): Refactor autofix definition, add abstraction before creating changes#662
Conversation
9a61882 to
27e5265
Compare
| ], function(Input, TableTable) {␊ | ||
| const input = new Input();␊ | ||
| const Button = new SapMButton2();␊ | ||
| const Button = new SapMButton1();␊ |
There was a problem hiding this comment.
Improvement: Existing import form surrounding sap.ui.define is now reused.
| var isPhone = Device.system.phone;␊ | ||
| var isTablet = Device.system.tablet;␊ | ||
| var isAndroidPhone = Device.os.android && Device.system.tablet;␊ | ||
| var isAndroidPhone = Device.os.android && Device.system.phone;␊ |
There was a problem hiding this comment.
Fix: This is the correct replacement for jQuery.device.is.android_phone
| var isAndroidTablet = Device.os.android && Device.system.tablet;␊ | ||
| var isIPhone = Device.os.ios && Device.system.phone;␊ | ||
| var isIPad = Device.os.ios && Device.system.ipad;␊ | ||
| var isIPad = Device.os.ios && Device.system.tablet;␊ |
There was a problem hiding this comment.
Fix: This is the correct replacement for jQuery.device.is.ipad. There is no Device.system.ipad property: https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.Device.system%23properties
| `sap.ui.define(["sap/ui/thirdparty/jquery"], async function (jQuery) {␊ | ||
| // https://github.com/SAP/ui5-linter/issues/590␊ | ||
| ␊ | ||
| var isStandAlone = window.navigator.standalone;␊ |
There was a problem hiding this comment.
Improvement: window or rather globalThis is only used when needed (i.e. if an identifier with name navigator already exists)
| var intervalCallId3 = jQuery.sap.intervalCall(1000, window, Array.isArray, ["myParam1"]);␊ | ||
| jQuery.sap.clearIntervalCall(intervalCallId);␊ | ||
| ␊ | ||
| var element = window.document.getElementById("popup");␊ |
There was a problem hiding this comment.
Improvement: See above
| ␊ | ||
| var person = {firstname: "Peter", lastname: "Miller" };␊ | ||
| var newObj = Object.create(person || null);␊ | ||
| var newObj = Object.create(person);␊ |
There was a problem hiding this comment.
Improvement: Autofix can now evaluate the type of identifiers, correctly detecting the object here.
| var myDetails = "These are the details";␊ | ||
| var myComponent = "jquery.sap.logger.jsunit";␊ | ||
| Log.debug(myLogMessage, myDetails, myComponent, function () { });␊ | ||
| Log.debug(myLogMessage, myDetails, myComponent, function () {});␊ |
There was a problem hiding this comment.
Improvement: Whitespaces in parameters are preserved
| var textUpperCase2 = jQuery.sap.charToUpperCase(xy); // Do not migrate vars. We don't know the type of xy␊ | ||
| var textUpperCase2 = jQuery.sap.charToUpperCase(xy, 0); // Do not migrate vars. We don't know the type of xy␊ | ||
| var textUpperCase2 = jQuery.sap.charToUpperCase(xy, 3); // // Do not migrate vars. We don't know the type of xy␊ | ||
| var textUpperCase2 = capitalize(xy);␊ |
There was a problem hiding this comment.
Improvement: Type and value of identifiers is now checked
| ObjectPath.set("name.lastname", "Miller", { name: { firstname: "me" } });␊ | ||
| ObjectPath.set("name.lastname", "Miller", { name: { firstname: "me" } });␊ | ||
| ObjectPath.set("", "Miller", { name: { firstname: "me" } });␊ | ||
| ObjectPath.set(undefined, "Miller", { name: { firstname: "me" } });␊ |
There was a problem hiding this comment.
undefined or null, replace it with an empty string.
I'm not sure why the first iteration kept the undefined (but not null). My understanding is that jQuery.sap.setObject always defaults falsy values to an empty string: https://github.com/SAP/openui5/blob/aad2c54fa60d58f681840a954395a08bfb96cb6c/src/sap.ui.core/src/jquery.sap.global.js#L898
ObjectPath.set(undefined, "Miller", { name: { firstname: "me" } }); will definitely result in an exception due to the missing split function on undefined: https://github.com/SAP/openui5/blob/7ac020cdf6e5fa56a96d17aadeec7a0159beff14/src/sap.ui.core/src/sap/base/util/ObjectPath.js#L37
| // 2. Replace the code with the following:␊ | ||
| // -> var store = new Storage(Storage.Type.local, "mystore");␊ | ||
| var store = new Storage(jQuery.sap.storage.Type.local, "mystore");␊ | ||
| var store = new Storage(Storage.Type.local, "mystore");␊ |
There was a problem hiding this comment.
Improvement: Simultaneous fixes in a call expression's property access and its arguments are now possible.
|
|
||
| > AutofixResult: /jQuerySapExtendNoFix.js | ||
|
|
||
| `sap.ui.define(["sap/base/util/merge"], function(merge) {␊ |
There was a problem hiding this comment.
Improvement: Import is not added if fixes are not applied
| Theming.setTheme("customTheme"); // Can be autofixed when the 2nd argument is undefined␊ | ||
| ␊ | ||
| Core.ready(function() {console.log();});␊ | ||
| Core.ready(function() {console.log();});␊ |
There was a problem hiding this comment.
Fix: Duplicate fixes resolved
|
Test failure is due to code coverage only. Will try to improve it 👍 |
…e creating changes
4f453a9 to
1d0746c
Compare
FixHints are still present but should be completely replaced by the Fix class and its subclasses and the generateChanges module.
Concept
a) Collect all module declarations/requires
b) Provide fixes with corresponding nodes of the Source-AST
a) In case of conflicts, discard the whole fix associated with the conflicting range. Prefer smaller range fixes
a) Request a list of modules they require, the positions where they want to access them and optionally a preferred name for the identifier (all together referred to as "import requests")
b) Request a list of modules they no longer require, together with the identifier currently used to access those
Fixes, Improvements and Changes
See my review comments below for fixes, improvements and changes