Skip to main content

Write your own linting rules using regular expressions.

Project description

/(re)lint/

reLint

Regular Expression Linter

Write your own linting rules using regular expressions.

PyPi Version Test Coverage GitHub License

Installation

python3 -m pip install relint

Examples & Recipes – The reLint Cookbook

Usage

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] or --git-diff [-g]:

git diff --unified=0 | relint my_file.py --diff

Custom message format

Customize the output message format with the --msg-template=<format string> option. Python format syntax is suported for the message template and the following fields are available:

  • filename The name of the file being linted.

  • line_no The line number of the match.

  • match The matched text.

  • test.* Any attribute of the test rule, e.g. test.name or test.hint.

pre-commit

You can automate the linting process by adding a pre-commit hook to your project. Add the following entry to your .pre-commit-config.yaml:

- repo: https://github.com/codingjoe/relint
  rev: 1.4.0
  hooks:
    - id: relint
      args: [-W]  # optional, if you want to fail on warnings during commit

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-2.2.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relint-2.2.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file relint-2.2.0.tar.gz.

File metadata

  • Download URL: relint-2.2.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for relint-2.2.0.tar.gz
Algorithm Hash digest
SHA256 78a0dd74ee249e71f174cbb1e814ced668683a9e745420183b1c2ac63eff8067
MD5 2f1b5fbb211b6678a46b83d25a52d8fc
BLAKE2b-256 20c01606ffde4e72eb665661f168d831617b07be6c214cf5046332a2edbe5c08

See more details on using hashes here.

File details

Details for the file relint-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: relint-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for relint-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f62e0245a81952d1c57be57faf98ebd47b30cd60e52cfa7c6aa50fb34ee309d6
MD5 8e2e3c149c9af4673a6ce6ef17294eae
BLAKE2b-256 23e955bb8bb46223a6ab0373e18055cfb56f840b48a8a184d56fdb4f341904f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page