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

Allow up to two empty lines on module level and single empty lines otherwise
authorŁukasz Langa <lukasz@langa.pl>
Tue, 27 Mar 2018 05:54:08 +0000 (22:54 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Tue, 27 Mar 2018 05:55:56 +0000 (22:55 -0700)
Fixes #74

README.md
black.py
tests/empty_lines.py

index 69df9bc5046dc0d4f018546cf849e1686edd49b7..182e2649dcf24c3f3342098552e685132e574702 100644 (file)
--- a/README.md
+++ b/README.md
@@ -218,10 +218,10 @@ always emit an extra empty line after ``return``, ``raise``, ``break``,
 ``continue``, and ``yield``.  This is to make changes in control flow
 more prominent to readers of your code.
 
-*Black* will allow single empty lines left by the original editors,
-except when they're added within parenthesized expressions.  Since such
-expressions are always reformatted to fit minimal space, this whitespace
-is lost.
+*Black* will allow single empty lines inside functions, and single and
+double empty lines on module level left by the original editors, except
+when they're within parenthesized expressions.  Since such expressions
+are always reformatted to fit minimal space, this whitespace is lost.
 
 It will also insert proper spacing before and after function definitions.
 It's one line before and after inner functions and two lines before and
@@ -338,6 +338,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 * fixed 18.3a4 regression: don't crash and burn on empty lines with
   trailing whitespace (#80)
 
+* only allow up to two empty lines on module level and only single empty
+  lines within functions (#74)
+
 
 ### 18.3a4
 
index 9ea46944b1e042260b57db4382cb6cfd0826f6ab..da7af03aebf3f5511a93f12c61283c6603541c03 100644 (file)
--- a/black.py
+++ b/black.py
@@ -754,13 +754,13 @@ class EmptyLineTracker:
 
     def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
         max_allowed = 1
-        if current_line.is_comment and current_line.depth == 0:
+        if current_line.depth == 0:
             max_allowed = 2
         if current_line.leaves:
             # Consume the first leaf's extra newlines.
             first_leaf = current_line.leaves[0]
             before = first_leaf.prefix.count('\n')
-            before = min(before, max(before, max_allowed))
+            before = min(before, max_allowed)
             first_leaf.prefix = ''
         else:
             before = 0
index 8f00ddced4bc4b15c64d3fee4994ae16c108e6dc..ec04337670dfd0b22211422d59419ac0e761fff4 100644 (file)
@@ -12,15 +12,19 @@ def f():
     if t == token.COMMENT:  # another trailing comment
         return DOUBLESPACE
 
+
     assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
 
+
     prev = leaf.prev_sibling
     if not prev:
         prevp = preceding_leaf(p)
         if not prevp or prevp.type in OPENING_BRACKETS:
 
+
             return NO
 
+
         if prevp.type == token.EQUAL:
             if prevp.parent and prevp.parent.type in {
                 syms.typedargslist,