Prettier-atom: Prettier auto formats JSON removing quotes

Created on 20 Oct 2017  路  7Comments  路  Source: prettier/prettier-atom

When turning prettier on save. It formats my json by removing the parens.

For example if I have this,

const apples = {
    'red': 'with seeds'
}

// It changes it to this,

const apples = {
    red: 'with seeds'
}

I am using eslint and have a pretty extensive eslintrc file but when I delete the file I still have the same problem. So I think this is for sure a setting within prettier. But I cannot figure out which one.

Does anyone know how to change the behavior for formatting objects? I want to be able to write json without it being formatting when I save the file to turn it into a JS Object.

question

Most helpful comment

On VSCode, when using a .prettierrc config file, set/include property quoteProps and set it to preserve: "quoteProps": "preserve"

All 7 comments

@wuno Are you sure that Atom recognizes that you are in a JSON scope and not a JS scope?

I was wondering about that and looking around to see how I could determine that.
I am using eslint as well but when I remove all my rules it does the same thing. When I open the app in webstorm the problem does not persist. So it is for sure a prettier thing.

I am sure it is just a setting I just cannot figure out which one it is.

Prettier will always remove quotes when possible, e.g. it will preserve them if you use property names with dashes or whitespace.
If you want it to stay consistent, you can use the quote-props ESLint rule and enable autofix.

Side note: The sample you showed us is JavaScript, and it removed quotes (the title was a bit misleading).

This is my current rule in .eslintrc

"quote-props": [1, "as-needed"],

You are saying I can change this and it will work closer to what i am expecting? Also I shall change the name, sorry about that.

If you want to always use quotes for object properties, use "always".
All the options are described here.

On VSCode, when using a .prettierrc config file, set/include property quoteProps and set it to preserve: "quoteProps": "preserve"

On VSCode, when using a .prettierrc config file, set/include property quoteProps and set it to preserve: "quoteProps": "preserve"

It will always add quotes to the property or only when it needs?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zimme picture zimme  路  6Comments

iamphill picture iamphill  路  5Comments

mgrip picture mgrip  路  5Comments

mrmurphy picture mrmurphy  路  5Comments

derwaldgeist picture derwaldgeist  路  5Comments