mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 23:34:17 +00:00
Merge pull request #1609 from PyCQA/explicit
don't consider default codes as explicitly selected unless listed
This commit is contained in:
commit
92031ae589
2 changed files with 40 additions and 15 deletions
|
|
@ -47,6 +47,15 @@ class Decision(enum.Enum):
|
||||||
Selected = "selected error"
|
Selected = "selected error"
|
||||||
|
|
||||||
|
|
||||||
|
def _explicitly_chosen(
|
||||||
|
*,
|
||||||
|
option: Optional[List[str]],
|
||||||
|
extend: Optional[List[str]],
|
||||||
|
) -> Tuple[str, ...]:
|
||||||
|
ret = [*(option or []), *(extend or [])]
|
||||||
|
return tuple(sorted(ret, reverse=True))
|
||||||
|
|
||||||
|
|
||||||
def _select_ignore(
|
def _select_ignore(
|
||||||
*,
|
*,
|
||||||
option: Optional[List[str]],
|
option: Optional[List[str]],
|
||||||
|
|
@ -73,11 +82,13 @@ class DecisionEngine:
|
||||||
"""Initialize the engine."""
|
"""Initialize the engine."""
|
||||||
self.cache: Dict[str, Decision] = {}
|
self.cache: Dict[str, Decision] = {}
|
||||||
|
|
||||||
self.using_default_select = (
|
self.selected_explicitly = _explicitly_chosen(
|
||||||
options.select is None and options.extend_select is None
|
option=options.select,
|
||||||
|
extend=options.extend_select,
|
||||||
)
|
)
|
||||||
self.using_default_ignore = (
|
self.ignored_explicitly = _explicitly_chosen(
|
||||||
options.ignore is None and options.extend_ignore is None
|
option=options.ignore,
|
||||||
|
extend=options.extend_ignore,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.selected = _select_ignore(
|
self.selected = _select_ignore(
|
||||||
|
|
@ -86,7 +97,6 @@ class DecisionEngine:
|
||||||
extended_default=options.extended_default_select,
|
extended_default=options.extended_default_select,
|
||||||
extend=options.extend_select,
|
extend=options.extend_select,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.ignored = _select_ignore(
|
self.ignored = _select_ignore(
|
||||||
option=options.ignore,
|
option=options.ignore,
|
||||||
default=defaults.IGNORE,
|
default=defaults.IGNORE,
|
||||||
|
|
@ -105,11 +115,10 @@ class DecisionEngine:
|
||||||
Ignored.Implicitly if the selected list is not empty but no match
|
Ignored.Implicitly if the selected list is not empty but no match
|
||||||
was found.
|
was found.
|
||||||
"""
|
"""
|
||||||
if code.startswith(self.selected):
|
if code.startswith(self.selected_explicitly):
|
||||||
if self.using_default_select:
|
return Selected.Explicitly
|
||||||
return Selected.Implicitly
|
elif code.startswith(self.selected):
|
||||||
else:
|
return Selected.Implicitly
|
||||||
return Selected.Explicitly
|
|
||||||
else:
|
else:
|
||||||
return Ignored.Implicitly
|
return Ignored.Implicitly
|
||||||
|
|
||||||
|
|
@ -125,11 +134,10 @@ class DecisionEngine:
|
||||||
Selected.Implicitly if the ignored list is not empty but no match
|
Selected.Implicitly if the ignored list is not empty but no match
|
||||||
was found.
|
was found.
|
||||||
"""
|
"""
|
||||||
if code.startswith(self.ignored):
|
if code.startswith(self.ignored_explicitly):
|
||||||
if self.using_default_ignore:
|
return Ignored.Explicitly
|
||||||
return Ignored.Implicitly
|
elif code.startswith(self.ignored):
|
||||||
else:
|
return Ignored.Implicitly
|
||||||
return Ignored.Explicitly
|
|
||||||
else:
|
else:
|
||||||
return Selected.Implicitly
|
return Selected.Implicitly
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -224,3 +224,20 @@ def test_user_can_extend_select_to_enable_plugin_default_ignored():
|
||||||
)
|
)
|
||||||
|
|
||||||
assert decider.decision_for("P002") is style_guide.Decision.Selected
|
assert decider.decision_for("P002") is style_guide.Decision.Selected
|
||||||
|
|
||||||
|
|
||||||
|
def test_plugin_extends_default_ignore_but_extend_selected():
|
||||||
|
decider = style_guide.DecisionEngine(
|
||||||
|
create_options(
|
||||||
|
# user options --extend-select P002 --extend-ignore E501
|
||||||
|
select=None,
|
||||||
|
ignore=None,
|
||||||
|
extend_select=["P002"],
|
||||||
|
extend_ignore=["E501"],
|
||||||
|
# a plugin is installed and extends default ignore
|
||||||
|
extended_default_select=["P"],
|
||||||
|
extended_default_ignore=["P002"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert decider.decision_for("P002") is style_guide.Decision.Selected
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue