Repository: ambv/black
Pull request #166 (2018-04-24 14:42:50)

[#154] Handle comments between decorators properly

coveralls: ## Pull Request Test Coverage Report for [Build 281](https://coveralls.io/builds/16671618)

* **9** of **9**  **(100.0%)** changed or added relevant lines in **2** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.02%**) to **95.184%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/16671618/badge)](https://coveralls.io/builds/16671618) |
| :-- | --: |
| Change from base [Build 274](https://coveralls.io/builds/16660639): |  0.02% |
| Covered Lines: | 1759 |
| Relevant Lines: | 1848 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/README.md b/README.md
index 9906771..05bff36 100644
--- a/README.md
+++ b/README.md
@@ -368,9 +368,21 @@ Configuration:
 * `g:black_linelength` (defaults to `88`)
 * `g:black_virtualenv` (defaults to `~/.vim/black`)
 
-To install, copy the plugin from [vim/plugin/black.vim](https://github.com/ambv/black/tree/master/vim/plugin/black.vim).
+To install with [vim-plug](https://github.com/junegunn/vim-plug):
+
+```
+Plug 'ambv/black',
+```
+
+or with [Vundle](https://github.com/VundleVim/Vundle.vim):
+
+```
+Plugin 'ambv/black'
+```
+
+or you can copy the plugin from [plugin/black.vim](https://github.com/ambv/black/tree/master/plugin/black.vim).
 Let me know if this requires any changes to work with Vim 8's builtin
-`packadd`, or Pathogen, or Vundle, and so on.
+`packadd`, or Pathogen, and so on.
 
 This plugin **requires Vim 7.0+ built with Python 3.6+ support**.  It
 needs Python 3.6 to be able to run *Black* inside the Vim process which
diff --git a/black.py b/black.py
index 15a7547..a03b9aa 100644
--- a/black.py
+++ b/black.py
@@ -1044,6 +1044,10 @@ def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
                 # 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


Test patch:
diff --git a/vim/plugin/black.vim b/plugin/black.vim
similarity index 100%
rename from vim/plugin/black.vim
rename to plugin/black.vim
diff --git a/tests/comments6.py b/tests/comments6.py
new file mode 100644
index 0000000..0565015
--- /dev/null
+++ b/tests/comments6.py
@@ -0,0 +1,8 @@
+@property
+# TODO: X
+@property
+# TODO: Y
+# TODO: Z
+@property
+def foo():
+    pass
diff --git a/tests/test_black.py b/tests/test_black.py
index dd3beed..9c029df 100644
--- a/tests/test_black.py
+++ b/tests/test_black.py
@@ -626,6 +626,14 @@ def test_check_diff_use_together(self) -> None:
             )
             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()