Skip to content

Commit f4f6e55

Browse files
authored
Merge pull request #674 from brianv0/docstring_support
Support for W505 - doc line length
2 parents 11ba4cc + 6ef3190 commit f4f6e55

File tree

10 files changed

+280
-186
lines changed

10 files changed

+280
-186
lines changed

docs/intro.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Quick help is available on the command line::
157157
--count print total number of errors and warnings to standard
158158
error and set exit code to 1 if total is not null
159159
--max-line-length=n set maximum allowed line length (default: 79)
160+
--max-doc-length=n set maximum allowed doc line length and perform these
161+
checks (unchecked if not set)
160162
--hang-closing hang closing bracket instead of matching indentation of
161163
opening bracket's line
162164
--format=format set the error format [default|pylint|<custom>]
@@ -169,9 +171,9 @@ Quick help is available on the command line::
169171
Configuration:
170172
The project options are read from the [pycodestyle] section of the
171173
tox.ini file or the setup.cfg file located in any parent folder of the
172-
path(s) being processed. Allowed options are: exclude, filename, select,
173-
ignore, max-line-length, hang-closing, count, format, quiet, show-pep8,
174-
show-source, statistics, verbose.
174+
path(s) being processed. Allowed options are: exclude, filename,
175+
select, ignore, max-line-length, max-doc-length, hang-closing, count,
176+
format, quiet, show-pep8, show-source, statistics, verbose.
175177

176178
--config=path user config file location
177179
(default: ~/.config/pycodestyle)
@@ -406,6 +408,8 @@ This is the current list of error and warning codes:
406408
+------------+----------------------------------------------------------------------+
407409
| W504 (*)   | line break after binary operator                         |
408410
+------------+----------------------------------------------------------------------+
411+
| W505 (\*^) | doc line too long (82 > 79 characters) |
412+
+------------+----------------------------------------------------------------------+
409413
+------------+----------------------------------------------------------------------+
410414
| **W6** | *Deprecation warning* |
411415
+------------+----------------------------------------------------------------------+
@@ -423,14 +427,15 @@ This is the current list of error and warning codes:
423427
+------------+----------------------------------------------------------------------+
424428

425429

426-
**(*)** In the default configuration, the checks **E121**, **E123**, **E126**,
427-
**E133**, **E226**, **E241**, **E242**, **E704**, **W503** and **W504** are ignored
430+
**(*)** In the default configuration, the checks **E121**, **E123**, **E126**, **E133**,
431+
**E226**, **E241**, **E242**, **E704**, **W503**, **W504** and **W505** are ignored
428432
because they are not rules unanimously accepted, and `PEP 8`_ does not enforce them.
429433
Please note that if the option **--ignore=errors** is used,
430434
the default configuration will be overridden and ignore only the check(s) you skip.
431435
The check **W503** is mutually exclusive with check **W504**.
432436
The check **E133** is mutually exclusive with check **E123**. Use switch
433-
``--hang-closing`` to report **E133** instead of **E123**.
437+
``--hang-closing`` to report **E133** instead of **E123**. Use switch
438+
``--max-doc-length=n`` to report **W505**.
434439

435440
**(^)** These checks can be disabled at the line level using the ``# noqa``
436441
special comment. This possibility should be reserved for special cases.

pycodestyle.py

Lines changed: 193 additions & 114 deletions
Large diffs are not rendered by default.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ license_file = LICENSE
88
select =
99
ignore = E226,E24,W504
1010
max_line_length = 79
11+
max_doc_length = 72

testsuite/E26.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def oof():
5050
#foo not parsed
5151
"""
5252

53-
###########################################################################
54-
# A SEPARATOR #
55-
###########################################################################
53+
####################################################################
54+
# A SEPARATOR #
55+
####################################################################
5656

57-
# ####################################################################### #
58-
# ########################## another separator ########################## #
59-
# ####################################################################### #
57+
# ################################################################ #
58+
# ####################### another separator ###################### #
59+
# ################################################################ #

testsuite/E50.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,27 @@
6262
#: E501 E225 E226
6363
very_long_identifiers=and_terrible_whitespace_habits(are_no_excuse+for_long_lines)
6464
#
65-
#: E501
65+
#: E501 W505
6666
'''multiline string
6767
with a long long long long long long long long long long long long long long long long line
6868
'''
69-
#: E501
69+
#: E501 W505
7070
'''same thing, but this time without a terminal newline in the string
7171
long long long long long long long long long long long long long long long long line'''
7272
#
7373
# issue 224 (unavoidable long lines in docstrings)
7474
#: Okay
7575
"""
7676
I'm some great documentation. Because I'm some great documentation, I'm
77-
going to give you a reference to some valuable information about some API
78-
that I'm calling:
77+
going to give you a reference to some valuable information about some
78+
API that I'm calling:
7979
8080
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
8181
"""
82-
#: E501
82+
#: E501 W505
8383
"""
8484
longnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaceslongnospaces"""
85-
#: E501
85+
#: E501 W505
8686
# Regression test for #622
8787
def foo():
8888
"""Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pulvinar vitae
@@ -92,19 +92,20 @@ def foo():
9292
This
9393
almost_empty_line
9494
"""
95-
#: E501
95+
#: E501 W505
9696
"""
9797
This
9898
almost_empty_line
9999
"""
100-
#: E501
100+
#: E501 W505
101101
# A basic comment
102102
# with a long long long long long long long long long long long long long long long long line
103103

104104
#
105105
#: Okay
106106
# I'm some great comment. Because I'm so great, I'm going to give you a
107-
# reference to some valuable information about some API that I'm calling:
107+
# reference to some valuable information about some API that I'm
108+
# calling:
108109
#
109110
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
110111

@@ -118,7 +119,7 @@ def foo():
118119
# almost_empty_line
119120

120121
#
121-
#: E501
122+
#: E501 W505
122123
# This
123124
# almost_empty_line
124125

testsuite/support.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ def init_tests(pep8style):
151151
152152
A test file can provide many tests. Each test starts with a
153153
declaration. This declaration is a single line starting with '#:'.
154-
It declares codes of expected failures, separated by spaces or 'Okay'
155-
if no failure is expected.
154+
It declares codes of expected failures, separated by spaces or
155+
'Okay' if no failure is expected.
156156
If the file does not contain such declaration, it should pass all
157-
tests. If the declaration is empty, following lines are not checked,
158-
until next declaration.
157+
tests. If the declaration is empty, following lines are not
158+
checked, until next declaration.
159159
160160
Examples:
161161

testsuite/test_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ def parse_argv(argstring):
209209
self.assertEqual(options.select, ('E24',))
210210
self.assertEqual(options.ignore, ('',))
211211

212+
options = parse_argv('--max-doc-length=72').options
213+
self.assertEqual(options.max_doc_length, 72)
214+
215+
options = parse_argv('').options
216+
self.assertEqual(options.max_doc_length, None)
217+
212218
pep8style = pycodestyle.StyleGuide(paths=[E11])
213219
self.assertFalse(pep8style.ignore_code('E112'))
214220
self.assertFalse(pep8style.ignore_code('W191'))

testsuite/test_blank_lines.py

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def assertNoErrors(self, actual):
3535

3636
class TestBlankLinesDefault(BlankLinesTestCase):
3737
"""
38-
Tests for default blank with 2 blank lines for top level and 1 blank line
39-
for methods.
38+
Tests for default blank with 2 blank lines for top level and 1
39+
blank line for methods.
4040
"""
4141

4242
def test_initial_no_blank(self):
@@ -51,8 +51,8 @@ def test_initial_no_blank(self):
5151

5252
def test_initial_lines_one_blank(self):
5353
"""
54-
It will accept 1 blank lines before the first line of actual code,
55-
even if in other places it asks for 2
54+
It will accept 1 blank lines before the first line of actual
55+
code, even if in other places it asks for 2
5656
"""
5757
result = self.check("""
5858
def some_function():
@@ -63,8 +63,8 @@ def some_function():
6363

6464
def test_initial_lines_two_blanks(self):
6565
"""
66-
It will accept 2 blank lines before the first line of actual code,
67-
as normal.
66+
It will accept 2 blank lines before the first line of actual
67+
code, as normal.
6868
"""
6969
result = self.check("""
7070
@@ -76,8 +76,8 @@ def some_function():
7676

7777
def test_method_less_blank_lines(self):
7878
"""
79-
It will trigger an error when less than 1 blank lin is found before
80-
method definitions.
79+
It will trigger an error when less than 1 blank lin is found
80+
before method definitions.
8181
"""
8282
result = self.check("""# First comment line.
8383
class X:
@@ -93,8 +93,8 @@ def b():
9393

9494
def test_method_less_blank_lines_comment(self):
9595
"""
96-
It will trigger an error when less than 1 blank lin is found before
97-
method definition, ignoring comments.
96+
It will trigger an error when less than 1 blank lin is found
97+
before method definition, ignoring comments.
9898
"""
9999
result = self.check("""# First comment line.
100100
class X:
@@ -111,8 +111,8 @@ def b():
111111

112112
def test_top_level_fewer_blank_lines(self):
113113
"""
114-
It will trigger an error when less 2 blank lines are found before top
115-
level definitions.
114+
It will trigger an error when less 2 blank lines are found
115+
before top level definitions.
116116
"""
117117
result = self.check("""# First comment line.
118118
# Second line of comment.
@@ -146,8 +146,8 @@ class AFarEnoughClass(object):
146146

147147
def test_top_level_more_blank_lines(self):
148148
"""
149-
It will trigger an error when more 2 blank lines are found before top
150-
level definitions.
149+
It will trigger an error when more 2 blank lines are found
150+
before top level definitions.
151151
"""
152152
result = self.check("""# First comment line.
153153
# Second line of comment.
@@ -177,8 +177,8 @@ class AFarEnoughClass(object):
177177

178178
def test_method_more_blank_lines(self):
179179
"""
180-
It will trigger an error when more than 1 blank line is found before
181-
method definition
180+
It will trigger an error when more than 1 blank line is found
181+
before method definition
182182
"""
183183
result = self.check("""# First comment line.
184184
@@ -209,8 +209,8 @@ def veryFar(self):
209209

210210
def test_initial_lines_more_blank(self):
211211
"""
212-
It will trigger an error for more than 2 blank lines before the first
213-
line of actual code.
212+
It will trigger an error for more than 2 blank lines before the
213+
first line of actual code.
214214
"""
215215
result = self.check("""
216216
@@ -222,8 +222,8 @@ def some_function():
222222

223223
def test_blank_line_between_decorator(self):
224224
"""
225-
It will trigger an error when the decorator is followed by a blank
226-
line.
225+
It will trigger an error when the decorator is followed by a
226+
blank line.
227227
"""
228228
result = self.check("""# First line.
229229
@@ -245,8 +245,8 @@ def some_method(self):
245245

246246
def test_blank_line_decorator(self):
247247
"""
248-
It will accept the decorators which are adjacent to the function and
249-
method definition.
248+
It will accept the decorators which are adjacent to the function
249+
and method definition.
250250
"""
251251
result = self.check("""# First line.
252252
@@ -340,7 +340,8 @@ def b():
340340
def test_method_nested_fewer_follow_lines(self):
341341
"""
342342
It will trigger an error when less than 1 blank line is
343-
found between a method and previous definitions, even when nested.
343+
found between a method and previous definitions, even when
344+
nested.
344345
"""
345346
result = self.check("""
346347
def a():
@@ -374,7 +375,8 @@ class C:
374375
def test_method_nested_ok(self):
375376
"""
376377
Will not trigger an error when 1 blank line is found
377-
found between a method and previous definitions, even when nested.
378+
found between a method and previous definitions, even when
379+
nested.
378380
"""
379381
result = self.check("""
380382
def a():
@@ -394,8 +396,8 @@ class C:
394396

395397
class TestBlankLinesTwisted(BlankLinesTestCase):
396398
"""
397-
Tests for blank_lines with 3 blank lines for top level and 2 blank line
398-
for methods as used by the Twisted coding style.
399+
Tests for blank_lines with 3 blank lines for top level and 2 blank
400+
line for methods as used by the Twisted coding style.
399401
"""
400402

401403
def setUp(self):
@@ -408,8 +410,8 @@ def tearDown(self):
408410

409411
def test_initial_lines_one_blanks(self):
410412
"""
411-
It will accept less than 3 blank lines before the first line of actual
412-
code.
413+
It will accept less than 3 blank lines before the first line of
414+
actual code.
413415
"""
414416
result = self.check("""
415417
@@ -422,8 +424,8 @@ def some_function():
422424

423425
def test_initial_lines_tree_blanks(self):
424426
"""
425-
It will accept 3 blank lines before the first line of actual code,
426-
as normal.
427+
It will accept 3 blank lines before the first line of actual
428+
code, as normal.
427429
"""
428430
result = self.check("""
429431
@@ -436,8 +438,8 @@ def some_function():
436438

437439
def test_top_level_fewer_blank_lines(self):
438440
"""
439-
It will trigger an error when less 2 blank lines are found before top
440-
level definitions.
441+
It will trigger an error when less 2 blank lines are found
442+
before top level definitions.
441443
"""
442444
result = self.check("""# First comment line.
443445
# Second line of comment.
@@ -476,8 +478,8 @@ class AFarEnoughClass(object):
476478

477479
def test_top_level_more_blank_lines(self):
478480
"""
479-
It will trigger an error when more 2 blank lines are found before top
480-
level definitions.
481+
It will trigger an error when more 2 blank lines are found
482+
before top level definitions.
481483
"""
482484
result = self.check("""# First comment line.
483485
# Second line of comment.

0 commit comments

Comments
 (0)