Comments (5)
Similar to #10. Maybe this could be a setting where you can specify the files you want trailing commas in or there could be a list of defaults.
from dprint-plugin-json.
Hi there. I'm investigating moving my monorepo from prettier to dprint, and this issue is one of the pain points for me. An option for this would be great!
I would even go so as far to say that files like "tsconfig.json" and "./.vscode/settings.json" should be parsed as JSONC by default without the end-user having to specify anything in their config. (Because this is what VSCode reports in the bottom-right-hand-corner as what the file actually is.)
from dprint-plugin-json.
Yes!
I propose that we either enforce trailing commas in these types of files or that we make a new setting to allow this. I imagine it looking something like
"filesWithTrailingCommas": [
"**/.vscode/extensions.json",
"**/.vscode/launch.json",
"**/.vscode/settings.json",
"**/.vscode/tasks.json",
"**/tsconfig*.json",
"**/jsconfig*.json"
]
and it could default to that value that I said right there
You may have a better idea of what to call the setting or how to structure it. I am just saying an idea.
from dprint-plugin-json.
In a perfect world, Microsoft would have decided to name those files .jsonc instead of .json, but I don't think that is going to happen :)
from dprint-plugin-json.
You may skip reading this. It isn't that important. Click to expand this section:
This was also a problem, back when I used prettier, until I found this hacky workarround. I tried to do that same hacky workaround with dprint but it didn't work because dprint/dprint-plugin-prettier#39 is still broken. The hack I tried was to have dprint.json say
{
"json": {
"associations": [
"**/*.json",
"!**/.vscode/extensions.json",
"!**/.vscode/launch.json",
"!**/.vscode/settings.json",
"!**/tsconfig*.json",
"!**/jsconfig.json"
]
},
"prettier": {
"overrides": [
{
"files": [
"**/.vscode/extensions.json",
"**/.vscode/launch.json",
"**/.vscode/settings.json",
"**/tsconfig*.json",
"**/jsconfig*.json"
],
"options": {
"parser": "json5",
"quoteProps": "preserve",
"singleQuote": false,
"trailingComma": "all"
}
}
]
},
"includes": [
"**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml,md,mdx,toml,vue,html,css,scss,sass,less,hbs,graphql,gql}"
],
"excludes": [
"**/node_modules",
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.84.0.wasm",
"https://plugins.dprint.dev/json-0.17.1.wasm",
"https://plugins.dprint.dev/markdown-0.15.2.wasm",
"https://plugins.dprint.dev/toml-0.5.4.wasm",
"https://plugins.dprint.dev/prettier-0.24.0.json@9a57d0d8e440ad90d07a503166af47e7a6a886abd46767933f9c279f72468596"
]
}
But that hack is ugly! I would much prefer we do something different. And, like I said, it doesn't work anyway.
from dprint-plugin-json.
Related Issues (17)
- JSON formatting is super slow on a 700KB single line JSON file
- Add trailing comma configuration
- Panic on invalid JSON
- Unable to parse correctly number with exponent and no sign HOT 1
- fails to format json with invalid unicode HOT 1
- format invalid code ?
- Too slow formatting this single line JSON file HOT 3
- Allow disabling the new line requirement HOT 1
- Allow formatting keys with no quotes
- Formatting JSONC can lose comments yet still indicate success
- Can't formatting over 4 files with `.sh` script HOT 6
- 🙏🏻[feat/req] add 'preferSingleLine' option HOT 2
- Rewrite formatter to format a stream of bytes
- Invalid UTF-8 chars prevent formatting HOT 2
- no meaningful error message given for `\u200b` in text HOT 5
- Have ignore comments apply to trailing commas
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dprint-plugin-json.