Skip to content

Commit

Permalink
Run swiftformat with some rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jul 4, 2022
1 parent 6c009bf commit 70aaf9c
Show file tree
Hide file tree
Showing 135 changed files with 585 additions and 616 deletions.
22 changes: 12 additions & 10 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

--exclude ElementX/Sources/Generated

--disable all
--disable wrapMultiLineStatementBraces
--disable blankLinesAtStartOfScope
--disable blankLinesAtEndOfScope
--disable hoistPatternLet

--enable blankLinesAroundMark
--enable blankLinesBetweenScopes
--enable consecutiveBlankLines
--enable consecutiveSpaces
--enable linebreakAtEndOfFile
--enable linebreaks
--enable trailingSpace

--trimwhitespace nonblank-lines
--commas inline
--ifdef no-indent
--nospaceoperators ...,..<
--stripunusedargs closure-only
--trimwhitespace nonblank-lines
--wrapparameters after-first
--redundanttype inferred
--emptybraces spaced
8 changes: 4 additions & 4 deletions Dangerfile.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import Danger
import Foundation

SwiftLint.lint(inline: true)

Expand All @@ -19,15 +19,15 @@ if danger.github.pullRequest.body?.isEmpty ?? true {
let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
let changelogFiles = editedFiles.filter { $0.hasPrefix("changelog.d/") }

if editedFiles.count > 0 && changelogFiles.isEmpty {
if editedFiles.count > 0, changelogFiles.isEmpty {
warn("Please add a changelog.")
}

// Check for a ticket number
if let ticketNumberRegex = try? NSRegularExpression(pattern: "#\\d+") {
let missingTicketNumber = !danger.git.commits.filter {
!$0.message.contains("vector-im/element-x-ios/issues/") &&
ticketNumberRegex.firstMatch(in: $0.message, options: [], range: .init(location: 0, length: $0.message.utf16.count)) == nil
ticketNumberRegex.firstMatch(in: $0.message, options: [], range: .init(location: 0, length: $0.message.utf16.count)) == nil
}.isEmpty

if missingTicketNumber {
Expand Down Expand Up @@ -63,7 +63,7 @@ if requiresSignOff {
!$0.message.contains(signOff)
}.isEmpty

if !hasPRBodySignOff && isMissingCommitsSignOff {
if !hasPRBodySignOff, isMissingCommitsSignOff {
fail("Please add a sign-off to either the PR description or to the commits themselves.")
}
}
Expand Down
2 changes: 1 addition & 1 deletion DesignKit/Sources/Buttons/ElementActionButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.
//

import SwiftUI
import DesignTokens
import SwiftUI

public extension ButtonStyle where Self == ElementActionButtonStyle {
/// The CTA button style as defined in Compound.
Expand Down
2 changes: 1 addition & 1 deletion DesignKit/Sources/Buttons/ElementGhostButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.
//

import SwiftUI
import DesignTokens
import SwiftUI

public extension ButtonStyle where Self == ElementGhostButtonStyle {
/// The Ghost button style as defined in Compound.
Expand Down
46 changes: 23 additions & 23 deletions DesignKit/Sources/Fonts/ElementSharedFonts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,111 +35,111 @@ public class ElementSharedFonts {

/// Returns an instance of the font associated with the text style and scaled appropriately for the content size category defined in the trait collection.
/// Keep this method private method at the moment and create a DesignKit.Fonts.TextStyle if needed.
fileprivate func font(forTextStyle textStyle: UIFont.TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> UIFont {
return UIFont.preferredFont(forTextStyle: textStyle, compatibleWith: traitCollection)
private func font(forTextStyle textStyle: UIFont.TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> UIFont {
UIFont.preferredFont(forTextStyle: textStyle, compatibleWith: traitCollection)
}
}

// MARK: - Fonts protocol

extension ElementSharedFonts {
public extension ElementSharedFonts {

public var largeTitle: SharedFont {
var largeTitle: SharedFont {
let uiFont = font(forTextStyle: .largeTitle)
return SharedFont(uiFont: uiFont, font: .largeTitle)
}

public var largeTitleB: SharedFont {
var largeTitleB: SharedFont {
let uiFont = largeTitle.uiFont.bold
return SharedFont(uiFont: uiFont, font: .largeTitle.bold())
}

public var title1: SharedFont {
var title1: SharedFont {
let uiFont = font(forTextStyle: .title1)
return SharedFont(uiFont: uiFont, font: .title)
}

public var title1B: SharedFont {
var title1B: SharedFont {
let uiFont = title1.uiFont.bold
return SharedFont(uiFont: uiFont, font: .title.bold())
}

public var title2: SharedFont {
var title2: SharedFont {
let uiFont = font(forTextStyle: .title2)
return SharedFont(uiFont: uiFont, font: .title2)
}

public var title2B: SharedFont {
var title2B: SharedFont {
let uiFont = title2.uiFont.bold
return SharedFont(uiFont: uiFont, font: .title2.bold())
}

public var title3: SharedFont {
var title3: SharedFont {
let uiFont = font(forTextStyle: .title3)
return SharedFont(uiFont: uiFont, font: .title3)
}

public var title3SB: SharedFont {
var title3SB: SharedFont {
let uiFont = title3.uiFont.semiBold
return SharedFont(uiFont: uiFont, font: .title3.weight(.semibold))
}

public var headline: SharedFont {
var headline: SharedFont {
let uiFont = font(forTextStyle: .headline)
return SharedFont(uiFont: uiFont, font: .headline)
}

public var subheadline: SharedFont {
var subheadline: SharedFont {
let uiFont = font(forTextStyle: .subheadline)
return SharedFont(uiFont: uiFont, font: .subheadline)
}

public var body: SharedFont {
var body: SharedFont {
let uiFont = font(forTextStyle: .body)
return SharedFont(uiFont: uiFont, font: .body)
}

public var bodySB: SharedFont {
var bodySB: SharedFont {
let uiFont = body.uiFont.semiBold
return SharedFont(uiFont: uiFont, font: .body.weight(.semibold))
}

public var callout: SharedFont {
var callout: SharedFont {
let uiFont = font(forTextStyle: .callout)
return SharedFont(uiFont: uiFont, font: .callout)
}

public var calloutSB: SharedFont {
var calloutSB: SharedFont {
let uiFont = callout.uiFont.semiBold
return SharedFont(uiFont: uiFont, font: .callout.weight(.semibold))
}

public var footnote: SharedFont {
var footnote: SharedFont {
let uiFont = font(forTextStyle: .footnote)
return SharedFont(uiFont: uiFont, font: .footnote)
}

public var footnoteSB: SharedFont {
var footnoteSB: SharedFont {
let uiFont = footnote.uiFont.semiBold
return SharedFont(uiFont: uiFont, font: .footnote.weight(.semibold))
}

public var caption1: SharedFont {
var caption1: SharedFont {
let uiFont = font(forTextStyle: .caption1)
return SharedFont(uiFont: uiFont, font: .caption)
}

public var caption1SB: SharedFont {
var caption1SB: SharedFont {
let uiFont = caption1.uiFont.semiBold
return SharedFont(uiFont: uiFont, font: .caption.weight(.semibold))
}

public var caption2: SharedFont {
var caption2: SharedFont {
let uiFont = font(forTextStyle: .caption2)
return SharedFont(uiFont: uiFont, font: .caption2)
}

public var caption2SB: SharedFont {
var caption2SB: SharedFont {
let uiFont = caption2.uiFont.semiBold
return SharedFont(uiFont: uiFont, font: .caption2.weight(.semibold))
}
Expand Down
6 changes: 3 additions & 3 deletions DesignKit/Sources/Fonts/UIFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public extension UIFont {
// MARK: - Shortcuts

var bold: UIFont {
return withTraits(.traitBold)
withTraits(.traitBold)
}

var semiBold: UIFont {
return withWeight(weight: .semibold)
withWeight(weight: .semibold)
}

var italic: UIFont {
return withTraits(.traitItalic)
withTraits(.traitItalic)
}
}
4 changes: 2 additions & 2 deletions DesignKit/Sources/TextFields/BorderedInputFieldStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// limitations under the License.
//

import SwiftUI
import DesignTokens
import Introspect
import SwiftUI

/// A bordered style of text input
///
Expand Down Expand Up @@ -48,7 +48,7 @@ public struct BorderedInputFieldStyle: TextFieldStyle {
}

private var backgroundColor: Color {
if !isEnabled && colorScheme == .dark {
if !isEnabled, colorScheme == .dark {
return .element.quinaryContent
}
return .element.background
Expand Down
2 changes: 1 addition & 1 deletion DesignKit/Sources/TextFields/ElementTextFieldStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.
//

import SwiftUI
import DesignTokens
import SwiftUI

@available(iOS 15.0, *)
public extension TextFieldStyle where Self == ElementTextFieldStyle {
Expand Down
2 changes: 1 addition & 1 deletion DesignKitTests/DesignKitTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import DesignKit
import XCTest

final class DesignKitTests: XCTestCase {
func testExample() throws {
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2022 Element. All rights reserved.
//

import UIKit
import Combine
import UIKit

class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
private let window: UIWindow
Expand Down
28 changes: 14 additions & 14 deletions ElementX/Sources/AppCoordinatorStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ class AppCoordinatorStateMachine {

init() {
stateMachine = StateMachine(state: .initial) { machine in
machine.addRoutes(event: .startWithAuthentication, transitions: [ .initial => .signedOut ])
machine.addRoutes(event: .attemptedSignIn, transitions: [ .signedOut => .signingIn ])
machine.addRoutes(event: .succeededSigningIn, transitions: [ .signingIn => .homeScreen ])
machine.addRoutes(event: .failedSigningIn, transitions: [ .signingIn => .signedOut ])
machine.addRoutes(event: .startWithAuthentication, transitions: [.initial => .signedOut])
machine.addRoutes(event: .attemptedSignIn, transitions: [.signedOut => .signingIn])
machine.addRoutes(event: .succeededSigningIn, transitions: [.signingIn => .homeScreen])
machine.addRoutes(event: .failedSigningIn, transitions: [.signingIn => .signedOut])

machine.addRoutes(event: .startWithExistingSession, transitions: [ .initial => .restoringSession ])
machine.addRoutes(event: .succeededRestoringSession, transitions: [ .restoringSession => .homeScreen ])
machine.addRoutes(event: .failedRestoringSession, transitions: [ .restoringSession => .signedOut ])
machine.addRoutes(event: .startWithExistingSession, transitions: [.initial => .restoringSession])
machine.addRoutes(event: .succeededRestoringSession, transitions: [.restoringSession => .homeScreen])
machine.addRoutes(event: .failedRestoringSession, transitions: [.restoringSession => .signedOut])

machine.addRoutes(event: .attemptSignOut, transitions: [ .settingsScreen => .signingOut ])
machine.addRoutes(event: .attemptSignOut, transitions: [.settingsScreen => .signingOut])

machine.addRoutes(event: .succeededSigningOut, transitions: [ .signingOut => .signedOut ])
machine.addRoutes(event: .failedSigningOut, transitions: [ .signingOut => .settingsScreen ])
machine.addRoutes(event: .succeededSigningOut, transitions: [.signingOut => .signedOut])
machine.addRoutes(event: .failedSigningOut, transitions: [.signingOut => .settingsScreen])

machine.addRoutes(event: .showSettingsScreen, transitions: [ .homeScreen => .settingsScreen ])
machine.addRoutes(event: .dismissedSettingsScreen, transitions: [ .settingsScreen => .homeScreen ])
machine.addRoutes(event: .showSettingsScreen, transitions: [.homeScreen => .settingsScreen])
machine.addRoutes(event: .dismissedSettingsScreen, transitions: [.settingsScreen => .homeScreen])

machine.addRoutes(event: .showSessionVerificationScreen, transitions: [ .homeScreen => .sessionVerificationScreen ])
machine.addRoutes(event: .dismissedSessionVerificationScreen, transitions: [ .sessionVerificationScreen => .homeScreen ])
machine.addRoutes(event: .showSessionVerificationScreen, transitions: [.homeScreen => .sessionVerificationScreen])
machine.addRoutes(event: .dismissedSessionVerificationScreen, transitions: [.sessionVerificationScreen => .homeScreen])

// Transitions with associated values need to be handled through `addRouteMapping`
machine.addRouteMapping { event, fromState, _ in
Expand Down
10 changes: 5 additions & 5 deletions ElementX/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

// fixme: Use `Bundle.elementLanguage = ".."` when we have the functionality
// FIXME: Use `Bundle.elementLanguage = ".."` when we have the functionality
// use `en` as fallback language
Bundle.elementFallbackLanguage = "en"

Expand All @@ -34,17 +34,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private var isRunningUnitTests: Bool {
#if DEBUG
ProcessInfo.processInfo.environment["IS_RUNNING_UNIT_TESTS"] == "1"
ProcessInfo.processInfo.environment["IS_RUNNING_UNIT_TESTS"] == "1"
#else
false
false
#endif
}

private var isRunningUITests: Bool {
#if DEBUG
ProcessInfo.processInfo.environment["IS_RUNNING_UI_TESTS"] == "1"
ProcessInfo.processInfo.environment["IS_RUNNING_UI_TESTS"] == "1"
#else
false
false
#endif
}
}
6 changes: 3 additions & 3 deletions ElementX/Sources/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ final class BuildSettings {
static let bugReportApplicationId = "riot-ios"
static let bugReportUISIId = "element-auto-uisi"

static let bugReportGHLabels: [String] = ["Element-X"]
static let bugReportGHLabels = ["Element-X"]

// MARK: - Settings screen

static let settingsCrashButtonVisible: Bool = true
static let settingsShowTimelineStyle: Bool = true
static let settingsCrashButtonVisible = true
static let settingsShowTimelineStyle = true

// MARK: - Room screen

Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Other/Benchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import Foundation

struct Benchmark {
static private var trackingIdentifiers = [String: CFAbsoluteTime]()
private static var trackingIdentifiers = [String: CFAbsoluteTime]()

static public var trackingEnabled = false
public static var trackingEnabled = false

static func startTrackingForIdentifier(_ identifier: String, message: String? = nil) {
guard trackingEnabled else {
Expand Down
Loading

0 comments on commit 70aaf9c

Please sign in to comment.