Skip to content

Commit dd41ebb

Browse files
committed
[FIX] Linting empty files should not cause errors
1 parent 265a266 commit dd41ebb

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

packages/ui5-linter/src/detectors/typeChecker/host.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ export async function createVirtualCompilerHost(
6666
}
6767
}
6868

69-
function getFile(fileName: string) {
70-
const vFile = files.get(fileName);
71-
if (vFile) {
72-
return vFile;
69+
function getFile(fileName: string) : string | undefined {
70+
// NOTE: This function should be kept in sync with "fileExists"
71+
72+
if (files.has(fileName)) {
73+
return files.get(fileName);
7374
}
7475
if (fileName.startsWith("/types/")) {
7576
const fsPath = mapToTypePath(fileName);
@@ -106,8 +107,18 @@ export async function createVirtualCompilerHost(
106107
return false;
107108
},
108109
fileExists: (fileName) => {
109-
// console.log(`${fileName}: ${files.has(fileName)}`);
110-
return !!getFile(fileName);
110+
// NOTE: This function should be kept in sync with "getFile"
111+
112+
if (files.has(fileName)) {
113+
return true;
114+
}
115+
if (fileName.startsWith("/types/")) {
116+
const fsPath = mapToTypePath(fileName);
117+
if (fsPath) {
118+
return ts.sys.fileExists(fsPath);
119+
}
120+
}
121+
return false;
111122
},
112123
getCurrentDirectory: () => options.rootDir || "/",
113124
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -138,7 +149,7 @@ export async function createVirtualCompilerHost(
138149
return sourceFileCache.get(fileName);
139150
}
140151
const sourceText = getFile(fileName);
141-
if (!sourceText) {
152+
if (sourceText === undefined) {
142153
throw new Error(`File not found: ${fileName}`);
143154
}
144155

packages/ui5-linter/test/fixtures/linter/projects/com.ui5.troublesome.app/webapp/emptyFile.js

Whitespace-only changes.

packages/ui5-linter/test/lib/linter/snapshots/linter.ts.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ Generated by [AVA](https://avajs.dev).
334334
messages: [],
335335
warningCount: 0,
336336
},
337+
{
338+
coverageInfo: [],
339+
errorCount: 0,
340+
fatalErrorCount: 0,
341+
filePath: 'webapp/emptyFile.js',
342+
messages: [],
343+
warningCount: 0,
344+
},
337345
{
338346
coverageInfo: [],
339347
errorCount: 0,
Binary file not shown.

0 commit comments

Comments
 (0)