Skip to content

Commit 372d80b

Browse files
feat(autofix): Fix deprecated Configuration APIs
Based on #683 and #685 JIRA: CPOUI5FOUNDATION-1038 --------- Co-authored-by: Max Reichmann <[email protected]>
1 parent 8547e58 commit 372d80b

File tree

9 files changed

+1296
-2
lines changed

9 files changed

+1296
-2
lines changed

src/linter/ui5Types/fix/collections/sapUiCoreFixes.ts

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,132 @@ t.declareModule("sap/ui/core/Configuration", [
1919
moduleName: "sap/base/i18n/Localization",
2020
mustNotUseReturnValue: true,
2121
})),
22+
t.method("getAccessibility", accessExpressionFix({
23+
moduleName: "sap/ui/core/ControlBehavior",
24+
propertyAccess: "isAccessibilityEnabled",
25+
})),
26+
t.method("getActiveTerminologies", accessExpressionFix({
27+
moduleName: "sap/base/i18n/Localization",
28+
propertyAccess: "getActiveTerminologies",
29+
})),
30+
t.method("getAllowlistService", accessExpressionFix({
31+
moduleName: "sap/ui/security/Security",
32+
propertyAccess: "getAllowlistService",
33+
})),
34+
t.method("getAnimation", callExpressionFix({
35+
moduleName: "sap/ui/core/ControlBehavior",
36+
propertyAccess: "getAnimationMode",
37+
// Note: The new API returns an enum value instead of a boolean, therefore
38+
// migration is currently not possible if the return value is used
39+
// This could be optimized with an advanced migration that detects how the return
40+
// value is used and e.g. migrates to something like
41+
// (getAnimationMode() !== sap.ui.core.Configuration.AnimationMode.none)
42+
// Right now this migration probably wont apply for most cases
43+
mustNotUseReturnValue: true,
44+
})),
45+
t.method("getAnimationMode", accessExpressionFix({
46+
scope: FixScope.FirstChild,
47+
moduleName: "sap/ui/core/ControlBehavior",
48+
})),
49+
t.method("getCalendarType", accessExpressionFix({
50+
moduleName: "sap/base/i18n/Formatting",
51+
scope: FixScope.FirstChild,
52+
})),
53+
t.method("getCalendarWeekNumbering", accessExpressionFix({
54+
moduleName: "sap/base/i18n/Formatting",
55+
scope: FixScope.FirstChild,
56+
})),
57+
t.method("getFrameOptions", accessExpressionFix({
58+
moduleName: "sap/ui/security/Security",
59+
scope: FixScope.FirstChild,
60+
})),
61+
t.method("getFormatLocale", callExpressionGeneratorFix({
62+
moduleName: "sap/base/i18n/Formatting",
63+
generator: (ctx, [moduleIdentifier]) => {
64+
return `${moduleIdentifier}.getLanguageTag().toString()`;
65+
},
66+
})),
67+
t.method("getLanguage", accessExpressionFix({
68+
moduleName: "sap/base/i18n/Localization",
69+
scope: FixScope.FirstChild,
70+
})),
71+
t.method("getLanguageTag", callExpressionGeneratorFix({
72+
moduleName: "sap/base/i18n/Localization",
73+
generator: (ctx, [localizationIdentifier]) => {
74+
return `${localizationIdentifier}.getLanguageTag().toString()`;
75+
},
76+
})),
2277
t.method("getLocale", callExpressionGeneratorFix({
2378
moduleImports: [{
2479
moduleName: "sap/ui/core/Locale",
2580
}, {
2681
moduleName: "sap/base/i18n/Localization",
2782
}],
28-
generator(ctx, identifierNames) {
29-
return `new ${identifierNames[0]}(${identifierNames[1]}.getLanguageTag())`;
83+
generator(ctx, [localeIdentifier, localizationIdentifier]) {
84+
return `new ${localeIdentifier}(${localizationIdentifier}.getLanguageTag())`;
3085
},
3186
})),
87+
t.method("getRTL", accessExpressionFix({
88+
moduleName: "sap/base/i18n/Localization",
89+
propertyAccess: "getRTL",
90+
})),
91+
t.method("getSAPLogonLanguage", accessExpressionFix({
92+
moduleName: "sap/base/i18n/Localization",
93+
scope: FixScope.FirstChild,
94+
})),
95+
t.method("getSecurityTokenHandlers", accessExpressionFix({
96+
moduleName: "sap/ui/security/Security",
97+
scope: FixScope.FirstChild,
98+
})),
99+
t.method("getTheme", accessExpressionFix({
100+
moduleName: "sap/ui/core/Theming",
101+
scope: FixScope.FirstChild,
102+
})),
103+
t.method("getTimezone", accessExpressionFix({
104+
moduleName: "sap/base/i18n/Localization",
105+
scope: FixScope.FirstChild,
106+
})),
107+
t.method("getUIDPrefix", accessExpressionFix({
108+
moduleName: "sap/ui/base/ManagedObjectMetadata",
109+
scope: FixScope.FirstChild,
110+
})),
111+
t.method("getWhitelistService", accessExpressionFix({
112+
moduleName: "sap/ui/security/Security",
113+
propertyAccess: "getAllowlistService",
114+
})),
115+
t.method("setAnimationMode", accessExpressionFix({
116+
moduleName: "sap/ui/core/ControlBehavior",
117+
scope: FixScope.FirstChild,
118+
})),
119+
t.method("setCalendarType", callExpressionFix({
120+
moduleName: "sap/base/i18n/Formatting",
121+
propertyAccess: "setCalendarType",
122+
mustNotUseReturnValue: true,
123+
})),
124+
t.method("setCalendarWeekNumbering", callExpressionFix({
125+
moduleName: "sap/base/i18n/Formatting",
126+
propertyAccess: "setCalendarWeekNumbering",
127+
mustNotUseReturnValue: true,
128+
})),
129+
t.method("setFormatLocale", callExpressionFix({
130+
moduleName: "sap/base/i18n/Formatting",
131+
propertyAccess: "setLanguageTag",
132+
mustNotUseReturnValue: true,
133+
})),
134+
t.method("setSecurityTokenHandlers", accessExpressionFix({
135+
moduleName: "sap/ui/security/Security",
136+
scope: FixScope.FirstChild,
137+
})),
138+
t.method("setTheme", callExpressionFix({
139+
moduleName: "sap/ui/core/Theming",
140+
propertyAccess: "setTheme",
141+
mustNotUseReturnValue: true,
142+
})),
143+
t.method("setTimezone", callExpressionFix({
144+
moduleName: "sap/base/i18n/Localization",
145+
propertyAccess: "setTimezone",
146+
mustNotUseReturnValue: true,
147+
})),
32148
]),
33149
]);
34150

test/e2e/snapshots/runtime.ts.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,98 @@ Generated by [AVA](https://avajs.dev).
1313
> stdout
1414
1515
[
16+
{
17+
errorCount: 12,
18+
fatalErrorCount: 0,
19+
filePath: 'test/qunit/Configuration.qunit.js',
20+
messages: [
21+
{
22+
column: 2,
23+
line: 3,
24+
message: 'Import of deprecated module \'sap/ui/core/Configuration\'',
25+
ruleId: 'no-deprecated-api',
26+
severity: 2,
27+
},
28+
{
29+
column: 27,
30+
line: 39,
31+
message: 'Call to deprecated function \'getAnimation\' of class \'Configuration\'',
32+
ruleId: 'no-deprecated-api',
33+
severity: 2,
34+
},
35+
{
36+
column: 34,
37+
line: 41,
38+
message: 'Call to deprecated function \'getAnimation\' of class \'Configuration\'',
39+
ruleId: 'no-deprecated-api',
40+
severity: 2,
41+
},
42+
{
43+
column: 28,
44+
line: 43,
45+
message: 'Call to deprecated function \'getAnimation\' of class \'Configuration\'',
46+
ruleId: 'no-deprecated-api',
47+
severity: 2,
48+
},
49+
{
50+
column: 16,
51+
line: 48,
52+
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode)',
53+
ruleId: 'no-deprecated-api',
54+
severity: 2,
55+
},
56+
{
57+
column: 36,
58+
line: 141,
59+
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.minimal)',
60+
ruleId: 'no-deprecated-api',
61+
severity: 2,
62+
},
63+
{
64+
column: 58,
65+
line: 142,
66+
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.minimal)',
67+
ruleId: 'no-deprecated-api',
68+
severity: 2,
69+
},
70+
{
71+
column: 36,
72+
line: 144,
73+
message: 'Use of deprecated property \'AnimationMode\' (globalConfiguration.AnimationMode.full)',
74+
ruleId: 'no-deprecated-api',
75+
severity: 2,
76+
},
77+
{
78+
column: 58,
79+
line: 145,
80+
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.full)',
81+
ruleId: 'no-deprecated-api',
82+
severity: 2,
83+
},
84+
{
85+
column: 36,
86+
line: 147,
87+
message: 'Use of deprecated property \'AnimationMode\' (Configuration.AnimationMode.none)',
88+
ruleId: 'no-deprecated-api',
89+
severity: 2,
90+
},
91+
{
92+
column: 58,
93+
line: 148,
94+
message: 'Use of deprecated property \'AnimationMode\' (globalConfiguration.AnimationMode.none)',
95+
ruleId: 'no-deprecated-api',
96+
severity: 2,
97+
},
98+
{
99+
column: 20,
100+
line: 221,
101+
message: 'Use of deprecated theme \'sap_belize\'',
102+
ruleId: 'no-deprecated-theme',
103+
severity: 2,
104+
},
105+
],
106+
warningCount: 0,
107+
},
16108
{
17109
errorCount: 2,
18110
fatalErrorCount: 0,

test/e2e/snapshots/runtime.ts.snap

654 Bytes
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
sap.ui.define([
2+
"sap/ui/core/Configuration",
3+
], (ConfigurationRenamed) => {
4+
ConfigurationRenamed.getAccessibility();
5+
ConfigurationRenamed.getActiveTerminologies();
6+
ConfigurationRenamed.getAllowlistService();
7+
ConfigurationRenamed.getAnimation();
8+
const a = ConfigurationRenamed.getAnimation(); // Do not migrate since return value differs
9+
ConfigurationRenamed.getAnimationMode();
10+
// Although the return type of the replacement is different,
11+
// getAnimationMode() is still migratable since old and new return types are congruent:
12+
if (ConfigurationRenamed.getAnimationMode() === ConfigurationRenamed.AnimationMode.minimal) {
13+
14+
}
15+
ConfigurationRenamed.getCalendarType();
16+
ConfigurationRenamed.getCalendarWeekNumbering();
17+
ConfigurationRenamed.getFrameOptions();
18+
ConfigurationRenamed.getLanguage();
19+
ConfigurationRenamed.getRTL();
20+
ConfigurationRenamed.getSAPLogonLanguage();
21+
ConfigurationRenamed.getSecurityTokenHandlers();
22+
ConfigurationRenamed.getTheme();
23+
ConfigurationRenamed.getTimezone();
24+
ConfigurationRenamed.getUIDPrefix();
25+
ConfigurationRenamed.getWhitelistService();
26+
ConfigurationRenamed.setAnimationMode(ConfigurationRenamed.AnimationMode.minimal);
27+
ConfigurationRenamed.setSecurityTokenHandlers([() => {console.log("*Security token handler*");}]);
28+
ConfigurationRenamed.getLanguageTag();
29+
ConfigurationRenamed.getFormatLocale();
30+
31+
// Migration to two new modules
32+
ConfigurationRenamed.getLocale();
33+
34+
// Complex migrations
35+
ConfigurationRenamed.setCalendarType(sCalendarType);
36+
ConfigurationRenamed.setCalendarWeekNumbering(sCalendarWeekNumbering);
37+
ConfigurationRenamed.setFormatLocale(sFormatLocale);
38+
ConfigurationRenamed.setLanguage(sLanguage, sSAPLogonLanguage);
39+
ConfigurationRenamed.setLanguage(sLanguage);
40+
ConfigurationRenamed.setRTL(bRTL);
41+
ConfigurationRenamed.setTheme(sTheme);
42+
ConfigurationRenamed.setTimezone(sTimezone);
43+
44+
// Do not migrate these methods, as they used to return "this" and now return "undefined".
45+
// Further more, now the functionality is moved into multiple modules.
46+
ConfigurationRenamed.setRTL(false).setLanguage("en");
47+
const setCalendar = (type) => ConfigurationRenamed.setCalendarType(type);
48+
const typedCalendar = sType ? ConfigurationRenamed.setCalendarType(sType) : null;
49+
debug("msg 2", ConfigurationRenamed.setFormatLocale(sFormatLocale));
50+
debug("msg 2", (ConfigurationRenamed.setFormatLocale(sFormatLocale)));
51+
debug("msg 2", ((((ConfigurationRenamed.setFormatLocale(sFormatLocale))))));
52+
var time = ConfigurationRenamed.setTimezone(sTimezone);
53+
var info = {
54+
theme: ConfigurationRenamed.setTheme(sTheme)
55+
};
56+
ConfigurationRenamed.setTheme(sTheme) ?? ConfigurationRenamed.setTimezone(sTimezone);
57+
ConfigurationRenamed.setCalendarWeekNumbering(sCalendarWeekNumbering) ? "a" : "b";
58+
ConfigurationRenamed.setCalendarType(sCalendarType), ConfigurationRenamed.setCalendarWeekNumbering(sCalendarWeekNumbering);
59+
fnCall(ConfigurationRenamed.setLanguage(sLanguage));
60+
});

0 commit comments

Comments
 (0)