-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Check pattern existence before glob #7587
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
src/cli/util.js
Outdated
| // `dot pattern` and `expand directories` support need handle differently | ||
| // for backward compatibility reason only expand `directories` like a glob pattern | ||
| // see https://github.com/prettier/prettier/pull/6639#issuecomment-548949954 | ||
| isGlobPattern(pattern) |
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.
Just information: test* can be directory and can be glob 😄 But maybe it is good idea to check on directory firstly, also we can use https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options to check on glob, I think that's why I decided that we need to do an update first
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.
@evilebottnawi is-glob is original from eslint, we don't have fast-glob yet, we don't want both fast-glob and globby, we can switch to globby function later https://github.com/sindresorhus/globby#globbyhasmagicpatterns-options
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.
Yes, agree 👍
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.
I don't understand this if. Why include <dir>/**/* if <dir> looks like a pattern, but is a directory? I read #6639 (comment), but it doesn't make it any clearer to me.
The comment in the code says "for backward compatibility reason", but I checked: Prettier 1.19.1 doesn't behave like this
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.
Run
$ npx prettier src
[error] No matching files. Patterns tried: src !**/node_modules/** !./node_modules/** !**/.{git,svn,hg}/** !./.{git,svn,hg}/**We don't expand dirname, unless it's pattern like !dir and it's a dir, we search all files in this !dir, because this is we want to do in this pr, otherwise, we still say we don't glob anything in src
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.
If we don't expand this [foo] dir , people will still not able to format all files inside [foo] , because prettier [foo]/**/* will not glob any file, he has to prettier [foo]/1.js [foo]/2.js [foo]/3.js, but we do this, he can prettier [foo]. And we are going to support prettier foo #6128 , just not in this PR.
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.
That's why there exists escaping syntax in globs. fast-glob uses backslashes for that, which, unfortunately, makes the Windows story messier... I'll check how ESLint handles this.
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 a mess. The same command eslint "x\[foo\]/*.js" matches different files on Linux (x[foo] → foo.js) and Windows (x → [foo → ] → foo.js).
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.
An alternative escaping syntax works though: eslint "x[[]foo]/*.js".
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.
And we are going to support prettier foo #6128 , just not in this PR.
Let's move all the work with directories to that PR. For now, in this PR, let's just skip directories. To format files inside [foo], people have the escaping syntax.
|
@evilebottnawi ready for review. |
Co-Authored-By: Georgii Dolzhykov <[email protected]>
…nto check-file-before-glob
…nto check-file-before-glob # Conflicts: # src/cli/util.js
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.
Let's add tests for ./directory/directory/directory/../../file.js, ./directory/./file.js
f30b9dc to
4236201
Compare
4236201 to
7493647
Compare
|
|
Let's fix conflicts |
# Conflicts: # src/cli/util.js
|
WIP |
|
/cc @thorn0 I think we can merge to continue working on |
Fixes #6854
docs/directory)changelog_unreleased/*/pr-XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨