Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
noppefoxwolf committed Jul 21, 2021
1 parent a7f5d6d commit 0d5b441
Show file tree
Hide file tree
Showing 56 changed files with 941 additions and 553 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Format

on:
push:
branches:
- main

jobs:
swift_format:
name: swift-format
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Tap
run: brew tap pointfreeco/formulae
- name: Install
run: brew install Formulae/swift-format@5.3
- name: Format
run: make format
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Run swift-format
branch: "main"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54 changes: 54 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"version": 1,
"lineLength": 100,
"indentation": {
"spaces": 4
},
"tabWidth": 4,
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": true,
"lineBreakBeforeEachGenericRequirement": true,
"prioritizeKeepingFunctionOutputTogether": false,
"indentConditionalCompilationBlocks": false,
"lineBreakAroundMultilineExpressionChainComponents": true,
"indentSwitchCaseLabels": false,
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": false,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": false,
"FileScopedDeclarationPrivacy": false,
"FullyIndirectEnum": false,
"GroupNumericLiterals": false,
"IdentifiersMustBeASCII": false,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": false,
"NoBlockComments": false,
"NoCasesWithOnlyFallthrough": false,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoVoidReturnOnFunctionSignature": true,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": false,
"OrderedImports": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"UseLetInEveryBoundCaseVariable": false,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": false,
"UseTripleSlashForDocumentationComments": false,
"ValidateDocumentationComments": false
}
}
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
format:
@swift format \
--ignore-unparsable-files \
--configuration .swift-format \
--in-place \
--recursive \
./Sources/
14 changes: 12 additions & 2 deletions Sources/DebugMenu/DebugMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import UIKit

@available(iOSApplicationExtension, unavailable)
public struct DebugMenu {
public static func install(windowScene: UIWindowScene? = nil, items: [DebugMenuPresentable] = [], complications: [ComplicationPresentable] = [], options: [Options] = Options.default) {
InAppDebuggerWindow.install(windowScene: windowScene, debuggerItems: items, complications: complications, options: options)
public static func install(
windowScene: UIWindowScene? = nil,
items: [DebugMenuPresentable] = [],
complications: [ComplicationPresentable] = [],
options: [Options] = Options.default
) {
InAppDebuggerWindow.install(
windowScene: windowScene,
debuggerItems: items,
complications: complications,
options: options
)
}
}
6 changes: 3 additions & 3 deletions Sources/DebugMenu/Entity/AnyDebugItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ struct AnyDebugItem: Hashable, Identifiable, DebugMenuPresentable {
let id: String
let debuggerItemTitle: String
let action: DebugMenuAction

init(_ item: DebugMenuPresentable) {
id = UUID().uuidString
debuggerItemTitle = item.debuggerItemTitle
action = item.action
}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
}

static func == (lhs: AnyDebugItem, rhs: AnyDebugItem) -> Bool {
lhs.id == rhs.id
}
Expand Down
37 changes: 22 additions & 15 deletions Sources/DebugMenu/Entity/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,43 @@ import Foundation

public class Application {
public static var current: Application = .init()

public var appName: String {
Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String
}

public var version: String {
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
}

public var build: String {
Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as! String
}

public var buildNumber: Int {
Int(build) ?? 0
}

public var bundleIdentifier: String {
Bundle.main.bundleIdentifier ?? ""
}

public var locale: String {
Locale.current.identifier
}

public var preferredLocalizations: String {
Bundle.main.preferredLocalizations.joined(separator: ",")
}

public var isTestFlight: Bool {
#if DEBUG
return false
#else
return Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
#endif
}

public var size: String {
let byteCount = try? getByteCount()
let formatter = ByteCountFormatter()
Expand All @@ -58,12 +58,21 @@ public class Application {
extension Application {
public func getByteCount() throws -> UInt64 {
let bundlePath = Bundle.main.bundlePath
let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let libraryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
let documentPath = NSSearchPathForDirectoriesInDomains(
.documentDirectory,
.userDomainMask,
true
)[0]
let libraryPath = NSSearchPathForDirectoriesInDomains(
.libraryDirectory,
.userDomainMask,
true
)[0]
let tmpPath = NSTemporaryDirectory()
return try [bundlePath, documentPath, libraryPath, tmpPath].map(getFileSize(atDirectory:)).reduce(0, +)
return try [bundlePath, documentPath, libraryPath, tmpPath].map(getFileSize(atDirectory:))
.reduce(0, +)
}

internal func getFileSize(atDirectory path: String) throws -> UInt64 {
let files = try FileManager.default.subpathsOfDirectory(atPath: path)
var fileSize: UInt64 = 0
Expand All @@ -74,5 +83,3 @@ extension Application {
return fileSize
}
}


3 changes: 1 addition & 2 deletions Sources/DebugMenu/Entity/ComplicationPresentable.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// File.swift
//
//
//
// Created by Tomoya Hirano on 2021/05/29.
//
Expand All @@ -14,4 +14,3 @@ public protocol ComplicationPresentable {
func update()
var fetcher: MetricsFetcher { get }
}

16 changes: 13 additions & 3 deletions Sources/DebugMenu/Entity/DebugMenuPresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ public protocol DebugMenuPresentable {
}

public enum DebugMenuAction {
case didSelect(action: (_ controller: UIViewController, _ completions: @escaping (DebugMenuResult) -> Void) -> Void)
case didSelect(
action: (_ controller: UIViewController, _ completions: @escaping (DebugMenuResult) -> Void)
-> Void
)
case execute(action: (_ completions: @escaping (DebugMenuResult) -> Void) -> Void)
case toggle(current: () -> Bool, action: (_ isOn: Bool, _ completions: @escaping (DebugMenuResult) -> Void) -> Void)
case slider(current: () -> Double, range: ClosedRange<Double>, action: (_ value: Double, _ completions: @escaping (DebugMenuResult) -> Void) -> Void)
case toggle(
current: () -> Bool,
action: (_ isOn: Bool, _ completions: @escaping (DebugMenuResult) -> Void) -> Void
)
case slider(
current: () -> Double,
range: ClosedRange<Double>,
action: (_ value: Double, _ completions: @escaping (DebugMenuResult) -> Void) -> Void
)
}
Loading

0 comments on commit 0d5b441

Please sign in to comment.