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

javascript - Prettier format a json file - Stack Overflow

programmeradmin0浏览0评论

I have a unformatted json file that gets stored in my application with the following structure

src
 /forms
   /test
     - abc.json

I am using husky and lint-staged to make use of prettier and linting on pre-mit. The configuration resides in my package.json as following

  "husky": {
    "hooks": {
      "pre-mit": "lint-staged --relative",
      "pre-push": "tsc"
    }
  },
  "lint-staged": {
    "src/**/*.{ts, json}": [
      "prettier --write",
      "eslint --fix"
    ]
  },
  ....
  ..

But for some reason the abc.json file never gets formatted when I push my code to github. What am I missing?

I have a unformatted json file that gets stored in my application with the following structure

src
 /forms
   /test
     - abc.json

I am using husky and lint-staged to make use of prettier and linting on pre-mit. The configuration resides in my package.json as following

  "husky": {
    "hooks": {
      "pre-mit": "lint-staged --relative",
      "pre-push": "tsc"
    }
  },
  "lint-staged": {
    "src/**/*.{ts, json}": [
      "prettier --write",
      "eslint --fix"
    ]
  },
  ....
  ..

But for some reason the abc.json file never gets formatted when I push my code to github. What am I missing?

Share Improve this question asked Jan 7, 2022 at 0:26 RRPRRP 2,8539 gold badges32 silver badges55 bronze badges 7
  • Do your .ts files get formatted? I think the glob pattern is src/**/\*.{ts, json} instead of src/**/*.{ts, json} – Tyress Commented Jan 7, 2022 at 1:27
  • 1 @Tyress yes the .ts files gets formatted – RRP Commented Jan 7, 2022 at 1:33
  • @RRP Did you at all try removing src and considering all ts and json files for formatting ? **/*.{ts,json,} – Vipulw Commented Jan 15, 2022 at 10:46
  • @Vipulw yep tried that as well still no luck, the .json file just doesn't get formatted – RRP Commented Jan 16, 2022 at 23:46
  • @RRP what is the parser defined in .prettierrc? – Ben Commented Jun 6, 2022 at 8:57
 |  Show 2 more ments

1 Answer 1

Reset to default 3

There's an error in your glob pattern. Patterns within curly braces should only be delimited by a ma

You have:

"src/**/*.{ts, json}"

Instead, remove the space in the pattern as follows:

"src/**/*.{ts,json}"

发布评论

评论列表(0)

  1. 暂无评论