Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

IOS-3269 :: Feature internal :: configure step in the GitHub action to execute swift lint + swift format #47

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Swiftlint
# IMPORTANT: using --lenient to avoid errors. Once all errors are fixed, it should be deleted and run a normal "swiftlint lint"
run: swiftlint lint --lenient

- name: Select Xcode
run: sudo xcode-select -switch /Applications/Xcode_$XCODE_VERSION.app && /usr/bin/xcodebuild -version

Expand Down
42 changes: 42 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# file options

--exclude Tests/XCTestManifests.swift,Snapshots,DerivedData

# format options

--allman false
--binarygrouping 4,8
--commas always
--comments indent
--decimalgrouping 3,6
--elseposition same-line
--guardelse same-line
--empty void
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--header ignore
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef indent
--indent 4
--indentcase false
--importgrouping testable-bottom
--linebreaks lf
--octalgrouping 4,8
--operatorfunc spaced
--patternlet hoist
--ranges spaced
--self remove
--semicolons never
--stripunusedargs always
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve
--maxwidth 115
--redundanttype explicit

# rules

--enable isEmpty
--disable wrapMultilineStatementBraces
70 changes: 70 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
disabled_rules: # rule identifiers to exclude from running
# - trailing_whitespace
- todo
opt_in_rules: # some rules are only opt-in
# Find all the available rules by running:
# swiftlint rules
- empty_count
- unavailable_function
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- DerivedData
analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
- explicit_self

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length:
warning: 160
error: 160
ignores_urls: true
ignores_function_declarations: true
ignores_comments: true

# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 400 # error
# or they can set both explicitly
file_length:
warning: 500
error: 700
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded:
- iPhone
- T
- K
- kSec
identifier_name:
# additional_allowed_characters:
# - _
allowed_symbols: "_"
min_length: # only min_length
warning: 0
error: 1 # only error
max_length:
warning: 50
error: 70
excluded: # excluded via string array
- id
- URL
- SwiftUI
function_parameter_count:
warning: 7
error : 9
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
# warnings should be fixed immediately
warning_threshold: 10
nesting:
type_level: 3
63 changes: 36 additions & 27 deletions Example/Harmony/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,36 @@
// Copyright (c) 2017 Mobile Jazz. All rights reserved.
//

import UIKit
import Harmony
import SwiftUI
import UIKit

let applicationComponent: ApplicationComponent = ApplicationDefaultModule()

enum ApplicationUI {
case UIKit
case SwiftUI
}

// Modify this property to change the UI implementation!
let applicationUI: ApplicationUI = .SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var observable : Observable<Int>!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
var observable: Observable<Int>!

func application(_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
switch applicationUI {
case .UIKit:
let splash = SplashViewController()
let container = ContainerViewController(splash)

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = container
window?.makeKeyAndVisible()

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainVC = storyboard.instantiateInitialViewController()!
Expand All @@ -43,41 +44,49 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
case .SwiftUI:
let splash = SplashView()
let container = ContainerViewController(UIHostingController(rootView: splash))

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = container
window?.makeKeyAndVisible()

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
let main = NavigationView {
ItemListView(viewState: ItemListViewState())
}
container.set(UIHostingController(rootView: main), animation: .crossDisolve)
}
}

return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

func applicationWillResignActive(_: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types
// of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the
// application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games
// should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

func applicationDidEnterBackground(_: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough
// application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of
// applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

func applicationWillEnterForeground(_: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the
// changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

func applicationDidBecomeActive(_: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application
// was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

func applicationWillTerminate(_: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also
// applicationDidEnterBackground:.
}
}
18 changes: 9 additions & 9 deletions Example/Harmony/Core/ApplicationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2021 CocoaPods. All rights reserved.
//

import Harmony
import Alamofire
import Harmony

// Enabling vastra service as an object validation
extension VastraService: ObjectValidation {}
Expand All @@ -17,17 +17,17 @@ protocol ApplicationComponent {
}

class ApplicationDefaultModule: ApplicationComponent {

private lazy var logger: Logger = DeviceConsoleLogger()
private lazy var backgroundExecutor: Executor = DispatchQueueExecutor()

private lazy var apiClient: Session = {
// Alamofire Session Manager
let sessionManager = Session(interceptor: BaseURLRequestAdapter(URL(string:"https://demo3068405.mockable.io")!,
[UnauthorizedStatusCodeRequestRetrier()]))
let sessionManager =
Session(interceptor: BaseURLRequestAdapter(URL(string: "https://demo3068405.mockable.io")!,
[UnauthorizedStatusCodeRequestRetrier()]))
return sessionManager
}()

private lazy var storage: AnyDataSource<Data> = {
// Storage (FileSystem)
let storage = FileSystemStorageDataSource(fileManager: FileManager.default,
Expand All @@ -37,16 +37,16 @@ class ApplicationDefaultModule: ApplicationComponent {

// Storage (UserDefaults)
// let storage = DeviceStorageDataSource<Data>(UserDefaults.standard, prefix: "ItemEntity")

// Storage (Keychain)
// let storage = KeychainDataSource<Data>(KeychainService("com.mobilejazz.storage.item"))

// Attaching a logger
return AnyDataSource(
DebugDataSource(storage, logger: self.logger)
)
}()

lazy var itemComponent: ItemComponent = ItemDefaultModule(executor: self.backgroundExecutor,
apiClient: self.apiClient,
storage: self.storage)
Expand Down
15 changes: 7 additions & 8 deletions Example/Harmony/Core/Features/Item/Data/ItemEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import Foundation

import Harmony

struct ItemEntity : VastraTimestampStrategyDataSource, Codable {
struct ItemEntity: VastraTimestampStrategyDataSource, Codable {
var id: String?
var name: String
var price: Double
var count: Int
var imageURL: URL?

init() {
self.init(id: nil, name: "Blank", price: 0.0, count: 0, imageURL: nil)
}
Expand All @@ -25,13 +25,12 @@ struct ItemEntity : VastraTimestampStrategyDataSource, Codable {
self.count = count
self.imageURL = imageURL
}
// MARK: VastraTimestampStrategyDataSource
var lastUpdate: Date? = nil

// MARK: VastraTimestampStrategyDataSource

var lastUpdate: Date?

func expiryTimeInterval() -> Time {
return .seconds(30)
}
}

Loading