Skip to content

Commit

Permalink
feat: Detect deprecated libs and components in manifest.json
Browse files Browse the repository at this point in the history
This PR analyses dependencies within manifest.json and adds detections
for deprecated libraries and components.
This results in new reporter messages with ruleId's
ui5-linter-no-deprecated-library and ui5-linter-no-deprecated-component.
This PR also adds the corresponding test snapshots.

JIRA: CPOUI5FOUNDATION-807
  • Loading branch information
maxreichmann committed Mar 19, 2024
1 parent 5d81856 commit 58ec8f9
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 13 deletions.
51 changes: 50 additions & 1 deletion src/linter/json/ManifestLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,31 @@ interface locType {
pos: number;
}

const deprecatedLibraries: Array<string> = [

Check failure on line 20 in src/linter/json/ManifestLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Array type using 'Array<string>' is forbidden. Use 'string[]' instead
"sap.ca.scfld.md",
"sap.ca.ui",
"sap.dragonfly",
"sap.landviz",
"sap.makit",
"sap.me",
"sap.ui.commons",
"sap.ui.suite",
"sap.ui.ux3",
"sap.ui.vtm",
"sap.uiext.inbox",
"sap.webanalytics.core",
"sap.zen.dsh",
"sap.zen.commons",
"sap.zen.crosstab",
];

const deprecatedComponents: Array<string> = [

Check failure on line 38 in src/linter/json/ManifestLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Array type using 'Array<string>' is forbidden. Use 'string[]' instead
"sap.zen.dsh.fioriwrapper",
];

export type jsonMapPointers = Record<string, {key: locType; keyEnd: locType; value: locType; valueEnd: locType}>;


Check failure on line 44 in src/linter/json/ManifestLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

More than 1 blank line not allowed
export interface jsonSourceMapType {
data: SAPJSONSchemaForWebApplicationManifestFile;
pointers: jsonMapPointers;
Expand Down Expand Up @@ -50,8 +73,34 @@ export default class ManifestLinter {
}

#analyzeManifest(manifest: SAPJSONSchemaForWebApplicationManifestFile) {
const {resources, models} = (manifest["sap.ui5"] ?? {} as JSONSchemaForSAPUI5Namespace);
const {resources, models, dependencies} = (manifest["sap.ui5"] ?? {} as JSONSchemaForSAPUI5Namespace);
const {dataSources} = (manifest["sap.app"] ?? {} as JSONSchemaForSAPAPPNamespace);

Check failure on line 78 in src/linter/json/ManifestLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Trailing spaces not allowed
// Detect deprecated libraries:
const libKeys: string[] = (dependencies?.libs && Object.keys(dependencies.libs)) || [];

Check failure on line 80 in src/linter/json/ManifestLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
libKeys.forEach((libKey: string) => {
if (deprecatedLibraries.includes(libKey)) {
this.#reporter?.addMessage({
node: `/sap.ui5/dependencies/libs/${libKey}`,
severity: LintMessageSeverity.Error,
ruleId: "ui5-linter-no-deprecated-library",
message: `Use of deprecated library '${libKey}'`,
});
}
});

// Detect deprecated components:
const componentKeys: string[] = (dependencies?.components && Object.keys(dependencies.components)) || [];

Check failure on line 93 in src/linter/json/ManifestLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
componentKeys.forEach((componentKey: string) => {
if (deprecatedComponents.includes(componentKey)) {
this.#reporter?.addMessage({
node: `/sap.ui5/dependencies/components/${componentKey}`,
severity: LintMessageSeverity.Error,
ruleId: "ui5-linter-no-deprecated-component",
message: `Use of deprecated component '${componentKey}'`,
});
}
});

if (resources?.js) {
this.#reporter?.addMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"minUI5Version": "1.119.0",
"libs": {
"sap.ui.core": {},
"sap.m": {}
"sap.m": {},
"sap.ui.commons": {}
}
},

Expand Down
20 changes: 19 additions & 1 deletion test/fixtures/linter/rules/NoDeprecatedApi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@
"minUI5Version": "1.119.0",
"libs": {
"sap.ui.core": {},
"sap.m": {}
"sap.m": {},
"sap.ca.scfld.md": {},
"sap.ca.ui": {},
"sap.dragonfly": {},
"sap.landviz": {},
"sap.makit": {},
"sap.me": {},
"sap.ui.commons": {},
"sap.ui.suite": {},
"sap.ui.ux3": {},
"sap.ui.vtm": {},
"sap.uiext.inbox": {},
"sap.webanalytics.core": {},
"sap.zen.dsh": {},
"sap.zen.commons": {},
"sap.zen.crosstab": {}
},
"components": {
"sap.zen.dsh.fioriwrapper": {}
}
},

Expand Down
Binary file modified test/lib/detectors/transpilers/amd/snapshots/transpiler.ts.snap
Binary file not shown.
Binary file modified test/lib/detectors/transpilers/xml/snapshots/transpiler.ts.snap
Binary file not shown.
138 changes: 133 additions & 5 deletions test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,38 +795,166 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 4,
errorCount: 20,
fatalErrorCount: 0,
filePath: 'manifest.json',
messages: [
{
column: 13,
column: 17,
fatal: undefined,
line: 47,
message: 'Use of deprecated library \'sap.ca.scfld.md\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 48,
message: 'Use of deprecated library \'sap.ca.ui\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 49,
message: 'Use of deprecated library \'sap.dragonfly\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 50,
message: 'Use of deprecated library \'sap.landviz\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 51,
message: 'Use of deprecated library \'sap.makit\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 52,
message: 'Use of deprecated library \'sap.me\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 53,
message: 'Use of deprecated library \'sap.ui.commons\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 54,
message: 'Use of deprecated library \'sap.ui.suite\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 55,
message: 'Use of deprecated library \'sap.ui.ux3\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 56,
message: 'Use of deprecated library \'sap.ui.vtm\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 57,
message: 'Use of deprecated library \'sap.uiext.inbox\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 58,
message: 'Use of deprecated library \'sap.webanalytics.core\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 59,
message: 'Use of deprecated library \'sap.zen.dsh\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 60,
message: 'Use of deprecated library \'sap.zen.commons\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 61,
message: 'Use of deprecated library \'sap.zen.crosstab\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 64,
message: 'Use of deprecated component \'sap.zen.dsh.fioriwrapper\'',
ruleId: 'ui5-linter-no-deprecated-component',
severity: 2,
},
{
column: 13,
fatal: undefined,
line: 76,
message: 'Use of deprecated property \'sap.ui5/resources/js\'',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 21,
fatal: undefined,
line: 71,
line: 89,
message: 'Use of deprecated property \'sap.ui5/models/odata-v4/settings/synchronizationMode\' of sap.ui.model.odata.v4.ODataModel',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 21,
fatal: undefined,
line: 77,
line: 95,
message: 'Use of deprecated property \'sap.ui5/models/odata-v4-via-dataSource/settings/synchronizationMode\' of sap.ui.model.odata.v4.ODataModel',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 81,
line: 99,
message: 'Use of deprecated model type \'sap.ui5/models/odata/type="sap.ui.model.odata.ODataModel"\'',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap
Binary file not shown.
Binary file modified test/lib/linter/rules/snapshots/NoGlobals.ts.snap
Binary file not shown.
18 changes: 13 additions & 5 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,38 +365,46 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 4,
errorCount: 5,
fatalErrorCount: 0,
filePath: 'webapp/manifest.json',
messages: [
{
column: 17,
fatal: undefined,
line: 47,
message: 'Use of deprecated library \'sap.ui.commons\'',
ruleId: 'ui5-linter-no-deprecated-library',
severity: 2,
},
{
column: 13,
fatal: undefined,
line: 58,
line: 59,
message: 'Use of deprecated property \'sap.ui5/resources/js\'',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 21,
fatal: undefined,
line: 71,
line: 72,
message: 'Use of deprecated property \'sap.ui5/models/odata-v4/settings/synchronizationMode\' of sap.ui.model.odata.v4.ODataModel',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 21,
fatal: undefined,
line: 77,
line: 78,
message: 'Use of deprecated property \'sap.ui5/models/odata-v4-via-dataSource/settings/synchronizationMode\' of sap.ui.model.odata.v4.ODataModel',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 17,
fatal: undefined,
line: 81,
line: 82,
message: 'Use of deprecated model type \'sap.ui5/models/odata/type="sap.ui.model.odata.ODataModel"\'',
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.

0 comments on commit 58ec8f9

Please sign in to comment.