Skip to content

Commit 7887e5d

Browse files
authored
* fix domluna#912 * v bump
1 parent 63228ba commit 7887e5d

File tree

12 files changed

+79
-38
lines changed

12 files changed

+79
-38
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "JuliaFormatter"
22
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
33
authors = ["Dominique Luna <[email protected]>"]
4-
version = "2.1.1"
4+
version = "2.1.2"
55

66
[deps]
77
CommonMark = "a80b9123-70ca-4bc0-993e-6e3bcb318db6"

src/styles/default/pretty.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ function pretty(
7676
p_do(style, node, s, ctx, lineage)
7777
elseif k === K"var"
7878
p_var(style, node, s, ctx, lineage)
79+
elseif is_try(node) ||
80+
# issue #912
81+
(k === K"else" && !isnothing(lineage) && lineage[end-1][1] === K"try")
82+
p_try(style, node, s, ctx, lineage)
7983
elseif is_if(node)
8084
p_if(style, node, s, ctx, lineage)
81-
elseif is_try(node)
82-
p_try(style, node, s, ctx, lineage)
8385
elseif k === K"toplevel"
8486
p_toplevel(style, node, s, ctx, lineage)
8587
elseif k === K"quote" && haschildren(node) && kind(node[1]) === K":"
@@ -219,7 +221,7 @@ function p_identifier(
219221
lineage::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
220222
)
221223
loc = cursor_loc(s)
222-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
224+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
223225
s.offset += span(cst)
224226
FST(IDENTIFIER, loc[2], loc[1], loc[1], val)
225227
end
@@ -232,7 +234,7 @@ function p_whitespace(
232234
lineage::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
233235
)
234236
loc = cursor_loc(s)
235-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
237+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
236238
s.offset += span(cst)
237239
FST(NONE, loc[2], loc[1], loc[1], val)
238240
end
@@ -246,7 +248,7 @@ function p_comment(
246248
)
247249
loc = cursor_loc(s)
248250
same_line = on_same_line(s, s.offset, s.offset + span(cst) - 1)
249-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
251+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
250252
if same_line && startswith(val, "#=") && endswith(val, "=#")
251253
s.offset += span(cst)
252254
return FST(HASHEQCOMMENT, loc[2], loc[1], loc[1], val)
@@ -275,7 +277,7 @@ function p_macroname(
275277
::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
276278
)
277279
loc = cursor_loc(s)
278-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
280+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
279281
s.offset += span(cst)
280282
FST(MACRONAME, loc[2], loc[1], loc[1], val)
281283
end
@@ -288,7 +290,7 @@ function p_operator(
288290
::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
289291
)
290292
loc = cursor_loc(s)
291-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
293+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
292294
s.offset += span(cst)
293295
t = FST(OPERATOR, loc[2], loc[1], loc[1], val)
294296
t.metadata = Metadata(kind(cst), JuliaSyntax.is_dotted(cst))
@@ -303,7 +305,7 @@ function p_keyword(
303305
::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
304306
)
305307
loc = cursor_loc(s)
306-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
308+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
307309
s.offset += span(cst)
308310
FST(KEYWORD, loc[2], loc[1], loc[1], val)
309311
end
@@ -316,7 +318,7 @@ function p_punctuation(
316318
::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
317319
)
318320
loc = cursor_loc(s)
319-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
321+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
320322
s.offset += span(cst)
321323
FST(PUNCTUATION, loc[2], loc[1], loc[1], val)
322324
end
@@ -445,7 +447,7 @@ function p_literal(
445447
lineage::Vector{Tuple{JuliaSyntax.Kind,Bool,Bool}},
446448
)
447449
loc = cursor_loc(s)
448-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
450+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
449451

450452
if !is_str_or_cmd(cst)
451453
if kind(cst) in KSet"Float Float32" && !startswith(val, "0x")
@@ -509,7 +511,7 @@ function p_stringh(
509511
end
510512
loc2 = cursor_loc(s, s.offset+span(cst)-1)
511513

512-
val = getsrcval(s.doc, s.offset:s.offset+span(cst)-1)
514+
val = getsrcval(s.doc, s.offset:(s.offset+span(cst)-1))
513515
startline = loc[1]
514516
endline = loc2[1]
515517

@@ -1551,12 +1553,14 @@ function p_try(
15511553
# the end of block it will be added as a comment in the parent node and hence
15521554
# have a lower indentation than the rest of the block. To counteract that we reduce
15531555
# the indent when we encounter "catch finally end" keywords.
1556+
#
1557+
# Apparently "try catch else end" is also valid.
15541558

15551559
childs = children(cst)
15561560
for c in childs
1557-
if kind(c) in KSet"try catch finally"
1561+
if kind(c) in KSet"try catch finally else"
15581562
if !haschildren(c)
1559-
if kind(c) in KSet"catch finally"
1563+
if kind(c) in KSet"catch finally else"
15601564
s.indent -= s.opts.indent
15611565
end
15621566
add_node!(t, pretty(style, c, s, ctx, lineage), s; max_padding = 0)
@@ -1566,7 +1570,7 @@ function p_try(
15661570
add_node!(t, n, s; max_padding = 0)
15671571
t.len = max(len, length(n))
15681572
end
1569-
elseif kind(c) === K"end"
1573+
elseif kind(c) in KSet"end"
15701574
s.indent -= s.opts.indent
15711575
add_node!(t, pretty(style, c, s, ctx, lineage), s)
15721576
elseif kind(c) === K"block"

src/styles/yas/pretty.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ function p_call(
418418
else
419419
0
420420
end
421-
val = getsrcval(s.doc, s.offset:s.offset+offset)
421+
val = getsrcval(s.doc, s.offset:(s.offset+offset))
422422
if val in s.opts.variable_call_indent
423423
return p_call(DefaultStyle(style), cst, s, ctx, lineage)
424424
end

test/files/ChainRules.jl/src/rulesets/Base/array.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function rrule(::typeof(cat), Xs::Union{AbstractArray,Number}...; dims)
252252
if d > ndimsX
253253
(prev[d] + 1)
254254
else
255-
((prev[d]+1):(prev[d]+sizeX[d]))
255+
((prev[d] + 1):(prev[d] + sizeX[d]))
256256
end
257257
else
258258
d > ndimsX ? 1 : (:)
@@ -293,7 +293,7 @@ function rrule(::typeof(hvcat), rows, values::Union{AbstractArray,Number}...)
293293
if d > ndimsX
294294
(prev[d] + 1)
295295
else
296-
((prev[d]+1):(prev[d]+sizeX[d]))
296+
((prev[d] + 1):(prev[d] + sizeX[d]))
297297
end
298298
else
299299
d > ndimsX ? 1 : (:)

test/files/ChainRules.jl/src/rulesets/Base/evalpoly.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if VERSION ≥ v"1.4"
55
N = length(p)
66
@inbounds y = p[N]
77
Δy = Δp[N]
8-
@inbounds for i in (N-1):-1:1
8+
@inbounds for i in (N - 1):-1:1
99
Δy = muladd(Δx, y, muladd(x, Δy, Δp[i]))
1010
y = muladd(x, y, p[i])
1111
end
@@ -39,7 +39,7 @@ if VERSION ≥ v"1.4"
3939
exs = []
4040
vars = []
4141
ex = :(p[$N])
42-
for i in 1:(N-1)
42+
for i in 1:(N - 1)
4343
yi = Symbol("y", i)
4444
push!(vars, yi)
4545
push!(exs, :($yi = $ex))
@@ -65,7 +65,7 @@ if VERSION ≥ v"1.4"
6565
@inbounds yn = one(x) * p[N]
6666
ys = similar(p, typeof(yn), N - 1)
6767
@inbounds ys[1] = yn
68-
@inbounds for i in 2:(N-1)
68+
@inbounds for i in 2:(N - 1)
6969
ys[i] = muladd(x, ys[i - 1], p[N - i + 1])
7070
end
7171
@inbounds y = muladd(x, ys[N - 1], p[1])
@@ -87,7 +87,7 @@ if VERSION ≥ v"1.4"
8787
exs = []
8888
vars = []
8989
N = length(p.parameters)
90-
for i in 2:(N-1)
90+
for i in 2:(N - 1)
9191
∂pi = Symbol("∂p", i)
9292
push!(vars, ∂pi)
9393
push!(exs, :(∂x = _evalpoly_backx(x, ys[$(N - i)], ∂x, ∂yi)))
@@ -139,7 +139,7 @@ if VERSION ≥ v"1.4"
139139
∂x = _evalpoly_backx(x, ys[N - 1], ∂yi)
140140
∂yi = x′ * ∂yi
141141
∂p[1] = ∂p1
142-
for i in 2:(N-1)
142+
for i in 2:(N - 1)
143143
∂x = _evalpoly_backx(x, ys[N - i], ∂x, ∂yi)
144144
∂p[i] = _evalpoly_backp(p[i], ∂yi)
145145
∂yi = x′ * ∂yi

test/files/ChainRules.jl/src/rulesets/Base/mapreduce.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ end
321321
lo, hi = firstindex(x), lastindex(x)
322322
z = something(findfirst(iszero, x), hi + 1)
323323
acc = zero(eltype(dy))
324-
@inbounds for k in (z-1):-1:lo
324+
@inbounds for k in (z - 1):-1:lo
325325
acc += y[k] * dy[k]
326326
dx[k] += acc / x[k]
327327
end
328328
@inbounds if z != hi + 1
329329
yk = z == 1 ? one(eltype(y)) : y[z - 1] # will be prod(x[j] for j=1:k if j!=z)
330330
dx[z] += yk * dy[z]
331-
for k in (z+1):hi
331+
for k in (z + 1):hi
332332
yk *= x[k]
333333
dx[z] += yk * dy[k]
334334
end

test/files/ChainRules.jl/src/rulesets/LinearAlgebra/matfun.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function _matfun!(::typeof(exp), A::StridedMatrix{T}) where {T<:BlasFloat}
202202
W = C[2] * P
203203
V = C[1] * P
204204
Apows = typeof(P)[]
205-
for k in 1:(div(size(C, 1), 2)-1)
205+
for k in 1:(div(size(C, 1), 2) - 1)
206206
k2 = 2 * k
207207
P *= A2
208208
push!(Apows, P)
@@ -247,7 +247,7 @@ function _matfun_frechet!(
247247
∂P = copy(∂A2)
248248
∂W = C[4] * ∂P
249249
∂V = C[3] * ∂P
250-
for k in 2:(length(Apows)-1)
250+
for k in 2:(length(Apows) - 1)
251251
k2 = 2 * k
252252
P = Apows[k - 1]
253253
∂P, ∂temp = mul!(mul!(∂temp, ∂P, A2), P, ∂A2, true, true), ∂P
@@ -261,7 +261,7 @@ function _matfun_frechet!(
261261
ldiv!(F, ∂X)
262262

263263
if si > 0
264-
for t in 1:(length(Xpows)-1)
264+
for t in 1:(length(Xpows) - 1)
265265
X = Xpows[t]
266266
∂X, ∂temp = mul!(mul!(∂temp, X, ∂X), ∂X, X, true, true), ∂X
267267
end
@@ -284,12 +284,12 @@ end
284284
function _balance!(X, ilo, ihi, scale, n)
285285
n = size(X, 1)
286286
if ihi < n
287-
for j in (ihi+1):n
287+
for j in (ihi + 1):n
288288
LinearAlgebra.rcswap!(j, Int(scale[j]), X)
289289
end
290290
end
291291
if ilo > 1
292-
for j in (ilo-1):-1:1
292+
for j in (ilo - 1):-1:1
293293
LinearAlgebra.rcswap!(j, Int(scale[j]), X)
294294
end
295295
end
@@ -319,12 +319,12 @@ function _unbalance!(X, ilo, ihi, scale, n)
319319
end
320320

321321
if ilo > 1
322-
for j in (ilo-1):-1:1
322+
for j in (ilo - 1):-1:1
323323
LinearAlgebra.rcswap!(j, Int(scale[j]), X)
324324
end
325325
end
326326
if ihi < n
327-
for j in (ihi+1):n
327+
for j in (ihi + 1):n
328328
LinearAlgebra.rcswap!(j, Int(scale[j]), X)
329329
end
330330
end

test/files/ChainRules.jl/src/rulesets/LinearAlgebra/symmetric.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ function _hermitrizelike!(A_, S::LinearAlgebra.RealHermSymComplexHerm)
513513
A = eltype(S) <: Real ? real(A_) : A_
514514
n = size(A, 1)
515515
for i in 1:n
516-
for j in (i+1):n
516+
for j in (i + 1):n
517517
A[i, j] = (A[i, j] + conj(A[j, i])) / 2
518518
A[j, i] = conj(A[i, j])
519519
end

test/files/ChainRules.jl/test/rulesets/LinearAlgebra/factorization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function rand_eigen(T::Type, n::Int)
3737
end
3838

3939
# make sure the sorting of eigenvalues is well defined
40-
λ = 10(_rand(T, n) .+ (0:3:(3(n-1))))
40+
λ = 10(_rand(T, n) .+ (0:3:(3(n - 1))))
4141

4242
return V * Diagonal(λ) / V
4343
end

test/files/blowup/axis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ function draw_axis3d(textbuffer, linebuffer, limits, ranges_labels, args...)
499499
if showgrid[i]
500500
c = gridcolors[i]
501501
thickness = gridthickness[i]
502-
for _j in (i+1):(i+N-1)
502+
for _j in (i + 1):(i + N - 1)
503503
j = mod1(_j, N)
504504
dir = unit(Point{N,Float32}, j)
505505
range = ranges[j]

0 commit comments

Comments
 (0)