Skip to content

Commit

Permalink
chore: Fix Lint errors (#3428)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphofmann committed Nov 17, 2023
1 parent 7c69adf commit bd2cb64
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 43 deletions.
10 changes: 6 additions & 4 deletions Sources/Sentry/SentryHub.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ - (void)startSession
if (_session != nil) {
lastSession = _session;
}

NSString* distinctId = [SentryInstallation idWithCacheDirectoryPath:options.cacheDirectoryPath];

_session = [[SentrySession alloc] initWithReleaseName:options.releaseName distinctId:distinctId];

NSString *distinctId =
[SentryInstallation idWithCacheDirectoryPath:options.cacheDirectoryPath];

_session = [[SentrySession alloc] initWithReleaseName:options.releaseName
distinctId:distinctId];

if (_errorsBeforeSession > 0 && options.enableAutoSessionTracking == YES) {
_session.errors = _errorsBeforeSession;
Expand Down
37 changes: 21 additions & 16 deletions Sources/Sentry/SentryInstallation.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,54 @@

NS_ASSUME_NONNULL_BEGIN

@interface SentryInstallation ()
@property(class, nonatomic, readonly) NSMutableDictionary<NSString*, NSString*>* installationStringsByCacheDirectoryPaths;
@interface
SentryInstallation ()
@property (class, nonatomic, readonly)
NSMutableDictionary<NSString *, NSString *> *installationStringsByCacheDirectoryPaths;
@end

@implementation SentryInstallation

+ (NSMutableDictionary<NSString*, NSString*>*)installationStringsByCacheDirectoryPaths
+ (NSMutableDictionary<NSString *, NSString *> *)installationStringsByCacheDirectoryPaths
{
static dispatch_once_t once;
static NSMutableDictionary* dictionary;

dispatch_once(&once, ^{
dictionary = [NSMutableDictionary dictionary];
});
static NSMutableDictionary *dictionary;

dispatch_once(&once, ^{ dictionary = [NSMutableDictionary dictionary]; });
return dictionary;
}

+ (NSString *)idWithCacheDirectoryPath:(NSString *)cacheDirectoryPath
{
@synchronized(self) {
NSString* installationString = self.installationStringsByCacheDirectoryPaths[cacheDirectoryPath];

NSString *installationString
= self.installationStringsByCacheDirectoryPaths[cacheDirectoryPath];

if (nil != installationString) {
return installationString;
}

NSString *cachePath = cacheDirectoryPath;
NSString *installationFilePath = [cachePath stringByAppendingPathComponent:@"INSTALLATION"];
NSData *installationData = [NSData dataWithContentsOfFile:installationFilePath];

if (nil == installationData) {
installationString = [NSUUID UUID].UUIDString;
NSData *installationStringData = [installationString dataUsingEncoding:NSUTF8StringEncoding];
NSData *installationStringData =
[installationString dataUsingEncoding:NSUTF8StringEncoding];
NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager createFileAtPath:installationFilePath contents:installationStringData attributes:nil]) {

if (![fileManager createFileAtPath:installationFilePath
contents:installationStringData
attributes:nil]) {
SENTRY_LOG_ERROR(
@"Failed to store installationID file at path %@", installationFilePath);
}
} else {
installationString = [[NSString alloc] initWithData:installationData encoding:NSUTF8StringEncoding];
installationString = [[NSString alloc] initWithData:installationData
encoding:NSUTF8StringEncoding];
}

self.installationStringsByCacheDirectoryPaths[cacheDirectoryPath] = installationString;
return installationString;
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ - (instancetype)init
SentryHttpStatusCodeRange *defaultHttpStatusCodeRange =
[[SentryHttpStatusCodeRange alloc] initWithMin:500 max:599];
self.failedRequestStatusCodes = @[ defaultHttpStatusCodeRange ];
self.cacheDirectoryPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)
.firstObject;
self.cacheDirectoryPath
= NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)
.firstObject;

#if SENTRY_HAS_METRIC_KIT
if (@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, *)) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentrySession.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @implementation SentrySession
* Default private constructor. We don't name it init to avoid the overlap with the default init of
* NSObject, which is not available as we specified in the header with SENTRY_NO_INIT.
*/
- (instancetype)initDefault:(NSString*)distinctId
- (instancetype)initDefault:(NSString *)distinctId
{
if (self = [super init]) {
_sessionId = [NSUUID UUID];
Expand All @@ -45,7 +45,7 @@ - (instancetype)initDefault:(NSString*)distinctId
return self;
}

- (instancetype)initWithReleaseName:(NSString *)releaseName distinctId:(NSString*)distinctId
- (instancetype)initWithReleaseName:(NSString *)releaseName distinctId:(NSString *)distinctId
{
if (self = [self initDefault:distinctId]) {
_init = @YES;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentrySession.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef NS_ENUM(NSUInteger, SentrySessionStatus) {
@interface SentrySession : NSObject <SentrySerializable, NSCopying>
SENTRY_NO_INIT

- (instancetype)initWithReleaseName:(NSString *)releaseName distinctId:(NSString*)distinctId;
- (instancetype)initWithReleaseName:(NSString *)releaseName distinctId:(NSString *)distinctId;

/**
* Initializes @c SentrySession from a JSON object.
Expand Down
6 changes: 3 additions & 3 deletions Sources/SentryCrash/Recording/SentryCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ - (BOOL)install
@"reporting disabled.");
return NO;
}

// Restore previous monitors when uninstall was called previously
if (self.monitoringFromUninstalledToRestore
&& self.monitoringWhenUninstalled != SentryCrashMonitorTypeNone) {
[self setMonitoring:self.monitoringWhenUninstalled];
self.monitoringWhenUninstalled = SentryCrashMonitorTypeNone;
self.monitoringFromUninstalledToRestore = NO;
}

NSString *pathEnd = [@"SentryCrash" stringByAppendingPathComponent:[self getBundleName]];
NSString* installPath = [self.basePath stringByAppendingPathComponent:pathEnd];
NSString *installPath = [self.basePath stringByAppendingPathComponent:pathEnd];

_monitoring = sentrycrash_install(self.bundleName.UTF8String, installPath.UTF8String);
if (self.monitoring == 0) {
Expand Down
3 changes: 2 additions & 1 deletion Tests/SentryTests/SentryCrash/SentryCrash+Test.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "SentryCrash.h"

@interface SentryCrash (Test)
@interface
SentryCrash (Test)
- (NSString *)getBundleName;
@end
18 changes: 11 additions & 7 deletions Tests/SentryTests/SentryCrash/SentryCrashTests.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "FileBasedTestCase.h"
#import "SentryCrash.h"
#import "SentryCrash+Test.h"
#import "SentryCrash.h"
#include "SentryCrashReportStore.h"

@interface SentryCrashTests : FileBasedTestCase
Expand Down Expand Up @@ -51,7 +51,8 @@ - (void)test_getScreenshots_TwoFiles

- (void)test_cleanBundleName
{
SentryCrash *sentryCrash = [[SentryCrash alloc] initWithBasePath:[self.tempPath stringByAppendingPathComponent:@"Something"]];
SentryCrash *sentryCrash = [[SentryCrash alloc]
initWithBasePath:[self.tempPath stringByAppendingPathComponent:@"Something"]];

NSString *clearedBundleName = [sentryCrash clearBundleName:@"Sentry/Test"];

Expand Down Expand Up @@ -86,13 +87,16 @@ - (void)test_install
{
SentryCrash *sentryCrash = [[SentryCrash alloc] initWithBasePath:self.tempPath];
NSString *pathEnd = [@"SentryCrash" stringByAppendingPathComponent:[sentryCrash getBundleName]];
NSString* installPath = [self.tempPath stringByAppendingPathComponent:pathEnd];
NSString *installPath = [self.tempPath stringByAppendingPathComponent:pathEnd];

XCTAssertEqual([sentryCrash install], YES);
XCTAssertTrue([NSFileManager.defaultManager fileExistsAtPath:installPath]);
XCTAssertTrue([NSFileManager.defaultManager fileExistsAtPath:[installPath stringByAppendingPathComponent:@"Reports"]]);
XCTAssertTrue([NSFileManager.defaultManager fileExistsAtPath:[installPath stringByAppendingPathComponent:@"Data"]]);
XCTAssertTrue([NSFileManager.defaultManager fileExistsAtPath:[installPath stringByAppendingPathComponent:@"Data/CrashState.json"]]);
XCTAssertTrue([NSFileManager.defaultManager
fileExistsAtPath:[installPath stringByAppendingPathComponent:@"Reports"]]);
XCTAssertTrue([NSFileManager.defaultManager
fileExistsAtPath:[installPath stringByAppendingPathComponent:@"Data"]]);
XCTAssertTrue([NSFileManager.defaultManager
fileExistsAtPath:[installPath stringByAppendingPathComponent:@"Data/CrashState.json"]]);
}

- (void)initReport:(uint64_t)reportId withScreenshots:(int)amount
Expand Down
9 changes: 6 additions & 3 deletions Tests/SentryTests/SentrySessionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ @implementation SentrySessionTests

- (void)testInitDefaultValues
{
SentrySession *session = [[SentrySession alloc] initWithReleaseName:@"1.0.0" distinctId:@"some-id"];
SentrySession *session = [[SentrySession alloc] initWithReleaseName:@"1.0.0"
distinctId:@"some-id"];
XCTAssertNotNil(session.sessionId);
XCTAssertEqual(1, session.sequence);
XCTAssertEqual(0, session.errors);
Expand All @@ -26,7 +27,8 @@ - (void)testInitDefaultValues

- (void)testSerializeDefaultValues
{
SentrySession *expected = [[SentrySession alloc] initWithReleaseName:@"1.0.0" distinctId:@"some-id"];
SentrySession *expected = [[SentrySession alloc] initWithReleaseName:@"1.0.0"
distinctId:@"some-id"];
NSDictionary<NSString *, id> *json = [expected serialize];
SentrySession *actual = [[SentrySession alloc] initWithJSONObject:json];

Expand All @@ -51,7 +53,8 @@ - (void)testSerializeDefaultValues

- (void)testSerializeExtraFieldsEndedSessionWithNilStatus
{
SentrySession *expected = [[SentrySession alloc] initWithReleaseName:@"io.sentry@5.0.0-test" distinctId:@"some-id"];
SentrySession *expected = [[SentrySession alloc] initWithReleaseName:@"io.sentry@5.0.0-test"
distinctId:@"some-id"];
NSDate *timestamp = [NSDate date];
[expected endSessionExitedWithTimestamp:timestamp];
expected.environment = @"prod";
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentryTests-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
#import "SentryId.h"
#import "SentryInAppLogic.h"
#import "SentryInitializeForGettingSubclassesNotCalled.h"
#import "SentryInstallation.h"
#import "SentryInstallation+Test.h"
#import "SentryInstallation.h"
#import "SentryInternalNotificationNames.h"
#import "SentryLevelMapper.h"
#import "SentryLog+TestInit.h"
Expand Down
6 changes: 4 additions & 2 deletions Tests/SentryTests/State/SentryInstallation+Test.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "SentryInstallation.h"

@interface SentryInstallation (Test)
@property(class, nonatomic, readonly) NSMutableDictionary<NSString*, NSString*>* installationStringsByCacheDirectoryPaths;
@interface
SentryInstallation (Test)
@property (class, nonatomic, readonly)
NSMutableDictionary<NSString *, NSString *> *installationStringsByCacheDirectoryPaths;
@end
1 change: 0 additions & 1 deletion Tests/SentryTests/State/SentryInstallationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ final class SentryInstallationTests: XCTestCase {
XCTAssertEqual(id1, SentryInstallation.id(withCacheDirectoryPath: basePath))
}
}

0 comments on commit bd2cb64

Please sign in to comment.