question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Duplicate keys for `check_yaml` hook

See original GitHub issue

According 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Aug 22, 2021

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 off

1reaction
asottilecommented, Aug 22, 2021

also for cirrus you should use {uninquename}_task for naming your keys to conform with yaml specification

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found