Honor the 'disable' directive at the end of a multiline comment
Closes #799
diff --git a/CHANGELOG b/CHANGELOG
index 9f2c8df..fe6e020 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,10 @@
# All notable changes to this project will be documented in this file.
# This project adheres to [Semantic Versioning](http://semver.org/).
+## [0.29.1] UNRELEASED
+### Fixed
+- Honor a disable directive at the end of a multiline comment.
+
## [0.29.0] 2019-11-28
### Added
- Add the `--quiet` flag to suppress output. The return code is 1 if there are
diff --git a/yapf/yapflib/style.py b/yapf/yapflib/style.py
index 77c9172..ba528c0 100644
--- a/yapf/yapflib/style.py
+++ b/yapf/yapflib/style.py
@@ -129,7 +129,7 @@
characters. Slightly right (one more indent character) if cannot
vertically align continuation lines with indent characters.
- For options FIXED, and VALIGN-RIGHT are only available when USE_TABS is
+ Options FIXED and VALIGN-RIGHT are only available when USE_TABS is
enabled."""),
CONTINUATION_INDENT_WIDTH=textwrap.dedent("""\
Indent width used for line continuations."""),
diff --git a/yapf/yapflib/yapf_api.py b/yapf/yapflib/yapf_api.py
index f5240ab..3f7c94a 100644
--- a/yapf/yapflib/yapf_api.py
+++ b/yapf/yapflib/yapf_api.py
@@ -252,7 +252,10 @@
while index < len(uwlines):
uwline = uwlines[index]
if uwline.is_comment and _EnableYAPF(uwline.first.value.strip()):
- break
+ if not re.search(DISABLE_PATTERN,
+ uwline.first.value.strip().split('\n')[-1].strip(),
+ re.IGNORECASE):
+ break
uwline.disable = True
index += 1
elif re.search(DISABLE_PATTERN, uwline.last.value.strip(), re.IGNORECASE):
diff --git a/yapftests/yapf_test.py b/yapftests/yapf_test.py
index e13955f..f1685a0 100644
--- a/yapftests/yapf_test.py
+++ b/yapftests/yapf_test.py
@@ -195,6 +195,19 @@
formatted_code, _, _ = yapf_api.FormatFile(filepath, style_config='pep8')
self.assertCodeEqual(code, formatted_code)
+ def testEnabledDisabledSameComment(self):
+ code = textwrap.dedent(u"""\
+ # yapf: disable
+ a(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, ddddddddddddddddddddddd, eeeeeeeeeeeeeeeeeeeeeeeeeee)
+ # yapf: enable
+ # yapf: disable
+ a(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, ddddddddddddddddddddddd, eeeeeeeeeeeeeeeeeeeeeeeeeee)
+ # yapf: enable
+ """)
+ with utils.TempFileContents(self.test_tmpdir, code) as filepath:
+ formatted_code, _, _ = yapf_api.FormatFile(filepath, style_config='pep8')
+ self.assertCodeEqual(code, formatted_code)
+
def testFormatFileLinesSelection(self):
unformatted_code = textwrap.dedent(u"""\
if a: b