Skip to content
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

prettierignore not working correctly in mono repo project #95

Open
michael13491 opened this issue Nov 17, 2019 · 11 comments
Open

prettierignore not working correctly in mono repo project #95

michael13491 opened this issue Nov 17, 2019 · 11 comments

Comments

@michael13491
Copy link

Hi,

I have an issue that is similar to #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
Copy link

andrei-ilyukovich commented Dec 19, 2019

@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
Copy link

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

@SchroederSteffen
Copy link

SchroederSteffen commented Dec 1, 2020

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
Copy link

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

@soberich
Copy link

Same here

1 similar comment
@GalDayan
Copy link

GalDayan commented Jun 7, 2021

Same here

@andrewmclagan
Copy link

Yeah cant use this with monorepo in this state

@JounQin
Copy link
Member

JounQin commented Jan 16, 2024

A minimal but runnable online reproduction is required.

@SukkaW
Copy link
Contributor

SukkaW commented Jan 17, 2024

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
Copy link
Member

JounQin commented Jan 17, 2024

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

@SukkaW
Copy link
Contributor

SukkaW commented Jan 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants