Force Prettier to run on otherwise ignored file #16169
Replies: 3 comments 4 replies
-
|
I'm running into this issue as well. In my situation, my project has a script that will generate a Understandably, Prettier ignores these files at this point. However, I do want to format this file for readability because the config file is generated as one line and can get pretty long. There are other JS files I do want formatted too. I have tried negating this rule in my .prettierignore file: I've also tried adding to my .prettierrc overrides: {
"semi": true,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"overrides": [
{
"files": "*.config.js",
"options": {
"tabWidth": 2,
"printWidth": 80
}
}
]
}Running I noticed that VS Code will format the file if I manually invoke the command "Format Document With..." and select "Prettier". It picks up my local project configuration but doesn't use the .gitignore file. The only way I can get those Alternatively, for my script that creates the Minimum repro with prettier v3.3.3: https://github.com/sphars/playground/tree/prettier/prettier-16169 |
Beta Was this translation helpful? Give feedback.
-
|
Though I agree that it makes Prettier seem stupid when it says "No matching files" after I give it the full path to a file that definitely exists. |
Beta Was this translation helpful? Give feedback.
-
|
I'd personally strongly recommend always making a copy of the file from node_modules to outside of node_modules rather than modifying it directly (and modification includes formatting) inside node_modules. (In fact I'd prefer if it was simple to write protect all of node_modules for any process except for the npm/yarn binary somehow) Unless you have node_modules committed to the repo (which I've never heard of anyone doing) it's all to easy to change something so you break something inside node_modules and not notice. Or even worse, acciudentally "fixing" a bug by making local changes inside node_modules only for it to break on every other computer when they don't have the accidental modifications. It wouldn't be such a problem if npm/yarn etc. kept some kind of diff themselves and actually removed local changes inside node_modules automatically when running |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry if I'm being daft, but either the docs are lacking or this doesn't seem to be supported, which is frustrating.
Often I need to delve into (minifed)
node_modulesto debug some issue, where formatting would be much appreciated. However, it seems to be impossible to force Prettier to write these files, even with a file path explicitly provided, i.e.,prettier --write node_modules/example/index.js.With a path to a specific module, the ignore file should be completely ignored, IMO. It's clear that I want that file formatted.
Is there any way of doing this?
Beta Was this translation helpful? Give feedback.
All reactions