Skip to content

Commit 9b83f62

Browse files
committed
feat: Detect usage of deprecated enum string values
1 parent 5fda0a9 commit 9b83f62

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

src/linter/ui5Types/SourceFileLinter.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,37 @@ export default class SourceFileLinter {
712712
if (!propertySymbol) {
713713
return;
714714
}
715+
716+
const propertyType = this.checker.getTypeOfSymbol(propertySymbol);
717+
718+
if (propertyType.isUnion()) {
719+
const valueType = this.checker.getTypeAtLocation(prop.initializer);
720+
721+
for (const type of propertyType.types) {
722+
// Find out whether the value is assignable to one of the types
723+
if (!this.checker.isTypeAssignableTo(valueType, type)) {
724+
continue;
725+
}
726+
// If the type is just a string literal (no enum value), we need to look for a matching
727+
// enum value in the list of types to check for its deprecation
728+
if (!(type.flags & ts.TypeFlags.EnumLiteral) && type.isStringLiteral()) {
729+
const enumType = propertyType.types.find((t) => {
730+
return t.symbol?.name === type.value;
731+
});
732+
if (!enumType) {
733+
continue;
734+
}
735+
const deprecationInfo = this.getDeprecationInfo(enumType.symbol);
736+
if (deprecationInfo) {
737+
this.#reporter.addMessage(MESSAGE.DEPRECATED_PROPERTY, {
738+
propertyName: type.value,
739+
details: deprecationInfo.messageDetails,
740+
}, prop);
741+
}
742+
}
743+
}
744+
}
745+
715746
const deprecationInfo = this.getDeprecationInfo(propertySymbol);
716747
if (!deprecationInfo) {
717748
return;

test/fixtures/linter/rules/NoDeprecatedApi/XMLView.view.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:core="sap.ui.core"
44
xmlns:table="sap.ui.table"
55
xmlns:tablePlugins="sap.ui.table.plugins"
6+
xmlns:form="sap.ui.layout.form"
67
>
78

89
<DateTimeInput /> <!-- DateTimeInput is deprecated -->
@@ -41,4 +42,17 @@
4142
<core:Fragment type="XML" fragmentName="myapp.fragment.Details" />
4243
<core:Fragment type="JS" fragmentName="myapp.fragment.Details" />
4344

45+
46+
<!-- SimpleFormLayout.ResponsiveLayout is deprecated -->
47+
<form:SimpleForm layout="ResponsiveLayout" />
48+
49+
<!-- FrameType.TwoThirds is deprecated -->
50+
<TileContent frameType="TwoThirds" />
51+
52+
<!-- InputType.Date is deprecated -->
53+
<Input type="Date" />
54+
55+
<!-- Negative test: ResponsiveGridLayout is not deprecated -->
56+
<form:SimpleForm layout="ResponsiveGridLayout" />
57+
4458
</mvc:View>

test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,130 +2135,154 @@ Generated by [AVA](https://avajs.dev).
21352135
[
21362136
{
21372137
coverageInfo: [],
2138-
errorCount: 15,
2138+
errorCount: 18,
21392139
fatalErrorCount: 0,
21402140
filePath: 'XMLView.view.xml',
21412141
messages: [
21422142
{
21432143
column: 2,
2144-
line: 8,
2144+
line: 9,
21452145
message: 'Import of deprecated module \'sap/m/DateTimeInput\'',
21462146
messageDetails: 'Deprecated test message',
21472147
ruleId: 'no-deprecated-api',
21482148
severity: 2,
21492149
},
21502150
{
21512151
column: 10,
2152-
line: 10,
2152+
line: 11,
21532153
message: 'Use of deprecated property \'blocked\' of class \'Button\'',
21542154
messageDetails: 'Deprecated test message',
21552155
ruleId: 'no-deprecated-api',
21562156
severity: 2,
21572157
},
21582158
{
21592159
column: 15,
2160-
line: 12,
2160+
line: 13,
21612161
message: 'Use of deprecated property \'groupBy\' of class \'Table\'',
21622162
messageDetails: 'Deprecated test message',
21632163
ruleId: 'no-deprecated-api',
21642164
severity: 2,
21652165
},
21662166
{
21672167
column: 4,
2168-
line: 13,
2168+
line: 14,
21692169
message: 'Use of deprecated property \'plugins\' of class \'Table\'',
21702170
messageDetails: 'Deprecated test message',
21712171
ruleId: 'no-deprecated-api',
21722172
severity: 2,
21732173
},
21742174
{
21752175
column: 3,
2176-
line: 19,
2176+
line: 20,
21772177
message: 'Use of deprecated property \'buttons\' of class \'SegmentedButton\'',
21782178
messageDetails: 'Deprecated test message',
21792179
ruleId: 'no-deprecated-api',
21802180
severity: 2,
21812181
},
21822182
{
21832183
column: 11,
2184-
line: 19,
2184+
line: 20,
21852185
message: 'Use of deprecated property \'tap\' of class \'Button\'',
21862186
messageDetails: 'Deprecated test message',
21872187
ruleId: 'no-deprecated-api',
21882188
severity: 2,
21892189
},
21902190
{
21912191
column: 2,
2192-
line: 22,
2192+
line: 23,
21932193
message: 'Usage of deprecated value \'JS\' for parameter \'type\' in \'sap/ui/core/mvc/View.create\'',
21942194
messageDetails: 'View.create (https://ui5.sap.com/1.120/#/api/sap.ui.core.mvc.View%23methods/sap.ui.core.mvc.View.create)',
21952195
ruleId: 'no-deprecated-api',
21962196
severity: 2,
21972197
},
21982198
{
21992199
column: 2,
2200-
line: 23,
2200+
line: 24,
22012201
message: 'Usage of deprecated value \'JSON\' for parameter \'type\' in \'sap/ui/core/mvc/View.create\'',
22022202
messageDetails: 'View.create (https://ui5.sap.com/1.120/#/api/sap.ui.core.mvc.View%23methods/sap.ui.core.mvc.View.create)',
22032203
ruleId: 'no-deprecated-api',
22042204
severity: 2,
22052205
},
22062206
{
22072207
column: 2,
2208-
line: 24,
2208+
line: 25,
22092209
message: 'Usage of deprecated value \'HTML\' for parameter \'type\' in \'sap/ui/core/mvc/View.create\'',
22102210
messageDetails: 'View.create (https://ui5.sap.com/1.120/#/api/sap.ui.core.mvc.View%23methods/sap.ui.core.mvc.View.create)',
22112211
ruleId: 'no-deprecated-api',
22122212
severity: 2,
22132213
},
22142214
{
22152215
column: 2,
2216-
line: 25,
2216+
line: 26,
22172217
message: 'Usage of deprecated value \'Template\' for parameter \'type\' in \'sap/ui/core/mvc/View.create\'',
22182218
messageDetails: 'View.create (https://ui5.sap.com/1.120/#/api/sap.ui.core.mvc.View%23methods/sap.ui.core.mvc.View.create)',
22192219
ruleId: 'no-deprecated-api',
22202220
severity: 2,
22212221
},
22222222
{
22232223
column: 2,
2224-
line: 27,
2224+
line: 28,
22252225
message: 'Import of deprecated module \'sap/ui/core/mvc/JSView\'',
22262226
messageDetails: 'Deprecated test message',
22272227
ruleId: 'no-deprecated-api',
22282228
severity: 2,
22292229
},
22302230
{
22312231
column: 2,
2232-
line: 28,
2232+
line: 29,
22332233
message: 'Import of deprecated module \'sap/ui/core/mvc/JSONView\'',
22342234
messageDetails: 'Deprecated test message',
22352235
ruleId: 'no-deprecated-api',
22362236
severity: 2,
22372237
},
22382238
{
22392239
column: 2,
2240-
line: 29,
2240+
line: 30,
22412241
message: 'Import of deprecated module \'sap/ui/core/mvc/HTMLView\'',
22422242
messageDetails: 'Deprecated test message',
22432243
ruleId: 'no-deprecated-api',
22442244
severity: 2,
22452245
},
22462246
{
22472247
column: 2,
2248-
line: 30,
2248+
line: 31,
22492249
message: 'Import of deprecated module \'sap/ui/core/mvc/TemplateView\'',
22502250
messageDetails: 'Deprecated test message',
22512251
ruleId: 'no-deprecated-api',
22522252
severity: 2,
22532253
},
22542254
{
22552255
column: 2,
2256-
line: 37,
2256+
line: 38,
22572257
message: 'Usage of deprecated value \'HTML\' for parameter \'type\' in \'sap/ui/core/Fragment.load\'',
22582258
messageDetails: 'Fragment.load (https://ui5.sap.com/1.120/#/api/sap.ui.core.Fragment%23methods/sap.ui.core.Fragment.load)',
22592259
ruleId: 'no-deprecated-api',
22602260
severity: 2,
22612261
},
2262+
{
2263+
column: 19,
2264+
line: 47,
2265+
message: 'Use of deprecated property \'ResponsiveLayout\'',
2266+
messageDetails: 'Deprecated test message',
2267+
ruleId: 'no-deprecated-api',
2268+
severity: 2,
2269+
},
2270+
{
2271+
column: 15,
2272+
line: 50,
2273+
message: 'Use of deprecated property \'TwoThirds\'',
2274+
messageDetails: 'Deprecated test message',
2275+
ruleId: 'no-deprecated-api',
2276+
severity: 2,
2277+
},
2278+
{
2279+
column: 9,
2280+
line: 53,
2281+
message: 'Use of deprecated property \'Date\'',
2282+
messageDetails: 'Deprecated test message',
2283+
ruleId: 'no-deprecated-api',
2284+
severity: 2,
2285+
},
22622286
],
22632287
warningCount: 0,
22642288
},
136 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)