Inconsistent quotes presence in yaml
See original GitHub issuePrettier 1.14.3 Playground link
--parser yaml
Input:
key1: value1
key2: 'value2'
Output:
key1: value1
key2: "value2"
Expected behavior:
Consistent quoting. Personally,
I would prefer to see optional quotes removed. This matches how prettier handles JavaScript object keys.
key1: value1
key2: value2
Enforcing quotes would also be acceptable. The most important thing is consistency.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Quote consistency in .info.yml files for Core modules
While looking at all the .info.yml files in the core modules, I noticed the usage of quotes was inconsistent. I am chose this...
Read more >May 13, 2021
YAML is the gift that does not stop taking. There is no published way of enforcing "gofmt" style formatting on YAML (without eating ......
Read more >YAML: Do I need quotes for strings in YAML?
Use quotes to force a string, e.g. if your key or value is 10 but you want it to return a String and...
Read more >YAML: It's Time to Move On
It's just simply not that big of a deal to add a few quotes and ... if a markup language is strict enough...
Read more >Strings in YAML - To Quote or not to Quote | tinita [blogs.perl.org]
The good news is, the YAML double quoted string works the same as in JSON, so if you know that already, you will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could this be implemented at least for simple string keys for now?
Prettier 2.0.5 Playground link
Input:
Output:
Expected behavior:
YAML seems so simple, but it turns out it isn’t.
At this moment, Prettier seems to support the failsafe schema. This means it supports mappings, sequences, and uninterpreted strings.
This the following YAML
is equivalent to the following JSON
When the JSON schema is used, it would be equivalent to the following JSON
The core schema adds even more notations.
And then there are custom schemas, so detecting wether it is safe to unquote strings is never safe. For example, http://yaml.org/type/ adds support for time stamps and
yes
/no
as boolean values (which is default in YAML 1.1).Prettier could add support for stricter YAML formatting, if it gets an option for the user to support a schema. This could even go beyond normalization of strings, such as stripping tags and normalizing type casing.