adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.9k stars 278 forks source link

Need rules for restricting key types #607

Closed HenryGessau closed 1 year ago

HenryGessau commented 1 year ago

We need rules for restricting the types that can be used for keys in key: value maps.

Node kinds

According to the YAML spec, nodes can be one of three kinds:

I would like to have a rule that specifies that a key node must not be a sequence or a mapping.

Scalar types

I would like to also have a rule that can control which type of scalar can be used for keys. The scalar types to consider are:

For example, JSON only supports string keys, so if I am converting YAML to JSON I want to check that all keys are strings.

adrienverge commented 1 year ago

Hello and thanks for this clear proposal and neat pull request at https://github.com/adrienverge/yamllint/pull/608!

But the goal of yamllint is to lint the form of YAML, not the content or its structure. We could imagine many new rules to check the type of keys (what you propose), or the type of values, or that all strings contain a substring, or that all keys match a regex, etc. But the purpose of yamllint is to be focused on YAML itself, so I'm not favorable to adding such new content-oriented rules.

About your use-case, I suggest trying to convert to JSON and see whether it works (like you explain at the end), or write or very simple script.

HenryGessau commented 1 year ago

Thanks for the clarification of the goal of yamllint.