Conversation
|
Bump! |
|
+1 |
|
@lizawang this PR is blocked by merge conflicts. |
|
I don't see anything standing out besides resolving merge conflicts. @bwendling. @EeyoreLee , @char101 any thoughts ? |
|
@Spitfire1900 - Thanks for your invitation. I think this feature should be considered cause the feature-request has 42 upvotes. A code review is essential before merging, e.g., the function |
| .. code-block:: python | ||
|
|
||
| fields = | ||
| { |
There was a problem hiding this comment.
This isn't legal Python. The opening bracket should go on the previous line.
| } | ||
|
|
||
| ``NEW_ALIGNMENT_AFTER_COMMENTLINE`` | ||
| Make it optional to start a new alignmetn block for assignment |
| # opening '(' | ||
| _SetUnbreakable(node.children[2]) | ||
| # ':' | ||
| # ':' |
There was a problem hiding this comment.
Probably don't need this change in the commit.
| _STYLE_HELP = dict( | ||
| ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT=textwrap.dedent("""\ | ||
| Align closing bracket with visual indentation."""), | ||
| ALIGN_DICT_COLON=textwrap.dedent("""\ |
There was a problem hiding this comment.
The other two knobs aren't added here?
|
|
||
| def _AlignDictColon(final_lines): | ||
| """Align colons in a dict to the same column""" | ||
| """NOTE One (nested) dict/list is one logical line!""" |
There was a problem hiding this comment.
Add this line as part of the previous docstring.
| prefix = line_tok.formatted_whitespace_prefix | ||
| newline = prefix.startswith('\n') | ||
| if newline: | ||
| # if comments inbetween, save, reset and continue to caluclate new alignment |
There was a problem hiding this comment.
Please reflow comment to 80-columns.
| this_line = line | ||
|
|
||
| line_tokens = this_line.tokens | ||
| for open_index in range(len(line_tokens)): |
| line_tok = line_tokens[open_index] | ||
|
|
||
| # check each time if the detected dict is the dict we aim for | ||
| if line_tok.value == '{' and line_tok.next_token.formatted_whitespace_prefix.startswith( |
There was a problem hiding this comment.
Please put the conditional in parentheses and reformat to 80-columns.
| final_lines_index += 1 | ||
|
|
||
|
|
||
| def _AlignDictColon(final_lines): |
There was a problem hiding this comment.
I know that this is similar to the _AlignTrailingComments function, but it's also much longer. Could you split some of the code out into separate functions to make it more readable?
|
Thanks for reviewing @bwendling 👍 |
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 features added are referred to the yapf function _AlignTrailingComments(final_lines).
The knobs
The main functions for all the knobs are added in reformatter.py.
knob: ALIGN_DICT_COLON
This is an option to align colons inside dictionary.
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.
Finally
In the end, the knobs are added into the style.py and tests for each one are also updated in yapftests folder.