huggingface / swift-transformers

Swift Package to implement a transformers-like API in Swift
Apache License 2.0
536 stars 46 forks source link

Automatic Formatting with `apple/swift-format` #90

Open ashvardanian opened 2 months ago

ashvardanian commented 2 months ago

When working with the repository, I am not always sure about how to style code, as Swift gives a lot of flexibility on where to put public clauses, how to indent the code and so on. Moreover, Xcode isn't friendly to "Format on Save". Luckily, there is a swift-format utility from Apple, that works very similar to clang-format.

We extensively use such systems in our codebases. They help keep the code sane when the number of contributors rises. If interested, you may want to add it to your Git hooks.

maiqingqiang commented 2 months ago

Nice! I've been waiting.

pcuenca commented 2 months ago

Thank you, this was surely needed! I'll review in depth soon. Would you say that the rules you chose are more or less standard across Swift codebases, or are there other alternatives? (I personally don't like to break up all function parameters in multiple lines, but willing to sacrifice for consistency).

ashvardanian commented 2 months ago

Not sure the standard exists in Swift. I'm now enabling these rules in the libraries I maintain - UForm, USearch, StringZilla. Maybe with enough popular libraries agreeing on the format, we can propose that missing standard 🤷‍♂️