-
Notifications
You must be signed in to change notification settings - Fork 281
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
truthy rule: add check-keys
option
#247
Merged
adrienverge
merged 1 commit into
adrienverge:master
from
ilyam8:truthy_add_check_keys_option
Apr 8, 2020
Merged
truthy rule: add check-keys
option
#247
adrienverge
merged 1 commit into
adrienverge:master
from
ilyam8:truthy_add_check_keys_option
Apr 8, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adrienverge
force-pushed
the
truthy_add_check_keys_option
branch
from
April 8, 2020 10:22
e640389
to
3d0fd01
Compare
adrienverge
approved these changes
Apr 8, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution Илья!
I just changed a few bytes for the linter to pass.
--- a/yamllint/rules/truthy.py
+++ b/yamllint/rules/truthy.py
@@ -30,9 +30,9 @@ This can be useful to prevent surprises from YAML parsers transforming
``'False'``, ``'false'``, ``'YES'``, ``'Yes'``, ``'yes'``, ``'NO'``,
``'No'``, ``'no'``, ``'ON'``, ``'On'``, ``'on'``, ``'OFF'``, ``'Off'``,
``'off'``.
-
-* ``check-keys`` by default, truthy rule applies to both keys and values.
-To disable key verification set this option to ``'false'``.
+* ``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
@@ -136,9 +136,9 @@ def check(conf, token, prev, next, nextnext, context):
if prev and isinstance(prev, yaml.tokens.TagToken):
return
- if not conf['check-keys']:
- if isinstance(prev, yaml.tokens.KeyToken) and isinstance(token, yaml.tokens.ScalarToken):
- 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 (token.value in (set(TRUTHY) - set(conf['allowed-values'])) and
--- a/tests/rules/test_truthy.py
+++ b/tests/rules/test_truthy.py
@@ -121,11 +121,22 @@ class TruthyTestCase(RuleTestCase):
' check-keys: false\n'
'key-duplicates: disable\n')
self.check('---\n'
- 'YES: 0\nYes: 0\nyes: 0\n'
- 'No: 0\nNo: 0\nno: 0\n'
- 'TRUE: 0\nTrue: 0\ntrue: 0\n'
- 'FALSE: 0\nFalse: 0\nfalse: 0\n'
- 'ON: 0\nOn: 0\non: 0\n'
- 'OFF: 0\nOff: 0\noff: 0\n'
- 'YES:\n Yes:\n yes:\n on: 0\n',
+ 'YES: 0\n'
+ 'Yes: 0\n'
+ 'yes: 0\n'
+ 'No: 0\n'
+ 'No: 0\n'
+ 'no: 0\n'
+ 'TRUE: 0\n'
+ 'True: 0\n'
+ 'true: 0\n'
+ 'FALSE: 0\n'
+ 'False: 0\n'
+ 'false: 0\n'
+ 'ON: 0\n'
+ 'On: 0\n'
+ 'on: 0\n'
+ 'OFF: 0\n'
+ 'Off: 0\n'
+ 'off: 0\n',
conf)
😲 |
ilyam8
commented
Apr 8, 2020
adrienverge
added a commit
that referenced
this pull request
Apr 8, 2020
adrienverge
added a commit
that referenced
this pull request
Jan 31, 2024
Specification of YAML ≤ 1.1 has 18 boolean values: true | True | TRUE | false | False | FALSE yes | Yes | YES | no | No | NO on | On | ON | off | Off | OFF Whereas YAML 1.2 spec recognizes only 6: true | True | TRUE | false | False | FALSE For documents that explicit state their YAML spec version at the top of the document, let's adapt the list of forbidden values. In the future, we should: - implement a configuration option to declare the default YAML spec version, e.g. `default-yaml-spec-version: 1.2`, - consider making 1.2 the default in a future release (this would be a slight breaking change, but yamllint always tried to be 1.2-compatible). - consider adapting yamllint to other 1.1 vs. 1.2 differences [^2]. Solves: #587 Related to: #559 #540 #430 #344 #247 #232 #158 [^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution [^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
adrienverge
added a commit
that referenced
this pull request
Jan 31, 2024
Specification of YAML ≤ 1.1 has 18 boolean values: true | True | TRUE | false | False | FALSE yes | Yes | YES | no | No | NO on | On | ON | off | Off | OFF Whereas YAML 1.2 spec recognizes only 6 [^1]: true | True | TRUE | false | False | FALSE For documents that explicit state their YAML spec version at the top of the document, let's adapt the list of forbidden values. In the future, we should: - implement a configuration option to declare the default YAML spec version, e.g. `default-yaml-spec-version: 1.2`, - consider making 1.2 the default in a future release (this would be a slight breaking change, but yamllint always tried to be 1.2-compatible). - consider adapting yamllint to other 1.1 vs. 1.2 differences [^2]. Solves: #587 Related to: #559 #540 #430 #344 #247 #232 #158 [^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution [^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
adrienverge
added a commit
that referenced
this pull request
Feb 4, 2024
Specification of YAML ≤ 1.1 has 22 boolean values: y | Y | n | N yes | Yes | YES | no | No | NO true | True | TRUE | false | False | FALSE on | On | ON | off | Off | OFF Whereas YAML 1.2 spec recognizes only 6 [^1]: true | True | TRUE | false | False | FALSE For documents that explicit state their YAML spec version at the top of the document, let's adapt the list of forbidden values. In the future, we should: - implement a configuration option to declare the default YAML spec version, e.g. `default-yaml-spec-version: 1.2`, - consider making 1.2 the default in a future release (this would be a slight breaking change, but yamllint always tried to be 1.2-compatible). - consider adapting yamllint to other 1.1 vs. 1.2 differences [^2]. Solves: #587 Related to: #559 #540 #430 #344 #247 #232 #158 [^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution [^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
adrienverge
added a commit
that referenced
this pull request
Feb 6, 2024
Specification of YAML ≤ 1.1 has 22 boolean values: y | Y | n | N yes | Yes | YES | no | No | NO true | True | TRUE | false | False | FALSE on | On | ON | off | Off | OFF Whereas YAML 1.2 spec recognizes only 6 [^1]: true | True | TRUE | false | False | FALSE For documents that explicit state their YAML spec version at the top of the document, let's adapt the list of forbidden values. In the future, we should: - implement a configuration option to declare the default YAML spec version, e.g. `default-yaml-spec-version: 1.2`, - consider making 1.2 the default in a future release (this would be a slight breaking change, but yamllint always tried to be 1.2-compatible). - consider adapting yamllint to other 1.1 vs. 1.2 differences [^2]. Solves: #587 Related to: #559 #540 #430 #344 #247 #232 #158 [^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution [^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
adrienverge
added a commit
that referenced
this pull request
Feb 6, 2024
Specification of YAML ≤ 1.1 has 22 boolean values: y | Y | n | N yes | Yes | YES | no | No | NO true | True | TRUE | false | False | FALSE on | On | ON | off | Off | OFF Whereas YAML 1.2 spec recognizes only 6 [^1]: true | True | TRUE | false | False | FALSE For documents that explicit state their YAML spec version at the top of the document, let's adapt the list of forbidden values. In the future, we should: - implement a configuration option to declare the default YAML spec version, e.g. `default-yaml-spec-version: 1.2`, - consider making 1.2 the default in a future release (this would be a slight breaking change, but yamllint always tried to be 1.2-compatible). - consider adapting yamllint to other 1.1 vs. 1.2 differences [^2]. Solves: #587 Related to: #559 #540 #430 #344 #247 #232 #158 [^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution [^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #158
This PR adds
check-keys
option to the truthy rule.If
check-keys
option is disabled the rule applies only to the values. Default is enabled.