Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello all yapf founders!
I have some new features I want to share with the yapf community.
This is also a response to issue #194 and issue #346.
The alignment feature added is referred to the yapf function _AlignTrailingComments(final_lines).
The knobs
The main functions for all the knobs are added in reformatter.py.
knob: ALIGN_ARGUMENT_ASSIGNMENT
This is an option to align the assignment operators of each block inside the argument list of a function call or a function definition.
The condition : it is only effective if all arguments inside the argument list are placed on separate lines.
The case when the typed argument name is too long that it has newlines, we can increase the column limit, otherwise it will be aligned with the last line of the unwrapped typed argument name that has the assignment operator:
New block of arguments starts with new alignment. There are 3 cases featured as an indication for new alignment block:
knob: NEW_ALIGNMENT_AFTER_COMMENTLINE
This option is made under the consideration that some programmers may prefer to remain the alignment with comment lines inside.
Preparations
To make the alignment functions possible, some other changes are made to other files.
subtype_assigner.py: a change is made to include the subtype TYPED_NAME_ARG_LIST to all tokens inside typed argument name. This is to recognize all tokens before '=' of very long typed name in arguments with typed names, e.g., a typed argument as below:
format_token.py: necessary boolean functions are added, is_argassign, is_argname, is_argname_start.
Finally
In the end, the knobs are added into the style.py and tests for each one are also updated in yapftests folder.