The package provides base classes and utils for flake8 plugin writing
Project description
flake8-plugin-utils
The package provides 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 assert_error, assert_not_error
def test_code_with_error():
assert_error(MyVisitor, 'class Y: pass', MyError)
def test_code_without_error():
assert_not_error(MyVisitor, 'x = 1')
Formatting
Your Error
s can take formatting arguments in their message
:
from flake8_plugin_utils import Error, Visitor, assert_error
class MyFormattedError(Error):
code = 'X101'
message = 'my error with {thing}'
class MyFormattedVisitor(Visitor):
def visit_ClassDef(self, node):
self.error_from_node(MyFormattedError, node, thing=node.name)
def test_code_with_error():
assert_error(
MyFormattedVisitor,
'class Y: pass',
MyFormattedError,
thing='Y',
)
License
MIT
Change Log
Unreleased
- ...
1.0.0 - 2019-05-23
- add message formatting to Error
0.2.1 - 2019-04-01
- don`t strip before src dedent in _error_from_src
- add is_none, is_true, is_false util functions
0.2.0 - 2019.02.21
- add assert methods
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-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ac5eb19773d5c7fdde60b0d901ae86be9c751bf697c61fdb6609b86872f3c6e |
|
MD5 | 6846f6f956cd2cc6cd03c041adb3a0ad |
|
BLAKE2b-256 | 46770f54088ab0dd5a46cae012079f8a6dae31c2c59c0060b62be497919c7523 |
Close
Hashes for flake8_plugin_utils-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24b4a3b216ad588951d3d7adef4645dcb3b32a33b878e03baa790b5a66bf3a73 |
|
MD5 | d38e9e0d27802723a3dd9f9b6ab09096 |
|
BLAKE2b-256 | f3d5709acf069f2c11551d4c39e1408f90500ba5c1e7f0333cd86a1e0ff3a24a |