]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix unstable format involving backslash + whitespace at beginning of file (#948)
authorJoe Antonakakis <jma353@cornell.edu>
Sun, 4 Aug 2019 09:03:19 +0000 (02:03 -0700)
committerZsolt Dollenstein <zsol.zsol@gmail.com>
Sun, 4 Aug 2019 09:03:19 +0000 (10:03 +0100)
black.py
tests/data/beginning_backslash.py [new file with mode: 0644]
tests/test_black.py

index f7022d8014c4a9aef3474d28ca153a60984a56d2..05edf1a2ae320c3bd3b9a11c57b2edd3a314a4cf 100644 (file)
--- a/black.py
+++ b/black.py
@@ -1480,7 +1480,13 @@ class EmptyLineTracker:
         lines (two on module-level).
         """
         before, after = self._maybe_empty_lines(current_line)
-        before -= self.previous_after
+        before = (
+            # Black should not insert empty lines at the beginning
+            # of the file
+            0
+            if self.previous_line is None
+            else before - self.previous_after
+        )
         self.previous_after = after
         self.previous_line = current_line
         return before, after
diff --git a/tests/data/beginning_backslash.py b/tests/data/beginning_backslash.py
new file mode 100644 (file)
index 0000000..66c347d
--- /dev/null
@@ -0,0 +1,12 @@
+\
+
+
+
+
+
+print("hello, world")
+
+# output
+
+
+print("hello, world")
index 7b3a8b66e2b3bd448676989056e39dc9aed83617..015243f7c1322fd28cb6ba33933acf6ef02f09f3 100644 (file)
@@ -639,6 +639,14 @@ class BlackTestCase(unittest.TestCase):
         black.assert_equivalent(source, actual)
         black.assert_stable(source, actual, black.FileMode())
 
+    @patch("black.dump_to_file", dump_to_stderr)
+    def test_beginning_backslash(self) -> None:
+        source, expected = read_data("beginning_backslash")
+        actual = fs(source)
+        self.assertFormatEqual(expected, actual)
+        black.assert_equivalent(source, actual)
+        black.assert_stable(source, actual, black.FileMode())
+
     def test_tab_comment_indentation(self) -> None:
         contents_tab = "if 1:\n\tif 2:\n\t\tpass\n\t# comment\n\tpass\n"
         contents_spc = "if 1:\n    if 2:\n        pass\n    # comment\n    pass\n"