mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 10:46:54 +00:00
Actually remove enabled extensions from ignore list
When we enable a plugin (when it's provided in the --enable-extensions) plugin, we need to remove it both from the extended default ignore list and the plain ignore list. Closes #239
This commit is contained in:
parent
ca4f631fb2
commit
1dfd6bae77
2 changed files with 34 additions and 2 deletions
|
|
@ -182,10 +182,17 @@ class Plugin(object):
|
|||
LOG.critical(str(failed_to_load))
|
||||
raise failed_to_load
|
||||
|
||||
def enable(self, optmanager):
|
||||
def enable(self, optmanager, options=None):
|
||||
"""Remove plugin name from the default ignore list."""
|
||||
optmanager.remove_from_default_ignore([self.name])
|
||||
optmanager.extend_default_select([self.name])
|
||||
if not options:
|
||||
return
|
||||
try:
|
||||
options.ignore.remove(self.name)
|
||||
except (ValueError, KeyError):
|
||||
LOG.debug('Attempted to remove %s from the ignore list but it was '
|
||||
'not a member of the list.', self.name)
|
||||
|
||||
def disable(self, optmanager):
|
||||
"""Add the plugin name to the default ignore list."""
|
||||
|
|
@ -202,7 +209,7 @@ class Plugin(object):
|
|||
parse_options(options)
|
||||
|
||||
if self.name in options.enable_extensions:
|
||||
self.enable(optmanager)
|
||||
self.enable(optmanager, options)
|
||||
|
||||
def register_options(self, optmanager):
|
||||
"""Register the plugin's command-line options on the OptionManager.
|
||||
|
|
|
|||
|
|
@ -162,3 +162,28 @@ def test_provide_options():
|
|||
plugin_obj.parse_options.assert_called_once_with(
|
||||
option_manager, option_values, None
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ignore_list, code, expected_list', [
|
||||
(['E', 'W', 'F', 'C9'], 'W', ['E', 'F', 'C9']),
|
||||
(['E', 'W', 'F'], 'C9', ['E', 'W', 'F']),
|
||||
])
|
||||
def test_enable(ignore_list, code, expected_list):
|
||||
"""Verify that enabling a plugin removes it from the ignore list."""
|
||||
options = mock.Mock(ignore=ignore_list)
|
||||
optmanager = mock.Mock()
|
||||
plugin = manager.Plugin(code, mock.Mock())
|
||||
|
||||
plugin.enable(optmanager, options)
|
||||
|
||||
assert options.ignore == expected_list
|
||||
|
||||
|
||||
def test_enable_without_providing_parsed_options():
|
||||
"""Verify that enabling a plugin removes it from the ignore list."""
|
||||
optmanager = mock.Mock()
|
||||
plugin = manager.Plugin('U4', mock.Mock())
|
||||
|
||||
plugin.enable(optmanager)
|
||||
|
||||
optmanager.remove_from_default_ignore.assert_called_once_with(['U4'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue