Skip to content

Commit

Permalink
fix: resolve all project warnings (#10830)
Browse files Browse the repository at this point in the history
* refactor: fix all warnings (except deprecations for now)

* refactor: update Swift test module to Swift 5

* refactor: update Swift test module to Swift 5 #2

* refactor: update Swift module template to Swift 5

* fix: properly lint hooks, restore app.js

* fix: fix eslint warnings

* fix: fix eslint

* fix linting issue

* remove duplicate 'use strict' directive

* remove duplicate hasProperty method declaration

* fix: address couple more warnings
  • Loading branch information
hansemannn authored and ssjsamir committed Sep 4, 2019
1 parent 1a8ae85 commit cd60eb9
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 72 deletions.
1 change: 1 addition & 0 deletions iphone/Classes/AppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifdef USE_TI_APP

#import "AppModule.h"
#import "TiUtils+Addons.h"
#import <TitaniumKit/ListenerEntry.h>
#import <TitaniumKit/TiApp.h>
#import <TitaniumKit/TiHost.h>
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifdef USE_TI_GEOLOCATION

#import "GeolocationModule.h"
#import "TiUtils+Addons.h"
#import <TitaniumKit/APSHTTPClient.h>
#import <TitaniumKit/NSData+Additions.h>
#import <TitaniumKit/TiApp.h>
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/PlatformModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "PlatformModule.h"
#import "TiPlatformDisplayCaps.h"
#import "TiUtils+Addons.h"
#import <TitaniumKit/TiApp.h>

#import <mach/mach.h>
Expand Down
4 changes: 4 additions & 0 deletions iphone/Classes/TiApp+Addons.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

@interface TiApp (Addons)

NS_ASSUME_NONNULL_BEGIN

#ifdef USE_TI_FETCH
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
#endif
Expand All @@ -29,4 +31,6 @@
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
#endif

NS_ASSUME_NONNULL_END

@end
2 changes: 1 addition & 1 deletion iphone/Classes/TiDatabaseResultSetProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ - (BOOL)next
- (JSValue *)field:(NSInteger)index withType:(JSValue *)optionalType
{
if (results != nil) {
id result = [results objectForColumnIndex:index];
id result = [results objectForColumnIndex:(int)index];
if ([result isKindOfClass:[NSData class]]) {
result = [[[TiBlob alloc] initWithData:result mimetype:@"application/octet-stream"] autorelease];
}
Expand Down
23 changes: 21 additions & 2 deletions iphone/TitaniumKit/TitaniumKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@
DB258CC41F09757E000D0D8D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0830;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "Hans Knoechel";
TargetAttributes = {
DB258CCC1F09757E000D0D8D = {
Expand All @@ -746,10 +746,11 @@
};
buildConfigurationList = DB258CC71F09757E000D0D8D /* Build configuration list for PBXProject "TitaniumKit" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = DB258CC31F09757E000D0D8D;
productRefGroup = DB258CCE1F09757E000D0D8D /* Products */;
Expand Down Expand Up @@ -878,15 +879,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -931,15 +940,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -972,6 +989,7 @@
buildSettings = {
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = NO;
CODE_SIGN_IDENTITY = "";
Expand Down Expand Up @@ -1012,6 +1030,7 @@
buildSettings = {
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = NO;
CODE_SIGN_IDENTITY = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
6 changes: 3 additions & 3 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ - (void)didStartNewContext:(KrollContext *)kroll
for (NSString *name in legacyModuleNames) {
// We must generate the block and copy it to put it into heap or else every instance of the block shares
// the same "name" value. See https://stackoverflow.com/questions/7750907/blocks-loops-and-local-variables
JSValue * (^lazyLoad)() = ^() {
JSValue * (^lazyLoad)(void) = ^() {
JSValue *result;
TiModule *mod = [host moduleNamed:name context:self];
if (mod != nil) {
Expand Down Expand Up @@ -486,7 +486,7 @@ - (void)didStartNewContext:(KrollContext *)kroll
for (NSString *name in moduleNames) {
// We must generate the block and copy it to put it into heap or else every instance of the block shares
// the same "name" value. See https://stackoverflow.com/questions/7750907/blocks-loops-and-local-variables
JSValue * (^lazyLoad)() = ^() {
JSValue * (^lazyLoad)(void) = ^() {
JSValue *result;
Class moduleClass = NSClassFromString([NSString stringWithFormat:@"%@Module", name]);
if (moduleClass != nil) {
Expand Down Expand Up @@ -530,7 +530,7 @@ - (void)didStartNewContext:(KrollContext *)kroll
if (preload != nil) {
for (NSString *name in preload) {
JSValue *moduleJSObject = titanium[name];
KrollObject *ti = (KrollObject *)JSObjectGetPrivate([moduleJSObject JSValueRef]);
KrollObject *ti = (KrollObject *)JSObjectGetPrivate(JSValueToObject(jsContext, moduleJSObject.JSValueRef, NULL));
NSDictionary *values = preload[name];
for (id key in values) {
id target = values[key];
Expand Down
4 changes: 2 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/ObjcProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ - (void)addEventListener:(NSString *)name withCallback:(JSValue *)callback
}
@finally {
pthread_rwlock_unlock(&_listenerLock);
[self _listenerAdded:name count:ourCallbackCount];
[self _listenerAdded:name count:(int)ourCallbackCount];
}
}

Expand Down Expand Up @@ -159,7 +159,7 @@ - (void)removeEventListener:(NSString *)name withCallback:(JSValue *)callback
@finally {
pthread_rwlock_unlock(&_listenerLock);
if (removed) {
[self _listenerRemoved:name count:ourCallbackCount];
[self _listenerRemoved:name count:(int)ourCallbackCount];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion iphone/TitaniumKit/TitaniumKit/Sources/API/TiAnimation.m
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ - (void)animate:(id)args
options |= ([autoreverse boolValue] ? (UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat) : 0);
options |= (([repeat intValue] > 0) ? UIViewAnimationOptionRepeat : 0);

void (^animation)() = ^{
void (^animation)(void) = ^{
CGFloat repeatCount = [repeat intValue];
if ((options & UIViewAnimationOptionAutoreverse)) {
// What we have to do here in order to get the 'correct' animation
Expand Down
2 changes: 1 addition & 1 deletion iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run on
@param _notificationName The name of the notification to schedule.
@param completionHandler The optional completion handler to invoke if requried.
*/
- (void)tryToPostNotification:(NSDictionary *)_notification withNotificationName:(NSString *)_notificationName completionHandler:(void (^)())completionHandler;
- (void)tryToPostNotification:(NSDictionary *)_notification withNotificationName:(NSString *)_notificationName completionHandler:(void (^)(void))completionHandler;

/**
Tries to post a given background-mode notification with the given name. If the app did not finish launching so far, it will be queued
Expand Down
19 changes: 13 additions & 6 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

NSString *TITANIUM_VERSION;

extern void UIColorFlushCache();
extern void UIColorFlushCache(void);

#define SHUTDOWN_TIMEOUT_IN_SEC 3
#define TIV @"TiVerify"

BOOL applicationInMemoryPanic = NO; // TODO: Remove in SDK 9.0+

// TODO: Remove in SDK 9.0+
TI_INLINE void waitForMemoryPanicCleared(); //WARNING: This must never be run on main thread, or else there is a risk of deadlock!
TI_INLINE void waitForMemoryPanicCleared(void); //WARNING: This must never be run on main thread, or else there is a risk of deadlock!

@interface TiApp ()
- (void)checkBackgroundServices;
Expand Down Expand Up @@ -573,6 +573,11 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
}
}

// This is required because iOS does not conform to it's own recommended Obj-C compiler rules (Strict prototypes).
// Muting the warnings until the UIApplicationDelegate fixes this.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler
{
RELEASE_TO_NIL(localNotification);
Expand Down Expand Up @@ -609,6 +614,8 @@ - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSS
completionHandler:completionHandler];
}

#pragma clang diagnostic pop

#pragma mark Apple Watchkit handleWatchKitExtensionRequest

- (void)application:(UIApplication *)application
Expand Down Expand Up @@ -689,9 +696,9 @@ - (void)tryToInvokeSelector:(SEL)selector withArguments:(NSOrderedSet<id> *)argu
}
}

- (void)tryToPostNotification:(NSDictionary *)_notification withNotificationName:(NSString *)_notificationName completionHandler:(void (^)())completionHandler
- (void)tryToPostNotification:(NSDictionary *)_notification withNotificationName:(NSString *)_notificationName completionHandler:(void (^)(void))completionHandler
{
typedef void (^NotificationBlock)();
typedef void (^NotificationBlock)(void);

NotificationBlock myNotificationBlock = ^void() {
[[NSNotificationCenter defaultCenter] postNotificationName:_notificationName object:self userInfo:_notification];
Expand Down Expand Up @@ -770,7 +777,7 @@ - (void)performCompletionHandlerWithKey:(NSString *)key andResult:(UIBackgroundF
- (void)performCompletionHandlerForBackgroundTransferWithKey:(NSString *)key
{
if ([backgroundTransferCompletionHandlers objectForKey:key] != nil) {
void (^completionHandler)();
void (^completionHandler)(void);
completionHandler = [backgroundTransferCompletionHandlers objectForKey:key];
[backgroundTransferCompletionHandlers removeObjectForKey:key];
completionHandler();
Expand Down Expand Up @@ -1260,7 +1267,7 @@ - (BOOL)handleShortcutItem:(UIApplicationShortcutItem *)shortcutItem queueToBoot
- (void)handleRemoteNotificationWithIdentifier:(NSString *)identifier
andUserInfo:(NSDictionary *)userInfo
responseInfo:(NSDictionary *)responseInfo
completionHandler:(void (^)())completionHandler
completionHandler:(void (^)(void))completionHandler
{
RELEASE_TO_NIL(remoteNotification);
[self generateNotification:userInfo];
Expand Down
6 changes: 4 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ extern "C" {
}

// create a mutable array that doesn't retain internal references to objects
NSMutableArray *TiCreateNonRetainingArray();
NSMutableArray *TiCreateNonRetainingArray(void);

// create a mutable dictionary that doesn't retain internal references to objects
NSMutableDictionary *TiCreateNonRetainingDictionary();
NSMutableDictionary *TiCreateNonRetainingDictionary(void);

CGPoint midpointBetweenPoints(CGPoint a, CGPoint b);
void TiLogMessage(NSString *str, ...);
Expand Down Expand Up @@ -523,12 +523,14 @@ enum {
}
#endif

#ifndef DebugLog
#define DebugLog(...) \
{ \
if ([TiSharedConfig defaultConfig].debugEnabled) { \
NSLog(__VA_ARGS__); \
} \
}
#endif

#define VAL_OR_NSNULL(foo) (((foo) != nil) ? ((id)foo) : [NSNull null])

Expand Down
4 changes: 2 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#include <unistd.h>
#endif

NSMutableArray *TiCreateNonRetainingArray()
NSMutableArray *TiCreateNonRetainingArray(void)
{
CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
callbacks.retain = NULL;
callbacks.release = NULL;
return (NSMutableArray *)CFArrayCreateMutable(nil, 0, &callbacks);
}

NSMutableDictionary *TiCreateNonRetainingDictionary()
NSMutableDictionary *TiCreateNonRetainingDictionary(void)
{
CFDictionaryKeyCallBacks keyCallbacks = kCFTypeDictionaryKeyCallBacks;
CFDictionaryValueCallBacks callbacks = kCFTypeDictionaryValueCallBacks;
Expand Down
4 changes: 2 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@

- (void)invokeOnThread:(id)callback_ method:(SEL)method_ withObject:(id)obj condition:(NSCondition *)condition_;
- (void)invokeOnThread:(id)callback_ method:(SEL)method_ withObject:(id)obj callback:(id)callback selector:(SEL)selector_;
- (void)invokeBlockOnThread:(void (^)())block;
+ (void)invokeBlock:(void (^)())block;
- (void)invokeBlockOnThread:(void (^)(void))block;
+ (void)invokeBlock:(void (^)(void))block;

- (void)evalJS:(NSString *)code;
- (id)evalJSAndWait:(NSString *)code;
Expand Down
4 changes: 2 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,14 @@ - (void)invokeOnThread:(id)callback_ method:(SEL)method_ withObject:(id)obj call
[self invoke:invocation];
}

- (void)invokeBlockOnThread:(void (^)())block
- (void)invokeBlockOnThread:(void (^)(void))block
{
pthread_mutex_lock(&KrollEntryLock);
block();
pthread_mutex_unlock(&KrollEntryLock);
}

+ (void)invokeBlock:(void (^)())block
+ (void)invokeBlock:(void (^)(void))block
{
pthread_mutex_lock(&KrollEntryLock);
block();
Expand Down
23 changes: 23 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ bool KrollDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef prope
+ (JSValueRef)toValue:(KrollContext *)context value:(id)obj;
+ (id)nonNull:(id)value;

/**
Checks if a property with the given name exists on our target.
Contains all the magic of valueForKey withouth trying to retrieve any actual
value.
The checks for property existance are done in the following order:
* The Kroll object's own statics and properties cache
* Dynamic getter and setter in the form of getSomeProperty or setSomeProperty
* Property on the actual target
* "toString" and "valueOf" are always available on all objects
* "className" has a special handling with valueForUndefinedKey, return true
for the sake of simplicity
* Method with the same name on the target and single parameter
* Method with the same name on the target and no parameter
* Create factory method
As soon as one of the above checks passes this method returns true, meaning
the property exists. If none of the checks passed the property does not exists
and the method returns false.
@param propertyName The property name to check for.
*/
- (BOOL)hasProperty:(NSString *)propertyName;
- (id)valueForKey:(NSString *)key;
- (void)deleteKey:(NSString *)key;
Expand Down

0 comments on commit cd60eb9

Please sign in to comment.