Add support for Duplicate keys for `check_yaml` hook
See original GitHub issueAccording to the YAML specification, keys must be unique:
3.2.1.1. Nodes: The content of a mapping node is an unordered set of key: value node pairs, with the restriction that each of the keys is unique.
Although, unfortunately, some real-world YAML configurations may not be conformant with this point and duplicate keys may appear. A clear example of this is the Cirrus CI configuration file, which can define multiple task
fields.
PyYAML enforces this option by default, which I totally agree with, but would be cool to specifically allow it. This is fairly simple to implement:
yaml = ruamel.yaml.YAML()
yaml.allow_duplicate_keys = True
yaml.load(stream)
https://yaml.readthedocs.io/en/latest/api.html#duplicate-keys
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Supported hooks - pre-commit
check-added-large-files - prevents giant files from being committed. ... top-level keys. check-git-config-email - This hook checks to ensure the Git config ...
Read more >Getting duplicate keys in YAML using Python - Stack Overflow
yaml looks like the most advanced YAML parser in Python and it looks moderately extensible, can it be extended to support duplicate fields?...
Read more >Ubuntu Manpage: yamllint -
yamllint - A linter for YAML files. yamllint does not only check for syntax validity, but for weirdnesses like key repetition and cosmetic...
Read more >pre-commit-hooks Changelog - pyup.io
`check-json`: report duplicate keys. - 558 PR by AdityaKhursale. - 554 issue by adamchainz. - `no-commit-to-branch`: add `main` to default blocked branches.
Read more >10 YAML tips for people who hate YAML | Enable Sysadmin
While its ability to reflect hierarchical values is significant and its ... support, you can add additional packages like yaml-mode to help.
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
indeed,
--unsafe
is a blanket flag to disable all of the strict checking. if you’re going to violate the specification then all bets are offalso for cirrus you should use
{uninquename}_task
for naming your keys to conform with yaml specification