Skip to content

Commit

Permalink
[NT-1176] Update SwiftFormat (#1164)
Browse files Browse the repository at this point in the history
* Xcode 11.4 updates

* Update swiftlint and whitelist line_length rule

* Update swiftformat and spaceAroundOperators rule

* Remove swiftlint, run swiftformat with wrap enabled

* Remove pre-push hook

* Fix error

* Tweak playground formatting
  • Loading branch information
justinswart authored Apr 22, 2020
1 parent 1b16c32 commit b379866
Show file tree
Hide file tree
Showing 161 changed files with 920 additions and 973 deletions.
7 changes: 5 additions & 2 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
# Reference `self` explicitly
--self insert

# ranges
--ranges no-space
# spaceAroundOperators
--nospaceoperators ...,..<

# wrap
--maxwidth 110

# trailingCommas
--commas inline
Expand Down
95 changes: 0 additions & 95 deletions .swiftlint.yml

This file was deleted.

8 changes: 1 addition & 7 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# PR size
warn("Big PR") if git.lines_of_code > 350

# SwiftLint
swiftlint.binary_path = 'bin/swiftlint'
swiftlint.config_file = '.swiftlint.yml'
swiftlint.strict = true
swiftlint.lint_files inline_mode: true
warn("Big PR") if git.lines_of_code > 500

# SwiftFormat
swiftformat.binary_path = "bin/swiftformat"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
initialize()
let controller = BackingViewController.configuredWith(project: .template, backer: .template)

// swiftformat:disable wrap
AppEnvironment.login(
AccessTokenEnvelope(
accessToken: "cafebeef",
Expand All @@ -28,6 +29,7 @@ AppEnvironment.replaceCurrentEnvironment(

let reward = .template
|> Reward.lens.description .~ "- PRINT COPY- A full color copy of the Far Away comic book, plus a sticker and a Far Away Button. Also includes the pdf and all other digital downloads. "
// swiftformat:enable wrap

let backing = .template
|> Backing.lens.amount .~ 1_000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ let buttonsStyles: [[(UIButton) -> UIButton]] = baseButtonsStyles.map { [$0, $0

let rowStackViewStyle =
UIStackView.lens.alignment .~ .top
<> UIStackView.lens.axis .~ .horizontal
<> UIStackView.lens.distribution .~ .equalSpacing
<> UIStackView.lens.spacing .~ 24.0
<> UIStackView.lens.axis .~ .horizontal
<> UIStackView.lens.distribution .~ .equalSpacing
<> UIStackView.lens.spacing .~ 24.0

buttonsStyles.forEach { styles in
let rowStackView = UIStackView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func paletteItemStackView(colorView colorView: UIView, labelsView: UIView) -> UI
|> UIStackView.lens.arrangedSubviews .~ [colorView, labelsView]
}

func labelsStackView(colorName colorName: String, startColor: UIColor, endColor: UIColor?, weight: Int? = nil) -> UIStackView {
func labelsStackView(colorName colorName: String, startColor: UIColor, endColor: UIColor?,
weight: Int? = nil) -> UIStackView {
var weightValue = ""
if let weight = weight {
weightValue = " - \(weight)"
Expand Down Expand Up @@ -66,7 +67,8 @@ func colorBlockStackView(color color: UIColor, colorName: String, weight: Int? =

//: A gradient color block with labels in a stack view.

func gradientBlockStackView(colorName colorName: String, startColor: UIColor, endColor: UIColor) -> UIStackView {
func gradientBlockStackView(colorName colorName: String, startColor: UIColor,
endColor: UIColor) -> UIStackView {
let view = GradientView()
view.startPoint = CGPoint(x: 0.0, y: 1.0)
view.endPoint = CGPoint(x: 1.0, y: 0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ let stats = [
let fundingStats = stats.enumerated().map { idx, pledged in
.template
|> ProjectStatsEnvelope.FundingDateStats.lens.cumulativePledged .~ pledged
|> ProjectStatsEnvelope.FundingDateStats.lens.date .~ (cosmicSurgery.dates.launchedAt + TimeInterval(idx * 86_400))
|> ProjectStatsEnvelope.FundingDateStats.lens.date .~ (
cosmicSurgery.dates.launchedAt + TimeInterval(idx * 86_400)
)
}

AppEnvironment.replaceCurrentEnvironment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let orientation = Orientation.portrait

let project = Project.cosmicSurgery

// swiftformat:disable wrap
let baseActivity = .template
|> Activity.lens.comment .~ (
.template
Expand All @@ -32,6 +33,7 @@ let baseActivity = .template
.template
|> Backing.lens.amount .~ 25
)
// swiftformat:enable wrap

let backingActivity = baseActivity
|> Activity.lens.category .~ .backing
Expand Down Expand Up @@ -76,7 +78,8 @@ let backingActivities = [
AppEnvironment.replaceCurrentEnvironment(
apiService: MockService(
oauthToken: OauthToken(token: "deadbeef"),
fetchProjectActivitiesResponse: activityCategories.map { baseActivity |> Activity.lens.category .~ $0 } + backingActivities
fetchProjectActivitiesResponse: activityCategories
.map { baseActivity |> Activity.lens.category .~ $0 } + backingActivities
),
currentUser: Project.cosmicSurgery.creator,
isVoiceOverRunning: { isVoiceOverRunning }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ AppEnvironment.replaceCurrentEnvironment(mainBundle: Bundle.framework)

AppEnvironment.replaceCurrentEnvironment(language: .en)
Strings.activity_empty_state_logged_in_message()
Strings.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)
Strings
.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)

AppEnvironment.replaceCurrentEnvironment(language: .es, locale: Locale(identifier: "es"))
Strings.activity_empty_state_logged_in_message()
Strings.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)
Strings
.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)

AppEnvironment.replaceCurrentEnvironment(language: .fr, locale: Locale(identifier: "fr"))
Strings.activity_empty_state_logged_in_message()
Strings.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)
Strings
.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)

AppEnvironment.replaceCurrentEnvironment(language: .de, locale: Locale(identifier: "de"))
Strings.activity_empty_state_logged_in_message()
Strings.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)
Strings
.dashboard_post_update_preview_confirmation_alert_this_will_notify_backers_that_a_new_update_is_available(
backer_count: 1_234
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import Prelude
import Prelude_UIKit
import UIKit

// swiftformat:disable wrap
let project = .cosmicSurgery
|> Project.lens.video .~ (
.template
|> Project.Video.lens.high .~ "https://d2pq0u4uni88oo.cloudfront.net/projects/1846844/video-562464-h264_high.mp4"
)
// swiftformat:enable wrap

AppEnvironment.replaceCurrentEnvironment(
apiService: MockService(
Expand Down
4 changes: 1 addition & 3 deletions Kickstarter-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {

self.viewModel.outputs.evaluateQualtricsTargetingLogic
.observeValues { [weak self] in
Qualtrics.shared.evaluateTargetingLogic() { result in
Qualtrics.shared.evaluateTargetingLogic { result in
self?.viewModel.inputs.didEvaluateQualtricsTargetingLogic(
with: result, properties: Qualtrics.shared.properties
)
Expand All @@ -249,7 +249,6 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {
self?.rootTabBarController?.present(navController, animated: true)
}

// swiftlint:disable discarded_notification_center_observer
NotificationCenter.default
.addObserver(forName: Notification.Name.ksr_sessionStarted, object: nil, queue: nil) { [weak self] _ in
self?.viewModel.inputs.userSessionStarted()
Expand All @@ -266,7 +265,6 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {
.addObserver(forName: Notification.Name.ksr_sessionEnded, object: nil, queue: nil) { [weak self] _ in
self?.viewModel.inputs.userSessionEnded()
}
// swiftlint:enable discarded_notification_center_observer

self.window?.tintColor = .ksr_green_700

Expand Down
31 changes: 24 additions & 7 deletions Kickstarter-iOS/DataSources/DiscoveryFiltersDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import KsApi
import Prelude
import XCTest

// swiftlint:disable line_length
internal final class DiscoveryFiltersDataSourceTests: XCTestCase {
fileprivate let collectionsHeader = DiscoveryFiltersDataSource.Section.collectionsHeader.rawValue
fileprivate let collections = DiscoveryFiltersDataSource.Section.collections.rawValue
Expand All @@ -28,8 +27,14 @@ internal final class DiscoveryFiltersDataSourceTests: XCTestCase {
)

XCTAssertEqual(4, self.dataSource.tableView(self.tableView, numberOfRowsInSection: self.collections))
XCTAssertEqual("DiscoverySelectableRowCell", self.dataSource.reusableId(item: 0, section: self.collections))
XCTAssertEqual(1, self.dataSource.tableView(self.tableView, numberOfRowsInSection: self.collectionsHeader))
XCTAssertEqual(
"DiscoverySelectableRowCell",
self.dataSource.reusableId(item: 0, section: self.collections)
)
XCTAssertEqual(
1,
self.dataSource.tableView(self.tableView, numberOfRowsInSection: self.collectionsHeader)
)
XCTAssertEqual(
"DiscoveryFiltersStaticRowCell",
self.dataSource.reusableId(item: 0, section: self.collectionsHeader)
Expand Down Expand Up @@ -80,8 +85,14 @@ internal final class DiscoveryFiltersDataSourceTests: XCTestCase {
)

XCTAssertEqual(2, self.dataSource.tableView(self.tableView, numberOfRowsInSection: self.categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 0, section: self.categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 1, section: self.categories))
XCTAssertEqual(
"DiscoveryExpandableRowCell",
self.dataSource.reusableId(item: 0, section: self.categories)
)
XCTAssertEqual(
"DiscoveryExpandableRowCell",
self.dataSource.reusableId(item: 1, section: self.categories)
)
XCTAssertEqual(1, self.dataSource.tableView(self.tableView, numberOfRowsInSection: self.categoriesHeader))
}

Expand Down Expand Up @@ -109,8 +120,14 @@ internal final class DiscoveryFiltersDataSourceTests: XCTestCase {
)

XCTAssertEqual(4, self.dataSource.tableView(self.tableView, numberOfRowsInSection: self.categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 0, section: self.categories))
XCTAssertEqual("DiscoveryExpandableRowCell", self.dataSource.reusableId(item: 1, section: self.categories))
XCTAssertEqual(
"DiscoveryExpandableRowCell",
self.dataSource.reusableId(item: 0, section: self.categories)
)
XCTAssertEqual(
"DiscoveryExpandableRowCell",
self.dataSource.reusableId(item: 1, section: self.categories)
)
XCTAssertEqual(
"DiscoveryExpandedSelectableRowCell",
self.dataSource.reusableId(item: 2, section: self.categories)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ internal final class ProjectActivitiesDataSourceTests: XCTestCase {
let tableView = UITableView()

func testDataSource() {
// swiftlint:disable:next force_unwrapping
let timeZone = TimeZone(abbreviation: "UTC")!
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = timeZone
Expand Down Expand Up @@ -54,7 +53,6 @@ internal final class ProjectActivitiesDataSourceTests: XCTestCase {
}

func testGroupedDatesIsFalse() {
// swiftlint:disable:next force_unwrapping
let timeZone = TimeZone(abbreviation: "UTC")!
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = timeZone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ final class SettingsAccountDataSource: ValueCellDataSource {
return value.cellType as? SettingsAccountCellType
} else if let currencyValue = self[indexPath] as? SettingsCellValue {
return currencyValue.cellType as? SettingsAccountCellType
// swiftlint:disable:next unused_optional_binding
} else if let _ = self[indexPath] as? Bool {
return SettingsAccountCellType.changeEmail
} else {
Expand Down
6 changes: 4 additions & 2 deletions Kickstarter-iOS/DataSources/SettingsDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ final class SettingsDataSourceTests: XCTestCase {
let indexPath1 = IndexPath(item: 0, section: 1)
let indexPath2 = IndexPath(item: 1, section: 1)

// swiftlint:disable:next line_length
XCTAssertEqual(SettingsCellType.notifications, self.dataSource.cellTypeForIndexPath(indexPath: indexPath1))
XCTAssertEqual(
SettingsCellType.notifications,
self.dataSource.cellTypeForIndexPath(indexPath: indexPath1)
)
XCTAssertEqual(SettingsCellType.newsletters, self.dataSource.cellTypeForIndexPath(indexPath: indexPath2))
}
}
Loading

0 comments on commit b379866

Please sign in to comment.