-
Notifications
You must be signed in to change notification settings - Fork 278
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
Add rule: truthy, to forbid truthy values that are not quoted. #22
Conversation
1 similar comment
@@ -279,7 +279,7 @@ def test_run_non_ascii_file(self): | |||
# Make sure the default localization conditions on this "system" | |||
# support UTF-8 encoding. | |||
loc = locale.getlocale() | |||
locale.setlocale(locale.LC_ALL, 'C.UTF-8') | |||
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') |
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.
C.UTF-8
didn't work for me on OS X...
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.
Please don't include this is this pull-request, we can do another one if needed.
(By the way en_US.UTF-8
isn't supposed to be present on non-English-speaking systems, and I know it isn't on Debian build system.)
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.
I have reverted this change, I can run the tests in docker so all good
docker run -v $PWD:/mnt -w /mnt python:2.7 python setup.py test
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.
This looks good, thanks @pdericson!
I just have a few remarks.
@@ -279,7 +279,7 @@ def test_run_non_ascii_file(self): | |||
# Make sure the default localization conditions on this "system" | |||
# support UTF-8 encoding. | |||
loc = locale.getlocale() | |||
locale.setlocale(locale.LC_ALL, 'C.UTF-8') | |||
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') |
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.
Please don't include this is this pull-request, we can do another one if needed.
(By the way en_US.UTF-8
isn't supposed to be present on non-English-speaking systems, and I know it isn't on Debian build system.)
@@ -26,3 +26,5 @@ rules: | |||
line-length: | |||
level: warning | |||
allow-non-breakable-inline-mappings: yes | |||
truthy: | |||
level: warning |
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.
I'd rather have it disabled in relaxed
conf. I know a bunch of people that are really attached to their yes
/no
in Ansible...
@@ -0,0 +1,33 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright (C) 2016 Adrien Vergé |
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.
Hey! I didn't write this. ;)
@@ -0,0 +1,56 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright (C) 2016 Adrien Vergé |
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.
Please put your name here :)
@@ -119,6 +120,9 @@ class SpecificationTestCase(RuleTestCase): | |||
'example-8.22': ('indentation: disable\n'), | |||
'example-10.1': ('colons: {max-spaces-before: 2}\n'), | |||
'example-10.2': ('indentation: {indent-sequences: no}\n'), | |||
'example-10.5': ('truthy: disable\n'), |
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.
Why this one?
@@ -65,6 +65,7 @@ class SpecificationTestCase(RuleTestCase): | |||
'example-2.16': ('empty-lines: {max-end: 1}\n'), | |||
'example-2.18': ('empty-lines: {max-end: 1}\n'), | |||
'example-2.19': ('empty-lines: {max-end: 1}\n'), | |||
'example-2.21': ('truthy: disable\n'), |
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.
Why this one?
if isinstance(token, yaml.tokens.ScalarToken): | ||
if token.value in TRUTHY and token.style is None: | ||
yield LintProblem(token.start_mark.line + 1, | ||
max(1, token.start_mark.column), |
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.
This should be token.start_mark.column + 1
. And why max()
?
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.
I copied this from commas.py, I can see why it's invalid now :)
self.check('---\n1: True\n', conf, problem=(2, 3)) | ||
self.check('---\nTrue: 1\n', conf, problem=(2, 1)) | ||
self.check('---\n1: "True"\n', conf) | ||
self.check('---\n"True": 1\n', conf) |
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.
Could you add this?
self.check('---\n'
'!!seq [\n'
' !!bool true, !!bool false,\n'
' !!bool "false", !!bool "FALSE",\n'
' !!bool "true", !!bool "True",\n'
' !!bool "false", !!bool "FALSE",\n'
']\n', conf)
self.check('---\n'
'!!seq [\n'
' !!bool true, !!bool True,\n'
']\n', conf, problem=(3, 23))
That's better, thanks! Have you got a chance to consider my other remarks? (the extra tests with |
']\n', conf) | ||
self.check('---\n' | ||
'!!seq [\n' | ||
' !!bool true, !!bool True,\n' |
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.
@adrienverge I'm wondering if !!bool True
should be allowed by the truthy rule. I haven't figured out yet if the explicit tag type is available to inspect or is lost during parsing by pyyaml...
Sorry, my session ended abruptly yesterday, I was addressing feedback during my commute |
@pdericson this is great, thanks for your contribution! |
just a quick heads up that the version of |
@ghiculescu Are you using Debian? Ubuntu? @debalance is kindly maintaining packages for Debian, which means new versions should also end up in next Ubuntu versions. For really up-to-date versions, we would need an Ubuntu maintainer (help wanted!) |
No description provided.