|
|
@ -30,6 +30,9 @@ This can be useful to prevent surprises from YAML parsers transforming
|
|
|
|
``'False'``, ``'false'``, ``'YES'``, ``'Yes'``, ``'yes'``, ``'NO'``,
|
|
|
|
``'False'``, ``'false'``, ``'YES'``, ``'Yes'``, ``'yes'``, ``'NO'``,
|
|
|
|
``'No'``, ``'no'``, ``'ON'``, ``'On'``, ``'on'``, ``'OFF'``, ``'Off'``,
|
|
|
|
``'No'``, ``'no'``, ``'ON'``, ``'On'``, ``'on'``, ``'OFF'``, ``'Off'``,
|
|
|
|
``'off'``.
|
|
|
|
``'off'``.
|
|
|
|
|
|
|
|
* ``check-keys`` disables verification for keys in mappings. By default,
|
|
|
|
|
|
|
|
``truthy`` rule applies to both keys and values. Set this option to ``false``
|
|
|
|
|
|
|
|
to prevent this.
|
|
|
|
|
|
|
|
|
|
|
|
.. rubric:: Examples
|
|
|
|
.. rubric:: Examples
|
|
|
|
|
|
|
|
|
|
|
@ -92,6 +95,22 @@ This can be useful to prevent surprises from YAML parsers transforming
|
|
|
|
- false
|
|
|
|
- false
|
|
|
|
- on
|
|
|
|
- on
|
|
|
|
- off
|
|
|
|
- off
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#. With ``truthy: {check-keys: false}``
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
the following code snippet would **PASS**:
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yes: 1
|
|
|
|
|
|
|
|
on: 2
|
|
|
|
|
|
|
|
true: 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
the following code snippet would **FAIL**:
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yes: Yes
|
|
|
|
|
|
|
|
on: On
|
|
|
|
|
|
|
|
true: True
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
import yaml
|
|
|
@ -109,14 +128,18 @@ TRUTHY = ['YES', 'Yes', 'yes',
|
|
|
|
|
|
|
|
|
|
|
|
ID = 'truthy'
|
|
|
|
ID = 'truthy'
|
|
|
|
TYPE = 'token'
|
|
|
|
TYPE = 'token'
|
|
|
|
CONF = {'allowed-values': list(TRUTHY)}
|
|
|
|
CONF = {'allowed-values': list(TRUTHY), 'check-keys': bool}
|
|
|
|
DEFAULT = {'allowed-values': ['true', 'false']}
|
|
|
|
DEFAULT = {'allowed-values': ['true', 'false'], 'check-keys': True}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check(conf, token, prev, next, nextnext, context):
|
|
|
|
def check(conf, token, prev, next, nextnext, context):
|
|
|
|
if prev and isinstance(prev, yaml.tokens.TagToken):
|
|
|
|
if prev and isinstance(prev, yaml.tokens.TagToken):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (not conf['check-keys'] and isinstance(prev, yaml.tokens.KeyToken) and
|
|
|
|
|
|
|
|
isinstance(token, yaml.tokens.ScalarToken)):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(token, yaml.tokens.ScalarToken):
|
|
|
|
if isinstance(token, yaml.tokens.ScalarToken):
|
|
|
|
if (token.value in (set(TRUTHY) - set(conf['allowed-values'])) and
|
|
|
|
if (token.value in (set(TRUTHY) - set(conf['allowed-values'])) and
|
|
|
|
token.style is None):
|
|
|
|
token.style is None):
|
|
|
|