-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block specific, error prone, yaml key names #694
Comments
Hello Avner, Indeed, although confusing in most contexts, this code is valid YAML! Yamllint doesn't currently provide a way to forbid specific types of keys. rules:
key-types:
# types from https://perlpunk.github.io/YAML-PP-p5/schemas.html
forbid-null: true|false # tag:[yaml.org](http://yaml.org/),2002:null
forbid-bool: true|false # tag:[yaml.org](http://yaml.org/),2002:bool
forbid-int: true|false # tag:[yaml.org](http://yaml.org/),2002:int
forbid-float: true|false # tag:[yaml.org](http://yaml.org/),2002:float
forbid-str: true|false # tag:[yaml.org](http://yaml.org/),2002:str |
This would be amazing! rules:
key-types:
forbid-as-key-null: true|false
etc.. But this is cosmetic, and I suspect you know what you are doing :) Would be amazing to see something like that implemented. Also, important to consider case here (Null, None, null, NULL etc). |
I'm not sure, because this rule would be about forbidding the use of specific types (null, boolean, integers, for instance values
I think in YAML 1.2 only the following values are null:
Contributions are welcome :) |
Thanks @adrienverge So, to be sure I get your suggestion here: dict_of_values:
null: 'value' In the above example, if I get this right, "null" is used as "Key" in the So I think I am asking about how to block "keys" with certain and specific "string values" that might be ok in YAML, but as soon as you are being "parsed" by python/javascript/etc the name chosen might cause issues down the line.. |
Hello Avner, I'm not sure I get you right, maybe there's a misunderstanding about the type of In your example YAML snippet, # Example 1: null value
dict_of_values:
null: 'value'
# Example 2: string value, with value "null"
dict_of_values:
'null': 'value' Unlike JSON, using the If your proposal is to create a rule to avoid the use of However if it's about forbidding specific key names (= string values like |
Thanks @adrienverge thanks for sticking with me on this :) I imagine this is a combination of my language barrier (yaml) and my language barrier (not native english).. But I feel we are making progress :) We are aligned on the goal here, it's on "null value" case. To illustrate the issue I am seeing: >>> import yaml
>>> yaml_string = """
... dict_of_values:
... null: 'value'
... """
>>> yaml.safe_load(yaml_string)
{'dict_of_values': {None: 'value'}}
>>> The resulting "None" is going to cause issues down the road and also creates interoperability issues because here is how it looks in a Javascript Yaml parser: {
"dict_of_values": {
"null": "value"
}
} Going back to your original suggestion:
Are you able to provide any pointers on how to progress this with a contribution ? |
Agreed 👍 then we're talking about the same thing 🙂
I suggest checking out CONTRIBUTING.rst first, then for a good start you can look at the code of other rules, in particular read some commits that introduced new rules into yamllint (you'll see they must come with tests and documentation). Good luck! |
@adrienverge Please see the initial suggested direction at #695 |
This "null" is valid, but will fail in many cases, depends on the programming language reading this yaml.
Is there any yamllint rule I could use to protect such "error prone key names" ? (I can think of none, false and true as additional candidates)
The text was updated successfully, but these errors were encountered: