4 ms·
I find trailing commas annoying because every once in a while I need to copy some object to use as JSON and... it doesn't work since JSON doesn't support traili
by davidmurdoch 7y ago
I find trailing commas annoying because every once in a while I need to copy some object to use as JSON and... it doesn't work since JSON doesn't support trailing commas.
- davidmurdoch 7y agoWhy the down vote? Prettier calls itself "an opinionated JavaScript formatter". It _had_ an opinion that I agreed with, and now it doesn't. I just offered a perspective on why I don't agree.
- amarshall 7y agoTo be fair, that's more of a JSON problem than a JS one. FWIW, JSON is also missing quote-less keys, object literal shorthand, non-decimal numbers, values that are non-simple literals, and probably a bunch else from JS object syntax. Just `JSON.stringify` whatever object it is instead.
- Groxx 7y agoNo comments either, which is one major reason I strongly oppose JSON as a config-file language :|
- tobr 7y agoThat’s not going to work with object keys anyway, which need to be quoted in JSON. You can’t even configure Prettier to do that unless your keys are invalid JS identifiers.
- j-f1 7y agoFortunately, if you use Prettier to format your JSON files too, it’ll quote unquoted properties and remove trailing commas: https://prettier.io/playground/#N4Igxg9gdgLgprEAuEwA6UAEmDOEC2cA0nAJ5KZoh6EBqAhgDYCucVANBgL4jsgQAHGAEtoOZKHoAnKRADuABWkJxKJnPqlxfAEZT6YANZwYAZQEHhUAObIYU1nwAWMfIwDqT4fBwWwcUxVvYQA3b1JkcBxtECscOCkYBX1rfHpkADMmeL4AKxwADwAhfSMTU3pCABkrOEzsuDzC0ytrRjgARWYIeHrGHJALKXipSPzoXkGpKxh3YQATGCdkAA4ABj4BWXj3fQFIrbgRkLq+AEdu+GTBVRB6HABaKDg4edfJqTgL4U-k+lT0kgsv1GtQ4PhhHYHKCcK12l0enUgQ0+DB6Do5otlkgAEyo-TCRitADCBDSkSOAFZJsx4gAVdGqYEDEKsACSUDesFMYGmQgAgpzTDBSO0+vEuFwgA https://prettier.io/playground/#N4Igxg9gdgLgprEAuEwA6UAEmDOE...