Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,37 @@ export default class SourceFileLinter {
if (!propertySymbol) {
return;
}

const propertyType = this.checker.getTypeOfSymbol(propertySymbol);

if (propertyType.isUnion()) {
const valueType = this.checker.getTypeAtLocation(prop.initializer);

for (const type of propertyType.types) {
// Find out whether the value is assignable to one of the types
if (!this.checker.isTypeAssignableTo(valueType, type)) {
continue;
}
// If the type is just a string literal (no enum value), we need to look for a matching
// enum value in the list of types to check for its deprecation
if (!(type.flags & ts.TypeFlags.EnumLiteral) && type.isStringLiteral()) {
const enumType = propertyType.types.find((t) => {
return t.symbol?.name === type.value;
});
if (!enumType) {
continue;
}
const deprecationInfo = this.getDeprecationInfo(enumType.symbol);
if (deprecationInfo) {
this.#reporter.addMessage(MESSAGE.DEPRECATED_PROPERTY, {
propertyName: type.value,
details: deprecationInfo.messageDetails,
}, prop);
}
}
}
}

const deprecationInfo = this.getDeprecationInfo(propertySymbol);
if (!deprecationInfo) {
return;
Expand Down
22 changes: 20 additions & 2 deletions test/fixtures/linter/rules/NoDeprecatedApi/NoDeprecatedApi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
sap.ui.define([
"sap/m/Button", "sap/m/DateTimeInput", "sap/base/util/includes", "sap/ui/Device", "sap/ui/core/library", "sap/ui/generic/app/navigation/service/NavigationHandler",
"sap/ui/table/Table", "sap/ui/table/plugins/MultiSelectionPlugin", "sap/ui/core/Configuration", "sap/m/library"
], function(Button, DateTimeInput, includes, Device, coreLib, NavigationHandler, Table, MultiSelectionPlugin, Configuration, mobileLib) {
"sap/ui/table/Table", "sap/ui/table/plugins/MultiSelectionPlugin", "sap/ui/core/Configuration", "sap/m/library",
"sap/m/Input", "sap/m/TileContent", "sap/ui/layout/form/SimpleForm"
], function(Button, DateTimeInput, includes, Device, coreLib, NavigationHandler, Table, MultiSelectionPlugin, Configuration, mobileLib, Input, TileContent, SimpleForm) {
"use strict";
var dateTimeInput = new DateTimeInput(); // Control is deprecated. A finding only appears for the module dependency, not for the usage.

Expand Down Expand Up @@ -77,4 +78,21 @@ sap.ui.define([
// (via local function name)
const sapUiXmlView = sap.ui.xmlview;
const view3 = sapUiXmlView("com.ui5.troublesome.app.view.MyView");

const simpleForm = new SimpleForm({
layout: "ResponsiveLayout" // SimpleFormLayout.ResponsiveLayout is deprecated
});

const tileContent = new TileContent({
frameType: "TwoThirds" // FrameType.TwoThirds is deprecated
});

const input = new Input({
type: "Date" // InputType.Date is deprecated
});

// Negative test: ResponsiveGridLayout is not deprecated
const simpleForm2 = new SimpleForm({
layout: "ResponsiveGridLayout" // ResponsiveGridLayout is not deprecated
});
});
14 changes: 14 additions & 0 deletions test/fixtures/linter/rules/NoDeprecatedApi/XMLView.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:core="sap.ui.core"
xmlns:table="sap.ui.table"
xmlns:tablePlugins="sap.ui.table.plugins"
xmlns:form="sap.ui.layout.form"
>

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


<!-- SimpleFormLayout.ResponsiveLayout is deprecated -->
<form:SimpleForm layout="ResponsiveLayout" />

<!-- FrameType.TwoThirds is deprecated -->
<TileContent frameType="TwoThirds" />

<!-- InputType.Date is deprecated -->
<Input type="Date" />

<!-- Negative test: ResponsiveGridLayout is not deprecated -->
<form:SimpleForm layout="ResponsiveGridLayout" />

</mvc:View>
Loading