Repository: domluna/JuliaFormatter.jl
Pull request #136 (2019-11-24 06:29:21)

Always nest lazy ops
ref #87 


Patch:
diff --git a/src/pretty.jl b/src/pretty.jl
index b3cda411..700f62e2 100644
--- a/src/pretty.jl
+++ b/src/pretty.jl
@@ -1283,31 +1283,6 @@ function nestable(x::CSTParser.EXPR)
     op.kind === Tokens.ANON_FUNC && return false
     op.kind === Tokens.PAIR_ARROW && return false
     CSTParser.precedence(op) in (1, 6) && return false
-    if op.kind == Tokens.LAZY_AND || op.kind == Tokens.LAZY_OR
-        arg = x.args[1]
-        while arg.typ === CSTParser.InvisBrackets
-            arg = arg.args[2]
-        end
-        if arg.typ === CSTParser.BinaryOpCall
-            op = arg.args[2].kind
-            (op == Tokens.LAZY_AND || op == Tokens.LAZY_OR) && return true
-        end
-
-        arg = x.args[3]
-        while arg.typ === CSTParser.InvisBrackets
-            arg = arg.args[2]
-        end
-        if arg.typ === CSTParser.BinaryOpCall
-            op = arg.args[2].kind
-            (op == Tokens.LAZY_AND || op == Tokens.LAZY_OR) && return true
-        end
-
-        return parent_is(
-            x,
-            x -> x.typ in (CSTParser.If, CSTParser.BinaryOpCall, CSTParser.While),
-            ignore_typs = [CSTParser.InvisBrackets],
-        )
-    end
     true
 end
 


Test patch:
diff --git a/test/files/Docs.jl b/test/files/Docs.jl
index 299ddebb..38ba748c 100644
--- a/test/files/Docs.jl
+++ b/test/files/Docs.jl
@@ -220,7 +220,8 @@ function doc!(__module__::Module, b::Binding, str::DocStr, @nospecialize sig = U
         # We allow for docstrings to be updated, but print a warning since it is possible
         # that over-writing a docstring *may* have been accidental.  The warning
         # is suppressed for symbols in Main, for interactive use (#23011).
-        __module__ == Main || @warn "Replacing docs for `$b :: $sig` in module `$(__module__)`"
+        __module__ == Main ||
+        @warn "Replacing docs for `$b :: $sig` in module `$(__module__)`"
     else
         # The ordering of docstrings for each Binding is defined by the order in which they
         # are initially added. Replacing a specific docstring does not change it's ordering.
diff --git a/test/runtests.jl b/test/runtests.jl
index a39b1e4f..0bd357ed 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -2596,8 +2596,10 @@ end
 
         str = """
         begin
-            a && b
-            a || b
+            a &&
+            b
+            a ||
+            b
         end"""
         @test fmt(str, 4, 1) == str
 
@@ -3025,19 +3027,26 @@ end
         @test fmt(str, 4, length(str)) == str_
 
         str_ = "(var1,var2) && var3"
+        str = """
+        (var1, var2) &&
+        var3"""
+        @test fmt(str_, 4, 19) == str
+        @test fmt(str_, 4, 15) == str
+
         str = """
         (
             var1,
             var2,
         ) && var3"""
-        @test fmt(str_, 4, 10) == str
+        @test fmt(str_, 4, 14) == str
 
         str = """
         (
             var1,
             var2,
-        ) && var3"""
-        @test fmt(str_, 4, 19) == str
+        ) &&
+        var3"""
+        @test fmt(str_, 4, 1) == str
 
         str_ = "(var1,var2) ? (var3,var4) : var5"
         str = """