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

Commit

Permalink
Strip whitespace in _fix_set_options (#431)
Browse files Browse the repository at this point in the history
This allows to specify e.g. "ignore" on multiple lines, without adding
additional commas:

    [pydocstyle]
    ignore = D100,D101,D102,D103,
      # "1 blank line required before class docstring"
      # Disabled by default, conflicts with D211.
      D203,
      # "Multi-line docstring summary should start at the second line" (vs. D212).
      D213,
  • Loading branch information
blueyed authored and Nurdok committed Nov 30, 2019
1 parent d3ea9a0 commit 96092cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ New Features
docstrings (#407).
* Added support for Python 3.8 (#423).
* Allow skipping errors on module level docstring via #noqa (#427).
* Whitespace is ignored with set options split across multiple lines (#221).

Bug Fixes

Expand Down
8 changes: 5 additions & 3 deletions src/pydocstyle/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,14 @@ def _fix_set_options(cls, options):
def _get_set(value_str):
"""Split `value_str` by the delimiter `,` and return a set.
Removes any occurrences of '' in the set.
Also expand error code prefixes, to avoid doing this for every
Removes empty values ('') and strips whitespace.
Also expands error code prefixes, to avoid doing this for every
file.
"""
return cls._expand_error_codes(set(value_str.split(',')) - {''})
return cls._expand_error_codes(
set([x.strip() for x in value_str.split(",")]) - {""}
)

for opt in optional_set_options:
value = getattr(options, opt)
Expand Down
10 changes: 10 additions & 0 deletions src/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,16 @@ def foo():
assert 'D300' not in out


def test_ignores_whitespace_in_fixed_option_set(env):
with env.open('example.py', 'wt') as example:
example.write("class Foo(object):\n 'Doc string'")
env.write_config(ignore="D100,\n # comment\n D300")
out, err, code = env.invoke()
assert code == 1
assert 'D300' not in out
assert err == ''


def test_bad_wildcard_add_ignore_cli(env):
"""Test adding a non-existent error codes with --add-ignore."""
with env.open('example.py', 'wt') as example:
Expand Down

0 comments on commit 96092cd

Please sign in to comment.