Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate key warnings #4

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Duplicate key warnings #4

wants to merge 7 commits into from

Conversation

tigris
Copy link

@tigris tigris commented Jul 11, 2021

We want a way to raise errors when there are duplicate keys in the config. This is becoming a bigger problem for us as our yaml files get bigger and bigger, or spread out across hundreds of files. An alternative to this would be to use a yaml / json lint program prior to using them in ConfigHound.

Some challenges here so far are that SafeYaml doesn't easily support a custom object_class at load time, as far as I can tell. I think we'd need to monkey patch something down in the Psych code, or look into other yaml parsers.

The toml parser we're using at the moment already hard fails on duplicate keys, so I feel implementing this feature for that might be quite troublesome, as we are setting the default to allow duplicates for backwards compatibility, and this would raise the question around breaking that for toml, if it was even possible to implement.

def self.find_duplicate_keys(raw)
require "psych"

# Blatantly stolen from https://stackoverflow.com/a/55705853

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

Copy link

@tata9001 tata9001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants