]> 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:

[#154] Handle comments between decorators properly (#166)
authorVishwas B Sharma <sharma.vishwas88@gmail.com>
Tue, 24 Apr 2018 16:38:12 +0000 (09:38 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Tue, 24 Apr 2018 16:38:12 +0000 (09:38 -0700)
black.py
tests/comments6.py [new file with mode: 0644]
tests/test_black.py

index 15a754742cc2212656d324fab4422ddad6982289..a03b9aad7607ffd4107b22b6382b6a00028d204c 100644 (file)
--- a/black.py
+++ b/black.py
@@ -1044,6 +1044,10 @@ class EmptyLineTracker:
                 # Don't insert empty lines between decorators.
                 return 0, 0
 
+            if is_decorator and self.previous_line and self.previous_line.is_comment:
+                # Don't insert empty lines between decorator comments.
+                return 0, 0
+
             newlines = 2
             if current_line.depth:
                 newlines -= 1
diff --git a/tests/comments6.py b/tests/comments6.py
new file mode 100644 (file)
index 0000000..0565015
--- /dev/null
@@ -0,0 +1,8 @@
+@property
+# TODO: X
+@property
+# TODO: Y
+# TODO: Z
+@property
+def foo():
+    pass
index dd3beed99abe0e5b6d7b3f37188fa41420f38493..9c029df7eb7b13a891070c30879f4778e4cca121 100644 (file)
@@ -626,6 +626,14 @@ class BlackTestCase(unittest.TestCase):
             )
             self.assertEqual(result.exit_code, 1)
 
+    @patch("black.dump_to_file", dump_to_stderr)
+    def test_comment_in_decorator(self) -> None:
+        source, expected = read_data("comments6")
+        actual = fs(source)
+        self.assertFormatEqual(expected, actual)
+        black.assert_equivalent(source, actual)
+        black.assert_stable(source, actual, line_length=ll)
+
 
 if __name__ == "__main__":
     unittest.main()