Flake8 string literal validation
Low maintenance activity. Last release 17 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install flake8-literalflake8-literal
flake8 plugin to validate string literals.
This plugin is used to enforce consistent styling of string literals, it recognizes inline literals, multline literals, and docstrings.
Quote Usage
You can choose between single or double quotes for each type of string, and the plugin will enforce consistent usage.
If the avoid-escape feature is on (default),
it will enforce using the opposite quote type when doing so
will avoid the use of escaped quotes.
It also recognizes continuation strings and will enforce a consistent quote style for the entire set when possible.
Raw Strings
This plugin checks the usage of raw strings, preventing unnecessary use of raw strings, and requiring raw strings when doing so will avoid an escaped backslash.
Because raw strings are commonly used in regular expression patterns, otherwise unnecessary raw strings are allowed by default when used as a regular expression pattern. There is an option to avoid raw strings in regular expression patterns, or to require them regardless of the presence of escapes. Note that this feature only works when using string literals directly in calls to re functions, and the functions must be called in the manner that they are imported. e.g.
from re import compile as regex_compile
x = regex_compile(r'this does not need to be raw')
would be acceptable, but
import re
pattern = r'this does not need to be raw'
x = re.compile(pattern)
or
import re
regex_compile = re.compile
y = regex_compile(r'this does not need to be raw')
would not.
Planned Features
- Enforcing multiline string usage
- String concatenation
- Format string usage
Installation
Standard python package installation:
pip install flake8-literal
Options
literal-inline-quotes
: Quote to use for inline string literals,
choices: single, double (default: single)
literal-multiline-quotes
: Quote to use for multiline string literals,
choices: single, double (default: single)
literal-docstring-quotes
: Quote to use for docstrings,
choices: single, double (default: double)