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

Commit ba92fe8

Browse files
committed
Merge pull request #135 from farmersez/exclude-all-errors
Supporting an empty list in the `--select=` option.
2 parents f3f90a4 + 729b48a commit ba92fe8

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

docs/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ New Features
1212
previously resulted in D100 errors ("Missing docstring in public module")
1313
will now result in D104 (#105, #127).
1414

15+
* Support the option to exclude all error codes. Running pep257 with
16+
`--select=` (or `select=` in the configuration file) will exclude all errors
17+
which could then be added one by one using `add-select`. Useful for projects
18+
new to pep257 (#132, #135).
19+
1520
Bug Fixes
1621

1722
* On Python 2.x, D302 ("Use u""" for Unicode docstrings") is not reported

src/pep257.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -692,15 +692,15 @@ def get_option_parser():
692692
help='show explanation of each error')
693693
option('-s', '--source', action='store_true',
694694
help='show source for each error')
695-
option('--select', metavar='<codes>', default='',
695+
option('--select', metavar='<codes>', default=None,
696696
help='choose the basic list of checked errors by specifying which '
697697
'errors to check for (with a list of comma-separated error '
698698
'codes). for example: --select=D101,D202')
699-
option('--ignore', metavar='<codes>', default='',
699+
option('--ignore', metavar='<codes>', default=None,
700700
help='choose the basic list of checked errors by specifying which '
701701
'errors to ignore (with a list of comma-separated error '
702702
'codes). for example: --ignore=D101,D202')
703-
option('--convention', metavar='<name>', default='',
703+
option('--convention', metavar='<name>', default=None,
704704
help='choose the basic list of checked errors by specifying an '
705705
'existing convention. Possible conventions: {0}'
706706
.format(', '.join(conventions)))
@@ -858,11 +858,11 @@ def filter(self, record):
858858

859859
def get_checked_error_codes(options):
860860
codes = set(ErrorRegistry.get_error_codes())
861-
if options.ignore:
861+
if options.ignore is not None:
862862
checked_codes = codes - set(options.ignore.split(','))
863-
elif options.select:
863+
elif options.select is not None:
864864
checked_codes = set(options.select.split(','))
865-
elif options.convention:
865+
elif options.convention is not None:
866866
checked_codes = getattr(conventions, options.convention)
867867
else:
868868
checked_codes = conventions.pep257

src/tests/test_pep257.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def foo():
168168

169169

170170
def test_select_cli():
171-
"""Test choosing error codes with --select in the CLI."""
171+
"""Test choosing error codes with `--select` in the CLI."""
172172
with Pep257Env() as env:
173173
with env.open('example.py', 'wt') as example:
174174
example.write(textwrap.dedent("""\
@@ -183,7 +183,7 @@ def foo():
183183

184184

185185
def test_select_config():
186-
"""Test choosing error codes with --select in the config file."""
186+
"""Test choosing error codes with `select` in the config file."""
187187
with Pep257Env() as env:
188188
with env.open('example.py', 'wt') as example:
189189
example.write(textwrap.dedent("""\
@@ -302,3 +302,47 @@ def test_illegal_convention():
302302
assert code == 2
303303
assert "Illegal convention 'illegal_conv'." in err
304304
assert 'Possible conventions: pep257' in err
305+
306+
307+
def test_empty_select_cli():
308+
"""Test excluding all error codes with `--select=` in the CLI."""
309+
with Pep257Env() as env:
310+
with env.open('example.py', 'wt') as example:
311+
example.write(textwrap.dedent("""\
312+
def foo():
313+
pass
314+
"""))
315+
316+
_, _, code = env.invoke_pep257(args="--select=")
317+
assert code == 0
318+
319+
320+
def test_empty_select_config():
321+
"""Test excluding all error codes with `select=` in the config file."""
322+
with Pep257Env() as env:
323+
with env.open('example.py', 'wt') as example:
324+
example.write(textwrap.dedent("""\
325+
def foo():
326+
pass
327+
"""))
328+
329+
env.write_config(select="")
330+
_, _, code = env.invoke_pep257()
331+
assert code == 0
332+
333+
334+
def test_empty_select_with_added_error():
335+
"""Test excluding all errors but one."""
336+
with Pep257Env() as env:
337+
with env.open('example.py', 'wt') as example:
338+
example.write(textwrap.dedent("""\
339+
def foo():
340+
pass
341+
"""))
342+
343+
env.write_config(select="")
344+
_, err, code = env.invoke_pep257(args="--add-select=D100")
345+
assert code == 1
346+
assert 'D100' in err
347+
assert 'D101' not in err
348+
assert 'D103' not in err

0 commit comments

Comments
 (0)