From 0d467edbf8a096ad821400df36cd42de15afd9a4 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Sat, 29 Dec 2018 14:41:46 +0000 Subject: [PATCH] Add .swiftlint.yml and fix linter warnings/errors --- .swiftlint.yml | 15 +++++++++ .travis.yml | 2 ++ Example/Gluon/AppDelegate.swift | 31 ++++++++++++++----- Example/Gluon/ViewController.swift | 4 ++- Example/Tests/GluonTest.swift | 9 ++++-- Gluon.xcodeproj/project.pbxproj | 30 ++++++++++++++++-- Package.swift | 12 ++++--- .../CompositeComponentWrapper.swift | 4 ++- Sources/Gluon/HostComponents/View.swift | 15 +++++++++ Sources/Gluon/Store.swift | 5 ++- Sources/Gluon/Structs.swift | 9 ------ 11 files changed, 104 insertions(+), 32 deletions(-) create mode 100644 .swiftlint.yml create mode 100644 Sources/Gluon/HostComponents/View.swift diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 00000000..156d360d --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,15 @@ +disabled_rules: +- trailing_comma +- identifier_name +- private_over_fileprivate +- void_return +- operator_whitespace +- nesting +- cyclomatic_complexity + +line_length: +- 80 +- 100 + +function_body_length: +- 50 diff --git a/.travis.yml b/.travis.yml index 0b6197d9..8990754d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ before_install: # - gem install cocoapods --pre # Since Travis is not always on latest version - brew update - brew install swiftformat +- brew outdated carthage swiftlint || brew upgrade carthage swiftlint # - brew outdated carthage || brew upgrade carthage # cache: cocoapods # podfile: Example/Podfile @@ -16,6 +17,7 @@ before_install: # - pod install --project-directory=Example script: - swiftformat --lint --verbose . +- swiftlint - xcodebuild test -enableCodeCoverage YES -scheme GluonCore after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/Example/Gluon/AppDelegate.swift b/Example/Gluon/AppDelegate.swift index b5b0b67e..723633c5 100644 --- a/Example/Gluon/AppDelegate.swift +++ b/Example/Gluon/AppDelegate.swift @@ -12,30 +12,45 @@ import UIKit class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + private typealias Options = [UIApplication.LaunchOptionsKey: Any] + + func application(_: UIApplication, didFinishLaunchingWithOptions _: Options?) + -> Bool { // Override point for customization after application launch. return true } 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. + // 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(_: 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. + // 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(_: 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. + // 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(_: 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. + // 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(_: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + // Called when the application is about to terminate. Save data if + // appropriate. See also applicationDidEnterBackground:. } } diff --git a/Example/Gluon/ViewController.swift b/Example/Gluon/ViewController.swift index 7c0bc272..2cb4a7a4 100644 --- a/Example/Gluon/ViewController.swift +++ b/Example/Gluon/ViewController.swift @@ -71,7 +71,9 @@ final class GluonViewController: UIViewController { } @IBAction func onTap(_: Any) { -// let counters = (0..<1_000_000).map { _ in Counter(props: NoProps(), children: []) } +// let counters = (0..<1_000_000).map { _ in +// Counter(props: NoProps(), children: []) +// } print(#file) } } diff --git a/Example/Tests/GluonTest.swift b/Example/Tests/GluonTest.swift index 9ee54e53..2d64a832 100644 --- a/Example/Tests/GluonTest.swift +++ b/Example/Tests/GluonTest.swift @@ -10,16 +10,19 @@ import XCTest class GluonTest: XCTestCase { override func setUp() { - // Put setup code here. This method is called before the invocation of each test method in the class. + // Put setup code here. This method is called before the invocation of each + // test method in the class. } override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. + // Put teardown code here. This method is called after the invocation of + // each test method in the class. } func testExample() { // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. + // Use XCTAssert and related functions to verify your tests produce the + // correct results. } func testPerformanceExample() { diff --git a/Gluon.xcodeproj/project.pbxproj b/Gluon.xcodeproj/project.pbxproj index 2dc8ab81..4d9a4a61 100644 --- a/Gluon.xcodeproj/project.pbxproj +++ b/Gluon.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ D1E0C83921D782200042A261 /* Frame.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C83821D782200042A261 /* Frame.swift */; }; D1E0C83E21D7AC570042A261 /* ControlWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C83D21D7AC570042A261 /* ControlWrapper.swift */; }; D1E0C84021D7AD480042A261 /* UIKitHostComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C83F21D7AD480042A261 /* UIKitHostComponent.swift */; }; + D1E0C84321D7BE9B0042A261 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1E0C84221D7BE9B0042A261 /* View.swift */; }; OBJ_104 /* GluonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_43 /* GluonTests.swift */; }; OBJ_105 /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_44 /* XCTestManifests.swift */; }; OBJ_107 /* GluonTestRenderer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "Gluon::GluonTestRenderer::Product" /* GluonTestRenderer.framework */; }; @@ -111,6 +112,7 @@ D1E0C83821D782200042A261 /* Frame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Frame.swift; sourceTree = ""; }; D1E0C83D21D7AC570042A261 /* ControlWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlWrapper.swift; sourceTree = ""; }; D1E0C83F21D7AD480042A261 /* UIKitHostComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitHostComponent.swift; sourceTree = ""; }; + D1E0C84221D7BE9B0042A261 /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = ""; }; "Gluon::Gluon::Product" /* Gluon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Gluon.framework; sourceTree = BUILT_PRODUCTS_DIR; }; "Gluon::GluonTestRenderer::Product" /* GluonTestRenderer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = GluonTestRenderer.framework; sourceTree = BUILT_PRODUCTS_DIR; }; "Gluon::GluonTests::Product" /* GluonTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = GluonTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -238,6 +240,7 @@ OBJ_27 /* Label.swift */, OBJ_28 /* StackView.swift */, D1E0C83621D780690042A261 /* Frame.swift */, + D1E0C84221D7BE9B0042A261 /* View.swift */, ); path = HostComponents; sourceTree = ""; @@ -281,7 +284,7 @@ name = Products; sourceTree = BUILT_PRODUCTS_DIR; }; - OBJ_5 /* */ = { + OBJ_5 = { isa = PBXGroup; children = ( OBJ_6 /* Package.swift */, @@ -291,7 +294,6 @@ OBJ_46 /* Products */, ); indentWidth = 2; - name = ""; sourceTree = ""; tabWidth = 2; }; @@ -330,6 +332,7 @@ buildPhases = ( OBJ_55 /* Sources */, OBJ_77 /* Frameworks */, + D1E0C84121D7BD360042A261 /* ShellScript */, ); buildRules = ( ); @@ -421,7 +424,7 @@ knownRegions = ( en, ); - mainGroup = OBJ_5 /* */; + mainGroup = OBJ_5; productRefGroup = OBJ_46 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -436,6 +439,26 @@ }; /* End PBXProject section */ +/* Begin PBXShellScriptBuildPhase section */ + D1E0C84121D7BD360042A261 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ OBJ_103 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -477,6 +500,7 @@ OBJ_61 /* Default.swift in Sources */, OBJ_62 /* Diffable.swift in Sources */, OBJ_63 /* Event.swift in Sources */, + D1E0C84321D7BE9B0042A261 /* View.swift in Sources */, OBJ_64 /* Hooks.swift in Sources */, OBJ_65 /* Button.swift in Sources */, OBJ_66 /* Label.swift in Sources */, diff --git a/Package.swift b/Package.swift index 0bb13bf8..f5aafc20 100644 --- a/Package.swift +++ b/Package.swift @@ -1,12 +1,14 @@ // swift-tools-version:4.2 -// The swift-tools-version declares the minimum version of Swift required to build this package. +// The swift-tools-version declares the minimum version of Swift required to +// build this package. import PackageDescription let package = Package( name: "Gluon", products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. + // Products define the executables and libraries produced by a package, + // and make them visible to other packages. .library( name: "Gluon", targets: ["Gluon"] @@ -25,8 +27,10 @@ let package = Package( // .package(url: /* package url */, from: "1.0.0"), ], targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. + // Targets are the basic building blocks of a package. A target can define + // a module or a test suite. + // Targets can depend on other targets in this package, and on products + // in packages which this package depends on. .target( name: "Gluon", dependencies: [] diff --git a/Sources/Gluon/ComponentWrapper/CompositeComponentWrapper.swift b/Sources/Gluon/ComponentWrapper/CompositeComponentWrapper.swift index 68529419..58c7d40a 100644 --- a/Sources/Gluon/ComponentWrapper/CompositeComponentWrapper.swift +++ b/Sources/Gluon/ComponentWrapper/CompositeComponentWrapper.swift @@ -20,7 +20,9 @@ final class CompositeComponentWrapper: ComponentWrapper { private let parentTarget: R.Target var state = [String: Any]() - init(_ node: Node, _ type: AnyCompositeComponent.Type, _ parentTarget: R.Target) { + init(_ node: Node, + _ type: AnyCompositeComponent.Type, + _ parentTarget: R.Target) { self.type = type self.parentTarget = parentTarget diff --git a/Sources/Gluon/HostComponents/View.swift b/Sources/Gluon/HostComponents/View.swift new file mode 100644 index 00000000..ca53806c --- /dev/null +++ b/Sources/Gluon/HostComponents/View.swift @@ -0,0 +1,15 @@ +// +// View.swift +// Gluon +// +// Created by Max Desiatov on 29/12/2018. +// + +public struct View: HostComponent { + public typealias Children = [Node] + + public let props: Props + public let children: [Node] + + public struct Props: Equatable {} +} diff --git a/Sources/Gluon/Store.swift b/Sources/Gluon/Store.swift index 7d96504a..a903bde8 100644 --- a/Sources/Gluon/Store.swift +++ b/Sources/Gluon/Store.swift @@ -5,8 +5,6 @@ // Created by Max Desiatov on 12/10/2018. // -import Foundation - /// Generic undo-redo manager that doesn't require rollback implementation in /// `apply` of a wrapped store. It saves previous snapshots of state in a stack /// and undo/redo actions allow traversing the state history. This might be @@ -76,7 +74,8 @@ public protocol Store { // } // //typealias Dispatch = (Action) -> () -//typealias Dispatcher = (state: S.State, dispatch: Dispatch) +//typealias Dispatcher = +// (state: S.State, dispatch: Dispatch) // FIXME: when contexts are available read state and dispatch // from the context and pass it to the mapper diff --git a/Sources/Gluon/Structs.swift b/Sources/Gluon/Structs.swift index d4ae4c3c..6363645a 100644 --- a/Sources/Gluon/Structs.swift +++ b/Sources/Gluon/Structs.swift @@ -84,12 +84,3 @@ enum ComponentType: Equatable { return type } } - -public struct View: HostComponent { - public typealias Children = [Node] - - public let props: Props - public let children: [Node] - - public struct Props: Equatable {} -}