Git Product home page Git Product logo

qr-hooks's Introduction

A collection of useful pre-commit hooks

Hooks

django-no-auto-migrations

Detect auto-named migrations eg. 0000_auto_202012251330.py

django-url-trailing-slash

Detect any URL paths in urls.py without a trailing slash

django-invalid-perm

Detect has_perm or @permission_required usage with an invalid perm (eg. has_perm("core:add_user"))

TODO

django-invalid-perm

  • Update regex for permission_required to account for multiple permissions eg. detect @permission_required(["user.change_user", "user:add_user"])

Contributing

Create a virtual env and install the requirements:

pip install -r requirements/test.txt

Run the tests:

pytest

qr-hooks's People

Contributors

dave-v avatar max-nicholson avatar taliraj avatar

Watchers

 avatar  avatar

qr-hooks's Issues

Exclude some migrations from `django-no-auto-migrations` check

When applying this hook to repos that have auto named migrations that have already been applied to production databases, it will always fail but we can't rename them. In other cases _auto_ may be a component of an explicitly named migration.

The main issue is when an old migration is reformatted by black, say, and then it cannot be committed without failing this check.

--no-verify can be used, but GitHub workflows running all pre-commit hooks will fail it.

Possible solution is to maintain a list of files to ignore, either in the config (but this would get ugly fast), or in a separate file (but then we have yet another file).

Using the number prefix of the migration could used to specify ranges, e.g.

exclude:
  - app1: <0023
  - app2: 0054

Handle `url`/`re_path` urls better in `django-url-trailing-slash`

The check currently fails for url(r"^$", ...) but doesn't for path("", ...), when these are effectively equivalent. In both cases, this is correct, and having an additional slash would be wrong.
More importantly, it fails for url(r"^media/(?P<path>.*)", ...) which does not need to end in a slash because of the .* at the end. In cases where that path is empty, the URL will already end in a slash.

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.