Skip to main content

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:

  1. 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
  1. 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.

Release files for refurb-plugin-example 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for refurb-plugin-example 1.0.0
File Size Uploaded
refurb-plugin-example-1.0.0.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for refurb-plugin-example 1.0.0
File Interpreter ABI Platform
refurb_plugin_example-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 30.4 kB

Release files / refurb-plugin-example-1.0.0.tar.gz

Download URL refurb-plugin-example-1.0.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fb103a28f1a6bb1b438b3666b73be1d728c708a622afc75a062a5845361a31bd
BLAKE2b-256 checksum
How to use checksums
7dcb2c271dc78a9f912eaa7190462d43bef34d33e32b89fe643e4f4b9bd21b90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.10.7 Linux/5.19.10-arch1-1

Release files / refurb_plugin_example-1.0.0-py2.py3-none-any.whl

Download URL refurb_plugin_example-1.0.0-py2.py3-none-any.whl
Size 15.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9f23138b4534c41c39f0b42358eb82d9b4dcb088b758cb3eefd03a3c4be81104
BLAKE2b-256 checksum
How to use checksums
80b3eca2b27e9a7a2d5623076059710416b301a34e8587bc1568cd3d3dd8d22f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.10.7 Linux/5.19.10-arch1-1

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page