diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-11-02 10:20:12 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-11-08 20:00:01 -0600 |
| commit | 4f04ca549b325e3b88756040e5baadb535b35e3f (patch) | |
| tree | e2cb0149466fe150f37a6984ea61e53b41dbe9f6 /src | |
| parent | 9553c8d8ccf54221153f498e28297d9cc74ca12d (diff) | |
| download | flake8-4f04ca549b325e3b88756040e5baadb535b35e3f.tar.gz | |
Handle a previously unhandled code scenario
Previously, we didn't handle the case where an error code was implicitly
ignored (by not being in --select) and implicitly selected (by not being
in --ignore). This means we need to update StyleGuide#_decision_for and
StyleGuide#is_user_selected to handle these cases.
Closes #242
Related-to #239
Related-to !132
Diffstat (limited to 'src')
| -rw-r--r-- | src/flake8/style_guide.py | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/flake8/style_guide.py b/src/flake8/style_guide.py index 739edd8..9f3b86f 100644 --- a/src/flake8/style_guide.py +++ b/src/flake8/style_guide.py @@ -64,8 +64,9 @@ class StyleGuide(object): self.stats = statistics.Statistics() self._selected = tuple(options.select) self._extended_selected = tuple(options.extended_default_select) - self._ignored = tuple(options.ignore) self._enabled_extensions = tuple(options.enable_extensions) + self._all_selected = self._selected + self._enabled_extensions + self._ignored = tuple(options.ignore) self._decision_cache = {} self._parsed_diff = {} @@ -82,17 +83,15 @@ class StyleGuide(object): Ignored.Implicitly if the selected list is not empty but no match was found. """ - if not (self._selected or self._enabled_extensions): - return Selected.Implicitly - - if code.startswith(self._selected + self._enabled_extensions): + if self._all_selected and code.startswith(self._all_selected): return Selected.Explicitly - # If it was not explicitly selected, it may have been implicitly - # selected because the check comes from a plugin that is enabled by - # default - if (self._extended_selected and - code.startswith(self._extended_selected)): + if (not self._all_selected and + (self._extended_selected and + code.startswith(self._extended_selected))): + # If it was not explicitly selected, it may have been implicitly + # selected because the check comes from a plugin that is enabled by + # default return Selected.Implicitly return Ignored.Implicitly @@ -118,10 +117,22 @@ class StyleGuide(object): def _decision_for(self, code): # type: (Error) -> Decision startswith = code.startswith - selected = sorted([s for s in self._selected if startswith(s)])[0] - ignored = sorted([i for i in self._ignored if startswith(i)])[0] + try: + selected = sorted([s for s in self._selected if startswith(s)])[0] + except IndexError: + selected = None + try: + ignored = sorted([i for i in self._ignored if startswith(i)])[0] + except IndexError: + ignored = None + + if selected is None: + return Decision.Ignored + + if ignored is None: + return Decision.Selected - if selected.startswith(ignored): + if selected.startswith(ignored) and selected != ignored: return Decision.Selected return Decision.Ignored @@ -150,8 +161,10 @@ class StyleGuide(object): selected is Selected.Implicitly) and ignored is Selected.Implicitly): decision = Decision.Selected - elif (selected is Selected.Explicitly and - ignored is Ignored.Explicitly): + elif ((selected is Selected.Explicitly and + ignored is Ignored.Explicitly) or + (selected is Ignored.Implicitly and + ignored is Selected.Implicitly)): decision = self._decision_for(code) elif (selected is Ignored.Implicitly or ignored is Ignored.Explicitly): |
