For *.ts files:
npx prettier 'src/**/*.ts' --write
If you want target other file extensions:
npx prettier 'src/**/*.{js,ts,mjs,cjs,json}' --write
Answer from Tiago Bértolo on Stack OverflowVideos
For *.ts files:
npx prettier 'src/**/*.ts' --write
If you want target other file extensions:
npx prettier 'src/**/*.{js,ts,mjs,cjs,json}' --write
To exclude files from formatting, create a .prettierignore file at the root of your project.
And to format only the *.ts files you should ignore everything but the *.ts files.
Example
# Ignore everything recursively
*
# But not the .ts files
!*.ts
# Check subdirectories too
!*/
In the code above, the * means to ignore everything including the subfolders, and the next line !*.ts tells the prettier to reverse the previous ignoring of the .ts files. The last line !*/ means to check the subdirectories too, but with the previous rule, it's only looking for the .ts files.
Check the prettier and gitignore docs for more information.
» npm install prettier
Hi there,
I'm using VS Code on Windows 11, and I have installed Prettier. However, I can only use it from the terminal.
If I execute npx Prettier --write dom.html in the terminal, it works fine.
If I go to the Command Palette and choose Format Document, the following error appears in the output:
["ERROR" - 10:38:49 AM] Invalid prettier configuration file detected. ["ERROR" - 10:38:49 AM] ENOENT: no such file or directory, open 'c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ C:\Users\ivanf\AppData\Roaming\npm\prettier' Error: ENOENT: no such file or directory, open 'c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ C:\Users\ivanf\AppData\Roaming\npm\prettier'
To make it more clear,
c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ is the project folder, and \Users\ivanf\AppData\Roaming\npm\prettier is where prettier is installed.
So it seems that in some configuration file the wrong path "PROJECT_FOLDER PRETTIER_HOME" is formed.
Unfortunately, I cannot locate such file, and I cannot understand why it works when called from the terminal.
Any advice or hints? Thank you in advance, Ivan.