diff --git a/src/linter/ui5Types/SourceFileLinter.ts b/src/linter/ui5Types/SourceFileLinter.ts index 1fe6d39dc..70494d193 100644 --- a/src/linter/ui5Types/SourceFileLinter.ts +++ b/src/linter/ui5Types/SourceFileLinter.ts @@ -28,7 +28,7 @@ export default class SourceFileLinter { constructor( context: LinterContext, resourcePath: ResourcePath, sourceFile: ts.SourceFile, sourceMap: string | undefined, checker: ts.TypeChecker, reportCoverage: boolean | undefined = false, - messageDetails: boolean | undefined = false, manifestContent: string | undefined + messageDetails: boolean | undefined = false, manifestContent?: string | undefined ) { this.#resourcePath = resourcePath; this.#sourceFile = sourceFile; @@ -498,16 +498,16 @@ export default class SourceFileLinter { if (manifestJson.manifest?.value === "\"json\"") { // The manifest is an external manifest.json file const parsedManifestContent = - JSON.parse(this.#manifestContent ?? "") as SAPJSONSchemaForWebApplicationManifestFile; + JSON.parse(this.#manifestContent ?? "{}") as SAPJSONSchemaForWebApplicationManifestFile; const {rootView, routing} = parsedManifestContent["sap.ui5"] ?? {} as JSONSchemaForSAPUI5Namespace; // @ts-expect-error async is part of RootViewDefFlexEnabled and RootViewDef rootViewAsyncFlag = rootView?.async as boolean; routingAsyncFlag = routing?.config?.async; } else { - /* eslint-disable @typescript-eslint/no-explicit-any */ + /* eslint-disable @typescript-eslint/no-explicit-any */ const instanceOfPropsRecord = (obj: any): obj is propsRecord => { - return obj && typeof obj === "object"; + return !!obj && typeof obj === "object"; }; let manifestSapui5Section: propsRecord | undefined; diff --git a/test/lib/linter/_linterHelper.ts b/test/lib/linter/_linterHelper.ts index 60d21dce0..9decba71a 100644 --- a/test/lib/linter/_linterHelper.ts +++ b/test/lib/linter/_linterHelper.ts @@ -28,11 +28,12 @@ export async function esmockDeprecationText() { context: LinterContext, filePath: string, sourceFile: SourceFile, sourceMap: string | undefined, checker: TypeChecker, reportCoverage: boolean | undefined = false, - messageDetails: boolean | undefined = false + messageDetails: boolean | undefined = false, + manifestContent?: string | undefined ) { // Don't use sinon's stubs as it's hard to clean after them in this case and it leaks memory. const linter = new SourceFileLinter( - context, filePath, sourceFile, sourceMap, checker, reportCoverage, messageDetails + context, filePath, sourceFile, sourceMap, checker, reportCoverage, messageDetails, manifestContent ); linter.getDeprecationText = () => "Deprecated test message"; return linter; diff --git a/test/lib/linter/snapshots/linter.ts.md b/test/lib/linter/snapshots/linter.ts.md index ab8fd7ad9..ee1ec1b18 100644 --- a/test/lib/linter/snapshots/linter.ts.md +++ b/test/lib/linter/snapshots/linter.ts.md @@ -271,8 +271,27 @@ Generated by [AVA](https://avajs.dev). errorCount: 0, fatalErrorCount: 0, filePath: 'webapp/Component.js', - messages: [], - warningCount: 0, + messages: [ + { + column: 9, + fatal: undefined, + line: 4, + message: 'Remove the async flag for "sap.ui5/rootView" from the manifest', + messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation', + ruleId: 'ui5-linter-no-sync-loading', + severity: 1, + }, + { + column: 9, + fatal: undefined, + line: 4, + message: 'Remove the async flag for "sap.ui5/routing/config" from the manifest', + messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation', + ruleId: 'ui5-linter-no-sync-loading', + severity: 1, + }, + ], + warningCount: 2, }, { coverageInfo: [ @@ -745,6 +764,33 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 [ + { + coverageInfo: [], + errorCount: 0, + fatalErrorCount: 0, + filePath: 'webapp/Component.js', + messages: [ + { + column: 9, + fatal: undefined, + line: 4, + message: 'Remove the async flag for "sap.ui5/rootView" from the manifest', + messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation', + ruleId: 'ui5-linter-no-sync-loading', + severity: 1, + }, + { + column: 9, + fatal: undefined, + line: 4, + message: 'Remove the async flag for "sap.ui5/routing/config" from the manifest', + messageDetails: 'https://sapui5.hana.ondemand.com/#/api/sap.ui.core.IAsyncContentCreation', + ruleId: 'ui5-linter-no-sync-loading', + severity: 1, + }, + ], + warningCount: 2, + }, { coverageInfo: [], errorCount: 1, diff --git a/test/lib/linter/snapshots/linter.ts.snap b/test/lib/linter/snapshots/linter.ts.snap index 4dafd76ff..33f8aa210 100644 Binary files a/test/lib/linter/snapshots/linter.ts.snap and b/test/lib/linter/snapshots/linter.ts.snap differ