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

Prettier --write command changed not only staged files. #599

Closed
DonikaV opened this issue Apr 3, 2019 · 9 comments
Closed

Prettier --write command changed not only staged files. #599

DonikaV opened this issue Apr 3, 2019 · 9 comments

Comments

@DonikaV
Copy link

DonikaV commented Apr 3, 2019

I have monorepo with lerna. The setup is like here https://github.com/sudo-suhas/lint-staged-multi-pkg/blob/master/package.json

Steps to reproduce

In each folder i have this .linkstagedrc.yml with

linters:
  "src/main/js/**/*.{js,jsx,mjs}":
    - "prettier --write 'src/main/js/**/*.{js,jsx,mjs}'"
    - "git add"

The problem is - i modified only one js file. I do commit, and then in git i see much more files than one. But i want modify only staged file.
Can someone help me with that? Thanks.

Environment

  • OS: Macos
  • Node.js: current LTS (10*)
  • lint-staged: latest
@borwahs
Copy link

borwahs commented Apr 13, 2019

I am running into the same issue with the following in package.json:

"lint-staged": {
    "*.{js,jsx,css}": [
      "prettier --write",
      "git add"
    ]
  },

I am not using lerna though.

@borwahs
Copy link

borwahs commented May 9, 2019

Disregard my comment. My issue was that our lint-staged was actually an older version which doesn't have #75 (fixing #62) in it.

@okonet okonet closed this as completed Jun 10, 2019
@okonet
Copy link
Collaborator

okonet commented Jun 10, 2019

@DonikaV your issue is with the config you're using. You pass glob as an argument and that's why prettier runs on all matching files. Instead, remove the glob from arguments since that's exactly what lint-staged is doing for you under the hood.

@DonikaV
Copy link
Author

DonikaV commented Jun 13, 2019

@okonet can you help me and say what exactly i should change? Thanks in advance.
Because backend guys complain about my improvements for frontend :D They dont want see this precommit hook been executed on his machines.

@okonet
Copy link
Collaborator

okonet commented Jun 13, 2019

@DonikaV I thought I did:

Instead, remove the glob from arguments since that's exactly what lint-staged is doing for you under the hood.

You should change it to this:

linters:
  "src/main/js/**/*.{js,jsx,mjs}":
-    - "prettier --write 'src/main/js/**/*.{js,jsx,mjs}'"
+    - "prettier --write"
    - "git add"

@DonikaV
Copy link
Author

DonikaV commented Jun 13, 2019

@okonet Thanks! Will try tomorrow.

@DonikaV
Copy link
Author

DonikaV commented Jun 14, 2019

@okonet works good! Thanks again!
Last question, can i somehow check if npm installed, if yes => run this hook, if not => skip?

@okonet
Copy link
Collaborator

okonet commented Jun 14, 2019

Not sure what you mean but I remember there is a package that allows not running recommit hooks based on user's settings. I can't find it though :-(

@DonikaV
Copy link
Author

DonikaV commented Jun 14, 2019

@okonet I mean, backend guys are to lazy and they don’t want run npm install. :D
Ok, I will try to find something in google :)

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

No branches or pull requests

3 participants