adrienverge / yamllint

A linter for YAML files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need rules for restricting key types

HenryGessau opened this issue · comments

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:

  • scalar
  • sequence
  • mapping

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:

  • str
  • int
  • float
  • bool
  • null
  • timestamp

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

Hello and thanks for this clear proposal and neat pull request at #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.

Thanks for the clarification of the goal of yamllint.