Skip to content
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

Format only uncommited(modifications) if are available #1629

Open
zeljkomarinkovic opened this issue Feb 22, 2024 · 6 comments
Open

Format only uncommited(modifications) if are available #1629

zeljkomarinkovic opened this issue Feb 22, 2024 · 6 comments

Comments

@zeljkomarinkovic
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link

insha commented Mar 8, 2024

@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
Copy link
Author

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

@insha
Copy link

insha commented Mar 8, 2024

@zeljkomarinkovic Here's the repo.

@zeljkomarinkovic
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants