Skip to content

Commit d96790f

Browse files
committed
fix: Do not show directory read errors
1 parent fe28717 commit d96790f

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/adapters/fileSystem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type FileSystem = {
22
fileExists: (filePath: string) => Promise<boolean>;
3-
readFile: (filePath: string) => Promise<Error | string>;
4-
writeFile: (filePath: string, contents: string) => Promise<Error | undefined>;
3+
readFile: (filePath: string) => Promise<NodeJS.ErrnoException | string>;
4+
writeFile: (filePath: string, contents: string) => Promise<NodeJS.ErrnoException | undefined>;
55
};

src/converters/comments/convertFileComments.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createStubConverter } from "../lintConfigs/rules/ruleConverter.stubs";
66
import { convertFileComments, ConvertFileCommentsDependencies } from "./convertFileComments";
77

88
const createStubDependencies = (
9-
readFileResult: string | Error,
9+
readFileResult: string | NodeJS.ErrnoException,
1010
): ConvertFileCommentsDependencies => ({
1111
converters: new Map([
1212
["ts-a", createStubConverter(["es-a"])],
@@ -39,6 +39,24 @@ describe("convertFileComments", () => {
3939
expect(result).toBe(readFileError);
4040
});
4141

42+
it("ignores the failure when attempting to read a directory", async () => {
43+
// Arrange
44+
const readDirError = new Error() as NodeJS.ErrnoException;
45+
readDirError.code = "EISDIR";
46+
const dependencies = createStubDependencies(readDirError);
47+
48+
// Act
49+
const result = await convertFileComments(
50+
dependencies,
51+
stubFileName,
52+
new Map<string, string[]>(),
53+
new Map<string, string[]>(),
54+
);
55+
56+
// Assert
57+
expect(result).toBe(undefined);
58+
});
59+
4260
it("doesn't overwrite a file when there are no matching comment directives", async () => {
4361
// Arrange
4462
const dependencies = createStubDependencies(`

src/converters/comments/convertFileComments.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export const convertFileComments = async (
1616
) => {
1717
const fileContent = await dependencies.fileSystem.readFile(filePath);
1818
if (fileContent instanceof Error) {
19+
if (fileContent.code === "EISDIR") {
20+
return undefined;
21+
}
22+
1923
return fileContent;
2024
}
2125

0 commit comments

Comments
 (0)