Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore node_modules from prettier

Using pretty-quick for beautification purpose

Prettier configuration and Eslint rules are affecting the node_modules. So, want to skip it.

Hence, 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.

like image 694
Mithun Shreevatsa Avatar asked Nov 16 '18 07:11

Mithun Shreevatsa


People also ask

Does prettier ignore Node_modules?

Prettier's CLI ignores node_modules by default.

How do I ignore a folder in prettier?

Use . prettierignore to ignore (i.e. not reformat) certain files and folders completely. Use “prettier-ignore” comments to ignore parts of files.

How do you make a prettier ignore line?

While this doesnt work for OP's example, one option is to add the prettier-ignore comment to the start of each line to be ignored, using the /* */ comment style, eg.


3 Answers

Prettier's CLI ignores node_modules by default.

like image 98
Salman Avatar answered Oct 03 '22 20:10

Salman


We must only do the changes for staged files by passing --staged to the existing command as shown below is the only solution i came up for now to move on.

"lint": "pretty-quick --staged & eslint "src/**/*.{js,jsx}" --quiet --fix"
like image 24
Mithun Shreevatsa Avatar answered Oct 03 '22 20:10

Mithun Shreevatsa


According the npm package description, prettier ignores the files you wrote a path in .prettierrc, .prettierignore, and .editorconfig.

You're gonna check it out below if you wanna know more.

https://www.npmjs.com/package/pretty-quick#configuration-and-ignore-files

like image 45
t.kuriyama Avatar answered Oct 03 '22 20:10

t.kuriyama