Skip to content

Commit

Permalink
Add SwiftLint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Hengyu committed Dec 5, 2023
1 parent 6e6c0d7 commit d669b7a
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 54 deletions.
7 changes: 7 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
trailing_comma:
mandatory_comma: true

opt_in_rules:
- fallthrough
- implicit_return
- sorted_imports
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ let package = Package(
.copy("Resources/PlatformNames.plist")
]
),
.testTarget(name: "FeedbackSwiftTests", dependencies: ["FeedbackSwift"])
.testTarget(name: "FeedbackSwiftTests", dependencies: ["FeedbackSwift"]),
]
)
2 changes: 1 addition & 1 deletion Sources/FeedbackSwift/Bundle+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) 2017 CAPH TECH. All rights reserved.
//

import Foundation
import Dispatch
import Foundation

var storedFeedbackBundle: Bundle?

Expand Down
10 changes: 5 additions & 5 deletions Sources/FeedbackSwift/CellFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ protocol CellFactoryProtocol {
}

extension CellFactoryProtocol {
static var reuseIdentifier: String { return String(describing: self) }
static var reuseIdentifier: String { String(describing: self) }

static func suitable(for item: Any) -> Bool { return item is Item }
static func suitable(for item: Any) -> Bool { item is Item }

static func configure(

Expand Down Expand Up @@ -54,15 +54,15 @@ public class AnyCellFactory {
configureCellClosure = cellFactory.configure(_:with:for:eventHandler:)
}

func suitable(for item: Any) -> Bool { return suitableClosure(item) }
func suitable(for item: Any) -> Bool { suitableClosure(item) }

func configure(
_ cell: UITableViewCell,
with item: Any,
for indexPath: IndexPath,
eventHandler: Any?
) -> UITableViewCell? {
return configureCellClosure(cell, item, indexPath, eventHandler)
configureCellClosure(cell, item, indexPath, eventHandler)
}
}

Expand Down Expand Up @@ -92,5 +92,5 @@ extension UITableView {
}

let cellFactoryFilter: (Any, [AnyCellFactory]) -> AnyCellFactory? = { item, factories in
return factories.first { $0.suitable(for: item) }
factories.first { $0.suitable(for: item) }
}
16 changes: 8 additions & 8 deletions Sources/FeedbackSwift/FeedbackItemsDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class FeedbackItemsDataSource {
var sections: [FeedbackItemsSection] = []

var numberOfSections: Int {
return filteredSections.count
filteredSections.count
}

public init(
Expand Down Expand Up @@ -46,7 +46,7 @@ public class FeedbackItemsDataSource {
items: [
AppNameItem(isHidden: hidesAppInfoSection, name: appName),
AppVersionItem(isHidden: hidesAppInfoSection),
AppBuildItem(isHidden: hidesAppInfoSection)
AppBuildItem(isHidden: hidesAppInfoSection),
]
)
)
Expand All @@ -59,13 +59,13 @@ public class FeedbackItemsDataSource {

extension FeedbackItemsDataSource {
private var filteredSections: [FeedbackItemsSection] {
return sections.filter { section in
sections.filter { section in
section.items.filter { !$0.isHidden }.isEmpty == false
}
}

private subscript(indexPath: IndexPath) -> FeedbackItemProtocol {
get { return filteredSections[indexPath.section][indexPath.item] }
get { filteredSections[indexPath.section][indexPath.item] }
set { filteredSections[indexPath.section][indexPath.item] = newValue }
}

Expand Down Expand Up @@ -106,13 +106,13 @@ class FeedbackItemsSection {
}

extension FeedbackItemsSection: Collection {
var startIndex: Int { return items.startIndex }
var endIndex: Int { return items.endIndex }
var startIndex: Int { items.startIndex }
var endIndex: Int { items.endIndex }

subscript(position: Int) -> FeedbackItemProtocol {
get { return items[position] }
get { items[position] }
set { items[position] = newValue }
}

func index(after index: Int) -> Int { return items.index(after: index) }
func index(after index: Int) -> Int { items.index(after: index) }
}
4 changes: 2 additions & 2 deletions Sources/FeedbackSwift/FeedbackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Copyright © 2017 CAPH TECH. All rights reserved.
//

import UIKit
import Dispatch
import MessageUI
import Photos
import UIKit

open class FeedbackViewController: UITableViewController {
public var mailComposeDelegate: MFMailComposeViewControllerDelegate?
Expand All @@ -30,7 +30,7 @@ open class FeedbackViewController: UITableViewController {
AnyCellFactory(SystemVersionCell.self),
AnyCellFactory(AppNameCell.self),
AnyCellFactory(AppVersionCell.self),
AnyCellFactory(AppBuildCell.self)
AnyCellFactory(AppBuildCell.self),
]

private lazy var feedbackEditingService: FeedbackEditingServiceProtocol = {
Expand Down
32 changes: 13 additions & 19 deletions Sources/FeedbackSwift/FeedbackWireframe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Copyright (c) 2017 CAPH TECH. All rights reserved.
//

import UIKit
import MobileCoreServices
import MessageUI
import MobileCoreServices
import UIKit
import UniformTypeIdentifiers

protocol FeedbackWireframeProtocol {
Expand Down Expand Up @@ -98,34 +98,28 @@ extension FeedbackWireframe: FeedbackWireframeProtocol {
#if os(iOS)
if UIImagePickerController.isSourceTypeAvailable(.camera) {
alertController.addAction(
UIAlertAction(
title: localized("feedback.Camera"),
style: .default) { _ in
authorizeCamera { granted in
if granted {
self.showImagePicker(sourceType: .camera)
} else {
self.showCameraAuthorizingAlert()
}
UIAlertAction(title: localized("feedback.Camera"), style: .default) { _ in
authorizeCamera { granted in
if granted {
self.showImagePicker(sourceType: .camera)
} else {
self.showCameraAuthorizingAlert()
}
})
}
}
)
}
#endif

if let deleteAction {
alertController.addAction(
UIAlertAction(
title: localized("feedback.Delete"),
style: .destructive
) { _ in
UIAlertAction(title: localized("feedback.Delete"), style: .destructive) { _ in
deleteAction()
}
)
}

alertController.addAction(
UIAlertAction(title: localized("feedback.Cancel"), style: .cancel)
)
alertController.addAction(UIAlertAction(title: localized("feedback.Cancel"), style: .cancel))

alertController.popoverPresentationController?.sourceView = viewController?.view
alertController.popoverPresentationController?.sourceRect = cellRect
Expand Down
23 changes: 7 additions & 16 deletions Sources/FeedbackSwift/Items/AppName/AppNameItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,16 @@
import Foundation

struct AppNameItem: FeedbackItemProtocol {
var name: String {
if let _name {
return _name
}
if let displayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
return displayName
}
if let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String {
return bundleName
}
return ""
}

private var _name: String?

let isHidden: Bool
let name: String

init(isHidden: Bool, name: String? = nil) {
self.isHidden = isHidden
self._name = name
self.name = name ?? AppNameItem.defaultName ?? ""
}

private static var defaultName: String? {
Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ??
Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String
}
}
2 changes: 1 addition & 1 deletion Sources/FeedbackSwift/Items/Topic/TopicItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct TopicItem: FeedbackItemProtocol {
Topic.question,
Topic.request,
Topic.bugReport,
Topic.other
Topic.other,
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/FeedbackSwiftTests/FeedbackSwiftTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import FeedbackSwift
import XCTest

final class FeedbackSwiftTests: XCTestCase {
func testExample() throws {
Expand Down

0 comments on commit d669b7a

Please sign in to comment.