Skip to content

Commit

Permalink
Add Swiftlint to git pre-commit (#6)
Browse files Browse the repository at this point in the history
* Add Swiftlint to bit pre-commit
  • Loading branch information
ruixhuang authored and mike-dydx committed Aug 21, 2024
1 parent 9a7b506 commit 41d0268
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class dydxMarketInfoViewBuilder: NSObject, ObjectBuilderProtocol {

private class dydxMarketInfoViewController: HostingViewController<PlatformView, dydxMarketInfoViewModel> {
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool {
if (request?.path == "/trade" || request?.path == "/market"), let presenter = presenter as? dydxMarketInfoViewPresenter {
if (request?.path == "/trade" || request?.path == "/market"), let presenter = presenter as? dydxMarketInfoViewPresenter {
presenter.marketId = request?.params?["market"] as? String ?? "ETH-USD"
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if request?.path == "/trade" {
Expand Down Expand Up @@ -133,8 +133,8 @@ private class dydxMarketInfoViewPresenter: HostedViewPresenter<dydxMarketInfoVie
Publishers
.CombineLatest(AbacusStateManager.shared.state.selectedSubaccountPositions,
$marketId
.compactMap { $0 }
.removeDuplicates())
.compactMap { $0 }
.removeDuplicates())
.sink { [weak self] subaccountPositions, marketId in
let position = subaccountPositions.first { (subaccountPosition: SubaccountPosition) in
subaccountPosition.id == marketId
Expand All @@ -154,7 +154,7 @@ private class dydxMarketInfoViewPresenter: HostedViewPresenter<dydxMarketInfoVie
/*
Comment out for now. Close Position would cause this to trigger and stops orderbook
*/
// AbacusStateManager.shared.setMarket(market: nil)
// AbacusStateManager.shared.setMarket(market: nil)
}

private func updatePositionSection(position: SubaccountPosition?) {
Expand All @@ -181,7 +181,7 @@ private class dydxMarketInfoViewPresenter: HostedViewPresenter<dydxMarketInfoVie
}
} else if presenter.isStarted {
presenter.stop()
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

ROOT_DIR=$(pwd)/../../

cp pre-commit ../.git/hooks

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
17 changes: 17 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# Redirect output to stderr.
exec 1>&2

# Stash any unstaged changes
git stash -q --keep-index

# Run SwiftLint only on staged files
git diff --cached --name-only --diff-filter=ACM | grep "\.swift$" | while read file; do
swiftlint --fix --format "$file" 2>/dev/null
done

# Stash the unstaged changes that were stashed previously
git stash pop -q

exit 0

0 comments on commit 41d0268

Please sign in to comment.