Python allows to use either single or double quotes for strings. I'd like to enforce only single quotes format in my projects.
Is there any specific rule in pylint or an existing pylint plugin to achieve that?
Python allows to use either single or double quotes for strings. I'd like to enforce only single quotes format in my projects.
Is there any specific rule in pylint or an existing pylint plugin to achieve that?
I recently wrote a pylint plugin for this: https://pypi.python.org/pypi/pylint-quotes
You can get it with
pip install pylint-quotes
Then to use it with pylint,
pylint --load-plugins pylint_quotes <module-or-package>
in the .pylintrc
file, you can configure which quotes to use:
# Set the linting for string quotes
string-quote=single
triple-quote=double
docstring-quote=double
I don't know if pylint
can currently do this, but there is an extension for flake8
called flake8-quotes
that does it.
Fast forward to 2023:
Proposed plugin does not work on Pylint >= 3.0.0.
Workaround: www.pylint.org/inconsistent-quotes/
Adds checker to .pylintrc
for quote usage consistency.
Meaning: in same file top level quotes should always be of same type. (double <> single)
© 2022 - 2024 — McMap. All rights reserved.