-
Notifications
You must be signed in to change notification settings - Fork 285
bug: swift_format doesn't respect .swift-format file #211
Description
Neovim version (nvim -v)
NVIM v0.9.4
Operating system/version
macOS 14.1.1 (23B81)
Add the debug logs
- I have set
log_level = vim.log.levels.DEBUGand pasted the log contents below.
Log file
Log file: /Users/garrett/dev/scrap/conform-swift/.repro//state/nvim/conform.log
22:37:11[DEBUG] Run command: { "swift-format" }
22:37:11[DEBUG] swift_format exited with code 0
22:38:05[DEBUG] Running formatters on /Users/garrett/dev/scrap/conform-swift/Package.swift: { "swift_format" }
22:38:05[INFO] Run swift_format on /Users/garrett/dev/scrap/conform-swift/Package.swift
22:38:05[DEBUG] Run command: { "swift-format" }
22:38:05[DEBUG] swift_format exited with code 0
22:39:40[DEBUG] Running formatters on /Users/garrett/dev/scrap/conform-swift/Package.swift: { "swift_format" }
22:39:40[INFO] Run swift_format on /Users/garrett/dev/scrap/conform-swift/Package.swift
22:39:40[DEBUG] Run command: { "swift-format", "--configuration", ".swift-format" }
22:39:40[DEBUG] swift_format exited with code 0
22:40:05[DEBUG] Running formatters on /Users/garrett/dev/scrap/conform-swift/Package.swift: { "swift_format" }
22:40:05[INFO] Run swift_format on /Users/garrett/dev/scrap/conform-swift/Package.swift
22:40:05[DEBUG] Run command: { "swift-format" }
22:40:05[DEBUG] swift_format exited with code 0
Formatters for this buffer:
swift_format ready (swift)
Other formatters:
Describe the bug
When using the configuration of swift-format included in conform.nvim (listed as swift_format), the presence of a .swift-format file is not respected when formatting Swift code. Running swift-format from the command line does respect the .swift-format file by default.
Adding prepend_args = { "--configuration", ".swift-format" } to the swift_format configuration does resolve the issue, but doesn't explain why the configuration file isn't respected by default.
Steps To Reproduce
mkdir conform-swift && cd conform-swiftswift package init --type executableecho '{ "indentation": { "tabs": 1 } }' > .swift-formatnvim -u repro.lua Package.swift:lua require("conform").format()- Uncomment the line in repro.lua that adds the
prepend_argsproperty - Repeat steps 4 and 5
Expected Behavior
The spaces used for indentation in the Package.swift file would be replaced with tabs, as configured in the .swift-format file.
It only works after adding the prepend_args property as detailed above.
Minimal example file
swift package init --type executable will create the Package.swift file I'm using to reproduce the issue, but I'll include it here also:
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "conform-swift",
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "conform-swift")
]
)Minimal init.lua
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
"folke/tokyonight.nvim",
{
"stevearc/conform.nvim",
config = function()
require("conform").setup({
log_level = vim.log.levels.DEBUG,
-- add your config here
formatters_by_ft = { swift = { "swift_format" } },
formatters = {
swift_format = {
-- Uncomment this line to see the .swift-format file respected
-- prepend_args = { "--configuration", ".swift-format" },
},
},
})
end,
},
-- add any other plugins here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
-- add anything else here
vim.o.list = trueAdditional context
I don't know if this is an issue with swift-format itself, but I can only reproduce it with conform.nvim