Skip to content

Commit

Permalink
feat: Detect deprecated libs and components in manifest.json (#34)
Browse files Browse the repository at this point in the history
- Analyze dependencies within manifest.json
- Add detections for deprecated libraries and components (manifest.json)
- Add new reporter messages with ruleId's
`ui5-linter-no-deprecated-library` and
`ui5-linter-no-deprecated-component`
- Update test snapshots

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

const deprecatedLibraries: string[] = [
"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: string[] = [
"sap.zen.dsh.fioriwrapper",
];

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

export interface jsonSourceMapType {
Expand Down Expand Up @@ -50,9 +72,35 @@ 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);

// Detect deprecated libraries:
const libKeys: string[] = (dependencies?.libs && Object.keys(dependencies.libs)) ?? [];
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)) ?? [];
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({
node: "/sap.ui5/resources/js",
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
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.
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 8aa74e1

Please sign in to comment.