diff --git a/prospector/config/__init__.py b/prospector/config/__init__.py index 665339a4..b22a54f1 100644 --- a/prospector/config/__init__.py +++ b/prospector/config/__init__.py @@ -105,19 +105,21 @@ def _get_profile(self, path, config): profile_name = 'default' extra_profiles = [] - if config.doc_warnings is not None and config.doc_warnings: - cmdline_implicit.append('doc_warnings') - if config.test_warnings is not None and config.test_warnings: - cmdline_implicit.append('test_warnings') - if config.no_style_warnings is not None and config.no_style_warnings: - cmdline_implicit.append('no_pep8') - if config.full_pep8 is not None and config.full_pep8: - cmdline_implicit.append('full_pep8') - - # Use the strictness profile only if no profile has been given - if config.strictness is not None and config.strictness: - cmdline_implicit.append('strictness_%s' % config.strictness) - strictness = config.strictness + if config.doc_warnings is not None and config.doc_warnings: + cmdline_implicit.append('doc_warnings') + if config.test_warnings is not None and config.test_warnings: + cmdline_implicit.append('test_warnings') + if config.no_style_warnings is not None and config.no_style_warnings: + cmdline_implicit.append('no_pep8') + if config.full_pep8 is not None and config.full_pep8: + cmdline_implicit.append('full_pep8') + if config.member_warnings is not None and config.member_warnings: + cmdline_implicit.append('member_warnings') + + # Use the strictness profile only if no profile has been given + if config.strictness is not None and config.strictness: + cmdline_implicit.append('strictness_%s' % config.strictness) + strictness = config.strictness # the profile path is # * anything provided as an argument diff --git a/prospector/config/configuration.py b/prospector/config/configuration.py index be225bb6..304fd4d1 100644 --- a/prospector/config/configuration.py +++ b/prospector/config/configuration.py @@ -24,6 +24,7 @@ def build_manager(): manager.add(soc.BooleanSetting('doc_warnings', default=None)) manager.add(soc.BooleanSetting('test_warnings', default=None)) manager.add(soc.BooleanSetting('no_style_warnings', default=None)) + manager.add(soc.BooleanSetting('member_warnings', default=None)) manager.add(soc.BooleanSetting('full_pep8', default=None)) manager.add(soc.IntegerSetting('max_line_length', default=None)) @@ -137,6 +138,12 @@ def build_command_line_source(prog=None, description='Performs static analysis o 'help': 'Don\'t create any warnings about style. This disables the' ' PEP8 tool and similar checks for formatting.', }, + 'member_warnings': { + 'flags': ['-m', '--member-warnings'], + 'help': 'Attempt to warn when code tries to access an attribute of a ' + 'class or member of a module which does not exist. This is disabled ' + 'by default as it tends to be quite inaccurate.' + }, 'full_pep8': { 'flags': ['-F', '--full-pep8'], 'help': 'Enables every PEP8 warning, so that all PEP8 style' diff --git a/prospector/profiles/profile.py b/prospector/profiles/profile.py index 7c9652b2..2d8aba37 100644 --- a/prospector/profiles/profile.py +++ b/prospector/profiles/profile.py @@ -26,6 +26,7 @@ def __init__(self, name, profile_dict, inherit_order): self.ignore_patterns = profile_dict.get('ignore-patterns', []) + profile_dict.get('ignore', []) self.output_format = profile_dict.get('output-format') + self.member_warnings = profile_dict.get('member-warnings') self.autodetect = profile_dict.get('autodetect') self.uses = [uses for uses in _ensure_list(profile_dict.get('uses', [])) if uses in ('django', 'celery')] self.max_line_length = profile_dict.get('max-line-length') @@ -63,7 +64,8 @@ def as_dict(self): 'output-format': self.output_format, 'autodetect': self.autodetect, 'uses': self.uses, - 'max-line-length': self.max_line_length + 'max-line-length': self.max_line_length, + 'member-warnings': self.member_warnings, } for tool in TOOLS.keys(): out[tool] = getattr(self, tool) @@ -146,7 +148,8 @@ def _merge_profile_dict(priority, base): out = dict(base.items()) for key, value in priority.items(): - if key in ('strictness', 'doc-warnings', 'test-warnings', 'output-format', 'autodetect', 'max-line-length'): + if key in ('strictness', 'doc-warnings', 'test-warnings', 'member-warnings', + 'output-format', 'autodetect', 'max-line-length',): # some keys are simple values which are overwritten out[key] = value elif key in ('ignore', 'ignore-patterns', 'ignore-paths', 'uses'): @@ -193,6 +196,13 @@ def _determine_test_warnings(profile_dict): return (None if test_warnings else 'no_test_warnings'), True +def _determine_member_warnings(profile_dict): + member_warnings = profile_dict.get('member-warnings') + if member_warnings is None: + return None, False + return ('member_warnings' if member_warnings else 'no_member_warnings'), True + + def _determine_implicit_inherits(profile_dict, already_inherits, shorthands_found): # Note: the ordering is very important here - the earlier items # in the list have precedence over the later items. The point of @@ -202,7 +212,8 @@ def _determine_implicit_inherits(profile_dict, already_inherits, shorthands_foun ('pep8', _determine_pep8(profile_dict)), ('docs', _determine_doc_warnings(profile_dict)), ('tests', _determine_test_warnings(profile_dict)), - ('strictness', _determine_strictness(profile_dict, already_inherits)) + ('strictness', _determine_strictness(profile_dict, already_inherits)), + ('members', _determine_member_warnings(profile_dict)), ] inherits = [] @@ -236,6 +247,9 @@ def _load_and_merge(name_or_path, profile_path, allow_shorthand=True, forced_inh if 'docs' not in shorthands_found: data, inherit_list = _append_profiles('no_doc_warnings', profile_path, data, inherit_list) + if 'members' not in shorthands_found: + data, inherit_list = _append_profiles('no_member_warnings', profile_path, data, inherit_list) + if 'tests' not in shorthands_found: data, inherit_list = _append_profiles('no_test_warnings', profile_path, data, inherit_list) diff --git a/prospector/profiles/profiles/default.yaml b/prospector/profiles/profiles/default.yaml index 009e30e3..992522c7 100644 --- a/prospector/profiles/profiles/default.yaml +++ b/prospector/profiles/profiles/default.yaml @@ -2,3 +2,4 @@ strictness: medium doc-warnings: false test-warnings: false autodetect: true +member-warnings: false diff --git a/prospector/profiles/profiles/member_warnings.yaml b/prospector/profiles/profiles/member_warnings.yaml new file mode 100644 index 00000000..a94ac577 --- /dev/null +++ b/prospector/profiles/profiles/member_warnings.yaml @@ -0,0 +1,6 @@ +allow-shorthand: false + +pylint: + enable: + - no-member + - no-name-in-module \ No newline at end of file diff --git a/prospector/profiles/profiles/no_member_warnings.yaml b/prospector/profiles/profiles/no_member_warnings.yaml new file mode 100644 index 00000000..8900d7b3 --- /dev/null +++ b/prospector/profiles/profiles/no_member_warnings.yaml @@ -0,0 +1,6 @@ +allow-shorthand: false + +pylint: + disable: + - no-member + - no-name-in-module