diff --git a/src/detectors/typeChecker/index.ts b/src/detectors/typeChecker/index.ts index 4f6de0e53..9a95d6769 100644 --- a/src/detectors/typeChecker/index.ts +++ b/src/detectors/typeChecker/index.ts @@ -57,9 +57,21 @@ export class TsProjectDetector extends ProjectBasedDetector { const namespace = project.getNamespace(); this.#projectBasePath = `/resources/${namespace}/`; + + const namespacePathMapping = [ + `${this.#projectBasePath}*`, + ]; + + // Special handling when linting sap/* namespaces (UI5 framework libraries): + // Add mapping for dynamic type lookup. Otherwise types within the sap library itself + // can't be resolved. + if (namespace.startsWith("sap/")) { + namespacePathMapping.push(`/types/@ui5/linter/dynamic-types/${namespace}/*`); + } + this.compilerOptions.paths = { - [`${namespace}/*`]: [`${this.#projectBasePath}*`], "sap/*": ["/types/@ui5/linter/dynamic-types/sap/*"], + [`${namespace}/*`]: namespacePathMapping, }; } diff --git a/test/fixtures/linter/projects/sap.f/src/sap/f/.library b/test/fixtures/linter/projects/sap.f/src/sap/f/.library new file mode 100644 index 000000000..1fd082a08 --- /dev/null +++ b/test/fixtures/linter/projects/sap.f/src/sap/f/.library @@ -0,0 +1,9 @@ + + + sap.f + + + sap.ui.core + + + diff --git a/test/fixtures/linter/projects/sap.f/src/sap/f/LinterTest.js b/test/fixtures/linter/projects/sap.f/src/sap/f/LinterTest.js new file mode 100644 index 000000000..abfb6fc2b --- /dev/null +++ b/test/fixtures/linter/projects/sap.f/src/sap/f/LinterTest.js @@ -0,0 +1 @@ +// This project is used to test the linter with the namespace of an OpenUI5 project. diff --git a/test/fixtures/linter/projects/sap.f/test/sap/f/LinterTest.js b/test/fixtures/linter/projects/sap.f/test/sap/f/LinterTest.js new file mode 100644 index 000000000..bd2ae9084 --- /dev/null +++ b/test/fixtures/linter/projects/sap.f/test/sap/f/LinterTest.js @@ -0,0 +1,9 @@ +// This project is used to test the linter with the namespace of an OpenUI5 project. + +sap.ui.require([ + "sap/f/Avatar", + "sap/m/DateTimeInput" +], (Avatar, DateTimeInput) => { + new Avatar(); + new DateTimeInput(); +}); diff --git a/test/lib/linter/linter.ts b/test/lib/linter/linter.ts index c772de935..4b4b1e1f7 100644 --- a/test/lib/linter/linter.ts +++ b/test/lib/linter/linter.ts @@ -89,3 +89,21 @@ test.serial("lint: All files of library.with.custom.paths", async (t) => { t.snapshot(res); }); + +test.serial("lint: All files of library with sap.f namespace", async (t) => { + const projectPath = path.join(fixturesProjectsPath, "sap.f"); + const {lintProject} = t.context; + + let res = await lintProject({ + rootDir: projectPath, + filePaths: [], + reportCoverage: true, + messageDetails: true, + }); + + res = res.sort((a: {filePath: string}, b: {filePath: string}) => { + return a.filePath.localeCompare(b.filePath); + }); + + t.snapshot(res); +}); diff --git a/test/lib/linter/snapshots/linter.ts.md b/test/lib/linter/snapshots/linter.ts.md index 64d85ed8d..6552b2386 100644 --- a/test/lib/linter/snapshots/linter.ts.md +++ b/test/lib/linter/snapshots/linter.ts.md @@ -981,3 +981,45 @@ Generated by [AVA](https://avajs.dev). warningCount: 0, }, ] + +## lint: All files of library with sap.f namespace + +> Snapshot 1 + + [ + { + coverageInfo: [], + errorCount: 0, + fatalErrorCount: 0, + filePath: 'src/sap/f/LinterTest.js', + messages: [], + warningCount: 0, + }, + { + coverageInfo: [], + errorCount: 2, + fatalErrorCount: 0, + filePath: 'test/sap/f/LinterTest.js', + messages: [ + { + column: 2, + fatal: undefined, + line: 4, + message: 'Import of deprecated module \'sap/f/Avatar\'', + messageDetails: 'Deprecated test message', + ruleId: 'ui5-linter-no-deprecated-api', + severity: 2, + }, + { + column: 2, + fatal: undefined, + line: 5, + message: 'Import of deprecated module \'sap/m/DateTimeInput\'', + messageDetails: 'Deprecated test message', + ruleId: 'ui5-linter-no-deprecated-api', + severity: 2, + }, + ], + warningCount: 0, + }, + ] diff --git a/test/lib/linter/snapshots/linter.ts.snap b/test/lib/linter/snapshots/linter.ts.snap index 7bd19f667..f7ba49539 100644 Binary files a/test/lib/linter/snapshots/linter.ts.snap and b/test/lib/linter/snapshots/linter.ts.snap differ