# [flake8-literal](https://github.com/plinss/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.
### 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`)
`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-re-pattern-raw`
: Control usage of raw string literals in regular expression patterns,
choices `avoid`, `allow`, `always` (default: `allow`)
`literal-include-name`
: Include plugin name in messages
`literal-no-include-name`
: Do not include plugin name in messages (default setting)
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 double 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
| LIT101 | Remove raw prefix when not using escapes
| LIT102 | Use raw prefix to avoid escaped slash
| LIT103 | Use raw prefix for re pattern
## Examples
```
x = "value" <-- LIT001
x = 'aren\'t escapes great?' <-- LIT011
x = "can\'t stop escaping" <-- LIT013
x = ('one' <-- LIT015
"o'clock")
x = r'no need to be raw' <-- LIT101
x = '\\windows\\path' <-- LIT102
x = re.compile(r'pattern') <-- (no error when literal-re-pattern-raw set to `allow` or `always`)
x = re.compile('pattern') <-- LIT103 (when literal-re-pattern-raw set to `always`)
```
Raw data
{
"_id": null,
"home_page": "",
"name": "flake8-literal",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "flake8,string,literal",
"author": "",
"author_email": "Peter Linss <pypi@linss.com>",
"download_url": "https://files.pythonhosted.org/packages/8d/3b/09cfdb3185986a761c535b87a3af998119ee452eedab18de0f1b1cfb8f32/flake8-literal-1.4.0.tar.gz",
"platform": null,
"description": "# [flake8-literal](https://github.com/plinss/flake8-literal)\n\nflake8 plugin to validate string literals.\n\nThis plugin is used to enforce consistent styling of string literals,\nit recognizes inline literals, \nmultline literals,\nand docstrings.\n\n### Quote Usage\n\nYou can choose between single or double quotes for each type of string,\nand the plugin will enforce consistent usage.\n\nIf the `avoid-escape` feature is on (default),\nit will enforce using the opposite quote type when doing so\nwill avoid the use of escaped quotes.\n\nIt also recognizes continuation strings \nand will enforce a consistent quote style for the entire set \nwhen possible.\n\n### Raw Strings\n\nThis plugin checks the usage of raw strings,\npreventing unnecessary use of raw strings, \nand requiring raw strings when doing so will avoid an escaped backslash.\n\nBecause raw strings are commonly used in regular expression patterns,\notherwise unnecessary raw strings are allowed by default \nwhen used as a regular expression pattern.\nThere is an option to avoid raw strings in regular expression patterns,\nor to require them regardless of the presence of escapes.\nNote that this feature only works when using string literals directly\nin calls to re functions,\nand the functions must be called in the manner that they are imported. \ne.g.\n```\nfrom re import compile as regex_compile\nx = regex_compile(r'this does not need to be raw')\n```\nwould be acceptable, but\n```\nimport re\npattern = r'this does not need to be raw'\nx = re.compile(pattern)\n```\nor\n```\nimport re\nregex_compile = re.compile\ny = regex_compile(r'this does not need to be raw')\n```\nwould not.\n\n### Planned Features\n\n* Enforcing multiline string usage\n* String concatenation \n* Format string usage\n\n\n## Installation\n\nStandard python package installation:\n\n pip install flake8-literal\n\n\n## Options\n\n`literal-inline-quotes`\n: Quote to use for inline string literals, \nchoices: `single`, `double` (default: `single`)\n\n`literal-multiline-quotes`\n: Quote to use for multiline string literals, \nchoices: `single`, `double` (default: `single`)\n\n`literal-docstring-quotes`\n: Quote to use for docstrings, \nchoices: `single`, `double` (default: `double`)\n\n`literal-avoid-escape`\n: Avoid escapes in inline string literals when possible (enabled by default)\n\n`literal-no-avoid-escape`\n: Disable escape avoidance in inline string literals\n\n`literal-re-pattern-raw`\n: Control usage of raw string literals in regular expression patterns,\nchoices `avoid`, `allow`, `always` (default: `allow`)\n\n`literal-include-name`\n: Include plugin name in messages\n\n`literal-no-include-name`\n: Do not include plugin name in messages (default setting)\n\nAll options may be specified on the command line with a `--` prefix,\nor can be placed in your flake8 config file.\n\n\n## Error Codes\n\n| Code | Message |\n|--------|---------|\n| LIT001 | Use single quotes for string\n| LIT002 | Use double quotes for string\n| LIT003 | Use single quotes for multiline string\n| LIT004 | Use double quotes for multiline string\n| LIT005 | Use single quotes for docstring\n| LIT006 | Use double quotes for docstring\n| LIT007 | Use triple single quotes for docstring\n| LIT008 | Use triple double quotes for docstring\n| LIT011 | Use double quotes for string to avoid escaped single quote\n| LIT012 | Use single quotes for string to avoid escaped double quote\n| LIT013 | Escaped single quote is not necessary\n| LIT014 | Escaped double quote is not necessary\n| LIT015 | Use double quotes for continuation strings to match\n| LIT016 | Use single quotes for continuation strings to match\n| LIT101 | Remove raw prefix when not using escapes\n| LIT102 | Use raw prefix to avoid escaped slash\n| LIT103 | Use raw prefix for re pattern\n\n\n## Examples\n\n```\nx = \"value\" <-- LIT001\nx = 'aren\\'t escapes great?' <-- LIT011\nx = \"can\\'t stop escaping\" <-- LIT013\nx = ('one' <-- LIT015\n \"o'clock\")\nx = r'no need to be raw' <-- LIT101\nx = '\\\\windows\\\\path' <-- LIT102\nx = re.compile(r'pattern') <-- (no error when literal-re-pattern-raw set to `allow` or `always`)\nx = re.compile('pattern') <-- LIT103 (when literal-re-pattern-raw set to `always`)\n```\n",
"bugtrack_url": null,
"license": "GNU Lesser General Public License v3",
"summary": "Flake8 string literal validation",
"version": "1.4.0",
"project_urls": {
"homepage": "https://github.com/plinss/flake8-literal"
},
"split_keywords": [
"flake8",
"string",
"literal"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f1422134712d48cb53e0c3374424dd2365837462be966e899c302ab3b1b10e47",
"md5": "2538babc42ee369a3b877e1e269ce6d6",
"sha256": "8672260cc05f47fbf278007ba370a6fa7665d226e7349938350d466dd56a63a3"
},
"downloads": -1,
"filename": "flake8_literal-1.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2538babc42ee369a3b877e1e269ce6d6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9855,
"upload_time": "2024-01-06T03:29:02",
"upload_time_iso_8601": "2024-01-06T03:29:02.943464Z",
"url": "https://files.pythonhosted.org/packages/f1/42/2134712d48cb53e0c3374424dd2365837462be966e899c302ab3b1b10e47/flake8_literal-1.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8d3b09cfdb3185986a761c535b87a3af998119ee452eedab18de0f1b1cfb8f32",
"md5": "391db3c52d93081e4af0ed12f0845765",
"sha256": "dbbcac7b871b8b29e1695701a983f9fecb1b1a421911d8bc75fa6343bdca1221"
},
"downloads": -1,
"filename": "flake8-literal-1.4.0.tar.gz",
"has_sig": false,
"md5_digest": "391db3c52d93081e4af0ed12f0845765",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 12957,
"upload_time": "2024-01-06T03:29:04",
"upload_time_iso_8601": "2024-01-06T03:29:04.664446Z",
"url": "https://files.pythonhosted.org/packages/8d/3b/09cfdb3185986a761c535b87a3af998119ee452eedab18de0f1b1cfb8f32/flake8-literal-1.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-06 03:29:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "plinss",
"github_project": "flake8-literal",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "flake8-literal"
}