prettier / pretty-quick

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

How to ignore node_modules from pretty-quick #50

Open hansiemithun opened 6 years ago

hansiemithun commented 6 years ago

Tried creating .prettierignore file having node_modules defined inside it

Have config setup rule like this below: `"lint": "pretty-quick & eslint \"src/*/.{js,jsx}\" --quiet --fix"

Giving error as:

SyntaxError: Nested mappings are not allowed in compact mappings (8:9)
  6 | artifact: 'file://dcs.tar.gz'
  7 | deploymentStrategy: default
> 8 | config: artifact:
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 9 |
    | ^
    at e (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/parser-yaml.js:1:323)
    at Object.parse (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/parser-yaml.js:1:156977)
    at Object.parse$2 [as parse] (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:7138:19)
    at coreFormat (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:10398:23)
    at format (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:10570:16)
    at formatWithCursor (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:10582:12)
    at /Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:34924:15
    at format (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:34943:12)
    at exports.default (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/pretty-quick/dist/formatFiles.js:18:41)
    at exports.default (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/pretty-quick/dist/index.js:54:29)
✨  Done in 4.19s.

Also tried configuring like this:

"lint": "pretty-quick --ignore-path=.prettierignore & eslint \"src/**/*.{js,jsx}\" --quiet --fix"

But no luck :( Can anyone help?

aleclarson commented 5 years ago

Have you tried adding /node_modules/ to your .gitignore?

mledom commented 5 years ago

@hansiemithun did you ever figure out what the issue was? I'm having the same issue and I can't figure out how ignore node_modules specifically node_modules/prettier/index.js

kevinsar commented 5 years ago

@aleclarson @hansiemithun did adding the directory to the .prettierignore file work? Or you can possibly try adding the flag --stage to only target staged files on commits. Those seem to work for me.

hansiemithun commented 5 years ago

@mledom, @kevinsar - the .prettierignore did not work for me, I am doing the same. Staging necessary files. Not able to find a solution so far

azz commented 5 years ago

@hansiemithun this is strange because pretty-quick gets files from git, which should never list node_modules (assuming node_modules is in .gitignore).

Could you run:

$ git ls-files --others --exclude-standard

and

$ git diff --name-only --diff-filter=ACMRTUB $(git merge-base HEAD master)

to check if they output any node_modules?

hansiemithun commented 5 years ago

Error doing the second step: @azz - diff: unrecognized option--name-only'`

azz commented 5 years ago

Sorry I edited my post. Missing the git.

hallya commented 5 years ago

@azz I have the same problem, node_modules is not print by any your commands. It is supposed to mean that my config is ok ?

KenStipek commented 5 years ago

I was able to get this to work by adding /node_modules to my .prettierignore, but I first had delete the pre-commit hook I had set up and reinstall it by reinstalling husky. Documented in the hook:

You can reinstall it using 'npm install husky --save-dev' or delete this hook

jellyfish-tom commented 3 years ago

You probably are interested in prettiering only staged files. You can do that by passing --staged flag:

pretty-quick --staged

JounQin commented 10 months ago

A minimal but runnable online reproduction is required.