Package provide base classes and utils for flake8 plugin writing
Project description
flake8-plugin-utils
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flake8-plugin-utils-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e6716c8c773e0803c41776d4eff1ef7653051a8aacbf8c7accd6969951ab7d0 |
|
MD5 | 8a11c77174857618b8ba18d810a3222a |
|
BLAKE2b-256 | a43ae420ca89fbabb3f0f70e015317b928091cb1ef768c325e1074d30d539d7a |
Close
Hashes for flake8_plugin_utils-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b9bb83903b6e6b3344f400e12fc7f2a61498164dce8301ac19a42475b640eb1 |
|
MD5 | 0eee185ede4dd883715a1079cf9d3841 |
|
BLAKE2b-256 | 72d4f88e34233fe0ea8abff892034523a6b8ecfea7c5aab80390d376b07d7350 |