Skip to content
Merged
120 changes: 118 additions & 2 deletions src/linter/ui5Types/fix/collections/sapUiCoreFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,132 @@ t.declareModule("sap/ui/core/Configuration", [
moduleName: "sap/base/i18n/Localization",
mustNotUseReturnValue: true,
})),
t.method("getAccessibility", accessExpressionFix({
moduleName: "sap/ui/core/ControlBehavior",
propertyAccess: "isAccessibilityEnabled",
})),
t.method("getActiveTerminologies", accessExpressionFix({
moduleName: "sap/base/i18n/Localization",
propertyAccess: "getActiveTerminologies",
})),
t.method("getAllowlistService", accessExpressionFix({
moduleName: "sap/ui/security/Security",
propertyAccess: "getAllowlistService",
})),
t.method("getAnimation", callExpressionFix({
moduleName: "sap/ui/core/ControlBehavior",
propertyAccess: "getAnimationMode",
// Note: The new API returns an enum value instead of a boolean, therefore
// migration is currently not possible if the return value is used
// This could be optimized with an advanced migration that detects how the return
// value is used and e.g. migrates to something like
// (getAnimationMode() !== sap.ui.core.Configuration.AnimationMode.none)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this be replaced like this in general?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment proposes that

if (Configuration.getAnimation())

becomes

if ((Configuration.getAnimationMode() !== sap.ui.core.Configuration.AnimationMode.none))

Now you're proposing that any usage of Configuration.getAnimation() could safely be replaced with (Configuration.getAnimationMode() !== sap.ui.core.Configuration.AnimationMode.none), right?

I guess that's correct!

@codeworrior codeworrior Jun 24, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was my proposal. But meanwhile I noticed that the code in sap/Ui/core/Configuration is slightly more complex (it checks the opposite, that none of the false values are set - depends on the evolution of the enum whether this remains equivalent).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved due being too unsafe to migrate?

// Right now this migration probably wont apply for most cases
mustNotUseReturnValue: true,
})),
t.method("getAnimationMode", accessExpressionFix({
scope: FixScope.FirstChild,
moduleName: "sap/ui/core/ControlBehavior",
})),
t.method("getCalendarType", accessExpressionFix({
moduleName: "sap/base/i18n/Formatting",
scope: FixScope.FirstChild,
})),
t.method("getCalendarWeekNumbering", accessExpressionFix({
moduleName: "sap/base/i18n/Formatting",
scope: FixScope.FirstChild,
})),
t.method("getFrameOptions", accessExpressionFix({
moduleName: "sap/ui/security/Security",
scope: FixScope.FirstChild,
})),
t.method("getFormatLocale", callExpressionGeneratorFix({
moduleName: "sap/base/i18n/Formatting",
generator: (ctx, [moduleIdentifier]) => {
return `${moduleIdentifier}.getLanguageTag().toString()`;
},
})),
t.method("getLanguage", accessExpressionFix({
moduleName: "sap/base/i18n/Localization",
scope: FixScope.FirstChild,
})),
t.method("getLanguageTag", callExpressionGeneratorFix({
moduleName: "sap/base/i18n/Localization",
generator: (ctx, [localizationIdentifier]) => {
return `${localizationIdentifier}.getLanguageTag().toString()`;
},
})),
t.method("getLocale", callExpressionGeneratorFix({
moduleImports: [{
moduleName: "sap/ui/core/Locale",
}, {
moduleName: "sap/base/i18n/Localization",
}],
generator(ctx, identifierNames) {
return `new ${identifierNames[0]}(${identifierNames[1]}.getLanguageTag())`;
generator(ctx, [localeIdentifier, localizationIdentifier]) {
return `new ${localeIdentifier}(${localizationIdentifier}.getLanguageTag())`;
},
})),
t.method("getRTL", accessExpressionFix({
moduleName: "sap/base/i18n/Localization",
propertyAccess: "getRTL",
})),
t.method("getSAPLogonLanguage", accessExpressionFix({
moduleName: "sap/base/i18n/Localization",
scope: FixScope.FirstChild,
})),
t.method("getSecurityTokenHandlers", accessExpressionFix({
moduleName: "sap/ui/security/Security",
scope: FixScope.FirstChild,
})),
t.method("getTheme", accessExpressionFix({
moduleName: "sap/ui/core/Theming",
scope: FixScope.FirstChild,
})),
t.method("getTimezone", accessExpressionFix({
moduleName: "sap/base/i18n/Localization",
scope: FixScope.FirstChild,
})),
t.method("getUIDPrefix", accessExpressionFix({
moduleName: "sap/ui/base/ManagedObjectMetadata",
scope: FixScope.FirstChild,
})),
t.method("getWhitelistService", accessExpressionFix({
moduleName: "sap/ui/security/Security",
propertyAccess: "getAllowlistService",
})),
t.method("setAnimationMode", accessExpressionFix({
moduleName: "sap/ui/core/ControlBehavior",
scope: FixScope.FirstChild,
})),
t.method("setCalendarType", callExpressionFix({
moduleName: "sap/base/i18n/Formatting",
propertyAccess: "setCalendarType",
mustNotUseReturnValue: true,
})),
t.method("setCalendarWeekNumbering", callExpressionFix({
moduleName: "sap/base/i18n/Formatting",
propertyAccess: "setCalendarWeekNumbering",
mustNotUseReturnValue: true,
})),
t.method("setFormatLocale", callExpressionFix({
moduleName: "sap/base/i18n/Formatting",
propertyAccess: "setLanguageTag",
mustNotUseReturnValue: true,
})),
t.method("setSecurityTokenHandlers", accessExpressionFix({
moduleName: "sap/ui/security/Security",
scope: FixScope.FirstChild,
})),
t.method("setTheme", callExpressionFix({
moduleName: "sap/ui/core/Theming",
propertyAccess: "setTheme",
mustNotUseReturnValue: true,
})),
t.method("setTimezone", callExpressionFix({
moduleName: "sap/base/i18n/Localization",
propertyAccess: "setTimezone",
mustNotUseReturnValue: true,
})),
]),
]);

Expand Down
92 changes: 92 additions & 0 deletions test/e2e/snapshots/runtime.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,98 @@ Generated by [AVA](https://avajs.dev).
> stdout

[
{
errorCount: 12,
fatalErrorCount: 0,
filePath: 'test/qunit/Configuration.qunit.js',
messages: [
{
column: 2,
line: 3,
message: 'Import of deprecated module \'sap/ui/core/Configuration\'',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 27,
line: 39,
message: 'Call to deprecated function \'getAnimation\' of class \'Configuration\'',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 34,
line: 41,
message: 'Call to deprecated function \'getAnimation\' of class \'Configuration\'',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 28,
line: 43,
message: 'Call to deprecated function \'getAnimation\' of class \'Configuration\'',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 16,
line: 48,
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 36,
line: 141,
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.minimal)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 58,
line: 142,
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.minimal)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 36,
line: 144,
message: 'Use of deprecated property \'AnimationMode\' (globalConfiguration.AnimationMode.full)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 58,
line: 145,
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.full)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 36,
line: 147,
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.none)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 58,
line: 148,
message: 'Use of deprecated property \'AnimationMode\' (globalConfiguration.AnimationMode.none)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 20,
line: 221,
message: 'Use of deprecated theme \'sap_belize\'',
ruleId: 'no-deprecated-theme',
severity: 2,
},
],
warningCount: 0,
},
{
errorCount: 2,
fatalErrorCount: 0,
Expand Down
Binary file modified test/e2e/snapshots/runtime.ts.snap
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
sap.ui.define([
"sap/ui/core/Configuration",
], (ConfigurationRenamed) => {
ConfigurationRenamed.getAccessibility();
ConfigurationRenamed.getActiveTerminologies();
ConfigurationRenamed.getAllowlistService();
ConfigurationRenamed.getAnimation();
const a = ConfigurationRenamed.getAnimation(); // Do not migrate since return value differs
ConfigurationRenamed.getAnimationMode();
// Although the return type of the replacement is different,
// getAnimationMode() is still migratable since old and new return types are congruent:
if (ConfigurationRenamed.getAnimationMode() === ConfigurationRenamed.AnimationMode.minimal) {

}
ConfigurationRenamed.getCalendarType();
ConfigurationRenamed.getCalendarWeekNumbering();
ConfigurationRenamed.getFrameOptions();
ConfigurationRenamed.getLanguage();
ConfigurationRenamed.getRTL();
ConfigurationRenamed.getSAPLogonLanguage();
ConfigurationRenamed.getSecurityTokenHandlers();
ConfigurationRenamed.getTheme();
ConfigurationRenamed.getTimezone();
ConfigurationRenamed.getUIDPrefix();
ConfigurationRenamed.getWhitelistService();
ConfigurationRenamed.setAnimationMode(ConfigurationRenamed.AnimationMode.minimal);
ConfigurationRenamed.setSecurityTokenHandlers([() => {console.log("*Security token handler*");}]);
ConfigurationRenamed.getLanguageTag();
ConfigurationRenamed.getFormatLocale();

// Migration to two new modules
ConfigurationRenamed.getLocale();

// Complex migrations
ConfigurationRenamed.setCalendarType(sCalendarType);
ConfigurationRenamed.setCalendarWeekNumbering(sCalendarWeekNumbering);
ConfigurationRenamed.setFormatLocale(sFormatLocale);
ConfigurationRenamed.setLanguage(sLanguage, sSAPLogonLanguage);
ConfigurationRenamed.setLanguage(sLanguage);
ConfigurationRenamed.setRTL(bRTL);
ConfigurationRenamed.setTheme(sTheme);
ConfigurationRenamed.setTimezone(sTimezone);

// Do not migrate these methods, as they used to return "this" and now return "undefined".
// Further more, now the functionality is moved into multiple modules.
ConfigurationRenamed.setRTL(false).setLanguage("en");
const setCalendar = (type) => ConfigurationRenamed.setCalendarType(type);
const typedCalendar = sType ? ConfigurationRenamed.setCalendarType(sType) : null;
debug("msg 2", ConfigurationRenamed.setFormatLocale(sFormatLocale));
debug("msg 2", (ConfigurationRenamed.setFormatLocale(sFormatLocale)));
debug("msg 2", ((((ConfigurationRenamed.setFormatLocale(sFormatLocale))))));
var time = ConfigurationRenamed.setTimezone(sTimezone);
var info = {
theme: ConfigurationRenamed.setTheme(sTheme)
};
ConfigurationRenamed.setTheme(sTheme) ?? ConfigurationRenamed.setTimezone(sTimezone);
ConfigurationRenamed.setCalendarWeekNumbering(sCalendarWeekNumbering) ? "a" : "b";
ConfigurationRenamed.setCalendarType(sCalendarType), ConfigurationRenamed.setCalendarWeekNumbering(sCalendarWeekNumbering);
fnCall(ConfigurationRenamed.setLanguage(sLanguage));
});
Loading