Skip to content

Commit

Permalink
Add a swiftlint rule to prefer final classes
Browse files Browse the repository at this point in the history
Summary:
There were only 2 instances in which I had to add a disable comment for prefer_final_classes due to subclassing

Used the following to add the final keyword (Adds final to any class that doesn't have final or open before it and doesn't have func after it)
```
find . -name '*.swift' | xargs perl -pi -e 's/(?<!final )(?<!open )(class (?!func).*\{)/final \1/g'
```

Reviewed By: samodom

Differential Revision: D34119233

fbshipit-source-id: 963d64fefc1686095d0bfe18ac7cb9677606f4e6
  • Loading branch information
jawwad authored and facebook-github-bot committed Feb 10, 2022
1 parent d48c929 commit 624db61
Show file tree
Hide file tree
Showing 219 changed files with 242 additions and 239 deletions.
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ custom_rules:
test_classes_should_be_final:
regex: "(?<!final )class.*XCTestCase\\b"
message: "Make test classes final"
prefer_final_classes:
regex: "(?<!(?:final|open) )class (?!func|var)[^\n]*\\{"
message: "Most classes should be declared as final even when not declared as open"

only_rules:
- array_init
Expand Down
2 changes: 1 addition & 1 deletion FBAEMKit/FBAEMKitTests/Helpers/SampleAEMData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import FBAEMKit
import Foundation

class SampleAEMData { // swiftlint:disable:this convenience_type
final class SampleAEMData { // swiftlint:disable:this convenience_type

enum Keys {
static let defaultCurrency = "default_currency"
Expand Down
2 changes: 1 addition & 1 deletion FBAEMKit/FBAEMKitTests/Helpers/SampleAEMInvocations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import FBAEMKit
import Foundation

class SampleAEMInvocations { // swiftlint:disable:this convenience_type
final class SampleAEMInvocations { // swiftlint:disable:this convenience_type
static func createGeneralInvocation1() -> AEMInvocation {
AEMInvocation(
campaignID: "test_campaign_1",
Expand Down
2 changes: 1 addition & 1 deletion FBAEMKit/FBAEMKitTests/Helpers/TestInvocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import FBAEMKit
import Foundation

@objcMembers
class TestInvocation: AEMInvocation {
final class TestInvocation: AEMInvocation {

var attributionCallCount = 0
var updateConversionCallCount = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#import "NSProcessInfo+Protocols.h"

@protocol FBSDKLogging;
@protocol FBSDKURLOpener;
@protocol FBSDKBridgeAPIResponseCreating;

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -56,7 +55,7 @@ NS_SWIFT_NAME(AuthenticationSession);
@interface FBSDKBridgeAPI (Testing)

@property (nonatomic, readonly, assign) id<FBSDKOperatingSystemVersionComparing> processInfo;
@property (nonatomic, readonly) id<FBSDKURLOpener> urlOpener;
@property (nonatomic, readonly) id<FBSDKInternalURLOpener> urlOpener;
@property (nonatomic, readonly) id<FBSDKLogging> logger;
@property (nonatomic, readonly) id<FBSDKBridgeAPIResponseCreating> bridgeAPIResponseFactory;
@property (nonatomic, readonly) id<FBSDKDynamicFrameworkResolving> frameworkLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ final class HybridAppEventsScriptMessageHandlerTests: XCTestCase {
)
}

class TestScriptMessage: WKScriptMessage {
final class TestScriptMessage: WKScriptMessage {
let stubbedName: String
let stubbedBody: Any

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import TestTools

@objcMembers
class RawAppEventsConfigurationResponseFixtures: NSObject {
final class RawAppEventsConfigurationResponseFixtures: NSObject {

enum Keys {
static let defaultATEStatus = "default_ate_status"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class AuthenticationSessionSpy: NSObject, AuthenticationSessionHandling {
final class AuthenticationSessionSpy: NSObject, AuthenticationSessionHandling {

var capturedURL: URL
var capturedCallbackURLScheme: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

@objcMembers
@objc(FBSDKLoginManager) // for NSClassFromString(@"FBSDKLoginManager")
class FBSDKLoginManager: NSObject {
final class FBSDKLoginManager: NSObject {
static var capturedOpenURL: URL?
static var capturedSourceApplication: String?
static var capturedAnnotation: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class SampleAppEvents: NSObject {
final class SampleAppEvents: NSObject {

static var validEvent: [String: String] {
["_eventName": "event1"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class SampleAppEventsConfigurations: NSObject {
final class SampleAppEventsConfigurations: NSObject {

static let `default` = AppEventsConfiguration.default()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class SampleEventBinding: NSObject {
final class SampleEventBinding: NSObject {

static func createValid(withName name: String) -> EventBinding {
let logger = TestEventLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import TestTools
@testable import FBSDKCoreKit

@objcMembers
class SampleGraphRequestConnections: NSObject {
final class SampleGraphRequestConnections: NSObject {

static var empty: GraphRequestConnecting {
TestGraphRequestConnection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
@testable import FBSDKCoreKit

@objcMembers
class SampleGraphRequests: NSObject {
final class SampleGraphRequests: NSObject {

static let valid = create()
static var withOutdatedVersionWithAttachment = create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class SampleRawRemoteEventBindings: NSObject {
final class SampleRawRemoteEventBindings: NSObject {

static var sampleDictionary: [String: Any] {
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import TestTools

@objcMembers
class SampleRawRemotePermissionList: NSObject {
final class SampleRawRemotePermissionList: NSObject {

static var missingPermissions: [String: Any] {
[
Expand Down Expand Up @@ -103,6 +103,6 @@ class SampleRawRemotePermissionList: NSObject {
}

@objcMembers
class SampleRawRemotePermission: NSObject {
final class SampleRawRemotePermission: NSObject {
static let missingTopLevelKey: [String: Any] = [:]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class SampleSKAdNetworkConversionConfiguration: NSObject {
final class SampleSKAdNetworkConversionConfiguration: NSObject {

static var configJson: [String: Any] {
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class ServerConfigurationFixtures: NSObject {
final class ServerConfigurationFixtures: NSObject {
/// A default configuration with valid inputs. This is the same default configuration used in production code
static var defaultConfig: ServerConfiguration {
ServerConfiguration.defaultServerConfiguration(forAppID: "1.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit

// swiftformat:disable indent
@objcMembers
class TestAEMReporter: NSObject, AEMReporterProtocol {
final class TestAEMReporter: NSObject, AEMReporterProtocol {

static var enableWasCalled = false
static var setConversionFilteringEnabledWasCalled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

class TestASIdentifierManager: ASIdentifierManager {
final class TestASIdentifierManager: ASIdentifierManager {
var stubbedAdvertisingIdentifier: UUID

init(stubbedAdvertisingIdentifier: UUID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestATEPublisher: NSObject, ATEPublishing {
final class TestATEPublisher: NSObject, ATEPublishing {
var publishATEWasCalled = false

func publishATE() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestATEPublisherFactory: NSObject, ATEPublisherCreating {
final class TestATEPublisherFactory: NSObject, ATEPublisherCreating {
var stubbedPublisher: ATEPublishing? = TestATEPublisher()
var capturedAppID: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import FBSDKCoreKit
import Foundation

@objcMembers
class TestAdvertiserIDProvider: NSObject, AdvertiserIDProviding {
final class TestAdvertiserIDProvider: NSObject, AdvertiserIDProviding {
var advertiserID: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import FBSDKCoreKit

class TestAppEventParametersExtractor: AppEventParametersExtracting {
final class TestAppEventParametersExtractor: AppEventParametersExtracting {
func activityParametersDictionary(
forEvent eventCategory: String,
shouldAccessAdvertisingID: Bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import UIKit

// swiftformat:disable indent
@objcMembers
class TestAppEvents: TestEventLogger,
SourceApplicationTracking,
AppEventsConfiguring,
ApplicationActivating,
ApplicationLifecycleObserving,
ApplicationStateSetting {
final class TestAppEvents: TestEventLogger,
SourceApplicationTracking,
AppEventsConfiguring,
ApplicationActivating,
ApplicationLifecycleObserving,
ApplicationStateSetting {
// swiftformat:enable indent
var wasActivateAppCalled = false
var wasStartObservingApplicationLifecycleNotificationsCalled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestAppEventsConfiguration: NSObject, AppEventsConfigurationProtocol {
final class TestAppEventsConfiguration: NSObject, AppEventsConfigurationProtocol {
static var stubbedDefaultConfiguration: TestAppEventsConfiguration?

var defaultATEStatus: AdvertisingTrackingStatus = .unspecified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestAppEventsConfigurationProvider: NSObject, AppEventsConfigurationProviding {
final class TestAppEventsConfigurationProvider: NSObject, AppEventsConfigurationProviding {
var stubbedConfiguration: AppEventsConfigurationProtocol?
var didRetrieveCachedConfiguration = false
var firstCapturedBlock: AppEventsConfigurationProvidingBlock?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import FBSDKCoreKit

class TestAppEventsDropDeterminer: AppEventDropDetermining {
final class TestAppEventsDropDeterminer: AppEventDropDetermining {

var shouldDropAppEvents = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import FBSDKCoreKit
import Foundation

@objcMembers
class TestAppEventsParameterProcessor: NSObject, AppEventsParameterProcessing, EventsProcessing {
final class TestAppEventsParameterProcessor: NSObject, AppEventsParameterProcessing, EventsProcessing {
var enableWasCalled = false
var capturedParameters: [AppEvents.ParameterName: Any]?
var capturedEventName: AppEvents.Name?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestAppEventsReporter: NSObject, AppEventsReporter {
final class TestAppEventsReporter: NSObject, AppEventsReporter {
var enableWasCalled = false
var capturedEvent: String?
var capturedCurrency: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestAppEventsState: AppEventsState {
final class TestAppEventsState: AppEventsState {
var capturedEventDictionary: [String: Any]?
var capturedIsImplicit = false
var isAddEventCalled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestAppEventsStateProvider: NSObject, AppEventsStateProviding {
final class TestAppEventsStateProvider: NSObject, AppEventsStateProviding {
var state: TestAppEventsState?
var capturedTokenString: String?
var capturedAppID: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestAppEventsStateStore: NSObject, AppEventsStatePersisting {
final class TestAppEventsStateStore: NSObject, AppEventsStatePersisting {
var capturedPersistedState: [Any] = []
var retrievePersistedAppEventStatesWasCalled = false
var clearPersistedAppEventsWasCalled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

class TestAppLink: AppLinkProtocol {
final class TestAppLink: AppLinkProtocol {
var sourceURL: URL?
var targets = [AppLinkTargetProtocol]()
var webURL: URL?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

class TestAppLinkFactory: AppLinkCreating {
final class TestAppLinkFactory: AppLinkCreating {
func createAppLink(
sourceURL: URL?,
targets: [AppLinkTargetProtocol],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@objcMembers
class TestAppLinkResolver: NSObject, AppLinkResolving {
final class TestAppLinkResolver: NSObject, AppLinkResolving {
var capturedURL: URL?
var capturedCompletion: AppLinkBlock?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import TestTools

class TestAppLinkResolverRequestBuilder: AppLinkResolverRequestBuilding {
final class TestAppLinkResolverRequestBuilder: AppLinkResolverRequestBuilding {

var stubbedGraphRequest = TestGraphRequest()
var stubbedIdiomSpecificField: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

class TestAppLinkTarget: AppLinkTargetProtocol {
final class TestAppLinkTarget: AppLinkTargetProtocol {

var url: URL?
var appStoreId: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

class TestAppLinkTargetFactory: AppLinkTargetCreating {
final class TestAppLinkTargetFactory: AppLinkTargetCreating {
func createAppLinkTarget(
url: URL?,
appStoreId: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

class TestAppLinkURL: AppLinkURLProtocol {
final class TestAppLinkURL: AppLinkURLProtocol {
var appLinkExtras: [String: Any]?

init(appLinkExtras: [String: Any] = [:]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import FBSDKCoreKit

class TestAppLinkURLFactory: AppLinkURLCreating {
final class TestAppLinkURLFactory: AppLinkURLCreating {
var stubbedAppLinkURL: TestAppLinkURL?

func createAppLinkURL(with url: URL) -> AppLinkURLProtocol {
Expand Down
Loading

0 comments on commit 624db61

Please sign in to comment.