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

[EMBR-4352] Run Swiftlint/Clang-format over RN iOS module #194

Merged
merged 12 commits into from
Oct 15, 2024
Merged
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: Google
IndentWidth: 4
UseTab: Never
BreakBeforeBraces: Attach
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cache: "npm"
- run: corepack enable
- run: yarn
- run: yarn lint
- run: yarn lint:js
- run: yarn test --watchAll=false --coverage
- run: yarn build
- uses: codecov/codecov-action@v4
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn run lint-staged
49 changes: 49 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
included:
- packages
- integration-tests
- examples

excluded:
- Pods
- node_modules

disabled_rules: # rule identifiers turned on by default to exclude from running
- identifier_name
- function_parameter_count
- notification_center_detachment
- compiler_protocol_init

opt_in_rules:
- conditional_returns_on_newline

reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, codeclimate, junit, html, emoji, sonarqube, markdown, github-actions-logging, summary)

file_length:
warning: 800
error: 1000

line_length:
ignores_comments: true
ignores_interpolated_strings: true

type_body_length:
warning: 600
error: 800

type_name:
max_length:
warning: 60
allowed_symbols: ["_"]

function_body_length:
warning: 100
error: 300

large_tuple:
warning: 4
error: 6

cyclomatic_complexity:
ignores_case_statements: true
warning: 20
error: 30
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#pragma once

#include <ReactCommon/JavaTurboModule.h>

#include <memory>
#include <string>

#include <ReactCommon/JavaTurboModule.h>

namespace facebook {
namespace react {

std::shared_ptr<TurboModule> MainApplicationModuleProvider(
const std::string moduleName,
const JavaTurboModule::InitParams &params);
const std::string moduleName, const JavaTurboModule::InitParams &params);

} // namespace react
} // namespace facebook
} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
#include <memory>
#include <string>

#include <ReactCommon/TurboModuleManagerDelegate.h>
#include <fbjni/fbjni.h>

#include <memory>
#include <string>

namespace facebook {
namespace react {

class MainApplicationTurboModuleManagerDelegate
: public jni::HybridClass<
MainApplicationTurboModuleManagerDelegate,
TurboModuleManagerDelegate> {
public:
// Adapt it to the package you used for your Java class.
static constexpr auto kJavaDescriptor =
"Lcom/embracetestsuite/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;";

static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>);

static void registerNatives();

std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const std::shared_ptr<CallInvoker> jsInvoker) override;
std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const JavaTurboModule::InitParams &params) override;

/**
* Test-only method. Allows user to verify whether a TurboModule can be
* created by instances of this class.
*/
bool canCreateTurboModule(std::string name);
: public jni::HybridClass<MainApplicationTurboModuleManagerDelegate,
TurboModuleManagerDelegate> {
public:
// Adapt it to the package you used for your Java class.
static constexpr auto kJavaDescriptor =
"Lcom/embracetestsuite/newarchitecture/modules/"
"MainApplicationTurboModuleManagerDelegate;";

static jni::local_ref<jhybriddata> initHybrid(
jni::alias_ref<jhybridobject>);

static void registerNatives();

std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const std::shared_ptr<CallInvoker> jsInvoker) override;
std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const JavaTurboModule::InitParams &params) override;

/**
* Test-only method. Allows user to verify whether a TurboModule can be
* created by instances of this class.
*/
bool canCreateTurboModule(std::string name);
};

} // namespace react
} // namespace facebook
} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ namespace react {

class MainComponentsRegistry
: public facebook::jni::HybridClass<MainComponentsRegistry> {
public:
// Adapt it to the package you used for your Java class.
constexpr static auto kJavaDescriptor =
"Lcom/embracetestsuite/newarchitecture/components/MainComponentsRegistry;";
public:
// Adapt it to the package you used for your Java class.
constexpr static auto kJavaDescriptor =
"Lcom/embracetestsuite/newarchitecture/components/"
"MainComponentsRegistry;";

static void registerNatives();
static void registerNatives();

MainComponentsRegistry(ComponentFactory *delegate);
MainComponentsRegistry(ComponentFactory *delegate);

private:
static std::shared_ptr<ComponentDescriptorProviderRegistry const>
sharedProviderRegistry();
private:
static std::shared_ptr<ComponentDescriptorProviderRegistry const>
sharedProviderRegistry();

static jni::local_ref<jhybriddata> initHybrid(
jni::alias_ref<jclass>,
ComponentFactory *delegate);
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>,
ComponentFactory *delegate);
};

} // namespace react
} // namespace facebook
} // namespace react
} // namespace facebook
6 changes: 3 additions & 3 deletions examples/react-native-test-suite/ios/CRLCrash.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
+ (void)registerCrash:(CRLCrash *)crash;
+ (void)unregisterCrash:(CRLCrash *)crash;

@property(nonatomic,copy,readonly) NSString *category;
@property(nonatomic,copy,readonly) NSString *title;
@property(nonatomic,copy,readonly) NSString *desc;
@property(nonatomic, copy, readonly) NSString *category;
@property(nonatomic, copy, readonly) NSString *title;
@property(nonatomic, copy, readonly) NSString *desc;

- (void)crash;

Expand Down
46 changes: 20 additions & 26 deletions examples/react-native-test-suite/ios/CRLCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,40 @@

@implementation CRLCrash

+ (void)initialize
{
static dispatch_once_t predicate = 0;

dispatch_once(&predicate, ^ { crashTypes = [[NSMutableSet alloc] init]; });
+ (void)initialize {
static dispatch_once_t predicate = 0;

dispatch_once(&predicate, ^{
crashTypes = [[NSMutableSet alloc] init];
});
}

+ (NSArray *)allCrashes
{
return crashTypes.allObjects;
+ (NSArray *)allCrashes {
return crashTypes.allObjects;
}

+ (void)registerCrash:(CRLCrash *)crash
{
[crashTypes addObject:crash];
+ (void)registerCrash:(CRLCrash *)crash {
[crashTypes addObject:crash];
}

+ (void)unregisterCrash:(CRLCrash *)crash
{
[crashTypes removeObject:crash];
+ (void)unregisterCrash:(CRLCrash *)crash {
[crashTypes removeObject:crash];
}

- (NSString *)category
{
return @"NONE";
- (NSString *)category {
return @"NONE";
}

- (NSString *)title
{
return @"NONE";
- (NSString *)title {
return @"NONE";
}

- (NSString *)desc
{
return @"NONE";
- (NSString *)desc {
return @"NONE";
}

- (void)crash
{
NSLog(@"I'm supposed to crash here.");
- (void)crash {
NSLog(@"I'm supposed to crash here.");
}

@end
32 changes: 17 additions & 15 deletions examples/react-native-test-suite/ios/CRLCrashCXXException.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
#import "CRLCrashCXXException.h"
#import <exception>

class kaboom_exception : public std::exception
{
virtual const char* what() const throw();
class kaboom_exception : public std::exception {
virtual const char *what() const throw();
};

const char* kaboom_exception::what() const throw()
{
return "If this had been a real exception, you would be cursing now.";
const char *kaboom_exception::what() const throw() {
return "If this had been a real exception, you would be cursing now.";
}

@implementation CRLCrashCXXException

- (NSString *)category { return @"Exceptions"; }
- (NSString *)title { return @"Throw C++ exception"; }
- (NSString *)desc { return @""
"Throw an uncaught C++ exception. "
"This is a difficult case for crash reporters to handle, "
"as it involves the destruction of the data necessary to generate a correct backtrace.";
- (NSString *)category {
return @"Exceptions";
}
- (NSString *)title {
return @"Throw C++ exception";
}
- (NSString *)desc {
return @""
"Throw an uncaught C++ exception. "
"This is a difficult case for crash reporters to handle, "
"as it involves the destruction of the data necessary to generate a correct backtrace.";
}

- (void)crash __attribute__((noreturn))
{
throw new kaboom_exception;
- (void)crash __attribute__((noreturn)) {
throw new kaboom_exception;
}

@end
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <Embrace/Embrace.h>
#import <React/RCTBundleURLProvider.h>

#import <React/RCTLinkingManager.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
return [RCTLinkingManager application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


[[Embrace sharedInstance] startWithLaunchOptions:launchOptions framework:EMBAppFrameworkReactNative];

self.moduleName = @"EmbraceTestSuite";
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};
return [super application:application didFinishLaunchingWithOptions:launchOptions];
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[Embrace sharedInstance] startWithLaunchOptions:launchOptions
framework:EMBAppFrameworkReactNative];

self.moduleName = @"EmbraceTestSuite";
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

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

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
int main(int argc, char *argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Loading
Loading