Enforce use of spaces required for disabled lines
diff --git a/CHANGELOG b/CHANGELOG
index 46975db..7edf6f4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,7 @@
- Allow for sensible splitting of array indices where appropriate.
- Prefer to not split before the ending bracket of an atom. This produces
better code in most cases.
+- Corrected how horizontal spaces were presevered in a disabled region.
## [0.4.0] 2015-10-07
### Added
diff --git a/yapf/yapflib/format_decision_state.py b/yapf/yapflib/format_decision_state.py
index 12443b7..a3a9813 100644
--- a/yapf/yapflib/format_decision_state.py
+++ b/yapf/yapflib/format_decision_state.py
@@ -280,7 +280,7 @@
previous = current.previous_token
top_of_stack = self.stack[-1]
- if current.spaces_required_before > 2:
+ if current.spaces_required_before > 2 or self.line.disable:
return current.spaces_required_before
if current.OpensScope():
diff --git a/yapftests/yapf_test.py b/yapftests/yapf_test.py
index 128bcac..55435e8 100644
--- a/yapftests/yapf_test.py
+++ b/yapftests/yapf_test.py
@@ -243,6 +243,17 @@
formatted_code = yapf_api.FormatFile(file1, style_config='pep8')[0]
self.assertCodeEqual(code, formatted_code)
+ def testDisabledHorizontalFormattingOnNewLine(self):
+ code = textwrap.dedent("""\
+ # yapf: disable
+ a = [
+ 1]
+ # yapf: enable
+ """)
+ file1 = self._MakeTempFileWithContents('testfile1.py', code)
+ formatted_code = yapf_api.FormatFile(file1, style_config='pep8')[0]
+ self.assertCodeEqual(code, formatted_code)
+
class CommandLineTest(unittest.TestCase):
"""Test how calling yapf from the command line acts."""