Skip to content
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

Merged
merged 2 commits into from
Oct 1, 2016
Merged

Add rule: truthy, to forbid truthy values that are not quoted. #22

merged 2 commits into from
Oct 1, 2016

Conversation

pdericson
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Sep 28, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling 27f5470 on pdericson:truthy into c163135 on adrienverge:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling 27f5470 on pdericson:truthy into c163135 on adrienverge:master.

@@ -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')
Copy link
Contributor Author

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...

Copy link
Owner

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.)

Copy link
Contributor Author

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

Copy link
Owner

@adrienverge adrienverge left a 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')
Copy link
Owner

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
Copy link
Owner

@adrienverge adrienverge Sep 29, 2016

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é
Copy link
Owner

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é
Copy link
Owner

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'),
Copy link
Owner

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'),
Copy link
Owner

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),
Copy link
Owner

@adrienverge adrienverge Sep 29, 2016

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()?

Copy link
Contributor Author

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)
Copy link
Owner

@adrienverge adrienverge Sep 29, 2016

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))

@coveralls
Copy link

coveralls commented Sep 29, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling a643c85 on pdericson:truthy into c163135 on adrienverge:master.

@coveralls
Copy link

coveralls commented Sep 29, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling bc3ed94 on pdericson:truthy into c163135 on adrienverge:master.

@coveralls
Copy link

coveralls commented Sep 29, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling 1576338 on pdericson:truthy into c163135 on adrienverge:master.

@coveralls
Copy link

coveralls commented Sep 29, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling 843eec5 on pdericson:truthy into c163135 on adrienverge:master.

@adrienverge
Copy link
Owner

That's better, thanks!

Have you got a chance to consider my other remarks? (the extra tests with !!bool and the spec examples you disable -- I think two of them are working fine and shouldn't be disabled)

@coveralls
Copy link

coveralls commented Oct 1, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling 475d316 on pdericson:truthy into c163135 on adrienverge:master.

']\n', conf)
self.check('---\n'
'!!seq [\n'
' !!bool true, !!bool True,\n'
Copy link
Contributor Author

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...

@pdericson
Copy link
Contributor Author

Sorry, my session ended abruptly yesterday, I was addressing feedback during my commute

@coveralls
Copy link

coveralls commented Oct 1, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling f4c522d on pdericson:truthy into c163135 on adrienverge:master.

@coveralls
Copy link

coveralls commented Oct 1, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling 62fe116 on pdericson:truthy into c163135 on adrienverge:master.

@adrienverge
Copy link
Owner

@pdericson this is great, thanks for your contribution!

@adrienverge adrienverge merged commit ff27f88 into adrienverge:master Oct 1, 2016
@coveralls
Copy link

coveralls commented Oct 1, 2016

Coverage Status

Coverage increased (+0.02%) to 98.504% when pulling 5294ff5 on pdericson:truthy into c163135 on adrienverge:master.

@pdericson pdericson deleted the truthy branch October 3, 2016 21:47
@ghiculescu
Copy link

just a quick heads up that the version of yamllint that apt-get installs doesnt include this rule. the pip version does.

@adrienverge
Copy link
Owner

@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!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants