# flake8-multiline-conditionals-comprehensions
[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/tox/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)
[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/pylint/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)
[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/black/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)
[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/flake8/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)
flake8 plugin that works on conditional expressions and comprehension
expressions to enforce each segment to be put on a new line.
## Contents
* [Options](#options)
* [Comprehension Errors](#comprehension-errors)
* [Condition Errors](#condition-errors)
## Options
The flag `--select_mcc2` can be used to select the set of errors
to include. By default, the active errors are MCC200, MCC201, MCC202,
MCC220, MCC221, MCC223.
## Comprehension Errors
### MCC200
A comprehension expression should place each of its generators on a
separate line.
```python
# Bad
[x+y for x in range(10) for y in range(10)]
# Good
[
x + y
for x in range(10)
for y in range(10)
]
```
### MCC201
A multiline comprehension expression should place each of its segments
(map, generator, filter) on a separate line.
```python
# Bad
[x+y for x in range(10)
for y in range(10) if x+y > 5]
# Good
[
x + y
for x in range(10)
for y in range(10)
if x + y > 5
]
```
### MCC202
A comprehension expression should not contain multiple filters.
```python
# Bad
[x for x in range(10) if x % 2 == 0 if x % 3 == 0]
# Good
[x for x in range(10) if x % 2 == x % 3 == 0]
```
### MCC203
A comprehension expression should not span over multiple lines.
```python
# Bad
[x + y
for x in range(10) ]
# Good
[x+y for x in range(10)]
```
### MCC204
A comprehension expression should span over multiple lines.
```python
# Bad
[x for x in range(10)]
# Good
[x
for x in range(10)]
```
## Condition Errors
### MCC220
A multiline conditional expression should place each of its segments
on a separate line.
```python
# Bad
1
if something() else 0
# Good
1
if something()
else 0
```
### MCC221
A conditional expression used for assignment should be surrounded by
parantheses.
```python
# Bad
a = 1 if something() else 0
# Good
a = (1 if something() else 0)
```
### MCC222
A conditional expression should not contain further conditional
expressions.
```python
# Bad
1 if x > 0 else -1 if x < 0 else 0
# Good
if x > 0:
return 1
elif x < 0:
return -1
else:
return 0
```
### MCC223
A conditional expression should not span over multiple lines.
```python
# Bad
1
if something()
else 0
# Good
1 if something() else 0
```
### MCC224
A conditional expression should span over multiple lines.
```python
# Bad
1 if something() else 0
# Good
1
if something()
else 0
```
### MCC225
Conditional expressions should not be used.
Raw data
{
"_id": null,
"home_page": "https://github.com/atollk/flake8-multiline-conditionals-comprehensions",
"name": "flake8-multiline-conditionals-comprehensions",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "flake8,comprehensions,conditional",
"author": "Andreas Tollk\u00f6tter",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/44/3c/782f8e5a96daccb8405ed1013f4d11c2335eda226160e78f1ded7898b69d/flake8-multiline-conditionals-comprehensions-2.0.tar.gz",
"platform": null,
"description": "# flake8-multiline-conditionals-comprehensions\n\n[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/tox/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)\n[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/pylint/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)\n[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/black/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)\n[![Build Status](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/workflows/flake8/badge.svg)](https://github.com/atollk/flake8-multiline-conditionals-comprehensions/actions)\n\n\nflake8 plugin that works on conditional expressions and comprehension \nexpressions to enforce each segment to be put on a new line.\n\n## Contents\n * [Options](#options)\n * [Comprehension Errors](#comprehension-errors)\n * [Condition Errors](#condition-errors)\n\n## Options\nThe flag `--select_mcc2` can be used to select the set of errors\nto include. By default, the active errors are MCC200, MCC201, MCC202,\nMCC220, MCC221, MCC223.\n\n\n## Comprehension Errors\n\n### MCC200\n\nA comprehension expression should place each of its generators on a \nseparate line.\n\n```python\n# Bad\n[x+y for x in range(10) for y in range(10)]\n\n# Good\n[\n x + y\n for x in range(10)\n for y in range(10)\n]\n```\n\n\n### MCC201\n\nA multiline comprehension expression should place each of its segments\n(map, generator, filter) on a separate line.\n\n```python\n# Bad\n[x+y for x in range(10) \nfor y in range(10) if x+y > 5]\n\n# Good\n[\n x + y\n for x in range(10)\n for y in range(10)\n if x + y > 5\n]\n```\n\n\n### MCC202\n\nA comprehension expression should not contain multiple filters.\n\n```python\n# Bad\n[x for x in range(10) if x % 2 == 0 if x % 3 == 0]\n\n# Good\n[x for x in range(10) if x % 2 == x % 3 == 0]\n```\n\n### MCC203\n\nA comprehension expression should not span over multiple lines.\n\n```python\n# Bad\n[x + y \nfor x in range(10) ]\n\n# Good\n[x+y for x in range(10)]\n```\n\n### MCC204\n\nA comprehension expression should span over multiple lines.\n\n```python\n# Bad\n[x for x in range(10)]\n\n# Good\n[x \nfor x in range(10)]\n```\n\n\n\n## Condition Errors\n\n### MCC220\n\nA multiline conditional expression should place each of its segments\non a separate line.\n\n```python\n# Bad\n1 \nif something() else 0\n\n# Good\n1\nif something()\nelse 0\n```\n\n\n### MCC221\n\nA conditional expression used for assignment should be surrounded by\nparantheses.\n\n```python\n# Bad\na = 1 if something() else 0\n\n# Good\na = (1 if something() else 0)\n```\n\n\n### MCC222\n\nA conditional expression should not contain further conditional\nexpressions.\n\n```python\n# Bad\n1 if x > 0 else -1 if x < 0 else 0\n\n# Good\nif x > 0:\n return 1\nelif x < 0:\n return -1\nelse:\n return 0\n```\n\n\n### MCC223\n\nA conditional expression should not span over multiple lines.\n\n```python\n# Bad\n1\nif something()\nelse 0\n\n# Good\n1 if something() else 0\n```\n\n\n### MCC224\n\nA conditional expression should span over multiple lines.\n\n```python\n# Bad\n1 if something() else 0\n\n# Good\n1\nif something()\nelse 0\n```\n\n\n### MCC225\n\nConditional expressions should not be used.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A flake8 plugin to make sure complex conditional expressions and comprehension expressions are split over several lines.",
"version": "2.0",
"project_urls": {
"Homepage": "https://github.com/atollk/flake8-multiline-conditionals-comprehensions"
},
"split_keywords": [
"flake8",
"comprehensions",
"conditional"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cdd88be2af86ab41da877b8caef2ea79958fac68dea4f85b19eba26fd7b3eaf2",
"md5": "ddd5cbed97222a1da466b2b0f4c7071a",
"sha256": "b43fb271d3fbefc40cb44fe80568e4cac6320bb3ea4aceed17c913cd72d19ff7"
},
"downloads": -1,
"filename": "flake8_multiline_conditionals_comprehensions-2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ddd5cbed97222a1da466b2b0f4c7071a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 6230,
"upload_time": "2023-07-14T23:32:47",
"upload_time_iso_8601": "2023-07-14T23:32:47.844128Z",
"url": "https://files.pythonhosted.org/packages/cd/d8/8be2af86ab41da877b8caef2ea79958fac68dea4f85b19eba26fd7b3eaf2/flake8_multiline_conditionals_comprehensions-2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "443c782f8e5a96daccb8405ed1013f4d11c2335eda226160e78f1ded7898b69d",
"md5": "4252cb47e518a043fb9f47df46812ce3",
"sha256": "2cb7274984c0696ce3d8d914f92b0852a2705817142454c3141c8cb66c62119f"
},
"downloads": -1,
"filename": "flake8-multiline-conditionals-comprehensions-2.0.tar.gz",
"has_sig": false,
"md5_digest": "4252cb47e518a043fb9f47df46812ce3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 5086,
"upload_time": "2023-07-14T23:32:49",
"upload_time_iso_8601": "2023-07-14T23:32:49.155156Z",
"url": "https://files.pythonhosted.org/packages/44/3c/782f8e5a96daccb8405ed1013f4d11c2335eda226160e78f1ded7898b69d/flake8-multiline-conditionals-comprehensions-2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-14 23:32:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "atollk",
"github_project": "flake8-multiline-conditionals-comprehensions",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "flake8-multiline-conditionals-comprehensions"
}