Skip to content

Commit

Permalink
feat: Detect partially deprecated APIs (#286)
Browse files Browse the repository at this point in the history
Detect a set of prominent partially-deprecated API (e.g. deprecation of a single parameter of a method signature):

* sap/ui/core/theming/Parameters.get
* sap/ui/core/Component.createComponent (async flag is currently not described as deprecated, but is likely to
be done soon)
* sap/ui/core/routing/Router (async flag)
* sap/ui/model/json/JSONModel#loadData
* sap/ui/model/odata/v4/ODataModel constructor
* sap/ui/model/odata/v2/ODataModel#createEntry
* sap/ui/util/Mobile.init

Generic detection would be better, ideally expressed through the
generation of the respective TypeScript type definitions. However, that
would first require changes in the UI5 JSDoc plugin in order to allow
developers to properly express deprecated parameters. Discussions on
this are ongoing. For the time being this is a simple solution to detect
widely used deprecated parameters.

JIRA: CPOUI5FOUNDATION-788

---------

Co-authored-by: Matthias Osswald <mat.osswald@sap.com>
  • Loading branch information
RandomByte and matz3 authored Sep 12, 2024
1 parent 95872dc commit dc66f91
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 65 deletions.
93 changes: 93 additions & 0 deletions src/linter/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export enum MESSAGE {
NO_DIRECT_DATATYPE_ACCESS,
NO_DIRECT_ENUM_ACCESS,
NO_GLOBALS,
PARTIALLY_DEPRECATED_PARAMETERS_GET,
PARTIALLY_DEPRECATED_CREATE_COMPONENT,
PARTIALLY_DEPRECATED_ODATA_MODEL_V2_CREATE_ENTRY,
PARTIALLY_DEPRECATED_ODATA_MODEL_V2_CREATE_ENTRY_PROPERTIES_ARRAY,
PARTIALLY_DEPRECATED_JSON_MODEL_LOAD_DATA,
PARTIALLY_DEPRECATED_MOBILE_INIT,
PARTIALLY_DEPRECATED_CORE_ROUTER,
PARTIALLY_DEPRECATED_ODATA_MODEL_V4,
}
export const MESSAGE_INFO = {

Expand Down Expand Up @@ -145,4 +153,89 @@ export const MESSAGE_INFO = {
details: () => undefined,
},

[MESSAGE.PARTIALLY_DEPRECATED_PARAMETERS_GET]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: () =>
`Usage of deprecated variant of 'sap/ui/core/theming/Parameters.get'`,
details: () => `{@link sap.ui.core.theming.Parameters#sap.ui.core.theming.Parameters.get Parameters.get}`,
},

[MESSAGE.PARTIALLY_DEPRECATED_CREATE_COMPONENT]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: () =>
`Usage of deprecated value for parameter 'async' of 'sap/ui/core/Component#createComponent'`,
details: () => `Property 'async' must be either omitted or set to true. ` +
`{@link sap.ui.core.Component#createComponent See API reference}`,
},

[MESSAGE.PARTIALLY_DEPRECATED_ODATA_MODEL_V2_CREATE_ENTRY]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: () =>
`Usage of deprecated parameter 'batchGroupId' in 'sap/ui/model/odata/v2/ODataModel#createEntry'`,
details: () => `Use parameter 'groupId' instead. ` +
`{@link sap.ui.model.odata.v2.ODataModel#createEntry See API reference}`,
},

[MESSAGE.PARTIALLY_DEPRECATED_ODATA_MODEL_V2_CREATE_ENTRY_PROPERTIES_ARRAY]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: () =>
`Usage of deprecated value for parameter 'properties' in 'sap/ui/model/odata/v2/ODataModel#createEntry'`,
details: () =>
`Passing a list of property names is deprecated. Pass the initial values as an object instead. ` +
`{@link sap.ui.model.odata.v2.ODataModel#createEntry See API reference}`,
},

[MESSAGE.PARTIALLY_DEPRECATED_JSON_MODEL_LOAD_DATA]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: ({paramName}: {paramName: string}) =>
`Usage of deprecated value for parameter '${paramName}' of 'sap/ui/model/json/JSONModel#loadData'`,
details: ({paramName}: {paramName: string}) =>
`Parameter '${paramName}' must be either omitted or set to true. ` +
`{@link sap.ui.model.json.JSONModel#loadData See API reference}`,
},

[MESSAGE.PARTIALLY_DEPRECATED_MOBILE_INIT]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: ({paramName}: {paramName: string}) =>
`Usage of deprecated value for parameter '${paramName}' of 'sap/ui/util/Mobile#init'`,
details: ({paramName}: {paramName: string}) =>
`Parameter '${paramName}' must be either omitted or set to true. ` +
`{@link sap.ui.util.Mobile#init See API reference}`,
},

[MESSAGE.PARTIALLY_DEPRECATED_CORE_ROUTER]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: () =>
`Usage of deprecated value for parameter 'oConfig.async' of constructor 'sap/ui/core/Router'`,
details: () =>
`Parameter 'oConfig.async' must be set to true. ` +
`{@link sap/ui/core/routing/Router#constructor See API reference}`,
},

[MESSAGE.PARTIALLY_DEPRECATED_ODATA_MODEL_V4]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-partially-deprecated-api"],

message: () =>
`Usage of deprecated parameter 'mParameters.synchronizationMode' ` +
`of constructor 'sap/ui/model/odata/v4/ODataModel'`,
details: () =>
`Parameter 'synchronizationMode' is obsolete and must be omitted. ` +
`{@link sap/ui/model/odata/v4/ODataModel#constructor See API reference}`,
},

} as const;
Loading

0 comments on commit dc66f91

Please sign in to comment.