We're using flake8 and pylint to do our code style checks on a project.
But the problem is, none of those do any checks for how lines are split. Since consistency is nice in a project it looks really weird that we find
foo = long_function_name(var_one, var_two,
var_three, var_four)
foo = long_function_name(
var_one,
var_two,
var_three,
var_four)
foo = long_function_name(
var_one,
var_two,
var_three,
var_four
)
foo = {
a,
b}
foo = {
a,
b,
}
in our codebase. Sometimes different ways of closing a thing is right next to each other like in the example above.
Now is there a checker or a rule for pylint or flake or special checker that would just ensure:
Consistency is key in a clean codebase, and we can't rely on devs to stick to rules if those aren't automatically checked. So I need a checker for the cases mentioned.
You can use wemake-python-styleguide
. It is a set of flake8
plugins with lots of new rules.
To install it run: pip install wemake-python-styleguide
Running: flake8 your_module.py
This is still just a flake8
plugin!
The specific rule you are interested in is consistency.ParametersIndentationViolation
.
Correct code samples:
# Correct:
def my_function(arg1, arg2, arg3) -> None:
return None
print(1, 2, 3, 4, 5, 6)
def my_function(
arg1, arg2, arg3,
) -> None:
return None
print(
1, 2, 3, 4, 5, 6,
)
def my_function(
arg1,
arg2,
arg3,
) -> None:
return None
print(
first_variable,
2,
third_value,
4,
5,
last_item,
)
# Special case:
print('some text', 'description', [
first_variable,
second_variable,
third_variable,
last_item,
], end='')
Incorrect code samples:
call(1,
2,
3)
print(
1, 2,
3,
)
Docs: https://wemake-python-stylegui.de
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With