Check pattern existence before glob#7587
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.
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.
@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.
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.
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.
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.
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.
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.
An alternative escaping syntax works though: eslint "x[[]foo]/*.js".
There was a problem hiding this comment.
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 <thorn.mailbox@gmail.com>
…nto check-file-before-glob
…nto check-file-before-glob # Conflicts: # src/cli/util.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✨