stadiamaps / ferrostar

A FOSS navigation SDK built from the ground up for the future
https://stadiamaps.github.io/ferrostar/
Other
180 stars 25 forks source link

Run SwiftFormat on commit #370

Open Patrick-Kladek opened 15 hours ago

Patrick-Kladek commented 15 hours ago

Description

To reduce the feedback loop for a failed build when formatting is not acceptable we agreed to run the formatter as part of the commit. Using https://github.com/hallettj/git-format-staged allows us to only format staged files, leaving other files untouched.

Tasks

Infos for Reviewer

I tested this without SwiftFormat installed: The commit will fail with an error message explaining to install SwiftFormat. You still have the option to ignore the hook and commit directly.

Git, by default, does not distribute hooks when a repository is cloned. This design choice is intentional to prevent arbitrary code execution on users’ machines for security reasons. Therefore we need the workaround, where we configure the git hooks path as part for build-ios.sh

Patrick-Kladek commented 14 hours ago

I'm using https://fork.dev as my git client, so I can show some use cases:

Failure when swift file is committed and swiftformat is not installed

failure swiftformat not installed

Success after installing swiftformat

swift success

Android should be unaffected

java success

Patrick-Kladek commented 14 hours ago

@ianthetechie could this cause any issue with Windows? for a long time windows didn't support bash but that changed in recent years.