# \[ANN\] JuliaFormatter.jl

**URL:** https://discourse.julialang.org/t/ann-juliaformatter-jl/48084
**Category:** Package Announcements
**Tags:** package, announcement
**Created:** [October 10, 2020, 1:29am UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084 "2020-10-10T01:29:07Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [August 27, 2021, 1:23pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/21 "2021-08-27T13:23:01Z")

</div>

I don’t think so; `;`s in function calls are only relevant when splatting kwargs, afaict.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 27, 2021, 1:24pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/22 "2021-08-27T13:24:54Z")

</div>

In Julia, keyword argument is not optional (i.e. you can’t switch the order of positional argument by giving it a name), so `f(a=0)` is equivalent to `f(; a=0)` because as soon as you wrote `a=`, it’s a keyword argument, no matter if you explicitly put `;` before it or not

---

<div class="post-metadata">

### Author: ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)
#### Post date: [August 27, 2021, 1:30pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/23 "2021-08-27T13:30:29Z")

</div>

Thanks. And sorry, my question was not formulated right.  
In the following snipped, how can I avoid the insertion of the semicolon?

```julia
julia> format_text("DataFrame(mi = rand(3))",YASStyle())
"DataFrame(; mi=rand(3))"

```

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 27, 2021, 1:32pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/24 "2021-08-27T13:32:33Z")

</div>

why\* do you want to avoid it? it’s according to the code style you picked that all keyword arguments are preceded by `;`. Again, I want to stress that it absolutely shouldn’t break your code because they are equivalent

---

<div class="post-metadata">

### Author: ![domluna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domluna/32/18536_2.png) [@domluna](https://discourse.julialang.org/u/domluna)
#### Post date: [August 27, 2021, 1:35pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/25 "2021-08-27T13:35:10Z")

</div>

What about when you have something like foo(a=10; b = 20). is a=10 different from b=20 ?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 27, 2021, 1:36pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/26 "2021-08-27T13:36:15Z")

</div>

> [@domluna](#):
>
> foo(a=10; b = 20)

you can’t, because you can’t optionally add names to positional argument in Julia

```julia
julia> f(a; b) = a+b
f (generic function with 1 method)

julia> f(1;b=3)
4

julia> f(a=1;b=3)
ERROR: MethodError: no method matching f(; a=1, b=3)

```

this is incorrect:

> [@domluna](#):
>
> DataFrame(a=rand(3)) is slightly different from DataFrame(;a=rand(3))

---

<div class="post-metadata">

### Author: ![domluna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domluna/32/18536_2.png) [@domluna](https://discourse.julialang.org/u/domluna)
#### Post date: [August 27, 2021, 1:40pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/27 "2021-08-27T13:40:22Z")

</div>

I could swear this was a thing before, maybe it changed in 1.6

---

<div class="post-metadata">

### Author: ![domluna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domluna/32/18536_2.png) [@domluna](https://discourse.julialang.org/u/domluna)
#### Post date: [August 27, 2021, 1:42pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/28 "2021-08-27T13:42:54Z")

</div>

> [@bernhard](#):
>
> Thanks. And sorry, my question was not formulated right.  
> In the following snipped, how can I avoid the insertion of the semicolon?
> 
> ```julia
> julia> format_text("DataFrame(mi = rand(3))",YASStyle())
> "DataFrame(; mi=rand(3))"
> 
> ```

Sorry for derailing this a little bit but `;` will be inserted before arguments for all code styles. It’s more explicit which is why it’s favored, even if there are no non-positional arguments.

---

<div class="post-metadata">

### Author: ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)
#### Post date: [August 27, 2021, 1:52pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/29 "2021-08-27T13:52:19Z")

</div>

Ok. So I gather there is no argument that would let me control this.

Below is my MWE (ok I guess it is a WE) where the formatting breaks my code.

```julia
using JuliaFormatter
using Dash
using DashCoreComponents
using DashHtmlComponents
using DashTable

fileorig = joinpath(mktempdir(),"afile.jl")
txtorig = """html_div(style=Dict("width"=>"300px"),[dcc_dropdown(id = "input-id0", options = [Dict(("label" => "some text"), ("value" => "AA")), Dict("label" => "something else"), ("value" => "pdc")], value="AA",multi = false)])"""
open(fileorig,"w") do f
    write(f,txtorig)
end

include(fileorig) #works

format_file(fileorig,YASStyle())

include(fileorig) #fails

```

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [August 27, 2021, 2:00pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/30 "2021-08-27T14:00:23Z")

</div>

No, it was not a thing. Positional arguments have not been named since at least 0.7.

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [August 27, 2021, 2:03pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/31 "2021-08-27T14:03:21Z")

</div>

Huh, I did not realize that it’s allowed to mix positional and kwargs like that. JuliaFormatter should probably format `f(x = 2, 33, y = 4)` to `f(33; x = 2, y = 4)`.

---

<div class="post-metadata">

### Author: ![helgee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgee/32/2022_2.png) [@helgee](https://discourse.julialang.org/u/helgee)
#### Post date: [August 27, 2021, 2:03pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/32 "2021-08-27T14:03:22Z")

</div>

> [@jling](#):
>
> you can’t, because you can’t optionally add names to positional argument in Julia

The latter part of this sentence is correct while the former is not.

This code works:

```julia
julia> foo(a=10; b=20) = a, b
foo (generic function with 2 methods)

julia> foo(5)
(5, 20)

```

@jling is correct that you cannot call positional arguments by name but you can in fact assign them a default value, e.g.

```julia
# `a` is a positional argument with default value 10
julia> f(a=10) = a
f (generic function with 2 methods)

julia> f()
10

julia> f(5)
5

# `a` is a keyword argument with default value 10
julia> f(;a=10) = a * 2
f (generic function with 2 methods)

julia> f(a=5)
10

```

---

<div class="post-metadata">

### Author: ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)
#### Post date: [August 27, 2021, 2:05pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/33 "2021-08-27T14:05:42Z")

</div>

Thanks. I did not realize this was the cause here. I filed an issue with JuliaFormatter.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 27, 2021, 2:09pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/34 "2021-08-27T14:09:16Z")

</div>

> [@helgee](#):
>
> The latter part of this sentence is correct while the former is not.

I assumed that’s the calling of a function, not definition. In definition, `=` means default value, of course you can have `f(a=10; b=10)` otherwise how do you give default value to positional argument

---

<div class="post-metadata">

### Author: ![helgee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgee/32/2022_2.png) [@helgee](https://discourse.julialang.org/u/helgee)
#### Post date: [August 27, 2021, 2:10pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/35 "2021-08-27T14:10:35Z")

</div>

Gotcha! My misunderstanding, carry on 😬

---

<div class="post-metadata">

### Author: ![domluna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domluna/32/18536_2.png) [@domluna](https://discourse.julialang.org/u/domluna)
#### Post date: [August 27, 2021, 2:11pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/36 "2021-08-27T14:11:26Z")

</div>

> [@helgee](#):
>
> @jling is correct that you cannot call positional arguments by name but you can in fact assign them a default value, e.g.
> 
> ```julia
> 
> ```

This is what I was thinking of and in fact by moving the semicolon before the positional argument with the default value you lose the ability to give that argument a value without explitcitly using the keyword.

BlueStyle and YASStyle opt to make this explicit by default

```julia
julia> s0
"f(x = 2; y = 4)"

julia> format_text(s0, DefaultStyle())
"f(x = 2; y = 4)"

julia> format_text(s0, BlueStyle())
"f(; x=2, y=4)"

julia> format_text(s0, YASStyle())
"f(; x=2, y=4)"

```

This is not an option right now it but it could be

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 27, 2021, 2:14pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/37 "2021-08-27T14:14:12Z")

</div>

please stop confusing calling function from defining function, you’re calling the funtionc `f()`, what you thought about before (that makes a difference where `;` is), was function definition:

```julia
julia> s0 = "f(x = 2; y = 4) = 3"
"f(x = 2; y = 4) = 3"

julia> format_text(s0, DefaultStyle())
"f(x = 2; y = 4) = 3"

julia> format_text(s0, BlueStyle())
"f(x=2; y=4) = 3"

julia> format_text(s0, YASStyle())
"f(x=2; y=4) = 3"

```

I never though we’re talking about function definition because

> [@bernhard](#):
>
> ```julia
> #don't want:
> DataFrames.DataFrame(; a=rand(3))
> 
> #want:
> DataFrames.DataFrame(a=rand(3))
> 
> ```

was function calling

---

<div class="post-metadata">

### Author: ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)
#### Post date: [August 27, 2021, 2:23pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/38 "2021-08-27T14:23:29Z")

</div>

Apologies. My bad. I initially started with another example (where a leading ; is inserted).  
But at least that was a **minimal** example 🙂

---

<div class="post-metadata">

### Author: ![domluna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domluna/32/18536_2.png) [@domluna](https://discourse.julialang.org/u/domluna)
#### Post date: [August 27, 2021, 2:31pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/39 "2021-08-27T14:31:21Z")

</div>

@jling thanks for clearing this up. I think knowing this difference we can make a couple improvements to the formatter.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [August 27, 2021, 2:33pm UTC](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084/40 "2021-08-27T14:33:00Z")

</div>

AFAIK formatter doesn’t have a bug and handles it correctly (as can be seen above in my example after turning them into definition)

[Previous page](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084.md?page=1)

[Next page](https://discourse.julialang.org/t/ann-juliaformatter-jl/48084.md?page=3)
