A Flake8 plugin to ensure an expression can be written in one line without exceeding the maximum length limit
Project description
A Flake8 plugin to ensure an expression can be written in one line without exceeding the maximum length (160 characters by default) limit.
Installation
Install from pip with:
pip install flake8-fill-one-line
Reported errors
Code |
Rule |
---|---|
FOL001 |
import statement can be written in one line |
FOL002 |
function call can be written in one line |
FOL003 |
assignment can be written in one line |
FOL004 |
return statement can be written in one line |
FOL005 |
function definition can be written in one line |
FOL006 |
with statement can be written in one line |
Used options
max_line_length - option from Flake8, length limit for line
skip-std-names - ignore tuple(), list(), set(), dict() calls (used by default)
skip-multiline-arguments - ignore function calls with arguments on multiple lines (used by default)
Examples
Imports:
# wrong:
import sys, \
argparse
from random import randint as rand_int, \
sample, choice as \
random_choice
# right:
import sys, argparse
from random import randint as rand_int, sample, choice as random_choice
Calls and assignments
# wrong:
f(1, 2, 3,
4, 5, 6, 7,
8, 9)
# right:
f(1, 2, 3, 4, 5, 6, 7, 8, 9)
# wrong:
some_var = foo(1,
a=3,
b=42)
# right:
some_var = foo(1, a=3, b=42)
# wrong:
def f(a: int, b: int) -> int:
return f1(a,
b,
a + b)
# right:
def f(a: int, b: int) -> int:
return f1(a, b, a + b)
# wrong:
def foo(a: int, b: int):
return a - b * 3 if \
b < 4 \
else foo(a - 1, b + 1)
# right:
def foo(a: int, b: int):
return a - b * 3 if b < 4 else foo(a - 1, b + 1)
Function definitions
# wrong
def f(a,
b,
c):
return a + b * c
# right:
def f(a, b, c):
return a + b * c
# wrong
def f2(
a: str,
b: tuple, *some_args,
**kwargs_name
) -> str:
pass
# right:
def f2(a: str, b: tuple, *some_args, **kwargs_name) -> str:
pass
With statements
# wrong:
with open("some_file.txt") as \
f:
f.read()
# right:
with open("some_file.txt") as f:
f.read()
# wrong:
with open("f1.txt") as f1, \
open("f2.txt", "w") as f2:
f2.write(f1.read())
# right:
with open("f1.txt") as f1, open("f2.txt", "w") as f2:
f2.write(f1.read())
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
Hashes for flake8-fill-one-line-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29adba2beacb585307133d63e99bf21dfda06f8852b6599ae3ca08ac94d8eb91 |
|
MD5 | 6e94e8e3c7948111cc1c565eb808b59e |
|
BLAKE2b-256 | 60daeaded1135e3f712ba854f5e00cf04c47a1cbfaf3869ee39bc9e2128f2559 |