Optional extended detection in key-duplicates
fenuks opened this issue · 3 comments
Let's say I have this yaml document.
logging.level.root: DEBUG
logging.level.org.springframework: INFO
logging:
level:
root: DEBUG
org.springframework: INFO
In generated JSON
{
"logging.level.root": "DEBUG",
"logging.level.org.springframework": "INFO",
"logging": {
"level": {
"root": "DEBUG",
"org.springframework": "INFO"
}
}
}
no key is duplicated.
However, some programs, e.g. spring-based allow user to use second form so common prefix is written only once. Logically these are duplicates, so I wonder if key-duplicates
rule could have option to enable detection of this, or this is too specific?
Hello,
Thank you, this is very clear.
But just as you suspected, this is too specific.
Yamllint handles pure YAML, and logging.level.org.springframework: INFO
is different from logging: {level: {org.springframework: INFO}}
(by the way, it would be hard to know if we should read org.springframework: …
or org: {springframework: …}
)
I understand, thank you. I guess I will try to detect this with yq and some shell scripting.
by the way, it would be hard to know if we should read
org.springframework: …
ororg: {springframework: …}
)
To my understanding, the latter. Keys are always split on dots. Alternatively, dictionary keys could be joined to get flattened dot-delimited key, and then it's easy to check if there are duplicates.
For anybody wanting perform such check, this is how it can be achieved with a shell one-liner:
yq -r 'tostream | select(length==2) | (.[0] | join(".")) as $k | .[1] as $v | "\($k)"' file.yml | sort | uniq --repeated --count