Skip to main content

Package provide base classes and utils for flake8 plugin writing

Project description

flake8-plugin-utils

pypi Python: 3.6+ Downloads Build Status Code coverage License: MIT Code style: black

Package provide base classes and utils for flake8 plugin writing.

Installation

pip install flake8-plugin-utils

Example

Write simple plugin

from flake8_plugin_utils import Error, Visitor, Plugin

class MyError(Error):
    code = 'X100'
    message = 'my error'

class MyVisitor(Visitor):
    def visit_ClassDef(self, node):
        self.error_from_node(MyError, node)

class MyPlugin(Plugin):
    name = 'MyPlugin'
    version = '0.1.0'
    visitors = [MyVisitor]

and test it with pytest

from flake8_plugin_utils import get_error

def test_error_msg(tmpdir):
    assert get_error(MyPlugin, tmpdir, 'class Y: pass') == 'X100 my error'

@pytest.mark.parametrize('src', (
    'class X:\n    pass',
    'class Y: pass',
))
def test_error_exists(tmpdir, src):
    assert get_error(MyPlugin, tmpdir, src)

@pytest.mark.parametrize('src', (
    'def x():\n    pass',
    '\nx = 13',
))
def test_error_not_exists(tmpdir, src):
    assert not get_error(MyPlugin, tmpdir, src)

If you want build error message dynamically use property

class MyError(Error):
    code = 'X100'

    @property
    def message(self):
        return f'{self.code} my error from property'

License

MIT

Change Log

0.1.0 - 2019.02.09

  • initial

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-plugin-utils-0.1.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

flake8_plugin_utils-0.1.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page