flake8-literal is a Flake8 plugin designed to enforce consistent styling of string literals in Python code. It validates inline literals, multiline literals, and docstrings for quote usage (single or double quotes). Additionally, it includes checks for raw string usage, preventing unnecessary raw strings and enforcing their use when needed to avoid escaped backslashes. The current version is 1.5.0, and it is actively maintained.
pip install flake8-literalNo compatibility data collected yet for this library.
Install flake8-literal and then run `flake8` on your Python code. The plugin's checks will automatically be included. Configuration options can be specified in a `flake8` configuration file (e.g., `setup.cfg`, `pyproject.toml`, or `.flake8`) under the `[flake8]` section, or via command-line arguments.
Configure `flake8-literal` options (e.g., `literal-inline-quotes`) in your `setup.cfg` or `.flake8` file under the `[flake8]` section, or pass them as `--literal-inline-quotes=double` arguments to the `flake8` command.
Ensure `re` functions are called directly with raw string literals for `flake8-literal` to apply its raw string regex checks, or be aware that indirect assignments will bypass this specific check.
Always install `flake8` and its plugins within the same Python environment. If encountering unexpected behavior, check the `flake8` and `flake8-literal` documentation for any specific version compatibility notes. Use `pip install --upgrade flake8 flake8-literal` to ensure you have recent, compatible versions.
Change the string literal to use single quotes (e.g., `x = 'hello'`) or configure `flake8-literal` to allow or prefer double quotes by setting `literal-inline-quotes = double` in your flake8 configuration file (e.g., `.flake8`, `setup.cfg`).
Remove the `r` prefix from the string literal (e.g., `x = 'path'` instead of `x = r'path'` if 'path' contains no backslashes).
Add an `r` prefix to the string literal and remove the redundant backslash escapes (e.g., `re.compile(r'\d+')` instead of `re.compile('\\d+')`).First, ensure `flake8-literal` is installed via `pip install flake8-literal`. Then, check your Flake8 configuration file (e.g., `.flake8`, `setup.cfg`, `pyproject.toml`) to ensure `LIT` error codes are not ignored (e.g., remove `LIT` from `ignore = ...`) or explicitly select them (e.g., `select = E,F,W,LIT`).