Add custom SwiftLint rule to prevent missing foundation import to prevent error

Summary:
In D33750740 (8044535803) Hackbook started showing me the following error

```
objc attribute used without importing module 'Foundation'
```

This custom rule should prevent most cases of this. (It will only detect cases in which there are only empty lines between the license and the first objc)

Ran the following to add missing imports
```
git ls-files '*.swift' | xargs perl -0777 -pi -e s'/(of this source tree.\n \*\/)\n+\objc/\1\n\nimport Foundation\n\n\objc/'
```

Reviewed By: samodom

Differential Revision: D33783526

fbshipit-source-id: e75e1a66152d9a9790aa363d2fe7c71fd9446849
This commit is contained in:
Jawwad Ahmad
2022-01-26 14:02:02 -08:00
committed by Facebook GitHub Bot
parent 8a840e51c0
commit 4610b07bda
40 changed files with 81 additions and 0 deletions

View File

@@ -61,6 +61,9 @@ custom_rules:
objc_members_above_objc:
regex: "@objc[^\n]*?\n@objcMembers"
message: "Place @objcMembers above @objc"
objc_used_without_importing_foundation:
regex: "LICENSE file in the root directory of this source tree.\n \\*/\n+@objc"
message: "@objc attribute used without importing module 'Foundation'"
only_rules:
- array_init

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
@objc(FBSDKLoginManager) // for NSClassFromString(@"FBSDKLoginManager")
class FBSDKLoginManager: NSObject {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class SampleEventBinding: NSObject {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class SampleRawRemoteEventBindings: NSObject {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class ServerConfigurationFixtures: NSObject {
// swiftlint:disable line_length

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestATEPublisher: NSObject, ATEPublishing {
var publishATEWasCalled = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestATEPublisherFactory: NSObject, ATEPublisherCreating {
var stubbedPublisher: ATEPublishing? = TestATEPublisher()

View File

@@ -6,5 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
final class TestAccessTokenExpirer: NSObject, AccessTokenExpiring {}

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestAppEventsConfiguration: NSObject, AppEventsConfigurationProtocol {
static var stubbedDefaultConfiguration: TestAppEventsConfiguration?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestAppEventsConfigurationProvider: NSObject, AppEventsConfigurationProviding {
var stubbedConfiguration: AppEventsConfigurationProtocol?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestAppEventsReporter: NSObject, AppEventsReporter {
var enableWasCalled = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestAppEventsStateProvider: NSObject, AppEventsStateProviding {
var state: TestAppEventsState?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestAppEventsStateStore: NSObject, AppEventsStatePersisting {
var capturedPersistedState: [Any] = []

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestAppLinkResolver: NSObject, AppLinkResolving {
var capturedURL: URL?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestAppStoreReceiptProvider: AppStoreReceiptProviding {
var wasAppStoreReceiptURLRead = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestApplicationDelegateObserver: NSObject, FBSDKApplicationObserving {
var didFinishLaunchingCallCount = 0

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestBackgroundEventLogger: NSObject, BackgroundEventLogging {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestBridgeAPIResponseFactory: NSObject, BridgeAPIResponseCreating {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestCodelessEvents: NSObject, CodelessIndexing {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestDylibResolver: NSObject, FBSDKDynamicFrameworkResolving {
var stubSafariViewControllerClass: AnyClass?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestErrorConfigurationProvider: NSObject, ErrorConfigurationProviding {
var configuration: ErrorConfigurationProtocol?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestGateKeeperManager: NSObject, GateKeeperManaging {
static var gateKeepers = [String?: Bool]()

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestGraphRequestBody: GraphRequestBody {
var capturedKey: String?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestLogger: Logger {
static var capturedLoggingBehavior: LoggingBehavior?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestLoggerFactory: NSObject, LoggerCreating {
var capturedLoggingBehavior: LoggingBehavior?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestMetadataIndexer: NSObject, MetadataIndexing {
var enableWasCalled = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestPaymentObserver: NSObject, PaymentObserving {
var didStartObservingTransactions = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestTimeSpentRecorder: NSObject, SourceApplicationTracking, TimeSpentRecording {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestTouch: UITouch {
var stubbedView: UIView?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestURLSessionProxy: NSObject, URLSessionProxying {
var delegateQueue: OperationQueue?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestURLSessionProxyFactory: NSObject, URLSessionProxyProviding {
private var stubbedSessions: [TestURLSessionProxy]

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
class TestUserIDProvider: NSObject, UserIDProviding {
var userID: String?

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
final class TestInternalURLOpener: NSObject, ShareInternalURLOpening {
var canOpenURL = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
final class TestShareUtility: NSObject, _ShareUtilityProtocol {
static var stubbedValidateShareShouldThrow = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
public class TestBridgeAPIRequest: NSObject, BridgeAPIRequestProtocol {
public var actionID: String

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
public class TestBridgeAPIRequestOpener: NSObject, BridgeAPIRequestOpening {

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
public final class TestErrorFactory: NSObject, ErrorCreating {
public func error(

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objc public enum TestSDKErrorType: Int {
case general
case invalidArgument

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
public class TestSettings: NSObject, SettingsProtocol, SettingsLogging {
public var isEventDataUsageLimited = false

View File

@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
import Foundation
@objcMembers
public class UserDefaultsSpy: UserDefaults {
public var capturedObjectRetrievalKeys = [String]()