GithubHelp home page GithubHelp logo

flake8-quotes's Introduction

Flake8 Extension to lint for quotes.

Build Status

Major update in 2.0.0

We automatically encourage avoiding escaping quotes as per PEP 8. To disable this, use --no-avoid-escape (can be used in configuration file via avoid-escape).

Deprecation notice in 0.3.0

To anticipate multiline support, we are renaming --quotes to --inline-quotes. Please adjust your configurations appropriately.

Usage

If you are using flake8 it's as easy as:

pip install flake8-quotes

Now you don't need to worry about people like @sectioneight constantly complaining that you are using double-quotes and not single-quotes.

Warnings

This package adds flake8 warnings with the prefix Q0. You might want to enable this warning inside your flake8 configuration file. Typically that will be .flake8 inside the root folder of your project.

select = Q0

The current set of warnings is:

Code Description
Q000 Remove bad quotes
Q001 Remove bad quotes from multiline string
Q002 Remove bad quotes from docstring
Q003 Change outer quotes to avoid escaping inner quotes

Configuration

By default, we expect single quotes (') and look for unwanted double quotes ("). To expect double quotes (") and find unwanted single quotes ('), use the CLI option:

flake8 --inline-quotes '"'
# We also support "double" and "single"
# flake8 --inline-quotes 'double'
#
# We also support configuration for multiline quotes
# flake8 --inline-quotes '"' --multiline-quotes "'"
# We also support "'''"
# flake8 --inline-quotes '"' --multiline-quotes "'''"
#
# We also support docstring quotes similarly
# flake8 --inline-quotes '"' --docstring-quotes "'"
# flake8 --inline-quotes '"' --docstring-quotes "'''"

# We also support disabling escaping quotes
# flake8 --no-avoid-escape

or configuration option in tox.ini/setup.cfg.

[flake8]
inline-quotes = "
# We also support "double" and "single"
# inline-quotes = double
#
# We also support configuration for multiline quotes
# multiline-quotes = '
# We also support "'''"
# multiline-quotes = '''
#
# We also support docstring quotes similarly
# docstring-quotes = '
# docstring-quotes = '''
#
# We also support disabling escaping quotes
# avoid-escape = False

Caveats

We follow the PEP8 conventions to avoid backslashes in the string. So, no matter what configuration you are using (single or double quotes) these are always valid strings

s = 'double "quotes" wrapped in singles are ignored'
s = "single 'quotes' wrapped in doubles are ignored"

flake8-quotes's People

Contributors

2m avatar alexfikl avatar arnimarj avatar blueyed avatar cxong avatar dirk-thomas avatar dirn avatar do3cc avatar eklitzke avatar fpuga avatar ichimonji10 avatar jackwilsdon avatar joehitchen avatar johnthagen avatar julian avatar jwhitlock avatar karamanolev avatar kornicameister avatar kvdb avatar oxitnik avatar peterjc avatar skirpichev avatar sobolevn avatar tirkarthi avatar trevorcreech avatar twolfson avatar xzise avatar zheller avatar zyv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flake8-quotes's Issues

Code cannot be ignored in 3.0.2 and 0.8.1

This is only a preliminary result and don't know what exactly causes it but it seems like it is not possible to ignore Q000:

$ flake8 --ignore Q000 test/data/doubles.py 
test/data/doubles.py:1:25: Q000 Remove bad quotes.
test/data/doubles.py:2:25: Q000 Remove bad quotes.
test/data/doubles.py:3:25: Q000 Remove bad quotes.
$ flake8 --version
3.0.2 (flake8_quotes: 0.8.1, mccabe: 0.5.0, pycodestyle: 2.0.0, pyflakes: 1.2.3) CPython 3.5.2 on Linux

This might be related to the comments in TabbycatDebate/tabbycat@81ac70c.

Duplicate work

Hi, I have been coding past week also a flake8-quotes project, and when I tried to register my project, found this one here.

I will be changing the name of my project, but just in case you are interested, have a link https://github.com/txomon/flake8-quotes

I use combination of ast and file reading to parse correctly all the strings. Although for the moment I haven't finished the work (I don't support multi quote strings nor docstrings yet).

Have a nice day!

Is there a way to set all options at once?

I ran into the issue where I had an older version setting the inline-quotes and multiline-quotes.
I'm using single quotes for everything (including docstrings), so my tox tests all of a sudden started failing when it grabbed the new version of this. So I had to add in the new docstrings-quotes setting.

Does there exist, or will there be some master "quotes" setting, that will set it for all 3 options instead of having to have 3 options in my config?

Buggy behavior with empty dict literal and string:

Consider the following example:

def test():
    {}["a"]

and this configuration:

[flake8]
max-line-length = 119
select = Q0
inline-quotes = double

this ends up with Q002 Remove bad quotes from docstring when there is no docstring here involved.

Splitting this over two lines like:

def test():
    d = {}
    d["a"]

Resolves it.

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

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.

Test in Travis CI

It looks like we introduced a .travis.yml in #6 but it isn't currently being used. We should get this set up so we can automatically test Python 2 and Python 3. Otherwise, we should remove the unnecessary .travis.yml.

@zheller Thoughts?

using stdin no longer works

Running flake8 with the following syntax

cat file.py | flake8 -

does not work with flake8-quotes, but does work with other packages. This is most likely caused by the fact that recent versions of flake8 are now importing pycodestyle and not pep8.

This project seems incompatible with black

It seems that this project seems to be totally opposed to black double quoting and that is causing havoc if someone happens to install this plugin at user level flake8, as it will make flake8 report false errors in other projects.

Double quotes to wrap single quotes

flake8-quotes is flagging the string "TAG_field_'hello world'" and any others where double quotes are used to prevent escaping inner single quotes.

Check prefixed strings

Would it be sensible to check raw strings, unicode or bytes? I'm not exactly sure what your intentions are, but in at least u'…' should be checked, as it is a normal string on Python 3. And the change seems reasonably simple as the token contains the prefix. You could either strip the first character if it's in rub or if it is not in "'. Any invalid prefix should result in an error anyway.

You could use different error codes so that if someone doesn't care about how the quotes are formatted in raw strings, they can just ignore that code.

Add support for docstrings

I'd like to be able to enforce docstring quotes and normal string quotes separately, so I can require double quotes for docstrings and single quotes everywhere else.

Example of code that would pass the check (assuming we enforce double quotes for docstrings and single quotes for everything else):

def hello():
    """
    Prints "Hello, world!"
    """
    print('Hello, world!')

And an example of some code that would not pass using the aforementioned rules:

def hello():
    '''
    Prints "Hello, world!"
    '''
    print('Hello, world!')
def hello():
    '''
    Prints "Hello, world!"
    '''
    print("Hello, world!")
def hello():
    """
    Prints "Hello, world!"
    """
    print("Hello, world!")

strings on multiple lines with different quotes

I'm really keen to use this on pydantic, however there's one blocking issue

Take the following example:

        raise ConfigError(
            "validators should be used with fields and keyword arguments, not bare. "
            "E.g. usage should be `@validator('<field_name>', ...)`"
        )

I would say both lines should use double quotes so they're the same even though only one line includes single quotes.

I'm aware this would make analysis more complicated, but is it something you would consider? Either as default or via an option.

Doesn't seem to work with flake8 3.2.0

I was doing some testing with flake8-quotes (to see if it would work with pytest-flake8), and noticed that flake8-quotes doesn't seem to recognize errors I added. It turns out this is a problem with using flake8 3.2.0. The errors are found just fine if I roll back to flake8 3.0.4.

Incompatibility with flake8 v6

$ pip freeze |grep flake
flake8==6.0.0
flake8-quotes==3.3.1
pyflakes==3.0.0

$ flake8
Traceback (most recent call last):
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/bin/flake8", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8/main/cli.py", line 23, in main
    app.run(argv)
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8/main/application.py", line 198, in run
    self._run(argv)
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8/main/application.py", line 186, in _run
    self.initialize(argv)
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8/main/application.py", line 165, in initialize
    self.plugins, self.options = parse_args(argv)
                                 ^^^^^^^^^^^^^^^^
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8/options/parse_args.py", line 51, in parse_args
    option_manager.register_plugins(plugins)
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8/options/manager.py", line 259, in register_plugins
    add_options(self)
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8_quotes/__init__.py", line 103, in add_options
    cls._register_opt(parser, '--quotes', action='store',
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8_quotes/__init__.py", line 93, in _register_opt
    parser.add_option(*args, **kwargs)
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/site-packages/flake8/options/manager.py", line 281, in add_option
    self._current_group.add_argument(*option_args, **option_kwargs)
  File "/Users/mdiener/Work/emirge/miniforge3/envs/ceesd/lib/python3.11/argparse.py", line 1448, in add_argument
    raise ValueError('%r is not callable' % (type_func,))
ValueError: 'choice' is not callable

Q000 error on f-string for CPython 3.12

An example:

$ cat a.py
a = 'f'
b = [2, 3]
c = f'{a}({", ".join(map(str, b))})'
print(c)

No errors from the plugin on the CPython 3.11:

$ python -V
Python 3.11.3+
$ pip install -U flake518 flake8-quotes
[...]
$ flake518 a.py
$

While on the CPython 3.12 I got this error: a.py:3:12: Q000 Double quotes found but single quotes preferred.

Use flake8 provided tokens for analysis

The current flake8-quotes implementation don't use the infrastructure, provided by flake8 for plugins. The entry point QuoteChecker supports tree and filename arguments, but the first one (which is for AST tree, provided by flake8) - totally ignored! Then, QuoteChecker parses provided file by itself, which will lead to "invalid" issues like #92.

I believe, this is a wrong situation and you could use instead the following skeleton to run checks per physical lines, provided by flake8:

$ cat flake8_demo/setup.py 
from setuptools import find_packages, setup

setup(
  name='flake8-demo',
  packages=find_packages(),
  entry_points={
    'flake8.extension': [
      'X801 = flake8_demo.checker:demo_checker'],
  },
)
$ cat flake8_demo/flake8_demo/__init__.py 
$ cat flake8_demo/flake8_demo/checker.py 
import pprint


def demo_checker(physical_line, tokens):
    pprint.pprint(physical_line)


demo_checker.name = 'demo_checker'
demo_checker.version = '0.0.1'

This plugin correctly get input, provided by flake8/flake8-rst. For example:

$ cat demo.rst
Demo for flake8-rst and quotes

>>> a = "spam"
>>> f"no so short "
... f" formatted string with {a}"
'not so short formatted string with spam'

$ flake8-rst demo.rst 
'a = "spam"\n'
'f"no so short "\n'
'f" formatted string with {a}"\n'
demo.rst:3:5: D100 Missing docstring in public module
demo.rst:5:5: I002 no configuration found (.isort.cfg or [isort] in configs)
"""

Q003 error message is wrong for raw strings

I guess Q003: Change outer quotes to avoid escaping inner quotes was introduced with flake8-quotes 2.0.0 but this error is not appropriate for raw strings; e.g. r'\'' == r"\'" but the escape sequence cannot be omitted. Therefore there is no need to change the outer bound quotes in such cases.

No error after outer quotes are changed per Q003 if inner quotes are still escaped

Possibly related #69 , #77

  1. 'str\'i\'ng' Q003
  2. "str\'i\'ng" No errors

The first line gives Q003 while the second line emits no errors. I took the ultimate aim of Q003 to be to eliminate escaped quotes wherever possible: if I am correct, then I suggest we should emit an additional error to actually do the un-escaping.

I don't have a considered opinion about what that should look like, but if the pump needs priming it could be something like Q004 "Remove unnecessarily escaped quotes."

Friendlier error message

Hi. I was looking to add a linter for string literals to a project of mine and found this one, thanks for writing it.

I find the error message likely a bit too unclear for people however.

Specifically it'll tell someone to "remove bad quotes", when instead it seems clearer to say something of the form "Single quote string literal found, this codebase uses double quoted literals" (or vice versa based on the config).

Are you open to changing it?

Error when using the CLI option

I try use the CLI option but get error.

> flake8 --quotes='"'
Usage: flake8 [options] file file ...

flake8: error: option --quotes: invalid choice: "''" (choose from '"', "'")

Without the option it works fine.

flake8-quotes (0.8.1)
Python 3.5
Windows 10

Multiline quote raise wrong error

As you wrote:
We follow the PEP8 conventions to avoid backslashes in the string. So, no matter what configuration you are using (single or double quotes) these are always valid strings

s = 'double "quotes" wrapped in singles are ignored'
s = "single 'quotes' wrapped in doubles are ignored"

Many lines work fine, except some:

a = '''"Some text"'''

raise error: Q001 Remove bad quotes from multiline string
If I try to replace it:

a = """f"Some text""""

There python error: SyntaxError: EOL while scanning string literal

So, now it could be only:

a = '''"Some text"'''
a = """f"Some text\""""

version = flake8-quotes 3.0.0

Cannot check source on stdin

flake8-quotes fails with an exception when attempting to check source files provided on stdin.

$ git clone [email protected]:zheller/flake8-quotes.git
$ cd flake8-quotes
$ mkvirtualenv flake8-quotes
$ pip install flake8
# This will work (before flake8-quotes is installed):
$ cat flake8_quotes.py | flake8 -
stdin:56:80: E501 line too long (93 > 79 characters)
stdin:59:80: E501 line too long (100 > 79 characters)
stdin:62:80: E501 line too long (84 > 79 characters)
stdin:65:80: E501 line too long (100 > 79 characters)
stdin:81:80: E501 line too long (86 > 79 characters)
# But it will fail with flake8-quotes installed:
$ pip install -e .
(flake8-quotes)[mike@casey:flake8-quotes]$ cat flake8_quotes.py | flake8 -
Traceback (most recent call last):
  File "/home/mike/envs/flake8-quotes/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/mike/envs/flake8-quotes/lib/python3.4/site-packages/flake8/main.py", line 33, in main
    report = flake8_style.check_files()
  File "/home/mike/envs/flake8-quotes/lib/python3.4/site-packages/flake8/engine.py", line 176, in check_files
    return self._retry_serial(self._styleguide.check_files, paths=paths)
  File "/home/mike/envs/flake8-quotes/lib/python3.4/site-packages/flake8/engine.py", line 167, in _retry_serial
    return func(*args, **kwargs)
  File "/home/mike/envs/flake8-quotes/lib/python3.4/site-packages/pep8.py", line 1672, in check_files
    runner(path)
  File "/home/mike/envs/flake8-quotes/lib/python3.4/site-packages/flake8/engine.py", line 121, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File "/home/mike/envs/flake8-quotes/lib/python3.4/site-packages/pep8.py", line 1412, in check_all
    self.check_ast()
  File "/home/mike/envs/flake8-quotes/lib/python3.4/site-packages/pep8.py", line 1359, in check_ast
    for lineno, offset, text, check in checker.run():
  File "/home/mike/build/flake8-quotes/flake8_quotes.py", line 51, in run
    noqa_line_numbers = self.get_noqa_lines(file_contents)
  File "/home/mike/build/flake8-quotes/flake8_quotes.py", line 59, in get_noqa_lines
    tokens = [Token(t) for t in tokenize.generate_tokens(lambda L=iter(file_contents): next(L))]
ValueError: I/O operation on closed file.

Incorrect error message from `Q002` for docstrings

If I put "Docstring" in a file, flake8-quotes complains (as it should), but with the error Q002 Single quote docstring found but double quotes preferred. This is incorrect, as they are double quotes, just not triple.

Allow same quotation style for strings in parentheses?

Trying to make flake8 enforce consistent quotation style for me, I've stumbled upon some case I'm not sure how to deal with:

message = (
    "Please check your email for the verification code. "
    "If you didn't receive it, you can request another one "
    "in {seconds} seconds."
).format(seconds=seconds)

While the convention in that project is to strongly prefer single quotes, the second line suggests to use double ones to avoid backslashes (consistently with PEP8 recommendations). And I feel that it would be significantly better to have consistent quotation style for the whole block, rather than mix different styles.

Of course, I can slap a bunch of # noqa: Q000's but I think it would be very ugly.

I believe flake8-quotes should merge such strings - given that they all follow the same quoting style - into one prior to applying any checks. If the e.g. doubly-quoted string has a piece with has apostrophe in it, let it be. What do you think?

Incompatible with flake8 version 3

Execute the following, under either Python 2 or 3:

virtualenv env
source env/bin/activate
pip install --upgrade pip
pip install flake8-quotes
flake8

Or, execute the following under Python 3:

python -m venv env
source env/bin/activate
pip install --upgrade pip
pip install flake8-quotes
flake8

Either way, an error like the following will result:

(env) [ichimonji10@beech:tmp]$ flake8 .
Traceback (most recent call last):
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/plugins/manager.py", line 159, in load_plugin
    self._load(verify_requirements)
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/plugins/manager.py", line 137, in _load
    self._plugin = resolve()
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8_quotes/__init__.py", line 5, in <module>
    from flake8.engine import pep8
ImportError: No module named 'flake8.engine'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ichimonji10/tmp/env/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/main/application.py", line 299, in run
    self._run(argv)
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/main/application.py", line 285, in _run
    self.initialize(argv)
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/main/application.py", line 275, in initialize
    self.find_plugins()
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/main/application.py", line 143, in find_plugins
    self.check_plugins.load_plugins()
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/plugins/manager.py", line 369, in load_plugins
    plugins = list(self.manager.map(load_plugin))
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/plugins/manager.py", line 261, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/plugins/manager.py", line 367, in load_plugin
    return plugin.load_plugin()
  File "/home/ichimonji10/tmp/env/lib/python3.5/site-packages/flake8/plugins/manager.py", line 167, in load_plugin
    raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "flake8_quotes" due to No module named 'flake8.engine'.

For the record, here's the output of pip freeze:

flake8==3.0.0
flake8-quotes==0.7.0
mccabe==0.5.0
pycodestyle==2.0.0
pyflakes==1.2.3

Support variable docstrings

While not official, many documentation generators, e.g. Sphinx, pdoc, epydoc, PyCharm, etc., recognize docstrings after variables.

flake8-quotes however classifies these as multi-line strings, so when using single quotes for multi-line strings and double quotes for docstrings, I get a bunch of false positives.

Example:

class Foo:
    """Class docsting."""

    def __init__(self):
        """Constructor docstring."""
        self.var = '''
            multiline string
        '''
        """var docstring."""

version 0.10 reports error for every single docstring

flake8-quotes version 0.10 reports error Q000 for every single Python docstring everywhere. For example:

flake8 - <<EOF
> """Print hello world."""
> print('Hello, world!')
> EOF
stdin:1:1: Q000 Remove bad quotes.

Add a rule to prevent unnessary \' in single-quoted strings

PEP-8 states:

When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability.

Therefore 'isn\'t' should be rewritten as "isn't", but flake8-quotes currently does not recognize the first form as an error. I'd like to suggest adding it.

IndentationError while checking doctest's in the sphinx docs

Steps to reproduce:

  1. install the Diofant from sources
  2. install flake8-quotes
  3. run flake8-rst docs/tutorial/polys.rst

I got the following traceback:

Traceback (most recent call last):
  File "/home/sk/venv/dev/bin/flake8-rst", line 10, in <module>
    sys.exit(main())
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8_rst/cli.py", line 16, in main
    app.run(argv)
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8/main/application.py", line 393, in run
    self._run(argv)
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8/main/application.py", line 381, in _run
    self.run_checks()
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8/main/application.py", line 300, in run_checks
    self.file_checker_manager.run()
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8/checker.py", line 331, in run
    self.run_serial()
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8/checker.py", line 315, in run_serial
    checker.run_checks()
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8/checker.py", line 598, in run_checks
    self.run_ast_checks()
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8/checker.py", line 502, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8_quotes/__init__.py", line 169, in run
    noqa_line_numbers = self.get_noqa_lines(file_contents)
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8_quotes/__init__.py", line 177, in get_noqa_lines
    tokens = [Token(t) for t in tokenize.generate_tokens(lambda L=iter(file_contents): next(L))]
  File "/home/sk/venv/dev/lib/python3.7/site-packages/flake8_quotes/__init__.py", line 177, in <listcomp>
    tokens = [Token(t) for t in tokenize.generate_tokens(lambda L=iter(file_contents): next(L))]
  File "/usr/lib/python3.7/tokenize.py", line 572, in _tokenize
    ("<tokenize>", lnum, pos, line))
  File "<tokenize>", line 118
    ⎛ 2    ⎞
    ^
IndentationError: unindent does not match any outer indentation level

flake8 3.5+ support

Right now the default flake8 that will be used in the next version of Ubuntu GNU/Linux (Ubuntu 18.04) will be 3.5. Similarly, the flake8 in the "buster" / testing flavour of Debian GNU/Linux is at 3.5 - that will be the next version of Debian, to be released at some point.

And yet the requirements-dev lists the required flake8 is '<3.4.0,>=3.3.0'

Especially given an expressed interest in incorporating flake8-quotes into Debian/Ubuntu ( Debian RFP# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=887115 ), it will be worthwhile to expand to support the version of flake8 actually present in the next version of Debian/Ubuntu.

If there's nothing to add to add this support...it might be a matter of just changing requirements-dev.txt

Error: Couldn't install: flake8-quotes 0.2.2

$ ./bin/buildout 
Develop: '/home/user/sites/brasil.gov.integracaocaldav/.'
Unused options for buildout: 'package-min-coverage'.
Updating instance.
Updating test.
Installing code-analysis.
Getting distribution for 'flake8-quotes'.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1712, in main
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1716, in <lambda>
  File "/home/user/pythons/python279/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/home/user/pythons/python279/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/home/user/pythons/python279/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 211, in run
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 427, in easy_install
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 476, in install_item
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 655, in install_eggs
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 930, in build_and_install
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 919, in run_setup
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/sandbox.py", line 62, in run_setup
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/sandbox.py", line 105, in run
  File "/home/user/cache-python/eggs/setuptools-0.6c11-py2.7.egg/setuptools/sandbox.py", line 64, in <lambda>
  File "setup.py", line 3, in <module>
    from setuptools import find_packages
  File "/tmp/easy_install-7uVzSE/flake8-quotes-0.2.2/flake8_quotes.py", line 3, in <module>
ImportError: No module named pep8
An error occurred when trying to install flake8-quotes 0.2.2. Look above this message for any errors that were output by easy_install.
While:
  Installing code-analysis.
  Getting distribution for 'flake8-quotes'.
Error: Couldn't install: flake8-quotes 0.2.2

tox 2.5+ support

Same as #64 only for tox. requirements-dev.txt lists tox versions tox<2.4.0,>=2.3.1 - but the current version of tox in even Debian Stable is 2.5

Document all the validation codes in the README

The README currently says:

This package adds one flake8 warning Q0.

This is misleading, it looks like it currently defines four warnings which can all be enabled or disabled with the partial code Q0:

  • Q000 Remove bad quotes
  • Q001 Remove bad quotes from multiline string
  • Q002 Remove bad quotes from docstring
  • Q003 Change outer quotes to avoid escaping inner quotes

Support for the use case to enforce single-line strings, but not multiline strings

In our projects, we are trying to enforce always using ' for single line strings and flake8-quotes is perfect for that. However, for multiline strings, we use " for docstrings and ' for regular strings. Right now, they single-line strings and multiline strings emit the same warning, so we can't just ignore the latter. Also, --multiline-quotes allows configurability for that, but it's either ' or ", so in our project we can't use flake8-quotes at the moment. I think a good first step is to emit different errors for single-line and multiline. An optional next step is to have separate configurations for quotes for docstrings and regular multiline strings.

Incompatible with flake8 version 3

There is a beta version of flake8 version 3, which doesn't use config_options anymore so I get the following error:

Traceback (most recent call last):
  File "/home/xzise/.pyenv/versions/3.5.1/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 293, in run
    self._run(argv)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 279, in _run
    self.initialize(argv)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 270, in initialize
    self.register_plugin_options()
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/main/application.py", line 150, in register_plugin_options
    self.check_plugins.register_options(self.option_manager)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 451, in register_options
    list(self.manager.map(register_and_enable))
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 261, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 447, in register_and_enable
    call_register_options(plugin)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 357, in generated_function
    return method(optmanager, *args, **kwargs)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8/plugins/manager.py", line 207, in register_options
    add_options(optmanager)
  File "/home/xzise/.pyenv/versions/3.5.1/lib/python3.5/site-packages/flake8_quotes/__init__.py", line 38, in add_options
    parser.config_options.extend(['quotes', 'inline-quotes'])

More information:

Ignrones print statements

setup.cfg

[flake8]
inline-quotes = double

My ocde:

print('success - s3.upload_file')

Run

flake8

Expected - Error.
Result - no error show

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.