Skip to content

Commit

Permalink
fix #387 (#394)
Browse files Browse the repository at this point in the history
* fix #387

Handles the edge case where the first argument of a Call node
is nestable. For example:

```
new{T1,T2}(arg1,arg2)
```

In this case if the indent is set to the offset of the first argument after
`(` and `new{T1,T2}` is nested, the indentation will be incorrect.

before (aligned to after the initial position of `(`):

```
new{T1,
    T2}(arg1,
           arg2)
```

after (aligned to after new position of `(`):

```
new{T1,
    T2}(arg1,
        arg2)
```

* version bump
  • Loading branch information
domluna authored Apr 2, 2021
1 parent c3709d5 commit eba069a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JuliaFormatter"
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
authors = ["Dominique Luna <[email protected]>"]
version = "0.13.8"
version = "0.13.9"

[deps]
CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
Expand Down
9 changes: 8 additions & 1 deletion src/styles/yas/nest.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
function n_call!(ys::YASStyle, fst::FST, s::State)
style = getstyle(ys)
fst.indent = s.line_offset + sum(length.(fst[1:2]))

f = n -> n.typ === PLACEHOLDER || n.typ === NEWLINE

for (i, n) in enumerate(fst.nodes)
if i == 3
# The indent is set here to handle the edge
# case where the first argument of Call is
# nestable.
# ref https://github.com/domluna/JuliaFormatter.jl/issues/387
fst.indent = s.line_offset
end

if n.typ === NEWLINE
s.line_offset = fst.indent
elseif n.typ === PLACEHOLDER
Expand Down
9 changes: 9 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,13 @@
"""
@test bluefmt(str_, always_for_in = true) == str
end

@testset "issue 387" begin
str_ = """new{T1,T2}(arg1,arg2)"""
str = """
new{T1,
T2}(arg1,
arg2)"""
@test yasfmt(str_, 4, 1) == str
end
end

2 comments on commit eba069a

@domluna
Copy link
Owner Author

@domluna domluna commented on eba069a Apr 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/33454

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.9 -m "<description of version>" eba069ac8a4d5df76d5a0627c5964df2e714b4f8
git push origin v0.13.9

Please sign in to comment.