Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not show Errors from reading directories #1717

Conversation

hyperupcall
Copy link
Contributor

@hyperupcall hyperupcall commented Aug 2, 2023

PR Checklist

Overview

If a tsconfig.json contains something like the following:

{
    "include": ["cool"]
}

Then, an error shows up, for example, when using --comments:

✨ 143 rules replaced with their ESLint equivalents. ✨

⚡ 1 new package is required for this ESLint configuration. ⚡
  npm install eslint-config-prettier --save-dev
❌ 1 error running tslint-to-eslint: ❌
  Error: EISDIR: illegal operation on a directory, read

According to the TypeScript docs, a directory entry for include is valid:

If the last path segment in a pattern does not contain a file extension or wildcard charater, then it is treated as a directory, and files with supported extensions inside that directory are included (e.g. .ts, .tsx, and .d.ts by default, with .js and .jsx if allowJs is set to true).

This fixes that case.

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well (yay! thanks!) but I think I'd rather have the issue fixed closer to its source. What do you think?

I'm not against merging as-is if you think what's currently in the PR is a better approach, especially since this repo is old and relatively inactive.

@@ -16,6 +16,10 @@ export const convertFileComments = async (
) => {
const fileContent = await dependencies.fileSystem.readFile(filePath);
if (fileContent instanceof Error) {
if (fileContent.code === "EISDIR") {
return undefined;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Structure] I actually think the approach here isn't what I'd prefer. collectCommentFileNames is taking in a typescriptConfiguration that looks like:

{
  "compilerOptions": { "target": "es3" },
  "files": ["./cool/index.ts"],
  "include": ["cool"]
}

...but with an output commentFileNames like:

{
  exclude: undefined,
  include: [ './cool/index.ts', 'cool' ]
}

(note that the original TSConfig that made that is just { "include": ["cool"] }.

I think the right approach to fix this earlier in the system would be to have collectCommentFileNames filter out directories from its output. Or maybe just not use the "include" at all, if files has the full list of files?

What do you think?

Copy link
Contributor Author

@hyperupcall hyperupcall Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good! I have changed things so now collectCommentFileNames handles the filtering of directories. Sorry about the slow response/changes

@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author The PR author should address requested changes label Aug 3, 2023
@hyperupcall hyperupcall force-pushed the hyperupcall-no-read-directory branch from d96790f to d2f327b Compare September 30, 2023 10:08
@hyperupcall hyperupcall force-pushed the hyperupcall-no-read-directory branch from d2f327b to b4b2ce9 Compare September 30, 2023 10:13
@JoshuaKGoldberg JoshuaKGoldberg removed the status: waiting for author The PR author should address requested changes label Oct 9, 2023
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swell, thanks! This is looking great - and I appreciate you refactoring the internals. 🙌

I'll apply a couple of nits that honestly don't really change much.

src/adapters/fsFileSystem.ts Show resolved Hide resolved
src/comments/collectCommentFileNames.ts Show resolved Hide resolved
Comment on lines +41 to +46
.map((isDirectory, i) => {
if (isDirectory) {
return null;
}
return includeList[i];
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could one-line this if you really wanted 😄

Suggested change
.map((isDirectory, i) => {
if (isDirectory) {
return null;
}
return includeList[i];
})
.map((isDirectory, i) => !isDirectory && includeList[i])

@JoshuaKGoldberg
Copy link
Member

Oh, I don't have permissions to modify your fork. No worries - it's just nits.

@JoshuaKGoldberg JoshuaKGoldberg merged commit 13842ed into typescript-eslint:main Oct 9, 2023
@JoshuaKGoldberg
Copy link
Member

Published in tslint-to-eslint-config@2.14.1. Thanks @hyperupcall! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--comments throws EISDir when a directory is specified in TSConfig include
2 participants