Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cyyc1/flake8-clean-block
A flake8 plugin that enforces a blank line after if/for/while/with/try blocks in Python code
https://github.com/cyyc1/flake8-clean-block
flake8-extension flake8-extensions flake8-plugin flake8-plugins python
Last synced: 3 months ago
JSON representation
A flake8 plugin that enforces a blank line after if/for/while/with/try blocks in Python code
- Host: GitHub
- URL: https://github.com/cyyc1/flake8-clean-block
- Owner: cyyc1
- License: mit
- Created: 2022-10-02T03:29:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-08T21:54:04.000Z (about 2 years ago)
- Last Synced: 2024-07-09T22:32:03.835Z (4 months ago)
- Topics: flake8-extension, flake8-extensions, flake8-plugin, flake8-plugins, python
- Language: Python
- Homepage: https://pypi.org/project/flake8-clean-block/
- Size: 41 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-flake8-extensions - flake8-clean-block - Plugin to enforce a blank line after if/for/while/with/try blocks. (Clean code)
README
# flake8-clean-block
This is a [flake8](https://flake8.pycqa.org/en/latest/) plugin that enforces a blank line after `if`/`for`/`while`/`with`/`try` blocks in Python code.
## Installation
```bash
pip install flake8-clean-block
```## Violation codes
There is one violation code that this plugin reports:
| Code | Description |
| --------- | ------------------------------------------------------ |
| CLB100 | no blank line after the end of an indented block |## Style examples
### _Wrong_
This plugin considers the following styles wrong:
```python
for i in range(5):
print(i)
some_var = 2
``````python
for i in range(5):
print(i)
if k == 2:
print(k)
else:
print("k")
for j in range(5):
print(j)
``````python
for i in range(5): a += i
print(a)
``````python
with open('filename.txt', 'r') as fp:
content = fp.readlines()
print(content)
```### _Correct_
Correspondingly, here are the correct styles, because they are easier to read and less error-prone:
```python
for i in range(5):
print(i)some_var = 2
``````python
for i in range(5):
print(i)if k == 2:
print(k)
else:
print("k")for j in range(5):
print(j)
``````python
for i in range(5): a += iprint(a)
``````python
with open('filename.txt', 'r') as fp:
content = fp.readlines()print(content)
```## Rationale
When two lines belonging to different indentation level are right next to each other, it's difficult to read. Additionally, accidentally hitting the "tab" key on the outer line leads to subtle and hard-to-find bugs (and vice versa).
Therefore, it's better that we add at least one blank line between lines of different indentation levels.