yamllint icon indicating copy to clipboard operation
yamllint copied to clipboard

Bug: key-duplicates does not work when key is an array

Open rockerdaddy opened this issue 4 years ago • 1 comments

Test case:

$ cat test.yaml
---
field1:
  key1: val1
  key2: val2
  key1: val1

$ yamllint test.yaml
test.yaml
  5:3       error    duplication of key "key1" in mapping  (key-duplicates)


$ cat test2.yaml
---
field1:
  - key1: val1
  - key2: val2
  - key1: val1

$ yamllint test2.yaml

$ /bin/python3 -m pip show yamllint
Name: yamllint
Version: 1.23.0
Summary: A linter for YAML files.
Home-page: https://github.com/adrienverge/yamllint
Author: Adrien Vergé
Author-email: None
License: GPLv3
Location: /usr/lib/python3.6/site-packages
Requires: pathspec, pyyaml
Required-by:

rockerdaddy avatar Jun 01 '20 18:06 rockerdaddy

Hello,

This is totally expected: your second example would translate as:

{
  "field1": [
    {
      "key1": "val1"
    },
    {
      "key2": "val2"
    },
    {
      "key1": "val1"
    }
  ]
}

which does not cause any ambiguity nor value override, because each one of the mappings is indenpendent.

adrienverge avatar Jun 01 '20 19:06 adrienverge

Damn. No option for it? This is the exact thing I need to catch.

IProduceWidgets avatar Dec 10 '23 01:12 IProduceWidgets

Hello, this is not an issue and intended to work like that. There is no key duplication in the example test2.yaml.

adrienverge avatar Dec 10 '23 15:12 adrienverge