GithubHelp home page GithubHelp logo

moseb / relint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codingjoe/relint

0.0 1.0 0.0 24 KB

Regular Expression based static file linter.

License: MIT License

Python 99.22% Shell 0.78%

relint's Introduction

ReLint

Regular Expression Linter

Write your own linting rules using regular expressions.

Installation

pip install relint

Usage

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

- name: No ToDo
  pattern: "[tT][oO][dD][oO]"
  hint: Get it done right away!
  filename:
    - "*.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 filename 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.yaml 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 my_file.py --diff

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

- repo: https://github.com/codingjoe/relint
  rev: 0.5.0
  hooks:
    - id: relint

You can find an example of relint-pre-commit.sh in this repository.

Samples

- name: db fixtures
  pattern: "def test_[^(]+\\([^)]*(customer|product)(, |\\))"
  hint: Use model_mommy recipies instead of db fixtures.
  filename:
    - "**/test_*.py"

- name: model_mommy recipies
  pattern: "mommy\\.make\\("
  hint: Please use mommy.make_recipe instead of mommy.make.
  filename:
    - "**/test_*.py"
    - "conftest.py"
    - "**/conftest.py"

- name: the database is lava
  pattern: "@pytest.fixture.*\\n[ ]*def [^(]+\\([^)]*(db|transactional_db)(, |\\))"
  hint: Please do not create db fixtures but model_mommy recipies instead.
  filename:
    - "*.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."
  filename:
    - "*/management/commands/*.py"

relint's People

Contributors

anapaulagomes avatar codingjoe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.