Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure prettier to check all files with a specific extension

I have installed prettier via

yarn add prettier

I would like prettier to only format typescript code (I am developing AWS CDK project, there is no src folder by convention & there could be typescript files here and there). In other words, I would like prettier to check all files in my project that has extension *.ts.

I checked its documentation for configuration. But there is no such option to specify file extension.

How can I run prettier for only *ts files then? Is it even possible? If not, what could be the workaround?

like image 873
user842225 Avatar asked Dec 06 '25 21:12

user842225


1 Answers

For *.ts files:

npx prettier 'src/**/*.ts' --write

If you want target other file extensions:

npx prettier 'src/**/*.{js,ts,mjs,cjs,json}' --write
like image 111
Tiago Bértolo Avatar answered Dec 08 '25 13:12

Tiago Bértolo