New D210 check for white spaces. #95

Merged
merged 2 commits into from Jan 19, 2015

Projects

None yet

2 participants

@jirikuncar
Contributor

This is a proposal for checking whitespaces in docstrings.

  • number
  • error message
@Nurdok
Member
Nurdok commented Jan 13, 2015

First of all, thank you so much for investing in this. It's greatly appreciated.

I'm currently on my phone, so I only skimmed the changes, but I have a few issues:

  • Why did you choose the D290 error code? Always use the next available one in the appropriate category.
  • The check name should be more specific. The entire D2xx category is about whitespace issues, so it's not enough to call it that.
@Nurdok
Member
Nurdok commented Jan 13, 2015

You should also update the README file with the new error.

@jirikuncar
Contributor
  • number

Why did you choose the D290 error code? Always use the next available one in the appropriate category.

I'm not sure about the number and error message. Do you have any proposal?

@jirikuncar
Contributor

@Nurdok based on README, I've changed the error code to 210. Is it ok?

@jirikuncar jirikuncar changed the title from New D290 check for white spaces. to New D210 check for white spaces. Jan 13, 2015
@Nurdok
Member
Nurdok commented Jan 17, 2015

D210 is okay, but please also address my other comments.

@jirikuncar
Contributor

Can you please provide the message?

@Nurdok Nurdok commented on an outdated diff Jan 17, 2015
@@ -778,6 +778,17 @@ def check_newline_after_last_paragraph(self, definition, docstring):
'quotes on separate line')
@check_for(Definition)
+ def check_whitespaces(self, definition, docstring):
+ """D210: White spaces around doctring should be trimmed."""
+ if docstring:
+ lines = eval(docstring).split('\n')
+ if lines[0].startswith(' ') or \
+ len(lines) == 1 and lines[0].endswith(' '):
+ return Error(
@Nurdok
Nurdok Jan 17, 2015 Member

Put the line break in the string.

return Error('D210: White spaces around docstring should '
             'be trimmed.')
@Nurdok Nurdok commented on an outdated diff Jan 17, 2015
test_pep257.py
@@ -76,7 +76,8 @@ def test_ignore_list():
no blank line after one-liner is bad. Also this - \"\"\"
return foo
"""
- expected_error_codes = set(('D100', 'D400', 'D401', 'D205', 'D209'))
+ expected_error_codes = set((
+ 'D100', 'D400', 'D401', 'D205', 'D209', 'D210'))
@Nurdok
Nurdok Jan 17, 2015 Member

Break the line as part of the list:

expected_error_codes = set(('D100', 'D400', 'D401', 'D205', 'D209',
                            'D210'))
@Nurdok Nurdok commented on an outdated diff Jan 17, 2015
@@ -778,6 +778,17 @@ def check_newline_after_last_paragraph(self, definition, docstring):
'quotes on separate line')
@check_for(Definition)
+ def check_whitespaces(self, definition, docstring):
@Nurdok
Nurdok Jan 17, 2015 Member

Give the check a more specific name, like check_surrounding_whitespaces.

@Nurdok Nurdok commented on an outdated diff Jan 17, 2015
@@ -778,6 +778,17 @@ def check_newline_after_last_paragraph(self, definition, docstring):
'quotes on separate line')
@check_for(Definition)
+ def check_whitespaces(self, definition, docstring):
+ """D210: White spaces around doctring should be trimmed."""
@Nurdok
Nurdok Jan 17, 2015 Member

Change the message to "D210: No whitespaces allowed surrounding docstring text."

@jirikuncar
Contributor

@Nurdok thanks for your comments and time. :shipit:

@Nurdok Nurdok and 1 other commented on an outdated diff Jan 19, 2015
@@ -778,6 +778,16 @@ def check_newline_after_last_paragraph(self, definition, docstring):
'quotes on separate line')
@check_for(Definition)
+ def check_surrounding_whitespaces(self, definition, docstring):
+ """D210: White spaces around doctring should be trimmed."""
@Nurdok
Nurdok Jan 19, 2015 Member

You should update the error message here as well (you updated only the README) and in the tests.

@jirikuncar
jirikuncar Jan 19, 2015 Contributor

Ups. Sorry about it :(

@Nurdok
Member
Nurdok commented Jan 19, 2015

I left one more comment in the actual code - but notice that the build is now failing on your branch. Make sure your tests pass.

@jirikuncar
Contributor

@Nurdok please note that I've also added sudo: false to .travis.yml in order to use container based infrastructure (see http://docs.travis-ci.com/user/workers/container-based-infrastructure/).

@Nurdok Nurdok and 1 other commented on an outdated diff Jan 19, 2015
@@ -778,6 +778,16 @@ def check_newline_after_last_paragraph(self, definition, docstring):
'quotes on separate line')
@check_for(Definition)
+ def check_surrounding_whitespaces(self, definition, docstring):
+ """D210: No whitespaces allowed surrounding docstring text."""
+ if docstring:
+ lines = eval(docstring).split('\n')
+ if lines[0].startswith(' ') or \
+ len(lines) == 1 and lines[0].endswith(' '):
+ return Error("D210: No whitespaces allowed "
@Nurdok
Nurdok Jan 19, 2015 Member

This indentation looks wrong.

@jirikuncar
jirikuncar Jan 19, 2015 Contributor

Aaaah, broken :autoindent :(

jirikuncar added some commits Jan 12, 2015
@jirikuncar jirikuncar New D210 check for surrounding whitespaces.
Signed-off-by: Jiri Kuncar <jiri.kuncar@cern.ch>
Reviewed-by: Amir Rachum <nurdok@gmail.com>
5e9db04
@jirikuncar jirikuncar Travis: usage of container-based infrastructure
Signed-off-by: Jiri Kuncar <jiri.kuncar@cern.ch>
dcd60de
@jirikuncar
Contributor

@Nurdok sorry for so many iterations. Please let me know when you release it on PyPI so I can remove it from my package https://github.com/jirikuncar/invenio-kwalitee/blob/master/invenio_kwalitee/kwalitee.py#L82-L93. Thanks

@Nurdok Nurdok merged commit 8307b73 into PyCQA:master Jan 19, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@Nurdok
Member
Nurdok commented Jan 19, 2015

@jirikuncar Merged. It will probably take a few weeks before I make another release. In any case, thank you so much for investing the time and effort into this. I really can't thank you enough!

@jirikuncar jirikuncar deleted the jirikuncar:D290-whitespaces branch Jan 19, 2015
@Nurdok Nurdok modified the milestone: Next Release Mar 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment