zheller / flake8-quotes

Flake8 extension for checking quotes in python
MIT License
178 stars 39 forks source link

Flake8 pre-commit hook doesn't work with flake8-quotes #116

Closed sevapopov2 closed 1 year ago

sevapopov2 commented 1 year ago

Problem

I have the following issue. I set up my flake8 in my virtual pipenv environment together with flake8-quotes as I do it usually and everything works great. However when I try to set up flake8 pre-commit hook it seems like flake8-quotes extension doesn't work. When pre-commit is running there are errors that tripple double quotes should be used instead of single tripple quotes. However the docstring-quotes is set to ' as shown below

code sample

'''Main file to launch the game.'''

import pygame

# Initialize pygame
pygame.init()
# Set game title and window size
pygame.display.set_mode((400, 500))
# Check if game is running
running = True
# Keep the game running while exit button is not pressed
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

flake8-quotes configuration in setup.cfg

# Setup flake8-quotes
docstring-quotes = '
avoid-escape = False

pre-commit output

$ pipenv pre-commit run
flake8...................................................................Failed                                                                             
- hook id: flake8                                                                                                                                           
- exit code: 1                                                                                                                                              

main.py:1:1: D300 Use """triple double quotes"""                                                                                                            
'''Main file to launch the game.'''                                                                                                                         
^                                                                                                                                                           
src/__init__.py:1:1: D300 Use """triple double quotes"""                                                                                                    
'''A directory to be used as package for game files.'''                                                                                                     
^                                                                                                                                                           
src/consts.py:1:1: D300 Use """triple double quotes"""                                                                                                      
'''Constants used in the game project.'''                                                                                                                   
^                                                                                                                                                           
3     D300 Use """triple double quotes"""                                                                                                                   
3

flake8 hook's setup in .pre-commit-config.yaml

  - repo: https://github.com/pycqa/flake8
    rev: 6.1.0
    hooks:
      - id: flake8
        additional_dependencies:
          [
            flake8-builtins,
            flake8-docstrings,
            flake8-import-order,
            flake8-variables-names,
            flake8-quotes,
          ]
        # exclude: migrations

I wrote to Flake8 as you can see in this issue but they recommended to write here. flake8 6.1.0, flake8-quotes 3.3.2, pre-commit 3.3.3. I can provide more info if needed.

sevapopov2 commented 1 year ago

I actually found the problem and write the solution here in case it can be useful for someone. The problem was that I forgot to install flake8-docstrings extension for my project. That is why it worked differently with my local environment and pre-commit. It did not do anything at all with flake8-quotes at all. Thank you and I hope someone finds it any useful!