Skip to main content

Flake8 string literal validation

Project description

flake8-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. You can choose between single or double quotes for each type of string.

If the avoid-escape feature is on (default), it will enforce using the opposite quote type when doing so avoid the use of escaped quotes.

It also recognizes continuation strings and will enforce a consistent quote style for the entire set when possible.

In addition it checks the usage of raw strings, preventing unnecessary use of raw strings, and using raw strings when doing so will avoid an escaped backslash.

More features coming soon.

Installation

Standard python package installation:

pip install flake8-noqa

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)

literal-avoid-escape : Avoid escapes in inline string literals when possible (enabled by default)

literal-no-avoid-escape : Disable escape avoidance in inline string literals

literal-include-name : Include plugin name in messages (default setting)

literal-no-include-name : Remove plugin name from messages

All options may be specified on the command line with a -- prefix, or can be placed in your flake8 config file.

Error Codes

Code Message
LIT001 Use single quotes for string
LIT002 Use double quotes for string
LIT003 Use single quotes for multiline string
LIT004 Use double quotes for multiline string
LIT005 Use single quotes for docstring
LIT006 Use double quotes for docstring
LIT007 Use triple single quotes for docstring
LIT008 Use triple double quotes for docstring
LIT011 Use double quotes for string to avoid escaped single quote
LIT012 Use single quotes for string to avoid escaped single quote
LIT013 Escaped single quote is not necessary
LIT014 Escaped double quote is not necessary
LIT015 Use double quotes for continuation strings to match
LIT016 Use single quotes for continuation strings to match
LIT021 Remove raw prefix when not using escapes
LIT022 Use raw prefix to avoid escaped slash

Examples

x = "value"  <-- LIT001
x = 'aren\'t escapes great?'  <-- LIT010
x = ('one'  <-- LIT012
     "o'clock")
x = r'no need to be raw'  <-- LIT020

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

flake8_literal-1.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file flake8_literal-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: flake8_literal-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for flake8_literal-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 627f737e4917e8875d2ac9df5a2ccfc60e30f137d06c9be8ed6ac8891d70d70a
MD5 2b8e7302b2ac90778ae55770605ffb89
BLAKE2b-256 bc44f9dddc638b1e90fc51335541dc9804c8ff723728f7eabc04dc99570dbd4c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page