Skip to content

Commit 289c945

Browse files
committed
refactor: Only check for enums if value is string
1 parent c5c8944 commit 289c945

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/linter/ui5Types/SourceFileLinter.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -717,27 +717,28 @@ export default class SourceFileLinter {
717717

718718
if (propertyType.isUnion()) {
719719
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) {
720+
if (valueType?.isStringLiteral()) {
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)) {
733724
continue;
734725
}
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);
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+
}
741742
}
742743
}
743744
}

test/fixtures/linter/rules/NoDeprecatedApi/NoDeprecatedApi.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
sap.ui.define([
22
"sap/m/Button", "sap/m/DateTimeInput", "sap/base/util/includes", "sap/ui/Device", "sap/ui/core/library", "sap/ui/generic/app/navigation/service/NavigationHandler",
33
"sap/ui/table/Table", "sap/ui/table/plugins/MultiSelectionPlugin", "sap/ui/core/Configuration", "sap/m/library",
4-
"sap/m/Input", "sap/m/TileContent", "sap/ui/layout/form/SimpleForm"
5-
], function(Button, DateTimeInput, includes, Device, coreLib, NavigationHandler, Table, MultiSelectionPlugin, Configuration, mobileLib, Input, TileContent, SimpleForm) {
4+
"sap/m/Input", "sap/m/TileContent", "sap/ui/layout/form/SimpleForm", "sap/m/ResponsivePopover"
5+
], function(Button, DateTimeInput, includes, Device, coreLib, NavigationHandler, Table, MultiSelectionPlugin, Configuration, mobileLib, Input, TileContent, SimpleForm, ResponsivePopover) {
66
"use strict";
77
var dateTimeInput = new DateTimeInput(); // Control is deprecated. A finding only appears for the module dependency, not for the usage.
88

@@ -91,8 +91,12 @@ sap.ui.define([
9191
type: "Date" // InputType.Date is deprecated
9292
});
9393

94-
// Negative test: ResponsiveGridLayout is not deprecated
9594
const simpleForm2 = new SimpleForm({
96-
layout: "ResponsiveGridLayout" // ResponsiveGridLayout is not deprecated
95+
layout: "ResponsiveGridLayout" // Negative test: ResponsiveGridLayout is not deprecated
96+
});
97+
98+
const responsivePopover = new ResponsivePopover({
99+
// ui5lint-disable-next-line no-globals
100+
placement: sap.m.PlacementType.Auto // Negative test: PlacementType.Auto is not deprecated
97101
});
98102
});

0 commit comments

Comments
 (0)