Skip to content

Commit

Permalink
refactor: Improve messages and extract hard-coded texts
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Sep 13, 2024
1 parent 0fa39ea commit d1ab9bc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/linter/LinterContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ export default class LinterContext {
severity: messageInfo.severity,
line: rawMessage.position ? rawMessage.position.line : undefined,
column: rawMessage.position ? rawMessage.position.column : undefined,
message: messageFunc(rawMessage.args),
message: messageFunc(rawMessage.args || {}),
};

if (this.#includeMessageDetails) {
const detailsFunc = messageInfo.details as (args: MessageArgs[M]) => string | undefined;
const messageDetails = detailsFunc(rawMessage.args);
const messageDetails = detailsFunc(rawMessage.args || {});
if (messageDetails) {
message.messageDetails = resolveLinks(messageDetails);
}
Expand Down
11 changes: 3 additions & 8 deletions src/linter/manifestJson/ManifestLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ export default class ManifestLinter {
});

if (resources?.js) {
this.#reporter?.addMessage(MESSAGE.DEPRECATED_PROPERTY, {
propertyName: "sap.ui5/resources/js",
details: "", // TODO
}, "/sap.ui5/resources/js");
this.#reporter?.addMessage(MESSAGE.DEPRECATED_MANIFEST_JS_RESOURCES, "/sap.ui5/resources/js");
}

const modelKeys: string[] = (models && Object.keys(models)) ?? [];
Expand Down Expand Up @@ -116,10 +113,8 @@ export default class ManifestLinter {

if (curModel.type === "sap.ui.model.odata.v4.ODataModel" &&
curModel.settings && "synchronizationMode" in curModel.settings) {
this.#reporter?.addMessage(MESSAGE.DEPRECATED_PROPERTY_OF_CLASS, {
propertyName: "synchronizationMode",
className: "sap.ui.model.odata.v4.ODataModel",
details: "As of Version 1.110.0, this parameter is obsolete.",
this.#reporter?.addMessage(MESSAGE.DEPRECATED_ODATA_MODEL_V4_SYNCHRONIZATION_MODE, {
modelName: modelKey,
}, `/sap.ui5/models/${modelKey}/settings/synchronizationMode`);
}
});
Expand Down
25 changes: 18 additions & 7 deletions src/linter/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum MESSAGE {
DEPRECATED_COMPONENT,
DEPRECATED_FUNCTION_CALL,
DEPRECATED_LIBRARY,
DEPRECATED_MANIFEST_JS_RESOURCES,
DEPRECATED_MODULE_IMPORT,
DEPRECATED_PROPERTY_OF_CLASS,
DEPRECATED_PROPERTY,
Expand All @@ -43,7 +44,7 @@ export enum MESSAGE {
PARTIALLY_DEPRECATED_JSON_MODEL_LOAD_DATA,
PARTIALLY_DEPRECATED_MOBILE_INIT,
PARTIALLY_DEPRECATED_CORE_ROUTER,
PARTIALLY_DEPRECATED_ODATA_MODEL_V4,
DEPRECATED_ODATA_MODEL_V4_SYNCHRONIZATION_MODE,
PARSING_ERROR,
SVG_IN_XML,
}
Expand Down Expand Up @@ -137,6 +138,16 @@ export const MESSAGE_INFO = {
details: () => undefined,
},

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

message: () =>
`Use of deprecated property 'sap.ui5/resources/js'`,
details: () => "As of version 1.94, the usage of js resources is deprecated. " +
"Please use regular dependencies instead.",
},

[MESSAGE.DEPRECATED_MODULE_IMPORT]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["ui5-linter-no-deprecated-api"],
Expand Down Expand Up @@ -283,15 +294,15 @@ export const MESSAGE_INFO = {
`{@link sap/ui/core/routing/Router#constructor See API reference}`,
},

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ export default class SourceFileLinter {
}

if (synchronizationModeProb) {
this.#reporter.addMessage(MESSAGE.PARTIALLY_DEPRECATED_ODATA_MODEL_V4, synchronizationModeProb);
this.#reporter.addMessage(MESSAGE.DEPRECATED_ODATA_MODEL_V4_SYNCHRONIZATION_MODE, synchronizationModeProb);
}
}

Expand Down
27 changes: 14 additions & 13 deletions test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,17 @@ Generated by [AVA](https://avajs.dev).
{
column: 3,
line: 29,
message: 'Usage of deprecated parameter \'mParameters.synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\'',
messageDetails: 'Parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-partially-deprecated-api',
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\'',
messageDetails: 'As of version 1.110.0, parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-deprecated-property',
severity: 2,
},
{
column: 3,
line: 32,
message: 'Usage of deprecated parameter \'mParameters.synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\'',
messageDetails: 'Parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-partially-deprecated-api',
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\'',
messageDetails: 'As of version 1.110.0, parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-deprecated-property',
severity: 2,
},
{
Expand Down Expand Up @@ -1661,23 +1661,24 @@ Generated by [AVA](https://avajs.dev).
column: 13,
line: 79,
message: 'Use of deprecated property \'sap.ui5/resources/js\'',
ruleId: 'ui5-linter-no-deprecated-property',
messageDetails: 'As of version 1.94, the usage of js resources is deprecated. Please use regular dependencies instead.',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 21,
line: 92,
message: 'Use of deprecated property \'synchronizationMode\' of class \'sap.ui.model.odata.v4.ODataModel\'',
messageDetails: 'As of Version 1.110.0, this parameter is obsolete.',
ruleId: 'ui5-linter-no-deprecated-api',
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\' (model: \'odata-v4\')',
messageDetails: 'As of version 1.110.0, parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-deprecated-property',
severity: 2,
},
{
column: 21,
line: 98,
message: 'Use of deprecated property \'synchronizationMode\' of class \'sap.ui.model.odata.v4.ODataModel\'',
messageDetails: 'As of Version 1.110.0, this parameter is obsolete.',
ruleId: 'ui5-linter-no-deprecated-api',
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\' (model: \'odata-v4-via-dataSource\')',
messageDetails: 'As of version 1.110.0, parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-deprecated-property',
severity: 2,
},
{
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap
Binary file not shown.
15 changes: 8 additions & 7 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,23 +454,24 @@ Generated by [AVA](https://avajs.dev).
column: 13,
line: 59,
message: 'Use of deprecated property \'sap.ui5/resources/js\'',
ruleId: 'ui5-linter-no-deprecated-property',
messageDetails: 'As of version 1.94, the usage of js resources is deprecated. Please use regular dependencies instead.',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 21,
line: 72,
message: 'Use of deprecated property \'synchronizationMode\' of class \'sap.ui.model.odata.v4.ODataModel\'',
messageDetails: 'As of Version 1.110.0, this parameter is obsolete.',
ruleId: 'ui5-linter-no-deprecated-api',
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\' (model: \'odata-v4\')',
messageDetails: 'As of version 1.110.0, parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-deprecated-property',
severity: 2,
},
{
column: 21,
line: 78,
message: 'Use of deprecated property \'synchronizationMode\' of class \'sap.ui.model.odata.v4.ODataModel\'',
messageDetails: 'As of Version 1.110.0, this parameter is obsolete.',
ruleId: 'ui5-linter-no-deprecated-api',
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\' (model: \'odata-v4-via-dataSource\')',
messageDetails: 'As of version 1.110.0, parameter \'synchronizationMode\' is obsolete and must be omitted. See API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'ui5-linter-no-deprecated-property',
severity: 2,
},
{
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.

0 comments on commit d1ab9bc

Please sign in to comment.