prettier / pretty-quick

⚡ Get Pretty Quick
https://npm.im/pretty-quick
MIT License
2.22k stars 83 forks source link

prettierignore not working correctly in mono repo project #95

Open michael13491 opened 4 years ago

michael13491 commented 4 years ago

Hi,

I have an issue that is similar to https://github.com/azz/pretty-quick/issues/14

My project folder structure is:

root/
  .git
  webapp/
    package.json
    .prettierignore  
    index.js
    foo/
      test.js

.prettierignore contains:

# ignore everything except foo dir
/*
!/foo

My problem is that pretty-quick does not seem to read .prettierignore rule correctly.

When I run npx pretty-quick --check, it fails to find foo/test.js as changed file. However, when i run npx prettier --check "**/*.js", it will pick up foo/test.js

$ npx pretty-quick --check
�🔍  Finding changed files since git revision 77e111a.
�🎯  Found 0 changed files.
✅  Everything is awesome!

$ npx prettier --check "**/*.js"
Checking formatting...
foo\test.js
Code style issues found in the above file(s). Forgot to run Prettier?

If I remove the rules in .prettierignore, pretty-quick is able to pick up the changed files:

$ npx pretty-quick --check
�🎯  Finding changed files since git revision 77e111a.
�🎯  Found 2 changed files.
⛔️  Check failed: webapp/foo/test.js
⛔️  Check failed: webapp/index.js

So it seems to me that pretty-quick is not reading the ignore rules correctly or am I missing something?

andrei-ilyukovich commented 4 years ago

@michael13491 I faced the same issue. It looks like prettier and pretty-quick treats .prettierignore file differently. Prettier try to apply ignore patterns against files relative to the current working directory (foo/test.js, index.js etc), but pretty-quick try to check file names relative to root of your repo (webapp/foo/test.js, webapp/index.js etc). I think that's why your patterns don't work for pretty-quick. I didn't check but something like that should work:

# ignore everything except foo dir
/*
!**/foo

Another option is to move .prettierignore to the root of your project (since pretty-quick apply root .prettierignore then one from working directory: docs ) but then content also should be updated slightly:

# ignore everything except foo dir
/*
!/webapp/foo
maheshsundaram commented 4 years ago

@andrei-ilyukovich you helped me resolve my problem, thank you! I was struggling to figure this out.

SchroederSteffen commented 3 years ago

Facing the same issue. Wouldn't the straight-forward solution be that pretty-quick should only consider files inside the folder from which it's being called? (instead of the whole surrounding git repository)

flybayer commented 3 years ago

This is also a significant problem for me, so switching to running prettier inside lint-staged for now

soberich commented 3 years ago

Same here

GalDayan commented 3 years ago

Same here

andrewmclagan commented 2 years ago

Yeah cant use this with monorepo in this state

JounQin commented 9 months ago

A minimal but runnable online reproduction is required.

SukkaW commented 9 months ago

I've observed something that could potentially be triggering the issue.

pretty-quick uses the ignore library to parse .prettierignore. Notably, the ignore library is specifically designed to comply with the gitignore specification.

prettier on the other hand, utilizes the micromatch library (which behaves differently than the gitignore specification) to parse the .prettierignore file.

JounQin commented 9 months ago

@SukkaW Thanks for your efforts here! I think we should align with prettier.

SukkaW commented 9 months ago

@SukkaW Thanks for your efforts here! I think we should align with prettier.

Under the hood it is the picomatch (which I introduced back in #180) that powers the micromatch. We could simply replace the ignore with the picomatch and the behavior should have be aligned then.