Skip to content
Snippets Groups Projects
Commit d9d46f67 authored by Amir Rachum's avatar Amir Rachum Committed by GitHub
Browse files

Merge pull request #279 from PyCQA/feature/nonexistent-code-warning

Print a warning where error code (/prefix) doesn't exist, e.g., --select=D9
parents de24da69 dfd3d775
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -15,6 +15,8 @@ New Features
* ``__init__`` methods missing a docstring are now reported as D107 instead of
D102 (#273, #277).
* Added support for Python 3.6 (#270).
* Specifying an invalid error code prefix (e.g., ``--select=D9``) will print
a warning message to ``stderr`` (#253, #279).
 
Bug Fixes
 
Loading
Loading
Loading
Loading
@@ -90,5 +90,7 @@ def setup_stream_handlers(conf):
log.addHandler(stdout_handler)
 
stderr_handler = logging.StreamHandler(sys.stderr)
msg_format = "%(levelname)s: %(message)s"
stderr_handler.setFormatter(logging.Formatter(fmt=msg_format))
stderr_handler.setLevel(logging.WARNING)
log.addHandler(stderr_handler)
Loading
Loading
@@ -129,7 +129,7 @@ class ConfigurationParser(object):
def get_files_to_check(self):
"""Generate files and error codes to check on each one.
 
Walk dir trees under `self._arguments` and generate yield filnames
Walk dir trees under `self._arguments` and yield file names
that `match` under each directory that `match_dir`.
The method locates the configuration for each file name and yields a
tuple of (filename, [error_codes]).
Loading
Loading
@@ -155,7 +155,7 @@ class ConfigurationParser(object):
for name in self._arguments:
if os.path.isdir(name):
for root, dirs, filenames in os.walk(name):
config = self._get_config(root)
config = self._get_config(os.path.abspath(root))
match, match_dir = _get_matches(config)
ignore_decorators = _get_ignore_decorators(config)
 
Loading
Loading
@@ -168,7 +168,7 @@ class ConfigurationParser(object):
yield (full_path, list(config.checked_codes),
ignore_decorators)
else:
config = self._get_config(name)
config = self._get_config(os.path.abspath(name))
match, _ = _get_matches(config)
ignore_decorators = _get_ignore_decorators(config)
if match(name):
Loading
Loading
@@ -446,12 +446,12 @@ class ConfigurationParser(object):
 
try:
for part in code_parts:
if len(part) < 4:
for code in codes:
if code.startswith(part):
expanded_codes.add(code)
else:
expanded_codes.add(part)
codes_to_add = {code for code in codes
if code.startswith(part)}
if not codes_to_add:
log.warn('Error code passed is not a prefix of any known '
'errors: %s', part)
expanded_codes.update(codes_to_add)
except TypeError as e:
raise IllegalConfiguration(e)
 
Loading
Loading
@@ -496,8 +496,8 @@ class ConfigurationParser(object):
return any([getattr(options, opt) is not None for opt in
cls.BASE_ERROR_SELECTION_OPTIONS])
 
@staticmethod
def _fix_set_options(options):
@classmethod
def _fix_set_options(cls, options):
"""Alter the set options from None/strings to sets in place."""
optional_set_options = ('ignore', 'select')
mandatory_set_options = ('add_ignore', 'add_select')
Loading
Loading
@@ -506,9 +506,11 @@ class ConfigurationParser(object):
"""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
file.
 
"""
return set(value_str.split(',')) - {''}
return cls._expand_error_codes(set(value_str.split(',')) - {''})
 
for opt in optional_set_options:
value = getattr(options, opt)
Loading
Loading
Loading
Loading
@@ -414,7 +414,9 @@ def test_bad_wildcard_add_ignore_cli(env):
assert code == 1
assert 'D203' in out
assert 'D300' in out
assert 'D3034' not in out
assert 'D3004' not in out
assert ('Error code passed is not a prefix of any known errors: D3004'
in err)
 
 
def test_conflicting_select_ignore_config(env):
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment