Mithun Shreevatsa
Mithun Shreevatsa

Reputation: 3619

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.

Upvotes: 11

Views: 26390

Answers (4)

Mithun Shreevatsa
Mithun Shreevatsa

Reputation: 3619

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"

Upvotes: 3

Salman
Salman

Reputation: 571

Prettier's CLI ignores node_modules by default.

Upvotes: 40

javimovi
javimovi

Reputation: 386

in the .eslintignore file, add the following line:

/node_modules/

Upvotes: 1

t.kuriyama
t.kuriyama

Reputation: 177

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

Upvotes: 3

Related Questions