Hi,
I noticed that when using JuliaFormatter v2.1.6 with VS Code and a local project environment (Project.toml
), there is a difference in how spaces are handled in indexing expressions, even without a .JuliaFormatter.toml
file. I think the spaces are just an example.
Minimal example:
- Create a folder with
Project.toml
containing:
[deps]
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
[compat]
JuliaFormatter = "2.1.6"
-
Instantiate the environment.
-
Create
test.jl
:
data = rand(2, 2, 2)
getindex(data,:,:,1) # here, no spaces around ":"
- Save in VS Code with Julia extension → VS Code automatically adds spaces:
getindex(data, :, :, 1)
- Format the file using the Julia formatter
julia --project=. -e 'using JuliaFormatter; format(".", verbose=true)'
CLI formatting removes the extra spaces and produces:
getindex(data,:,:,1)
Setup:
- Julia: 1.10.3 (also tried in other Julia 1.10 version, no 1.11 available right now)
- JuliaFormatter: 2.1.6 (from
Project.toml
) - VS Code Julia extension: latest stable
- Only a
Project.toml
,Manifest.toml
andtest.jl
exist in the folder - VS Code is using the local project environment
It seems the VS Code extension applies its own formatting on save, independently of JuliaFormatter CLI behavior or .JuliaFormatter.toml
options. This leads to differences in spacing between VS Code format-on-save and CLI formatting.
Is there any way to discipline this? I have tried using a .JuliaFormatter.toml
file, didn’t work.
I also posted this as an issue here.