-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: swift_format doesn't respect .swift-format file #211
Comments
Kind of crazy that the same command run on the command line produces different output. Is it being run from the same directory? If you add a |
@stevearc I've actually had a similar issue and I think using |
No change when using |
@heygarrett can you confirm if the suggestion from @isaacthefallenapple works? |
The suggestion from @isaacthefallenapple doesn't work for me, unfortunately. |
I unfortunately don't have a great way to reproduce this. Happy to provide pointers, but I think I'll need someone else to make a PR for this one. |
@heygarrett I had similar issues, this the config that works for me: formatters = {
swift_format = {
stdin = false,
args = { "$FILENAME", "--in-place" },
},
},
formatters_by_ft = {
swift = { "swift_format" },
}, This is very similar to what @isaacthefallenapple suggested, just need to add
|
Here's the log I have with my config
|
`swift-format` won't pick up `.swift-format` config file in stdin mode. We need to set `stdin = false` and `--in-place` to make it work with `conform.nvim`. [apple/swift-format/README.md](https://github.com/apple/swift-format/blob/e312ede68bd8549381f9e2edfef7e6c176e9a50e/README.md#L129-L131) > * `-i/--in-place`: Overwrites the input files when formatting instead of printing the results to standard output. _No backup of the original file is made before it is overwritten._ Fix stevearc#211
`swift-format` won't pick up `.swift-format` config file in stdin mode. We need to set `stdin = false` and `--in-place` to make it work with `conform.nvim`. [apple/swift-format/README.md](https://github.com/apple/swift-format/blob/e312ede68bd8549381f9e2edfef7e6c176e9a50e/README.md#L129-L131) > * `-i/--in-place`: Overwrites the input files when formatting instead of printing the results to standard output. _No backup of the original file is made before it is overwritten._ Fix #211
Fixed for me! Thanks! |
`swift-format` won't pick up `.swift-format` config file in stdin mode. We need to set `stdin = false` and `--in-place` to make it work with `conform.nvim`. [apple/swift-format/README.md](https://github.com/apple/swift-format/blob/e312ede68bd8549381f9e2edfef7e6c176e9a50e/README.md#L129-L131) > * `-i/--in-place`: Overwrites the input files when formatting instead of printing the results to standard output. _No backup of the original file is made before it is overwritten._ Fix stevearc/conform.nvim#211
Neovim version (nvim -v)
NVIM v0.9.4
Operating system/version
macOS 14.1.1 (23B81)
Add the debug logs
log_level = vim.log.levels.DEBUG
and pasted the log contents below.Log file
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-swift
swift package init --type executable
echo '{ "indentation": { "tabs": 1 } }' > .swift-format
nvim -u repro.lua Package.swift
:lua require("conform").format()
prepend_args
propertyExpected 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:Minimal init.lua
Additional context
I don't know if this is an issue with swift-format itself, but I can only reproduce it with conform.nvim
The text was updated successfully, but these errors were encountered: