最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I run prettier on a specific subdirectory on my project? - Stack Overflow

programmeradmin1浏览0评论

I have a typescript project structure something like this:

--workflows
    |--app1
         |--src
    |--app2
         |--src

I am trying to run prettier, but I only want to run on app1.

I tried something like this:

prettier --write \"workflows/app1/**/*.{js, ts}\"

This doesn't return any files.

But if I run something like this:

prettier --write \"workflows/**/*.{js, ts}\"

It returns all files under workflows directory.

What am I doing wrong? How can I get it to run only for files under app1?

I have a typescript project structure something like this:

--workflows
    |--app1
         |--src
    |--app2
         |--src

I am trying to run prettier, but I only want to run on app1.

I tried something like this:

prettier --write \"workflows/app1/**/*.{js, ts}\"

This doesn't return any files.

But if I run something like this:

prettier --write \"workflows/**/*.{js, ts}\"

It returns all files under workflows directory.

What am I doing wrong? How can I get it to run only for files under app1?

Share Improve this question asked Dec 23, 2021 at 17:34 olivonianolivonian 2211 gold badge2 silver badges6 bronze badges 4
  • Try it without escaping quotes, i.e. prettier --write "workflows/app1/**/*.{js, ts}". Escaping quotes actually includes them in the path. – Steve Commented Dec 23, 2021 at 17:41
  • @Steve I can't. I am writing it I package.json file. Something like this "scripts": { "review": "prettier --write \"workflows/app1/**/*.{js, ts}\"" } If if remove the escapes, it starts erroring out – olivonian Commented Dec 23, 2021 at 17:48
  • Ah, that makes sense. Since it's in JSON, it actually is running it without the escaped quotes. It looks to me like it should run correctly. – Steve Commented Dec 23, 2021 at 17:51
  • 1 It worked without using quotes prettier --write workflows/app1/**/*.{js, ts} – olivonian Commented Dec 23, 2021 at 18:06
Add a comment  | 

2 Answers 2

Reset to default 12

It worked without using quotes

prettier --write workflows/app1/**/*.{js, ts} 

Json looks like this:

"scripts": {
    "review": "prettier --write workflows/app1/**/*.{js,ts}"
    }

According to the docs you can use a .prettierignore file in the root of your project: https://prettier.io/docs/en/ignore.html

Simply create a file called .prettierignore and type the directories you want to exclude in your case:

app2

You can also use the --ignore-path option in the CLI

发布评论

评论列表(0)

  1. 暂无评论