Improve usage as build script (breaks undo/redo 100% of the time)

I'd like to use swift-formats format subcommand as a build script e.g. in an iOS project where I run the build script on every build to automatically reformat the code when needed. But "when needed" is actually the emphasis here, as of now with how swift-format works internally when the --in-place option is used, it will rewrite the entire file even when not a single character needs to be changed. This deletes the history of changes in code editors like Xcode and therefore breaks the undo/redo features unnecessarily. For me personally, 90% of the time the code doesn't need to be reformatted as I get used to the correct formatting over time, so this is quite annoying.

While I will be using the lint subcommand instead (without the --in-place option of course) to circumvent the problem, I think the other use case still might make sense for some, so it might make sense to not write the file if there's no changes to be made. I'm not sure if this will be a performance problem, but as it's one file write less it might even increase performance.

1 Like
Terms of Service

Privacy Policy

Cookie Policy