Home > database >  How to raise flake8 error when found particular string in whole project.?
How to raise flake8 error when found particular string in whole project.?

Time:12-06

When I run flake8 . command I want to raise flake8 error if "print_queries" string is present anywhere in project files checked into VCS (and not excluded).

Here's my flake8 configuration:

[flake8]
exclude = .venv, migrations, scaffoldapp
max-line-length = 130

per-file-ignores =
    # imported but not used
    */__init__.py: F401,F403
    */*urls.py: E122,E501
    */*settings.py: E501
    */*messages.py: E501
    */apps.py: F401
    */*employee_constant.py: W605

How can I deny checking print_queries string into VCS? I'm also using pre-commit.

CodePudding user response:

You can add the following pre-commit hook:

- repo: local
  hooks:
    - id: love_statement
      name: Check that `print_queries` is not used
      types: [python]
      entry: '@print_queries'
      language: pygrep

It will fail iff the string @print_queries is present anywhere in staged files.

  • Related