nicklockwood / SwiftFormat

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

Format only uncommited(modifications) if are available #1629

Open zeljkomarinkovic opened 4 months ago

zeljkomarinkovic commented 4 months ago

Maybe have missed something, so sorry if i did. But i tried to find solution without success.

I have been using SwiftFormat for some time now, and i love it. But recently started with new to me project where there are other developer working on. Now, i use SwiftFormat with kb shortcut to format on save, but problem is that it bring too much noise in commit.

So i was trying to set SwiftFormat to work only on changes that are made to some file if there is no changes, maybe just lint but do not format whole file.

Is this possible? Can this be a feature to consider if not done already?

Sorry again if i have missed something

Thanks :)

nicklockwood commented 4 months ago

When you say that you are running via a keyboard shortcut, do you mean running the command line tool, or the Xcode extension?

If you just want to be able to format the current open file with a keyboard shortcut, instead of the whole project, using the Xcode Extension may be the best way to do that.

Currently there is no way to limit the command line tool to run only on edited files, unless you use something like a git hook.

zeljkomarinkovic commented 4 months ago

When you say that you are running via a keyboard shortcut, do you mean running the command line tool, or the Xcode extension?

Xcode extension :)

If you just want to be able to format the current open file with a keyboard shortcut, instead of the whole project, using the Xcode Extension may be the best way to do that.

Currently there is no way to limit the command line tool to run only on edited files, unless you use something like a git hook.

So yes, im running XCode extension on kb shortcut, so every time i save file it formats that whole file, but now that i work with more devs it'q quite annoying to get all this changes in git commit.

If this is not possible is it possible to follow rules from SwiftLint since project is linted but not formated by SwiftLint. They are running SwiftLint as build phase via Pods

insha commented 4 months ago

@zeljkomarinkovic I have a script that I can run (either manually or as part of the build phase in Xcode) that does just that. It will format only the files have changed and nothing else. I have been using it for a long while now on a daily basis and my productivity has noticeblely improved (non-scientific and sample of few ;) ) . The script has been tweaked over the years to accommodate use case as I (and several other people) encountered them such as Xcode previews, CI, and such.

Let me know if you are interested and I will share.

zeljkomarinkovic commented 4 months ago

Sounds wonderful, just what im looking for. Please share :)

insha commented 4 months ago

@zeljkomarinkovic Here's the repo.

zeljkomarinkovic commented 3 months ago

@insha thanks, will put it to a good use :) Thanks