Skip to content

Commit

Permalink
Merge 5ab9475 into bbfebc2
Browse files Browse the repository at this point in the history
  • Loading branch information
gpshead committed Dec 20, 2020
2 parents bbfebc2 + 5ab9475 commit fdea4a4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -7,6 +7,7 @@
- Add 'BLANK_LINES_BETWEEN_TOP_LEVEL_IMPORTS_AND_VARIABLES' to support setting
a custom number of blank lines between top-level imports and variable
definitions.
- Ignore end of line `# copybara:` directives when checking line length.
### Fixed
- Exclude directories on Windows.

Expand Down
4 changes: 2 additions & 2 deletions yapf/yapflib/format_decision_state.py
Expand Up @@ -741,8 +741,8 @@ def MoveStateToNextToken(self):

# Calculate the penalty for overflowing the column limit.
penalty = 0
if (not current.is_pylint_comment and not current.is_pytype_comment and
self.column > self.column_limit):
if (not current.is_pylint_comment and not current.is_pytype_comment
and not current.is_copybara_comment and self.column > self.column_limit):
excess_characters = self.column - self.column_limit
penalty += style.Get('SPLIT_PENALTY_EXCESS_CHARACTER') * excess_characters

Expand Down
5 changes: 5 additions & 0 deletions yapf/yapflib/format_token.py
Expand Up @@ -378,3 +378,8 @@ def is_pylint_comment(self):
def is_pytype_comment(self):
return self.is_comment and re.match(r'#.*\bpytype:\s*(disable|enable)=',
self.value)

@property
def is_copybara_comment(self):
return self.is_comment and re.match(r'#.*\bcopybara:(strip|insert|replace)',
self.value)
3 changes: 2 additions & 1 deletion yapf/yapflib/reformatter.py
Expand Up @@ -259,7 +259,8 @@ def _CanPlaceOnSingleLine(uwline):
indent_amt = style.Get('INDENT_WIDTH') * uwline.depth
last = uwline.last
last_index = -1
if last.is_pylint_comment or last.is_pytype_comment:
if (last.is_pylint_comment or last.is_pytype_comment
or last.is_copybara_comment):
last = last.previous_token
last_index = -2
if last is None:
Expand Down
5 changes: 4 additions & 1 deletion yapftests/reformatter_buganizer_test.py
Expand Up @@ -166,7 +166,10 @@ class _():
def _():
X = (
_ares_label_prefix +
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') # pylint: disable=line-too-long
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' # pylint: disable=line-too-long
'PyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyType' # pytype: disable=attribute-error
'CopybaraCopybaraCopybaraCopybaraCopybaraCopybaraCopybaraCopybaraCopybara' # copybara:strip
)
"""
uwlines = yapf_test_helper.ParseAndUnwrap(code)
self.assertCodeEqual(code, reformatter.Reformat(uwlines))
Expand Down

0 comments on commit fdea4a4

Please sign in to comment.