77[ ![ black] ( https://img.shields.io/badge/code%20style-black-000000.svg )] ( https://github.com/psf/black )
88
99Flake8-plus is a plugin for [ Flake8] ( https://github.com/PyCQA/flake8 ) that detects
10- incorrect amounts of vertical whitespace before the first toplevel ` import ` statement.
11- By default, the plugin issues a warning if there are blank lines immediately preceding
12- the first toplevel ` import ` . The plugin can be configured to expect any number of blank
13- lines .
10+ incorrect amounts of vertical whitespace before the first toplevel ` import ` statement
11+ and before ` return ` statements. The plugin can be configured to expect any number of
12+ blank lines. By default, the plugin expects no blank lines before both ` import ` and
13+ ` return ` .
1414
1515## Installation
1616
@@ -30,28 +30,32 @@ $ flake8 --version
3030
3131## Configuration
3232
33- You can set the required number of blank lines before the first ` import ` . This can be
34- done from the command line:
33+ You can set the required number of blank lines before the first ` import ` as well as the
34+ number of blank lines required before a ` return ` . This can be done from the command
35+ line:
3536
3637``` shell
37- $ flake8 --blanks-before-imports 1
38+ $ flake8 --blanks-before-imports 1 --blanks-before-return 1
3839```
3940
4041Or from one of the ` setup.cfg ` , ` tox.ini ` , or ` .flake8 ` files:
4142
4243``` ini
4344[flake8]
4445blanks-before-imports =1
46+ blanks-before-return =1
4547```
4648
4749## Why no blank lines?
4850
49- Neither Black, Flake8 nor Pylint enforces a specific number of blank lines preceding the
50- first ` import ` and consequently there seems to be no consensus or standard. The table
51- below shows the frequency of the number of blank lines before the first toplevel
52- ` import ` statement in the code bases for [ Black] ( https://github.com/psf/black ) ,
53- [ Flake8] ( https://github.com/PyCQA/flake8 ) and [ Pylint] ( https://github.com/PyCQA/pylint )
54- (as of October 2022).
51+ ### Before ` import `
52+
53+ Neither [ Black] ( https://github.com/psf/black ) , [ Flake8] ( https://github.com/PyCQA/flake8 )
54+ nor [ Pylint] ( https://github.com/PyCQA/pylint ) enforces a specific number of blank lines
55+ preceding the first ` import ` and consequently there seems to be no consensus or
56+ standard. The table below shows the frequency of the number of blank lines before the
57+ first toplevel ` import ` statement in the code bases for Black, Flake8 and Pylint (as of
58+ October 2022).
5559
5660| Package | Total files | 0 blanks | 1 blank | 2 blanks | Folder |
5761| ------- | ----------: | -------: | ------: | -------: | ------------- |
@@ -65,8 +69,26 @@ Pylint code does not consistently include module docstrings (thereby breaking
6569` pylint(missing-module-docstring) ` ). For that reason, and also because this is a Flake8
6670plugin, the plugin follows the style of Flake8 as the default.
6771
72+ ### Before ` return `
73+
74+ Neither Black, Flake8 nor Pylint enforces a specific number of blank lines preceding
75+ ` return ` . However, they all use zero blank lines more frequently than they use any
76+ other number of blanks. The table below shows the frequency of the number of blank
77+ lines before a ` return ` statement in the code bases for Black, Flake8 and Pylint (as of
78+ October 2022).
79+
80+ | Package | Total ` return ` s | 0 blanks | 1 blank | 2 blanks | Folder |
81+ | ------- | --------------: | -------: | ------: | -------: | ------------- |
82+ | Black | 618 | 544 | 74 | 0 | ` src ` |
83+ | Flake8 | 174 | 155 | 19 | 0 | ` src/flake8/ ` |
84+ | Pylint | 1941 | 1852 | 89 | 0 | ` pylint ` |
85+
86+ Since zero blank lines is the style used most frequently, Flake8-plus uses that as that
87+ as the default.
88+
6889## Reported problems
6990
70- | Code | Description |
71- | ------ | ------------------------------------------------------- |
72- | PLU001 | "expected {} blank lines before first import, found {}" |
91+ | Code | Description |
92+ | ------ | ----------------------------------------------------------- |
93+ | PLU001 | "expected {} blank lines before first import, found {}" |
94+ | PLU002 | "expected {} blank lines before return statement, found {}" |
0 commit comments