Merge branch 'example-project' into 'master'

Add an example plugin project to source tree

Necessary to start investigating issue #239

See merge request !128
This commit is contained in:
Ian Cordasco 2016-10-26 11:39:07 +00:00
commit 185a073c29
6 changed files with 93 additions and 12 deletions

32
example-plugin/setup.py Normal file
View file

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
import setuptools
setuptools.setup(
name='flake8-example-plugin',
license='MIT',
version='1.0.0',
description='Example plugin to Flake8',
author='Ian Cordasco',
author_email='graffatcolmingov@gmail.com',
url='https://gitlab.com/pycqa/flake8',
package_dir={'': 'src/'},
packages=['flake8_example_plugin'],
entry_points={
'flake8.extension': [
'X1 = flake8_example_plugin:ExampleOne',
'X2 = flake8_example_plugin:ExampleTwo',
],
},
classifiers=[
'Framework :: Flake8',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Quality Assurance',
],
)

View file

@ -0,0 +1,9 @@
"""Module for an example Flake8 plugin."""
from .on_by_default import ExampleOne
from .off_by_default import ExampleTwo
__all__ = (
'ExampleOne',
'ExampleTwo',
)

View file

@ -0,0 +1,17 @@
"""Our first example plugin."""
class ExampleTwo(object):
"""Second Example Plugin."""
name = 'off-by-default-example-plugin'
version = '1.0.0'
off_by_default = True
def __init__(self, tree):
self.tree = tree
def run(self):
"""Do nothing."""
yield (1, 0, 'X200 The off-by-default plugin was enabled',
'OffByDefaultPlugin')

View file

@ -0,0 +1,15 @@
"""Our first example plugin."""
class ExampleOne(object):
"""First Example Plugin."""
name = 'on-by-default-example-plugin'
version = '1.0.0'
def __init__(self, tree):
self.tree = tree
def run(self):
"""Do nothing."""
for message in []:
yield message

View file

@ -65,6 +65,7 @@ class StyleGuide(object):
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._decision_cache = {}
self._parsed_diff = {}
@ -81,10 +82,10 @@ class StyleGuide(object):
Ignored.Implicitly if the selected list is not empty but no match
was found.
"""
if not self._selected:
if not (self._selected or self._enabled_extensions):
return Selected.Implicitly
if code.startswith(self._selected):
if code.startswith(self._selected + self._enabled_extensions):
return Selected.Explicitly
# If it was not explicitly selected, it may have been implicitly

View file

@ -15,6 +15,7 @@ def create_options(**kwargs):
kwargs.setdefault('extended_default_select', [])
kwargs.setdefault('ignore', [])
kwargs.setdefault('disable_noqa', False)
kwargs.setdefault('enable_extensions', [])
return optparse.Values(kwargs)
@ -50,18 +51,24 @@ def test_is_user_ignored_implicitly_selects_errors(ignore_list, error_code):
assert guide.is_user_ignored(error_code) is style_guide.Selected.Implicitly
@pytest.mark.parametrize('select_list,error_code', [
(['E111', 'E121'], 'E111'),
(['E111', 'E121'], 'E121'),
(['E11', 'E12'], 'E121'),
(['E2', 'E12'], 'E121'),
(['E2', 'E12'], 'E211'),
@pytest.mark.parametrize('select_list,enable_extensions,error_code', [
(['E111', 'E121'], [], 'E111'),
(['E111', 'E121'], [], 'E121'),
(['E11', 'E12'], [], 'E121'),
(['E2', 'E12'], [], 'E121'),
(['E2', 'E12'], [], 'E211'),
(['E1'], ['E2'], 'E211'),
([], ['E2'], 'E211'),
])
def test_is_user_selected_selects_errors(select_list, error_code):
def test_is_user_selected_selects_errors(select_list, enable_extensions,
error_code):
"""Verify we detect users explicitly selecting an error."""
guide = style_guide.StyleGuide(create_options(select=select_list),
listener_trie=None,
formatter=None)
guide = style_guide.StyleGuide(
options=create_options(select=select_list,
enable_extensions=enable_extensions),
listener_trie=None,
formatter=None,
)
assert (guide.is_user_selected(error_code) is
style_guide.Selected.Explicitly)