更漂亮的 VSCode JSON 格式错误
我正在尝试使用Prettier在VS Code中格式化JSON文件,但是,我还没有成功格式化任何 JSON 文件。我使用 Google 搜索了解决方案,但无法返回任何有用的搜索结果。我想知道怎么做,是能够修复我得到的错误,所以我可以使用 VSCode Prettier 扩展来格式化 JSON 文件。如果我无法弄清楚,我会满足于知道如何禁用 Prettier,并使用VS Code 'out-of-the-box'附带的"VS-Code Language Features"格式化 JSON 。
下面是我的.prettierrc
配置
{
"parser": "typescript",
"useTabs": false,
"tabWidth": 2,
"printWidth": 120,
"trailingComma": "none",
"singleQuote": true,
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "always",
"endOfLine": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": false,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true
}
这是我尝试格式化的 JSON 文件
{
"Requester": {
"City": "USBOS",
"PostCode": "02143"
}
}
这是在控制台中打印的更漂亮的错误
> "ERROR" -
> 7:14:26 AM] Error formatting document. ';' expected. (2:12) 1 | {
> 2 | "Requester": {
> | ^ 3 | "City": "USBOS", 4 | "PostCode": "02143" 5 | }, SyntaxError: ';' expected. (2:12) 1 | {
> 2 | "Requester": {
> | ^ 3 | "City": "USBOS", 4 | "PostCode": "02143" 5 | },
> at t (C:\JSONTest\node_modules\prettier\parser-typescript.js:1:285)
> at Object.parse (C:\JSONTest\node_modules\prettier\parser-typescript.js:14:180461)
> at Object.parse (C:\JSONTest\node_modules\prettier\index.js:9739:19)
> at coreFormat (C:\JSONTest\node_modules\prettier\index.js:13252:23)
> at format (C:\JSONTest\node_modules\prettier\index.js:13510:73)
> at formatWithCursor (C:\JSONTest\node_modules\prettier\index.js:13526:12)
> at C:\JSONTest\node_modules\prettier\index.js:44207:15
> at Object.format (C:\JSONTest\node_modules\prettier\index.js:44226:12)
> at c:\Users\mmartins.BROKER\.vscode\extensions\esbenp.prettier-vscode-3.18.0\src\PrettierEditService.ts:382:30
> at t.default.safeExecution (c:\Users\mmartins.BROKER\.vscode\extensions\esbenp.prettier-vscode-3.18.0\src\PrettierEditService.ts:414:27)
> at t.default.<anonymous> (c:\Users\mmartins.BROKER\.vscode\extensions\esbenp.prettier-vscode-3.18.0\src\PrettierEditService.ts:381:17)
> at Generator.next (<anonymous>)
> at s (c:\Users\mmartins.BROKER\.vscode\extensions\esbenp.?
> prettier-vscode-3.18.0\dist\extension.js:1:346242)