Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 8307b73

Browse files
committed
Merge pull request #95 from jirikuncar/D290-whitespaces
New D210 check for white spaces.
2 parents 56ebdb3 + dcd60de commit 8307b73

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Travis to install and run "tox" test runner, which is
44
# configured in tox.ini file.
55

6+
sudo: false
67
language: python
78
install: pip install tox --use-mirrors
89
script: tox

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ are grouped as follows:
114114
+--------------+--------------------------------------------------------------+
115115
| D209 | Put multi-line docstring closing quotes on separate line. |
116116
+--------------+--------------------------------------------------------------+
117+
| D210 | No whitespaces allowed surrounding docstring text. |
118+
+--------------+--------------------------------------------------------------+
117119
| **Quotes issues** |
118120
+--------------+--------------------------------------------------------------+
119121
| D300 | Use """triple double quotes""". |

pep257.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,16 @@ def check_newline_after_last_paragraph(self, definition, docstring):
777777
return Error('D209: Put multi-line docstring closing '
778778
'quotes on separate line')
779779

780+
@check_for(Definition)
781+
def check_surrounding_whitespaces(self, definition, docstring):
782+
"""D210: No whitespaces allowed surrounding docstring text."""
783+
if docstring:
784+
lines = eval(docstring).split('\n')
785+
if lines[0].startswith(' ') or \
786+
len(lines) == 1 and lines[0].endswith(' '):
787+
return Error("D210: No whitespaces allowed surrounding "
788+
"docstring text.")
789+
780790
@check_for(Definition)
781791
def check_triple_double_quotes(self, definition, docstring):
782792
r'''D300: Use """triple double quotes""".

test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ def asdfljdf24():
165165
Description."""
166166

167167

168+
@expect('D210: No whitespaces allowed surrounding docstring text.')
169+
def endswith():
170+
"""Whitespace at the end. """
171+
172+
173+
@expect('D210: No whitespaces allowed surrounding docstring text.')
174+
def around():
175+
""" Whitespace at everywhere. """
176+
177+
178+
@expect('D210: No whitespaces allowed surrounding docstring text.')
179+
def multiline():
180+
""" Whitespace at the begining.
181+
182+
This is the end.
183+
"""
184+
185+
168186
@expect('D300: Expected """-quotes, got \'\'\'-quotes')
169187
def lsfklkjllkjl():
170188
r'''Summary.'''

test_pep257.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
"""Use tox or py.test to run the test-suite."""
21
# -*- coding: utf-8 -*-
2+
3+
"""Use tox or py.test to run the test-suite."""
4+
35
from __future__ import with_statement
46

57
import os
@@ -76,7 +78,8 @@ def test_ignore_list():
7678
no blank line after one-liner is bad. Also this - \"\"\"
7779
return foo
7880
"""
79-
expected_error_codes = set(('D100', 'D400', 'D401', 'D205', 'D209'))
81+
expected_error_codes = set(('D100', 'D400', 'D401', 'D205', 'D209',
82+
'D210'))
8083
mock_open = mock.mock_open(read_data=function_to_check)
8184
with mock.patch('pep257.open', mock_open, create=True):
8285
errors = tuple(pep257.check(['filepath']))

0 commit comments

Comments
 (0)