Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup SwiftLint in the project and on CI #147

Merged
merged 7 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nodes with values to reuse in the pipeline.
common_params:
plugins: &common_plugins
- automattic/a8c-ci-toolkit#3.0.1
- automattic/a8c-ci-toolkit#3.1.0
env: &common_env
IMAGE_ID: xcode-15.2

Expand Down Expand Up @@ -29,6 +29,15 @@ steps:
#################
# Lint
#################
- label: ":swift: SwiftLint"
command: run_swiftlint --strict
plugins: *common_plugins
notify:
- github_commit_status:
context: "SwiftLint"
agents:
queue: "default"

- label: "🧹 Lint"
key: "lint"
command: |
Expand Down
32 changes: 32 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
swiftlint_version: 0.54.0

excluded:
- DerivedData
- fastlane
- vendor

# Rules – Opt-in only, so we can progressively introduce new ones
#
only_rules:
- colon
- comma
- comment_spacing
- control_statement
- discarded_notification_center_observer
- duplicate_imports
- empty_enum_arguments
- empty_parameters
- mark
- opening_brace
- overridden_super_call
- redundant_optional_initialization
- statement_position
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- unneeded_break_in_switch
- unused_closure_parameter
- vertical_whitespace
- void_return
- weak_delegate
3 changes: 0 additions & 3 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand Down Expand Up @@ -33,6 +32,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class KeyboardAnimationsExampleViewController: UIViewController {
}

let willHideObserver = NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { (notification) in
UIView.animate(withKeyboard: notification) { (beginFrame, endFrame) in
UIView.animate(withKeyboard: notification) { (_, _) in
self.bottomConstraintForAnimation.constant = 20
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
Expand Down
96 changes: 46 additions & 50 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import WordPressUI

///
///
class ViewController: UITableViewController
{

private typealias CompletionClosure = () -> ()

class ViewController: UITableViewController {

private typealias CompletionClosure = () -> Void

let cellIdentifier = "CellIdentifier"
var sections: [DemoSection]!

// MARK: LifeCycle Methods

override func viewDidLoad() {
super.viewDidLoad()

sections = [
DemoSection(title: "Fancy Alert", rows: [
DemoRow(title: "Fancy Alert", action: {
Expand All @@ -40,36 +39,36 @@ class ViewController: UITableViewController
])
]
}

// MARK: - Useful constants

private struct FancyAlertConstants {
static let title = "Fancy Alert"
static let message = "Introducing the Fancy Alert UI Experience. Designed to show alerts and information to the user in a standardized manner."

static let defaultButtonTitle = "Go Ahead"
static let cancelButtonTitle = "Cancel"
static let moreInfoButtonTitle = "More Information"

static let switchText = "Do not show this again"
}

// MARK: Fancy Alert

func showFancyAlert(moreInfoButton: FancyAlertViewController.Config.ButtonConfig? = nil,
switchConfig: FancyAlertViewController.Config.SwitchConfig? = nil) {
let defaultButton = FancyAlertViewController.Config.ButtonConfig(FancyAlertConstants.defaultButtonTitle) { (controller: FancyAlertViewController, button: UIButton) in

let defaultButton = FancyAlertViewController.Config.ButtonConfig(FancyAlertConstants.defaultButtonTitle) { (controller: FancyAlertViewController, _: UIButton) in

self.show(message: FancyAlertConstants.defaultButtonTitle, from: controller) {
controller.dismiss(animated: true)
}
}
let cancelButton = FancyAlertViewController.Config.ButtonConfig(FancyAlertConstants.cancelButtonTitle) { (controller: FancyAlertViewController, button: UIButton) in

let cancelButton = FancyAlertViewController.Config.ButtonConfig(FancyAlertConstants.cancelButtonTitle) { (controller: FancyAlertViewController, _: UIButton) in
controller.dismiss(animated: true)
}

let configuration = FancyAlertViewController.Config(
titleText: FancyAlertConstants.title,
bodyText: FancyAlertConstants.message,
Expand All @@ -79,23 +78,23 @@ class ViewController: UITableViewController
cancelButton: cancelButton,
moreInfoButton: moreInfoButton,
switchConfig: switchConfig)

let alert = FancyAlertViewController.controllerWithConfiguration(configuration: configuration)
alert.modalPresentationStyle = .custom
alert.transitioningDelegate = self

present(alert, animated: true, completion: nil)
}

func showFancyAlertWithMoreInfo() {
let moreInfoButton = FancyAlertViewController.Config.ButtonConfig(FancyAlertConstants.moreInfoButtonTitle) { [unowned self] (controller: FancyAlertViewController, button: UIButton) in
let moreInfoButton = FancyAlertViewController.Config.ButtonConfig(FancyAlertConstants.moreInfoButtonTitle) { [unowned self] (controller: FancyAlertViewController, _: UIButton) in

self.show(message: FancyAlertConstants.moreInfoButtonTitle, from: controller)
}

showFancyAlert(moreInfoButton: moreInfoButton)
}

func showFancyAlertWithSwitch() {
let switchConfig = FancyAlertViewController.Config.SwitchConfig(
initialValue: true,
Expand All @@ -107,7 +106,7 @@ class ViewController: UITableViewController
self.show(message: "OFF", from: controller)
}
})

showFancyAlert(switchConfig: switchConfig)
}

Expand All @@ -116,63 +115,61 @@ class ViewController: UITableViewController
func showFancyButtons() {
performSegue(withIdentifier: "FancyButtonsSegue", sender: self)
}

// MARK: - Test Messages for the User

private func show(message: String, from controller: UIViewController, completion onCompletion: CompletionClosure? = nil) {
let alertViewController = UIAlertController(title: nil, message: message, preferredStyle: .alert)
alertViewController.addActionWithTitle("Ok", style: .default) { alertAction in

alertViewController.addActionWithTitle("Ok", style: .default) { _ in
onCompletion?()
}

controller.present(alertViewController, animated: true, completion: nil)
}

// MARK: - TableView Methods

override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}



override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].rows.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
cell.accessoryType = .disclosureIndicator

let row = sections[indexPath.section].rows[indexPath.row]
cell.textLabel?.text = row.title

return cell
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let textView = UITextView()

textView.font = UIFont.boldSystemFont(ofSize: 14)
textView.textAlignment = .center
textView.isEditable = false
textView.text = sections[section].title
textView.backgroundColor = UIColor.lightGray

return textView
}



override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

sections[indexPath.section].rows[indexPath.row].action()
}

}

// MARK: - UIViewControllerTransitioningDelegate
Expand All @@ -182,12 +179,11 @@ extension ViewController: UIViewControllerTransitioningDelegate {
guard presented is FancyAlertViewController else {
return nil
}

return FancyAlertPresentationController(presentedViewController: presented, presenting: presenting)
}
}


typealias RowAction = () -> Void

struct DemoSection {
Expand Down
88 changes: 88 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"object": {
"pins": [
{
"package": "CollectionConcurrencyKit",
"repositoryURL": "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
"state": {
"branch": null,
"revision": "b4f23e24b5a1bff301efc5e70871083ca029ff95",
"version": "0.2.0"
}
},
{
"package": "CryptoSwift",
"repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git",
"state": {
"branch": null,
"revision": "7892a123f7e8d0fe62f9f03728b17bbd4f94df5c",
"version": "1.8.1"
}
},
{
"package": "SourceKitten",
"repositoryURL": "https://github.com/jpsim/SourceKitten.git",
"state": {
"branch": null,
"revision": "b6dc09ee51dfb0c66e042d2328c017483a1a5d56",
"version": "0.34.1"
}
},
{
"package": "swift-argument-parser",
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
"state": {
"branch": null,
"revision": "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version": "1.2.3"
}
},
{
"package": "swift-syntax",
"repositoryURL": "https://github.com/apple/swift-syntax.git",
"state": {
"branch": null,
"revision": "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version": "509.0.2"
}
},
{
"package": "SwiftLint",
"repositoryURL": "https://github.com/realm/SwiftLint",
"state": {
"branch": null,
"revision": "f17a4f9dfb6a6afb0408426354e4180daaf49cee",
"version": "0.54.0"
}
},
{
"package": "SwiftyTextTable",
"repositoryURL": "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state": {
"branch": null,
"revision": "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version": "0.9.0"
}
},
{
"package": "SWXMLHash",
"repositoryURL": "https://github.com/drmohundro/SWXMLHash.git",
"state": {
"branch": null,
"revision": "a853604c9e9a83ad9954c7e3d2a565273982471f",
"version": "7.0.2"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3",
"version": "5.0.6"
}
}
]
},
"version": 1
}
Loading