FR: Fix YAML keys with no space on lint ("key:val" instead of "key: val")
See original GitHub issueIs Your Feature Request Related to a Problem? Please Describe.
Assume you have the following frontmatter:
Name: Chapter 2 Races
Tags: Players-Handbook Part-1-Creating-A-Character Chapter-2-Races
alias:Chapter 2
Attempting to lint this will run into an error, because now the Tags
is assumed to be multi-line (or so I understand it at least). This issue is encountered during the Yaml-Key-Sort
-Rule:
plugin:obsidian-linter:68 [Obsidian Linter] Lint File Error in File '300 Personal/303 DND/00 Ressources/Books/5e PHB/3 Done/Part 1/Chapter 2 - Races/Chapter 2 Races.md':
Error "YAML Key Sort" encountered an error in the yaml: can not read a block mapping entry; a multiline key may not be an implicit key (4:14)
1 | Name: Chapter 2 Races
2 | Tags: Players-Handbook Part-1-Creating-A-Cha ...
3 | alias:Chapter 2
4 | creation date: 2022-08-28 21:36
------------------^
5 | modification date: 2022-12-03 20:13
YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key (4:14)
1 | Name: Chapter 2 Races
2 | Tags: Players-Handbook Part-1-Creating-A-Cha ...
3 | alias:Chapter 2
4 | creation date: 2022-08-28 21:36
------------------^
5 | modification date: 2022-12-03 20:13
at el (plugin:obsidian-linter:18:944)
at H (plugin:obsidian-linter:18:978)
at qc (plugin:obsidian-linter:25:1955)
at En (plugin:obsidian-linter:25:4870)
at Wc (plugin:obsidian-linter:25:7247)
at tl (plugin:obsidian-linter:26:258)
at Gc (plugin:obsidian-linter:26:469)
at Je (plugin:obsidian-linter:52:223)
at fn.apply (plugin:obsidian-linter:1998:177)
at fn.safeApply (plugin:obsidian-linter:68:1570)
Describe the Solution You’d Like
Add an option to insert a space after the :
if there is none.
Please include an example where applicable:
Name: Chapter 2 Races
Tags: Players-Handbook Part-1-Creating-A-Character Chapter-2-Races
alias:Chapter 2
would change into
alias: Chapter 2
creation date: 2022-08-28 21:36
modification date: 2022-12-03 20:13
Name: Chapter 2 Races
Tags: Players-Handbook Part-1-Creating-A-Character Chapter-2-Races
alias: Chapter 2
instead of aborting.
Describe Alternatives You’ve Considered
/
Additional Context
/
Issue Analytics
- State:
- Created 10 months ago
- Comments:5
Top Results From Across the Web
Spaces in YAML keys - Stack Overflow
Spaces are allowed in keys according to the specification and for those you don't need quotes (double or single, each with their own...
Read more >Allow : colons in data value flags yaml keys #637 - GitHub
YAML separates a key and a value using a colon and a space. So a colon can appear in a key as long...
Read more >10 YAML tips for people who hate YAML | Enable Sysadmin
Do you hate YAML? These tips might ease your pain. ... There are lots of formats for configuration files: a list of values,...
Read more >Rules — yamllint 1.28.0 documentation
When linting a document with yamllint, a series of rules (such as line-length , trailing-spaces , etc.) are checked against.
Read more >The Chart Template Developer's Guide - Helm V2
The Chart Template Developer's Guide. This guide provides an introduction to Helm's chart templates, with emphasis on the template language.
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
In that case, wouldn’t it make sense to make the setting optional, tag a disclaimer on to it that it doesn’t support mode x y z and call it a day? Just thinking loudly here right now; with something like a linter this cannot be the first edgecase that are just not feasible for support.
So it seems we have the following possibilities, after a bit of reading:
I had a bit more thought on it since my last post.
Stuff like the dict and list under judas and fruits seem most painful to me. For the rest, I see a couple groundrules:
:
can only break stuff if followed by a non-whitespace character. This means the first line of anydict
(martin/tabitha) can be ignored, or alternatively you would check if there are non-whitespace in the line until you encounter the linefeed.Dict
-entries (e.g.Matin D'vloper
forname
,Developer
forjob
,Tabitha Bitumen
), stuff can break if the space is missing. However, on each of these lines the first encountered (not escaped) set of:
must signify the end of the keyname, and the beginning of the value field. Thus, any (nonescaped):
that follows would be part of the syntax, and once those end you can check if the next character is a space (valid) or not (invalid)judas
/fruits
seem too much of a pain to consider.That’s my first idea here so far, at least. I’ll think about it over night a bit, gonna go leep now.
Valid scenarios include lists being nested in lists, dictionaries in dictionaries, lists in dictionaries, etc.