-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update README - Rename PLU100 -> PLU001 - Fix bug causing two blocks of blank lines with a comment between them to count as a single block - Rename test case files - Properly exclude test case files from linting - Remove unused config files - And more
- Loading branch information
Showing
21 changed files
with
206 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ | |
}, | ||
"MD013": { | ||
"line_length": 88 | ||
} | ||
}, | ||
"MD014": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,66 @@ | ||
# Flake8-plus | ||
|
||
Flake8-plus is a plugin for [Flake8](https://github.com/PyCQA/flake8) that detects | ||
incorrect amounts of vertical whitespace before the first toplevel `import` statement. | ||
By default, the plugin issues a warning if there are blank lines immediately preceding | ||
the first toplevel `import`. The plugin can be configured to expect any number of blank | ||
lines. | ||
|
||
## Installation | ||
|
||
Flake8-plus can be installed from PyPI using `pip`: | ||
|
||
```shell | ||
$ pip install flake8-plus | ||
``` | ||
|
||
You can verify that it has been installed as follows (the version numbers you see may | ||
vary): | ||
|
||
```shell | ||
$ flake8 --version | ||
5.0.4 (flake8-plus: 0.1.0, mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0) | ||
``` | ||
|
||
## Configuration | ||
|
||
You can set the required number of blank lines before the first `import`. This can be | ||
done from the command line: | ||
|
||
```shell | ||
$ flake8 --blanks-before-imports 1 | ||
``` | ||
|
||
Or from one of the `setup.cfg`, `tox.ini`, or `.flake8` files: | ||
|
||
```ini | ||
[flake8] | ||
blanks-before-imports=1 | ||
``` | ||
|
||
## Why no blank lines? | ||
|
||
Neither Black, Flake8 nor Pylint enforces a specific number of blank lines preceding the | ||
first `import` and consequently there seems to be no consensus or standard. The table | ||
below shows the frequency of the number of blank lines before the first toplevel | ||
`import` statement in the code bases for [Black](https://github.com/psf/black), | ||
[Flake8](https://github.com/PyCQA/flake8) and [Pylint](https://github.com/PyCQA/pylint) | ||
(as of October 2022). | ||
|
||
| Package | Total files | 0 blanks | 1 blank | 2 blanks | Folder | | ||
| ------- | ----------: | -------: | ------: | -------: | ------------- | | ||
| Black | 33 | 21 | 12 | 0 | `src` | | ||
| Flake8 | 32 | 32 | 0 | 0 | `src/flake8/` | | ||
| Pylint | 177 | 3 | 170 | 4 | `pylint` | | ||
|
||
Clearly, there is no real consensus. Black seems undecided, Flake8 consistently uses 0 | ||
blanks, and Pylint seems to prefer 1 blank line. However, it's worth noting that the | ||
Pylint code does not consistently include module docstrings (thereby breaking | ||
`pylint(missing-module-docstring)`). For that reason, and also because this is a Flake8 | ||
plugin, the plugin follows the style of Flake8 as the default. | ||
|
||
## Reported problems | ||
|
||
| Code | Description | | ||
| ------ | ------------------------------------------------------- | | ||
| PLU001 | "expected {} blank lines before first import, found {}" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
[ | ||
{ | ||
"filename": "comments_2_blanks_comment_1_blank.py", | ||
"cases": [ | ||
{ | ||
"blanks_expected": 0, | ||
"problems": [{ "line": 8, "col": 1, "blanks_before": 1 }] | ||
}, | ||
{ | ||
"blanks_expected": 1, | ||
"problems": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"filename": "docstring_1_blank.py", | ||
"cases": [ | ||
{ | ||
"blanks_expected": 0, | ||
"problems": [{ "line": 3, "col": 1, "blanks_before": 1 }] | ||
}, | ||
{ | ||
"blanks_expected": 1, | ||
"problems": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"filename": "docstring_2_blanks_comment_1_blank.py", | ||
"cases": [ | ||
{ | ||
"blanks_expected": 0, | ||
"problems": [{ "line": 6, "col": 1, "blanks_before": 1 }] | ||
}, | ||
{ | ||
"blanks_expected": 1, | ||
"problems": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"filename": "docstring_constant_1_blank.py", | ||
"cases": [ | ||
{ | ||
"blanks_expected": 0, | ||
"problems": [{ "line": 4, "col": 1, "blanks_before": 1 }] | ||
}, | ||
{ | ||
"blanks_expected": 1, | ||
"problems": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"filename": "docstring.py", | ||
"cases": [ | ||
{ | ||
"blanks_expected": 0, | ||
"problems": [] | ||
}, | ||
{ | ||
"blanks_expected": 1, | ||
"problems": [{ "line": 2, "col": 1, "blanks_before": 0 }] | ||
} | ||
] | ||
}, | ||
{ | ||
"filename": "multiline_docstring_1_blank.py", | ||
"cases": [ | ||
{ | ||
"blanks_expected": 0, | ||
"problems": [{ "line": 7, "col": 1, "blanks_before": 1 }] | ||
}, | ||
{ | ||
"blanks_expected": 1, | ||
"problems": [] | ||
} | ||
] | ||
} | ||
] |
10 changes: 10 additions & 0 deletions
10
tests/case_files/plu001/comments_2_blanks_comment_1_blank.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Comment 1 | ||
# Comment 2 | ||
# Comment 3 | ||
|
||
|
||
# pylint: disable=duplicate-code | ||
|
||
from __future__ import annotations | ||
|
||
import collections |
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
tests/case_files/plu001/docstring_2_blanks_comment_1_blank.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""Docstring.""" | ||
|
||
|
||
# pylint: disable=duplicate-code | ||
|
||
from __future__ import annotations | ||
|
||
import collections |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Docstring. | ||
Is this blank? | ||
""" | ||
|
||
import ast |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.