I am using black formatter. I have two newlines before and two newlines after function definition. I want one newline before and one newline after function definition.
Can i do it using black config file black --config FILE
. If so,how.
CodePudding user response:
You can not.
By using it, you agree to cede control over minutiae of hand-formatting._
It uses 2 lines to visually distinguish methods from empty lines in code structure. From the docs: Black will allow single empty lines inside functions, [...] It will also insert proper spacing before and after function definitions. It’s one line before and after inner functions and two lines before and after module-level functions and classes.
From: the docs of black.readthedocs.io
Command line options Black has quite a few knobs these days, although Black is opinionated so style configuration options are deliberately limited and rarely added. You can list them by running black --help.
CodePudding user response:
OP here, I ended up using yapf
.
The command looks like:
yapf --style={blank_lines_around_top_level_definition=1} file_name.py
for multiple arguments:
yapf --style={based_on_style=pep8} --style={blank_lines_around_top_level_definition=1} file_name.py
In vscode you can use the yapf
styles like:
"python.formatting.yapfArgs": [
"--style",
"{based_on_style: pep8, blank_lines_around_top_level_definition: 1}"
],