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

Question:

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.

Asked By: Abbas Shaikh

||

Answers:

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.

Answered By: SUTerliakov
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.