Commit c7495b9a authored by Joe Antonakakis's avatar Joe Antonakakis Committed by Zsolt Dollenstein
Browse files

Fix unstable format involving backslash + whitespace at beginning of file (#948)

parent 65ea568e
Loading
Loading
Loading
Loading
+7 −1
Changes for black.py: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1480,7 +1480,13 @@ def maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
        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
+12 −0
Changes for tests/data/beginning_backslash.py: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
\





print("hello, world")

# output


print("hello, world")
+8 −0
Changes for tests/test_black.py: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -639,6 +639,14 @@ def test_tuple_assign(self) -> None:
        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"