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

Swiftlint fixes & configuration changes; Make GestureManager.delegate weak #134

Merged
merged 15 commits into from
Feb 24, 2021
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ jobs:
- access-token-configs
- make-deps
- run: brew install swiftlint
- run: swiftlint lint --strict
- build-scheme:
scheme: MapboxMapsAnnotations
- build-scheme:
Expand Down
91 changes: 11 additions & 80 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,15 @@ allow_zero_lintable_files: true
excluded:
- Carthage
- Pods
- MapboxMapsStyle/Generated
reporter: "xcode"
whitelist_rules:
- block_based_kvo
- class_delegate_protocol
- closing_brace
- closure_parameter_position
- colon
- comma
- compiler_protocol_init
- control_statement
- cyclomatic_complexity
- deployment_target
- discarded_notification_center_observer
- discouraged_direct_init
- duplicate_enum_cases
- duplicate_imports
- dynamic_inline
- empty_enum_arguments
- empty_parameters
- empty_parentheses_with_trailing_closure
- explicit_top_level_acl
- file_length
- for_where
- force_cast
- function_parameter_count
- generic_type_name
- implicit_getter
- inert_defer
- is_disjoint
- large_tuple
- leading_whitespace
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_nsgeometry_functions
- mark
- multiple_closures_with_trailing_closure
- nesting
- no_fallthrough_only
- no_space_in_method_call
- notification_center_detachment
- nsobject_prefer_isequal
- opening_brace
- operator_whitespace
- orphaned_doc_comment
- private_over_fileprivate
- private_unit_test
- protocol_property_accessors_order
- reduce_boolean
- redundant_discardable_let
- redundant_objc_attribute
- redundant_optional_initialization
- redundant_set_access_control
- redundant_string_enum_value
- redundant_void_return
- return_arrow_whitespace
- statement_position
- superfluous_disable_command
- switch_case_alignment
- syntactic_sugar
- Sources/MapboxMaps/Style/Generated
- Tests/MapboxMapsTests/Style/Generated
disabled_rules:
- comment_spacing
- computed_accessors_order
- force_try
neelmistry94 marked this conversation as resolved.
Show resolved Hide resolved
- function_body_length
- identifier_name
- line_length
- shorthand_operator
- todo
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- type_body_length
- type_name
- unneeded_break_in_switch
- unused_capture_list
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
- unused_optional_binding
- unused_setter_value
- valid_ibinspectable
- vertical_parameter_alignment
- vertical_whitespace
- void_return
- weak_delegate
- xctfail_message
1 change: 0 additions & 1 deletion Examples/ExamplesTests/ExamplesTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import XCTest
@testable import Examples

//swiftlint:disable force_cast
class ExamplesTests: XCTestCase {

func testExampleClassExists() throws {
Expand Down
4 changes: 2 additions & 2 deletions Examples/ExamplesTests/TestableExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestableExampleTests: XCTestCase {

let existingImpl = method_getImplementation(method)

for example in Examples.all {
for example in Examples.all {
// Add a method for this test, but using the same implementation
let selectorName = "test\(example.type)"
let testSelector = Selector((selectorName))
Expand Down Expand Up @@ -62,7 +62,7 @@ class TestableExampleTests: XCTestCase {
switch result {
case .completed:
break

case .timedOut:
// TODO: check if this is a failure
print("Example timed out, was this intentional? Call finish() if possible.")
Expand Down
2 changes: 2 additions & 0 deletions Sources/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
opt_in_rules:
- explicit_top_level_acl
2 changes: 2 additions & 0 deletions Sources/MapboxMaps/Foundation/BaseMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import UIKit
import Turf

// swiftlint:disable file_length

public enum PreferredFPS: Int, Equatable {
/// The default frame rate. This can be either 30 FPS or 60 FPS, depending on
/// device capabilities.
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxMaps/Foundation/Camera/CameraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public class CameraManager {
// density of time steps at towards the start and end of the animation to avoid jiggling.
let timeSteps = stride(from: 0.0, through: 1.0, by: 0.025)
let keyTimes: [NSNumber] = Array(timeSteps).map {
NSNumber(floatLiteral: $0)
NSNumber(value: $0)
}

var animations: [CAAnimation] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public extension MapEvents {
case cameraDidChange
case resourceRequest

// swiftlint:disable:next cyclomatic_complexity
public init?(rawValue: String) {
switch rawValue {
case MapEvents.mapLoadingStarted :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Turf
import MapboxCommon

// swiftlint:disable cyclomatic_complexity

// MARK: - Geometry

extension Geometry {
Expand Down
6 changes: 4 additions & 2 deletions Sources/MapboxMaps/Gestures/GestureManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import CoreLocation
import MapboxMapsFoundation
#endif

// swiftlint:disable file_length

public enum GestureType: Hashable {
/// The pan gesture type
case pan
Expand Down Expand Up @@ -100,7 +102,7 @@ internal class GestureHandler {
}
}

public protocol GestureManagerDelegate {
public protocol GestureManagerDelegate: AnyObject {

/// Informs the delegate that a gesture haas begun. Could be used to cancel camera tracking.
func gestureBegan(for gestureType: GestureType)
Expand Down Expand Up @@ -143,7 +145,7 @@ public final class GestureManager: NSObject {
/// The camera manager that responds to gestures.
private let cameraManager: CameraManagerProtocol

public var delegate: GestureManagerDelegate?
public weak var delegate: GestureManagerDelegate?

internal init(for view: UIView, options: GestureOptions, cameraManager: CameraManagerProtocol) {
self.cameraManager = cameraManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ internal class PuckLocationIndicatorLayer: Puck {

// MARK: Layer Creation Functions
private extension PuckLocationIndicatorLayer {
// swiftlint:disable:next cyclomatic_complexity
func createPreciseLocationIndicatorLayer(location: Location) throws {
guard let style = self.locationSupportableMapView?.style else { return }

Expand Down
1 change: 1 addition & 0 deletions Sources/MapboxMaps/Ornaments/OrnamentsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ internal class OrnamentsManager: NSObject {
}
}

// swiftlint:disable:next cyclomatic_complexity
private func addToView(ornament: Ornament) {
if ornament.view == nil {
ornament.view = ornament.type.makeOrnament(for: self.view, visibility: ornament.visibility)
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxMaps/Style/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public class Style {
case .success(let retrievedLayer):
// Successfully retrieved the layer
layer = retrievedLayer
case .failure(_):
case .failure:

// Could not retrieve the layer
return .failure(.getStyleLayerFailed(nil))
Expand Down
1 change: 0 additions & 1 deletion StressTest/StressTest/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
}

18 changes: 7 additions & 11 deletions StressTest/StressTest/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ViewController: UIViewController {
annotations.reserveCapacity(100)

// Do any additional setup after loading the view.
resourceOptions = ResourceOptions(accessToken : AccountManager.shared.accessToken!)
resourceOptions = ResourceOptions(accessToken: AccountManager.shared.accessToken!)
mapView = MapView(with: view.bounds, resourceOptions: resourceOptions, styleURL: .streets)
view.addSubview(mapView)
NSLayoutConstraint.activate([
Expand Down Expand Up @@ -131,8 +131,7 @@ class ViewController: UIViewController {
if step % 2 == 0 {
if annotations.isEmpty {
addAnnotations(around: dest)
}
else {
} else {
removeAnnotations()
}
}
Expand All @@ -141,8 +140,7 @@ class ViewController: UIViewController {
if step % 5 == 0 {
if color == nil {
pushColorExpression()
}
else {
} else {
popColorExpression()
}
}
Expand Down Expand Up @@ -194,7 +192,7 @@ class ViewController: UIViewController {
}
}

func flyTo(end: CLLocationCoordinate2D, completion: @escaping ()->Void) {
func flyTo(end: CLLocationCoordinate2D, completion: @escaping () -> Void) {
let startOptions = mapView.cameraView.camera
let start = startOptions.center!

Expand Down Expand Up @@ -253,8 +251,7 @@ class ViewController: UIViewController {
try mapView.__map.setStyleLayerPropertyForLayerId(land,
property: "background-color",
value: jsonObject)
}
catch let error {
} catch let error {
print("Error setting background color: \(error)")
}
}
Expand All @@ -270,15 +267,14 @@ class ViewController: UIViewController {
try mapView.__map.setStyleLayerPropertyForLayerId(land,
property: "background-color",
value: color.value)
}
catch let error {
} catch let error {
print("Failed to reset the background color: \(error)")
}
}
color = nil
}

func takeSnapshot(_ completion: @escaping ()->Void) {
func takeSnapshot(_ completion: @escaping () -> Void) {
guard snapshotter == nil else {
fatalError()
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
disabled_rules:
# type_name can be reenabled with configuration
# `allowed_symbols: ['_']` after CircleCI starts
# installing swiftlint 0.42.0 or greater
- type_name
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import MetalKit
@testable import MapboxMapsFoundation
#endif

// swiftlint:disable explicit_top_level_acl explicit_acl
// swiftlint:disable:next type_body_length
class CameraManagerTests: XCTestCase {

var mapView: BaseMapView!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import XCTest
@testable import MapboxMaps

class DeallocationObserver {
var observe: ()->Void
var observe: () -> Void
deinit {
observe()
}
init(_ observe: @escaping ()->Void) {
init(_ observe: @escaping () -> Void) {
self.observe = observe
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ internal class FeatureQueryingTest: MapViewIntegrationTestCase {

// MARK: - Test querying a rendered map for features.

/**
/*
The purpose of this test is to ensure features are returned when querying
a default style. It does this zooming into an area with dense features,
and querying the center of the map to ensure there is a populated array of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class CustomHttpService: HttpServiceInterface {

// If the test sets an error, call the callback with immediately
if let error = forcedError {
let expected = MBXExpected<HttpResponseData, HttpRequestError>(error: error)
let response = HttpResponse(request: request, result: expected as! MBXExpected<AnyObject, AnyObject>)
let expected = MBXExpected<AnyObject, AnyObject>(error: error)
let response = HttpResponse(request: request, result: expected)
callback(response)
requestCompletion?()
return 0
Expand All @@ -30,9 +30,9 @@ class CustomHttpService: HttpServiceInterface {
var urlRequest = URLRequest(url: URL(string: request.url)!)

let methodMap: [HttpMethod: String] = [
.get : "GET",
.head : "HEAD",
.post : "POST"
.get: "GET",
.head: "HEAD",
.post: "POST"
]

urlRequest.httpMethod = methodMap[request.method]!
Expand All @@ -44,14 +44,13 @@ class CustomHttpService: HttpServiceInterface {
// `HttpResponse` takes an `MBXExpected` type. This is very similar to Swift's
// `Result` type.
// APIs using `MBXExpected` are prone to future changes.
let expected: MBXExpected<HttpResponseData, HttpRequestError>
let expected: MBXExpected<AnyObject, AnyObject>

if let error = error {
// Map NSURLError to HttpRequestErrorType
let requestError = HttpRequestError(type: .otherError, message: error.localizedDescription)
expected = MBXExpected(error: requestError)
}
else if let response = response as? HTTPURLResponse,
} else if let response = response as? HTTPURLResponse,
let data = data {

// Keys are expected to be lowercase
Expand All @@ -67,14 +66,13 @@ class CustomHttpService: HttpServiceInterface {

let responseData = HttpResponseData(headers: headers, code: Int64(response.statusCode), data: data)
expected = MBXExpected(value: responseData)
}
else {
} else {
// error
let requestError = HttpRequestError(type: .otherError, message: "Invalid response")
expected = MBXExpected(error: requestError)
}

let response = HttpResponse(request: request, result: expected as! MBXExpected<AnyObject, AnyObject>)
let response = HttpResponse(request: request, result: expected)
callback(response)
self.requestCompletion?()
}
Expand Down
Loading