-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Expand directories in CLI (2020) #7660
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
Conversation
93755e0 to
e26bd2f
Compare
|
Resolved files aren't globally sorted anymore. Instead, their order matches the order of the given patterns, and for each pattern, the corresponding group of files is sorted. This seems logical and acceptable while ditching the global sorting allows us to use generators to avoid various problems related to big arrays. Open problems:
|
2a38cf6 to
5637b04
Compare
d570c01 to
c896ba5
Compare
| .map(ext => "*" + (ext[0] === "." ? ext : "." + ext)) | ||
| .concat(filenames)}}`; | ||
| } | ||
| return supportedFilesGlob; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I format exts add by config override or plugins? I think we should glob all files
and inferParser then filter the files without parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I format exts add by config override or plugins?
Plugins - yes. There is a test for that.
Config overrides - no. Because configs are resolved on a later stage.
I think we should glob all files and inferParser then filter the files without parser
That's a good idea. I'll give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parser inference thing looks a bit complicated though. How about merging this PR as is and improving this later?
I feel this PR is already good enough for most of the use cases. People just want to run prettier . --write or prettier src --write. For more complicated scenarios, they can use globs.
alexander-akait
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Couple notes
src/cli/expand-patterns.js
Outdated
| for (const pattern of context.filePatterns) { | ||
| const absolutePath = path.resolve(cwd, pattern); | ||
|
|
||
| if (containsIgnoredPathSegment(absolutePath, cwd, ignoredDirectories)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using micromatch here, we already have it in our deps (from fast-glob)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is only for silent ignoring files in node_modules and VCS dirs. I think it's good enough.
e0b374d to
ae238af
Compare
|
I guess only problem is how to get |
|
Can you also post a log run |
|
What are the answers to the open problems?
|
alexander-akait
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job
# 2 and # 3 are the same problem, parser inference vs using extensions. As for # 1, Prettier 1.19.1 doesn't issue any warning if passed a glob that is fully ignored by |
Maybe we should using only |
I'd rather expect that
Yes. It's tricky. Not super difficult, but I'm sure that if I really start digging into it, I'll discover a dozen of new microissues there, so it might take long. The |
Yes, i think you are right. Do we have a test for this? |
This should work exactly if we used IMO these things shouldn't block this PR if these problems already existed when using a blob, but those problems were things I wished to fix for a very long time (that would end up being a 2.0 release), that are way more important than other things people are more concerned with 😅 |
That's not how it works now. It's the same issue, namely: what exactly is "supported files" when we're searching for all "supported files" in a directory? The current implementation in this PR: "supported files" = files with extensions and names taken from An ideal implementation: "supported files" = |
|
Ah, now I understand the problem
This sounds good to me |
|
My proposal is to postpone the ideal implementation until 3.0. |
Sounds good for me, we will also collect feedback and it will help us make it better |
|
Looks like @duailibe and @evilebottnawi both Okay with current implementation, I'm ok with it too. But I have a question, can we somehow hide this |
|
@fisker Currently (in 1.19.1 and in this PR), the "parser can't be inferred" error is not fatal. The error is logged, the file is skipped, Prettier CLI proceeds with next file. Why would we want to hide the error? ESLint doesn't have relevant behavior because it always uses the same parser, but I don't think it ever aborts the whole linting run because of a single file. |
|
@thorn0 I was thinking if eslint abort linting when error occurs, we can also ask people pass glob with valid extensions like Update: If eslint ignore error, we can also ignore it , so we don't need find "supported files" |
|
@fisker Not sure how what you wrote this time is different from what you wrote before about 'I was going to do something like glob all files from dir and yield {file, ignoreNoParserError: true}'. |
|
I'm okay with current implementation. This is only a idea of new possible/simple solution. |
|
I'm actually trying to rewrite it. Let's see how it goes. If it works, I'll open a new PR. |
|
Should we merge this and release v2.0? |
|
/cc @prettier/core Any review will be helpful. |
dougal83
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Great work. Could open a new PR to refactor at this point.
|
/cc @thorn0 Can we merge it and start to release next version? |
|
@evilebottnawi Okay, I'll do this today (if nobody objects). |
Closes #6085
Supersedes #6128
Supersedes #6285
docs/directory)changelog_unreleased/*/pr-XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨