Skip to content

codingjoe/relint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

dacfa3c · Nov 5, 2022

History

58 Commits
Oct 3, 2022
Oct 4, 2022
Oct 4, 2022
Oct 3, 2022
Oct 3, 2022
Oct 3, 2022
Sep 3, 2022
Nov 5, 2022
Oct 4, 2022
Nov 5, 2022
Oct 14, 2022
Oct 10, 2022
Oct 3, 2022
Oct 3, 2022

Repository files navigation

/(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

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