nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 640 forks source link

starting SwiftFormat from Xcode menu ignores ".swiftformat" config file #1191

Open DubonYaar opened 2 years ago

DubonYaar commented 2 years ago

I'm using Swift format for Xcode extension. I've added ".swiftformat" config file in the project folder, starting Swiftformat from Xcode's menu ignores the config file.

nicklockwood commented 2 years ago

This is a known issue (it's due to a limitation in the sandbox restrictions for extensions).

The good news is there's a workaround and it will hopefully be fixed soon. In the meantime, you have to load your .swiftformat file manually in the SwiftFormat for Xcode app to configure the extension.

DubonYaar commented 2 years ago

Thanks, How do I load the .swiftformat manually?

nicklockwood commented 2 years ago

Use the File > Open… menu in the app

mesqueeb commented 7 months ago

@nicklockwood is there any way I can help fix this issue? maybe via a donation? I need this so all my other computers and colleagues are on the same formatting rules as me.

nicklockwood commented 7 months ago

@mesqueeb it's a sandboxing limitation imposed by Apple (Xcode extensions can't access the file system). Others have tried to find workarounds but nothing has worked so far

mesqueeb commented 7 months ago

@nicklockwood how about adding a text input to the app where we can paste a public url to the config (eg on a public git repo) and then each time your app launches it will fetch the latest config from there.

mesqueeb commented 7 months ago

This is something I can try building and PR? Doesn't seem too difficult. Or does the sandbox also prevent https get calls?

nicklockwood commented 7 months ago

This is something I can try building and PR? Doesn't seem too difficult. Or does the sandbox also prevent https get calls?

I'm not sure if http requests are allowed actually - it might work. You can't show any UI though, so you'd have to enter the url through the helper app and then sync it across to the extension via user defaults (same way config works currently)

jubishop commented 1 week ago

is this still a known issue? how are people working around this?

nicklockwood commented 1 week ago

is this still a known issue? how are people working around this?

you have to load your .swiftformat file manually in the SwiftFormat for Xcode app to configure the extension.

jubishop commented 1 week ago

will this work regardless of location? for example if I load /.swiftformat into the SwiftFormat for Xcode app, will it apply to /myproject/ContentView.swift ?

jubishop commented 1 week ago

looks like the answer is yes :) thanks.