An example plugin for Refurb
Project description
Refurb Plugin Example
This repo is meant to be a good starting point for those who are looking to make plugins for Refurb.
For illustrative purposes, this plugin will emit an error when the following
print
statement is found:
print("Hello world!")
Setup
First things first, fork this repo. Make sure to change the name, but keep
the refurb-
prefix (for naming convention sake).
Next, clone:
$ git clone https://github.com/USERNAME/refurb-your-plugin
$ cd refurb-your-plugin
Of course, replacing refurb-your-plugin
with the name you picked.
Then, update the pyproject.toml
file with the your information.
You can run the setup.sh
script to do this for you, which will ask you a series
of questions. If the script does not work, you will have to update it manually
(you should only need to update the first two sections).
Check Discovery
In order for Refurb to find and use your check, 2 conditions must be met:
- You must export a class that starts with
Error
, which will contain the error metadata. Note:
- It must derive from
Error
- It cannot be named
ErrorCode
- You must have a function called
check
, which is the entry point for a given check.
The definition for a check
function looks something like this:
def check(node: CallExpr, errors: list[Error]) -> None:
...
Where CallExpr
is the node you want to accept, and errors
is where you append an
error if one occurs. You can accept multiple node types using a type union, like so:
def check(node: UnaryExpr | OpExpr, errors: list[Error]) -> None:
...
This check will accept both unary and binary expressions.
Any nested folders must contain an __init__.py
file. This might not be 100% necessary,
but from what I can tell, it is best to add it in anyways.
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
File details
Details for the file refurb-plugin-example-1.0.0.tar.gz
.
File metadata
- Download URL: refurb-plugin-example-1.0.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.7 Linux/5.19.10-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb103a28f1a6bb1b438b3666b73be1d728c708a622afc75a062a5845361a31bd |
|
MD5 | 870d33b3720becfee411d2f48b7c7ac9 |
|
BLAKE2b-256 | 7dcb2c271dc78a9f912eaa7190462d43bef34d33e32b89fe643e4f4b9bd21b90 |
File details
Details for the file refurb_plugin_example-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: refurb_plugin_example-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.7 Linux/5.19.10-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f23138b4534c41c39f0b42358eb82d9b4dcb088b758cb3eefd03a3c4be81104 |
|
MD5 | b36d957fdd0f48ed8bddc8747365d986 |
|
BLAKE2b-256 | 80b3eca2b27e9a7a2d5623076059710416b301a34e8587bc1568cd3d3dd8d22f |