From 85d6a678b48151a7fda95ff6cff7effc921e6f61 Mon Sep 17 00:00:00 2001 From: Frerk Saxen Date: Tue, 18 Jul 2023 12:07:53 +0200 Subject: [PATCH] feat: add check-yaml feature that allows key duplicates. --- pre_commit_hooks/check_yaml.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pre_commit_hooks/check_yaml.py b/pre_commit_hooks/check_yaml.py index 250794e..8fc7d75 100644 --- a/pre_commit_hooks/check_yaml.py +++ b/pre_commit_hooks/check_yaml.py @@ -53,8 +53,19 @@ def main(argv: Sequence[str] | None = None) -> int: ), ) parser.add_argument('filenames', nargs='*', help='Filenames to check.') + parser.add_argument( + '--allow_duplicate_keys', '--allow-duplicate-keys', action='store_true', + help=('In JSON mapping keys should be unique, in YAML they must be unique.' + 'PyYAML never enforced this although the YAML 1.1 specification already required this.' + 'Duplicate keys in mappings are no longer allowed by default.' + 'Use this parameter to allow duplicate keys in yaml files.' + ), + ) + args = parser.parse_args(argv) + yaml.allow_duplicate_keys = args.allow_duplicate_keys + load_fn = LOAD_FNS[Key(multi=args.multi, unsafe=args.unsafe)] retval = 0