Skip to content

Commit

Permalink
Add SwiftFormat to the project. (#129)
Browse files Browse the repository at this point in the history
* Run swiftformat for whitespace.
* Run swiftformat with some rules.
  • Loading branch information
pixlwave authored Jul 6, 2022
1 parent 26d8aff commit 02eb4b3
Show file tree
Hide file tree
Showing 188 changed files with 761 additions and 719 deletions.
17 changes: 17 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--swiftversion 5.6

--exclude ElementX/Sources/Generated

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

--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
10 changes: 5 additions & 5 deletions DesignKit/Sources/Buttons/ElementActionButtonStyle.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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 Expand Up @@ -70,17 +70,17 @@ public struct ElementActionButtonStyle_Previews: PreviewProvider {
Button("Enabled") { /* preview */ }
.buttonStyle(ElementActionButtonStyle())

Button("Disabled") { /* preview */ }
Button("Disabled") { /* preview */ }
.buttonStyle(ElementActionButtonStyle())
.disabled(true)

Button { /* preview */ } label: {
Button { /* preview */ } label: {
Text("Clear BG")
.foregroundColor(.element.alert)
}
.buttonStyle(ElementActionButtonStyle(color: .clear))

Button("Red BG") { /* preview */ }
Button("Red BG") { /* preview */ }
.buttonStyle(ElementActionButtonStyle(color: .element.alert))
}
.padding()
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
47 changes: 24 additions & 23 deletions DesignKit/Sources/Fonts/ElementSharedFonts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,110 +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
8 changes: 4 additions & 4 deletions DesignKit/Sources/Fonts/UIFont.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down 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)
}
}
2 changes: 1 addition & 1 deletion DesignKit/Sources/Shapes/RoundedCornerShape.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
6 changes: 3 additions & 3 deletions DesignKit/Sources/TextFields/BorderedInputFieldStyle.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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
27 changes: 23 additions & 4 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
62BBF5BE7B905222F0477FF2 /* MediaSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8210612D17A39369480FC183 /* MediaSource.swift */; };
63C9AF0FB8278AF1C0388A0C /* TemplateModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB10E673916D2B8D21FD197 /* TemplateModels.swift */; };
6647430A45B4A8E692909A8F /* EmoteRoomTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77C060C2ACC4CB7336A29E7 /* EmoteRoomTimelineItem.swift */; };
67C05C50AD734283374605E3 /* MatrixEntityRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */; };
67E391A2E00709FB41903B36 /* MockMediaProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6920A4869821BF72FFC58842 /* MockMediaProvider.swift */; };
6832733838C57A7D3FE8FEB5 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 04C28663564E008DB32B5972 /* Introspect */; };
684BDE198AE5AA1392288A73 /* SplashScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32CE6D4FF64C9A3C18619224 /* SplashScreen.swift */; };
Expand Down Expand Up @@ -279,7 +280,6 @@
EE8491AD81F47DF3C192497B /* DecorationTimelineItemProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184CF8C196BE143AE226628D /* DecorationTimelineItemProtocol.swift */; };
EEC40663922856C65D1E0DF5 /* KeychainControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB9C37196A4C79F24CE80C6 /* KeychainControllerTests.swift */; };
EF99A92701E401C4CD5ADC50 /* SplashScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE978A6118C131D7F2A04B3 /* SplashScreenModels.swift */; };
F03E16ED043C62FED5A07AE0 /* MatrixEntityRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B81C8227BBEA95CCE86037 /* MatrixEntityRegex.swift */; };
F040ABFEB0A2B142D948BA12 /* Untranslated.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = F75DF9500D69A3AAF8339E69 /* Untranslated.stringsdict */; };
F2DD8661B5C0BA2BB526FA6C /* KeychainControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CD51F9FDC91C231906D76C8 /* KeychainControllerProtocol.swift */; };
F4C3FEDB1B3A05376A1723A3 /* KeychainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A4427F9E0571B4E6E048A2B /* KeychainController.swift */; };
Expand Down Expand Up @@ -479,6 +479,7 @@
6920A4869821BF72FFC58842 /* MockMediaProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMediaProvider.swift; sourceTree = "<group>"; };
6A152791A2F56BD193BFE986 /* MemberDetailsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemberDetailsProvider.swift; sourceTree = "<group>"; };
6A901D95158B02CA96C79C7F /* InfoPlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoPlist.swift; sourceTree = "<group>"; };
6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixEntityRegex.swift; sourceTree = "<group>"; };
6B73A8C3118EAC7BF3F3EE7A /* SplashScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashScreenViewModelProtocol.swift; sourceTree = "<group>"; };
6D4777F0142E330A75C46FE4 /* SessionVerificationUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionVerificationUITests.swift; sourceTree = "<group>"; };
6DB53055CB130F0651C70763 /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -691,7 +692,6 @@
F6A8C632CEF4600107792899 /* TextRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineItem.swift; sourceTree = "<group>"; };
F73FF1A33198F5FAE9D34B1F /* FormattedBodyText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormattedBodyText.swift; sourceTree = "<group>"; };
F77C060C2ACC4CB7336A29E7 /* EmoteRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmoteRoomTimelineItem.swift; sourceTree = "<group>"; };
F7B81C8227BBEA95CCE86037 /* MatrixEntityRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixEntityRegex.swift; sourceTree = "<group>"; };
F9E785D5137510481733A3E8 /* TextRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineView.swift; sourceTree = "<group>"; };
FA154570F693D93513E584C1 /* RoomMessageFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMessageFactory.swift; sourceTree = "<group>"; };
FAB10E673916D2B8D21FD197 /* TemplateModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateModels.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1443,7 +1443,7 @@
CF4B39D52CAE7D21D276ABEE /* ElementNavigationController.swift */,
1027BB9A852F445B7623897F /* ElementSettings.swift */,
12A626D74BBE9F4A60763B45 /* ImageAnonymizer.swift */,
F7B81C8227BBEA95CCE86037 /* MatrixEntityRegex.swift */,
6AD1A853D605C2146B0DC028 /* MatrixEntityRegex.swift */,
44BBB96FAA2F0D53C507396B /* Extensions */,
8F9A844EB44B6AD7CA18FD96 /* HTMLParsing */,
06501F0E978B2D5C92771DC7 /* Logging */,
Expand Down Expand Up @@ -1659,6 +1659,7 @@
isa = PBXNativeTarget;
buildConfigurationList = B15427F8699AD5A5FC75C17E /* Build configuration list for PBXNativeTarget "ElementX" */;
buildPhases = (
B35AB66424BB30087EEE408C /* 🧹 SwiftFormat */,
A7130911BCB2DF3D249A1836 /* 🛠 SwiftGen */,
9797D588420FCBBC228A63C9 /* Sources */,
215E1D91B98672C856F559D0 /* Resources */,
Expand Down Expand Up @@ -1886,6 +1887,24 @@
shellPath = /bin/sh;
shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftgen >/dev/null; then\n swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml\nelse\n echo \"warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen\"\nfi\n";
};
B35AB66424BB30087EEE408C /* 🧹 SwiftFormat */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "🧹 SwiftFormat";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftformat >/dev/null; then\n swiftformat $PROJECT_DIR\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -1997,7 +2016,7 @@
2F30EFEB7BD39242D1AD96F3 /* LoginViewModelProtocol.swift in Sources */,
B94368839BDB69172E28E245 /* MXLog.swift in Sources */,
BCC3EDB7AD0902797CB4BBC2 /* MXLogger.m in Sources */,
F03E16ED043C62FED5A07AE0 /* MatrixEntityRegex.swift in Sources */,
67C05C50AD734283374605E3 /* MatrixEntityRegex.swift in Sources */,
EA1E7949533E19C6D862680A /* MediaProvider.swift in Sources */,
7002C55A4C917F3715765127 /* MediaProviderProtocol.swift in Sources */,
62BBF5BE7B905222F0477FF2 /* MediaSource.swift in Sources */,
Expand Down
Loading

0 comments on commit 02eb4b3

Please sign in to comment.