Skip to main content

Write your own linting rules using regular expressions

Project description

Regular Expression Linter

Write your own linting rules using regular expressions.


pip install relint


You can write your own regular rules in a YAML file, like so:

- name: No ToDo
  pattern: '(?i)todo' # case insensitive flag
  hint: Get it done right away!
  filePattern: .*\.(py|js)
  error: false

The name attribute is the name of your linter, the pattern can be any regular expression. The linter does lint entire files, therefore your expressions can match multiple lines and include newlines.

You can narrow down the file types your linter should be working with, by providing the optional filePattern attribute. The default is .*.

The optional error attribute allows you to only show a warning but not exit with a bad (non-zero) exit code. The default is true.

The following command will lint all files in the current directory:

relint -c .relint.yml **

The default configuration file name is .relint.yml within your working directory, but you can provide any YAML or JSON file.

If you prefer linting changed files (cached on git) you can use the option –diff [-d]:

git diff | relint --diff

This option is useful for pre-commit purposes. Here an example of how to use it with pre-commit framework:

- repo:
  rev: 1.2.0
    - id: relint

You can find an example of in this repository.


- name: db fixtures
  pattern: 'def test_[^(]+\([^)]*(customer|product)(, |\))'
  hint: Use model_bakery recipies instead of db fixtures.
  filePattern: test_.*\.py

- name: model_bakery recipies
  pattern: baker\.make\(
  hint: Please use baker.make_recipe instead of baker.make.
  filePattern: (test_.*|conftest)\.py

- name: the database is lava
  pattern: '@pytest.fixture.*\n[ ]*def [^(]+\([^)]*(db|transactional_db)(, |\))'
  hint: Please do not create db fixtures but model_bakery recipies instead.
  filePattern: .*\.py

- name: No logger in management commands
  pattern: (logger|import logging)
  hint: Please write to self.stdout or self.stderr in favor of using a logger.
  filePattern: \/management\/commands\/.*\.py

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

relint-1.3.2.tar.gz (6.5 kB view hashes)

Uploaded source

Built Distribution

relint-1.3.2-py2.py3-none-any.whl (5.9 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page