Skip to content

Commit

Permalink
馃挷[Native Checkout] - SwiftFormat (#687)
Browse files Browse the repository at this point in the history
* Remove SwiftFormat's hoisting rule

* Update SwiftFormat rules

* Format all Swift files added or updated by feature branch

* Fix line length violations

* Re-enable explicit self reference rule

* Format code with explicit self reference ON

* Update .init spacing

* Format decimals

* Format and operator

* Format comments

* Order SwiftFormat rules alphabetically

* Format selectors

* Format ChangeEmailViewController

* Order excluded swiftformat files alphabeticallyr

* Rename UIView+AutoLayout

* Fix formatter causing build errors

* Disable rules on new line

* Reformat indentation

* Rename ksr_swiftformat to format
  • Loading branch information
dusi authored and ifbarrera committed Aug 5, 2019
1 parent 6acbf27 commit 436cc3d
Show file tree
Hide file tree
Showing 59 changed files with 634 additions and 501 deletions.
1 change: 0 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# numberFormatting
--decimalgrouping 3
--hexgrouping "ignore"

# redundantSelf
# Reference `self` explicitly
Expand Down
3 changes: 2 additions & 1 deletion Kickstarter-iOS/DataSources/PledgeDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ final class PledgeDataSource: ValueCellDataSource {
currency: String,
delivery: String,
shipping: (location: String, amount: NSAttributedString?),
isLoggedIn: Bool) {
isLoggedIn: Bool
) {
self.appendRow(
value: delivery,
cellClass: PledgeDescriptionCell.self,
Expand Down
3 changes: 2 additions & 1 deletion Kickstarter-iOS/DataSources/PledgeDataSourceTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import XCTest
@testable import Kickstarter_Framework
@testable import Library
import XCTest

final class PledgeDataSourceTests: XCTestCase {
let dataSource = PledgeDataSource()
Expand Down Expand Up @@ -45,5 +45,6 @@ final class PledgeDataSourceTests: XCTestCase {
XCTAssertEqual(PledgeRowCell.defaultReusableId, self.dataSource.reusableId(item: 0, section: 2))
XCTAssertEqual(PledgeContinueCell.defaultReusableId, self.dataSource.reusableId(item: 1, section: 2))
}

// swiftlint:enable line_length
}
36 changes: 22 additions & 14 deletions Kickstarter-iOS/DataSources/ProjectPamphletContentDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal final class ProjectPamphletContentDataSource: ValueCellDataSource {
inSection: Section.subpages.rawValue
)

if !featureNativeCheckoutEnabled() {
if !self.featureNativeCheckoutEnabled() {
self.setRewardTitleArea(project: project)
}
}
Expand All @@ -48,7 +48,7 @@ internal final class ProjectPamphletContentDataSource: ValueCellDataSource {
inSection: Section.subpages.rawValue
)

if !featureNativeCheckoutEnabled() {
if !self.featureNativeCheckoutEnabled() {
self.setRewardTitleArea(project: project)
self.setRewards(project: project, visible)
}
Expand Down Expand Up @@ -80,9 +80,11 @@ internal final class ProjectPamphletContentDataSource: ValueCellDataSource {
self.set(values: [project], cellClass: NoRewardCell.self, inSection: Section.calloutReward.rawValue)
} else if let backing = project.personalization.backing {
self.set(values: [project], cellClass: PledgeTitleCell.self, inSection: Section.pledgeTitle.rawValue)
self.set(values: [(project, .right(backing))],
cellClass: DeprecatedRewardCell.self,
inSection: Section.calloutReward.rawValue)
self.set(
values: [(project, .right(backing))],
cellClass: DeprecatedRewardCell.self,
inSection: Section.calloutReward.rawValue
)
}
}

Expand All @@ -94,17 +96,23 @@ internal final class ProjectPamphletContentDataSource: ValueCellDataSource {

if !rewardData.isEmpty {
if visible {
self.set(values: [project],
cellClass: RewardsTitleCell.self,
inSection: Section.rewardsTitle.rawValue)
self.set(
values: [project],
cellClass: RewardsTitleCell.self,
inSection: Section.rewardsTitle.rawValue
)
}

self.set(values: availableRewards(for: project),
cellClass: DeprecatedRewardCell.self,
inSection: Section.availableRewards.rawValue)
self.set(values: unavailableRewards(for: project),
cellClass: DeprecatedRewardCell.self,
inSection: Section.unavailableRewards.rawValue)
self.set(
values: self.availableRewards(for: project),
cellClass: DeprecatedRewardCell.self,
inSection: Section.availableRewards.rawValue
)
self.set(
values: self.unavailableRewards(for: project),
cellClass: DeprecatedRewardCell.self,
inSection: Section.unavailableRewards.rawValue
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import UIKit

final class RewardsCollectionViewDataSource: ValueCellDataSource {
func load(rewards: [Reward]) {
self.set(values: rewards,
cellClass: RewardCell.self,
inSection: 0)
self.set(
values: rewards,
cellClass: RewardCell.self,
inSection: 0
)
}

override func configureCell(collectionCell cell: UICollectionViewCell, withValue value: Any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import XCTest
@testable import Kickstarter_Framework
@testable import KsApi
import XCTest

final class RewardsCollectionViewDataSourceTests: XCTestCase {
private let dataSource = RewardsCollectionViewDataSource()
private let collectionView = UICollectionView(frame: .zero,
collectionViewLayout: UICollectionViewFlowLayout())
private let collectionView = UICollectionView(
frame: .zero,
collectionViewLayout: UICollectionViewFlowLayout()
)

func testLoadRewards() {
let rewards = [Reward.template, Reward.template]
Expand Down
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Library/Nib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension NibLoading {
.first as? Self else {
assertionFailure("Nib not found")
return nil
}
}
// swiftformat:enable indent

return view
Expand Down
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Views/AmountInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AmountInputView: UIView {
|> ksr_addArrangedSubviewsToStackView()
}

required init?(coder aDecoder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down
85 changes: 44 additions & 41 deletions Kickstarter-iOS/Views/Cells/DeprecatedRewardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import KsApi
import Library
import Prelude

internal protocol RewardCellDelegate: class {
internal protocol RewardCellDelegate: AnyObject {
/// Called when the reward cell needs to perform an expansion animation.
func rewardCellWantsExpansion(_ cell: DeprecatedRewardCell)
}
Expand All @@ -11,42 +11,42 @@ internal final class DeprecatedRewardCell: UITableViewCell, ValueCell {
internal var delegate: RewardCellDelegate?
fileprivate let viewModel: RewardCellViewModelType = DeprecatedRewardCellViewModel()

@IBOutlet fileprivate weak var allGoneContainerView: UIView!
@IBOutlet fileprivate weak var allGoneLabel: UILabel!
@IBOutlet fileprivate weak var cardView: UIView!
@IBOutlet fileprivate weak var checkmarkImageView: UIImageView!
@IBOutlet fileprivate weak var conversionLabel: UILabel!
@IBOutlet fileprivate weak var descriptionLabel: UILabel!
@IBOutlet fileprivate weak var estimatedDeliveryDateLabel: UILabel!
@IBOutlet fileprivate weak var estimatedDeliveryLabel: UILabel!
@IBOutlet fileprivate weak var estimatedDeliveryDateStackView: UIStackView!
@IBOutlet fileprivate weak var footerLabel: UILabel!
@IBOutlet fileprivate weak var footerStackView: UIStackView!
@IBOutlet fileprivate weak var includesTitleLabel: UILabel!
@IBOutlet fileprivate weak var itemsContainerStackView: UIStackView!
@IBOutlet fileprivate weak var itemsHeaderStackView: UIStackView!
@IBOutlet fileprivate weak var itemsStackView: UIStackView!
@IBOutlet fileprivate weak var manageRewardButton: UIButton!
@IBOutlet fileprivate weak var minimumLabel: UILabel!
@IBOutlet fileprivate weak var minimumStackView: UIStackView!
@IBOutlet fileprivate weak var rewardTitleLabel: UILabel!
@IBOutlet fileprivate weak var rootStackView: UIStackView!
@IBOutlet fileprivate weak var selectRewardButton: UIButton!
@IBOutlet fileprivate weak var shippingLocationsLabel: UILabel!
@IBOutlet fileprivate weak var shippingLocationsStackView: UIStackView!
@IBOutlet fileprivate weak var shippingLocationsSummaryLabel: UILabel!
@IBOutlet fileprivate var allGoneContainerView: UIView!
@IBOutlet fileprivate var allGoneLabel: UILabel!
@IBOutlet fileprivate var cardView: UIView!
@IBOutlet fileprivate var checkmarkImageView: UIImageView!
@IBOutlet fileprivate var conversionLabel: UILabel!
@IBOutlet fileprivate var descriptionLabel: UILabel!
@IBOutlet fileprivate var estimatedDeliveryDateLabel: UILabel!
@IBOutlet fileprivate var estimatedDeliveryLabel: UILabel!
@IBOutlet fileprivate var estimatedDeliveryDateStackView: UIStackView!
@IBOutlet fileprivate var footerLabel: UILabel!
@IBOutlet fileprivate var footerStackView: UIStackView!
@IBOutlet fileprivate var includesTitleLabel: UILabel!
@IBOutlet fileprivate var itemsContainerStackView: UIStackView!
@IBOutlet fileprivate var itemsHeaderStackView: UIStackView!
@IBOutlet fileprivate var itemsStackView: UIStackView!
@IBOutlet fileprivate var manageRewardButton: UIButton!
@IBOutlet fileprivate var minimumLabel: UILabel!
@IBOutlet fileprivate var minimumStackView: UIStackView!
@IBOutlet fileprivate var rewardTitleLabel: UILabel!
@IBOutlet fileprivate var rootStackView: UIStackView!
@IBOutlet fileprivate var selectRewardButton: UIButton!
@IBOutlet fileprivate var shippingLocationsLabel: UILabel!
@IBOutlet fileprivate var shippingLocationsStackView: UIStackView!
@IBOutlet fileprivate var shippingLocationsSummaryLabel: UILabel!
@IBOutlet fileprivate var separatorViews: [UIView]!
@IBOutlet fileprivate weak var titleDescriptionStackView: UIStackView!
@IBOutlet fileprivate weak var viewYourPledgeButton: UIButton!
@IBOutlet fileprivate weak var youreABackerCheckmarkImageView: UIImageView!
@IBOutlet fileprivate weak var youreABackerContainerView: UIView!
@IBOutlet fileprivate weak var youreABackerLabel: UILabel!
@IBOutlet fileprivate weak var youreABackerStackView: UIStackView!
@IBOutlet fileprivate var titleDescriptionStackView: UIStackView!
@IBOutlet fileprivate var viewYourPledgeButton: UIButton!
@IBOutlet fileprivate var youreABackerCheckmarkImageView: UIImageView!
@IBOutlet fileprivate var youreABackerContainerView: UIView!
@IBOutlet fileprivate var youreABackerLabel: UILabel!
@IBOutlet fileprivate var youreABackerStackView: UIStackView!

internal override func awakeFromNib() {
super.awakeFromNib()

let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapped))
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(DeprecatedRewardCell.tapped))
tapRecognizer.cancelsTouchesInView = false
tapRecognizer.delaysTouchesBegan = false
tapRecognizer.delaysTouchesEnded = false
Expand All @@ -67,18 +67,19 @@ internal final class DeprecatedRewardCell: UITableViewCell, ValueCell {
_ = self
|> baseTableViewCellStyle()
|> DeprecatedRewardCell.lens.accessibilityTraits .~ UIAccessibilityTraits.button.rawValue
|> (DeprecatedRewardCell.lens.contentView..UIView.lens.layoutMargins) %~~ { _, cell in
|> (DeprecatedRewardCell.lens.contentView .. UIView.lens.layoutMargins) %~~ { _, cell in
cell.traitCollection.isRegularRegular
? .init(top: Styles.grid(2), left: Styles.grid(16), bottom: Styles.grid(4), right: Styles.grid(16))
: .init(top: Styles.grid(1), left: Styles.grid(2), bottom: Styles.grid(2), right: Styles.grid(2))
}
|> DeprecatedRewardCell.lens.contentView..UIView.lens.backgroundColor .~ projectCellBackgroundColor()
|> DeprecatedRewardCell.lens.contentView .. UIView.lens.backgroundColor .~ projectCellBackgroundColor()
|> UIView.lens.contentMode .~ .top

_ = self.rootStackView
|> UIStackView.lens.spacing .~ Styles.grid(4)
|> UIStackView.lens.layoutMargins
.~ .init(top: Styles.grid(3), left: Styles.grid(2), bottom: Styles.grid(2), right: Styles.grid(2))
|> UIStackView.lens.layoutMargins .~ .init(
top: Styles.grid(3), left: Styles.grid(2), bottom: Styles.grid(2), right: Styles.grid(2)
)
|> UIStackView.lens.isLayoutMarginsRelativeArrangement .~ true

_ = self.minimumStackView
Expand All @@ -96,8 +97,10 @@ internal final class DeprecatedRewardCell: UITableViewCell, ValueCell {
_ = [self.itemsContainerStackView, self.itemsHeaderStackView, self.itemsStackView]
||> UIStackView.lens.spacing .~ Styles.grid(2)

_ = [self.minimumStackView, self.titleDescriptionStackView,
self.itemsContainerStackView, self.footerStackView]
_ = [
self.minimumStackView, self.titleDescriptionStackView,
self.itemsContainerStackView, self.footerStackView
]
||> UIStackView.lens.layoutMargins .~ .init(topBottom: 0, leftRight: Styles.grid(2))
||> UIStackView.lens.isLayoutMarginsRelativeArrangement .~ true

Expand Down Expand Up @@ -157,7 +160,7 @@ internal final class DeprecatedRewardCell: UITableViewCell, ValueCell {
|> UIImageView.lens.tintColor .~ .ksr_text_dark_grey_500
|> UIImageView.lens.image %~ { _ in
UIImage(named: "checkmark-icon", in: .framework, compatibleWith: nil)
}
}

_ = self.youreABackerContainerView
|> roundedStyle(cornerRadius: 2)
Expand Down Expand Up @@ -234,13 +237,13 @@ internal final class DeprecatedRewardCell: UITableViewCell, ValueCell {
.observeForUI()
.observeValues { [weak self] in
self.doIfSome { $0.delegate?.rewardCellWantsExpansion($0) }
}
}

self.viewModel.outputs.updateTopMarginsForIsBacking
.observeForUI()
.observeValues { [weak self] isBacking in
self?.contentView.layoutMargins.top = Styles.grid(isBacking ? 3 : 1)
}
}

self.viewModel.outputs.items
.observeForUI()
Expand Down
3 changes: 2 additions & 1 deletion Kickstarter-iOS/Views/Cells/PledgeAmountCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class PledgeAmountCell: UITableViewCell, ValueCell {
UIView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private lazy var stepper: UIStepper = { UIStepper(frame: .zero) }()

// MARK: - Lifecycle
Expand All @@ -37,7 +38,7 @@ final class PledgeAmountCell: UITableViewCell, ValueCell {
self.spacer.widthAnchor.constraint(greaterThanOrEqualToConstant: Styles.grid(3)).isActive = true
}

required init?(coder aDecoder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down
8 changes: 4 additions & 4 deletions Kickstarter-iOS/Views/Cells/PledgeContinueCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class PledgeContinueCell: UITableViewCell, ValueCell {
self.setupSubviews()
}

required init?(coder aDecoder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand All @@ -27,14 +27,14 @@ final class PledgeContinueCell: UITableViewCell, ValueCell {
_ = self.continueButton
|> checkoutGreenButtonStyle
|> UIButton.lens.title(for: .normal) %~ { _ in
return Strings.Continue()
}
Strings.Continue()
}

_ = self.continueButton.titleLabel
?|> checkoutGreenButtonTitleLabelStyle
}

func configureWith(value: ()) {}
func configureWith(value _: ()) {}

private func setupSubviews() {
_ = (self.continueButton, self.contentView)
Expand Down
Loading

0 comments on commit 436cc3d

Please sign in to comment.