Skip to content

Conversation

@fisker
Copy link
Member

@fisker fisker commented Feb 14, 2020

Fixes #6854

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@fisker fisker changed the title [WIP] Check files and dirs before glob [WIP] Check pattern existence before glob Feb 14, 2020
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)
Copy link
Member

@alexander-akait alexander-akait Feb 14, 2020

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

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Yes, agree 👍

Copy link
Member

@thorn0 thorn0 Feb 16, 2020

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

Copy link
Member Author

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

Copy link
Member Author

@fisker fisker Feb 16, 2020

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.

Copy link
Member

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.

Copy link
Member

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).

Copy link
Member

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".

Copy link
Member

@thorn0 thorn0 Feb 17, 2020

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.

@fisker fisker changed the title [WIP] Check pattern existence before glob Check pattern existence before glob Feb 15, 2020
@fisker fisker marked this pull request as ready for review February 15, 2020 09:56
@fisker
Copy link
Member Author

fisker commented Feb 15, 2020

@evilebottnawi ready for review.

@thorn0 thorn0 mentioned this pull request Feb 16, 2020
…nto check-file-before-glob

# Conflicts:
#	src/cli/util.js
@thorn0 thorn0 added this to the 2.0 milestone Feb 17, 2020
@thorn0 thorn0 mentioned this pull request Feb 18, 2020
4 tasks
Copy link
Member

@alexander-akait alexander-akait left a 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

@fisker fisker force-pushed the check-file-before-glob branch 2 times, most recently from f30b9dc to 4236201 Compare February 18, 2020 15:43
@fisker fisker force-pushed the check-file-before-glob branch from 4236201 to 7493647 Compare February 18, 2020 15:45
@fisker
Copy link
Member Author

fisker commented Feb 18, 2020

Let's add tests for ./directory/directory/directory/../../file.js, ./directory/./file.js

7493647

@alexander-akait
Copy link
Member

Let's fix conflicts

# Conflicts:
#	src/cli/util.js
@fisker
Copy link
Member Author

fisker commented Feb 18, 2020

WIP

@alexander-akait
Copy link
Member

/cc @thorn0 I think we can merge to continue working on . and expand directories

@thorn0 thorn0 merged commit 647c041 into prettier:next Feb 19, 2020
@fisker fisker deleted the check-file-before-glob branch February 19, 2020 11:11
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label May 20, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants