flake8 plugin to prevent specific hanging indentations
Project description
flake8-hangover
Flake8 plugin to prevent specific hanging indentations (and more).
Installation
pip install flake8-hangover
Errors
| Code | Description |
|---|---|
| FHG001 | Function argument has hanging indentation |
| FHG002 | Function call positional argument has hanging indentation |
| FHG003 | Function call keyword argument has hanging indentation |
| FHG004 | First function argument must be on new line |
Examples
FHG001 Function argument has hanging indentation
# ERROR: Hanging indentation on `extra_param`
def _hello_world(param: pd.DataFrame, other_param: sklearn.base.BaseEstimator,
extra_param: Optional[Dict] = None) -> str:
...
# ERROR: Not hanging indentation, but params are "over indendented" by 2 tabs
# instead of just 1 tab
def _calc_pdp(
df: pd.DataFrame,
estimator: sklearn.base.BaseEstimator,
feature_columns: List[str], pdp_kwarg: Optional[Dict] = None,
) -> List[pdp.PDPIsolate]:
pdp_isolates = []
# OK: Correct indentation
# BUT! It will cause FHG004 error (it's more strict) for `param` argument
def _hello_world(param: pd.DataFrame, other_param: sklearn.base.BaseEstimator,
extra_param: Optional[Dict] = None) -> str:
...
# OK: Best practice
def _hello_world(
param: pd.DataFrame,
other_param: sklearn.base.BaseEstimator,
extra_param: Optional[Dict] = None,
) -> str:
...
FHG002 Function call positional argument has hanging indentation
# ERROR: Hanging indentation on `other_param`
if a != b:
error_message = get_error_message(param,
other_param)
# OK: Correct indentation
if a != b:
error_message = get_error_message(param,
other_param,
)
# OK: Best practice
if a != b:
error_message = get_error_message(
param,
other_param,
)
FHG003
# ERROR: Keyword argument `other_value` has hanging indentation
def foo():
result = my_func(value='name',
other_value='hello')
# Correct indentation, but looks terrible
# TODO: Rule like FHG004 for function calls is not yet implemented
def foo():
result = my_func(value='name',
other_value='hello')
# OK: Best practice
def foo():
result = my_func(
value='name',
other_value='hello',
)
FHG004 First function argument must be on new line
This is more strict rule that requires any function definition with multiline arguments to place first argument on new line.
# ERROR: Positional argument `foo` must be on new line
def test_something(foo, bar,
buzz):
...
# ERROR: Same thing but for keyword argument `foo`
def test_something(foo='Hello',
value='World',
):
return key + value
# OK: Argument `foo` is on new line
def test_something(
foo, bar, buzz,
):
...
# OK: Best practice (but sometimes it's not good looking for over 5 params, for example)
def test_something(
foo,
bar,
buzz,
):
...
TODO: Not yet implemented cases
Hanging indentation in cases with brackets like this is not yet checked by linter:
# Hanging indentation on `World`
my_string = ('Hello '
'World')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flake8-hangover-0.0.3.tar.gz.
File metadata
- Download URL: flake8-hangover-0.0.3.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71056d80d2a7e9ea5ec95e524fe2f160a433b38edafbb6d958a4bbc57aa15562
|
|
| MD5 |
47b98634b1af4e994be4d02e093451c8
|
|
| BLAKE2b-256 |
4280352bd1275a53c994b4785de5af9c71787466e78add555dbbeaf44bb2b95a
|
File details
Details for the file flake8_hangover-0.0.3-py3-none-any.whl.
File metadata
- Download URL: flake8_hangover-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9020975036415cf1515ff07f5cf247124feb6cc481ee04ef43db6acb908ec851
|
|
| MD5 |
5a80712ca9b6491809297a50cfb246a5
|
|
| BLAKE2b-256 |
eb6baf5dd5a901f1b14eacea99bbe5739edb66e3166c86102b3563e5b2dfa2d1
|