From 11a2ab1cc5e49894d3d27f0a32a9f006fed3a2f4 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 13 Sep 2024 08:19:55 -0700 Subject: [PATCH] Fix some basic warning while building (#46463) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46463 We had some basic warnings emitted by React Native components due to unused parameters or missing documentations. This change fixes some of those ## Changelog: [Internal] - Fix some build warnings Reviewed By: NickGerleman Differential Revision: D62583790 fbshipit-source-id: 329acc67ce64c00757a8568460ee68b85a62b6e9 --- .../AppDelegate/RCTRootViewFactory.h | 2 +- packages/react-native/React/Base/RCTUtils.h | 2 +- .../RCTSurfaceHostingView.h | 2 +- .../jsinspector-modern/HostAgent.h | 2 +- .../ios/ReactCommon/RCTTurboModule.mm | 4 +- .../RCTNativeSampleTurboModuleSpec.h | 4 ++ .../ios/ReactCommon/RCTSampleLegacyModule.mm | 4 +- .../ios/ReactCommon/RCTSampleTurboModule.mm | 4 +- .../LayoutAnimationKeyFrameManager.h | 8 ++-- .../react/renderer/core/RawValue.h | 40 +++++++++---------- .../renderer/debug/DebugStringConvertible.h | 36 ++++++++--------- .../react/renderer/graphics/Transform.h | 8 ++-- .../mounting/MountingOverrideDelegate.h | 9 +++-- .../react/renderer/mounting/ShadowTree.h | 1 - .../uimanager/UIManagerAnimationDelegate.h | 2 +- .../platform/ios/ReactCommon/RCTInstance.mm | 2 +- 16 files changed, 67 insertions(+), 63 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h index ebec3f45e46..d4220f6102f 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h @@ -183,7 +183,7 @@ typedef void (^RCTHostDidReceiveJSErrorStackBlock)( @property (nonatomic, strong, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter; - (instancetype)initWithConfiguration:(RCTRootViewFactoryConfiguration *)configuration - andTurboModuleManagerDelegate:(id)turboModuleManagerDelegate; + andTurboModuleManagerDelegate:(id _Nullable)turboModuleManagerDelegate; - (instancetype)initWithConfiguration:(RCTRootViewFactoryConfiguration *)configuration; diff --git a/packages/react-native/React/Base/RCTUtils.h b/packages/react-native/React/Base/RCTUtils.h index 5d145e3928f..313ffc2f7f9 100644 --- a/packages/react-native/React/Base/RCTUtils.h +++ b/packages/react-native/React/Base/RCTUtils.h @@ -112,7 +112,7 @@ RCT_EXTERN NSError *RCTErrorWithMessage(NSString *message); RCT_EXTERN NSError *RCTErrorWithNSException(NSException *exception); // Convert nil values to NSNull, and vice-versa -#define RCTNullIfNil(value) ((value) ?: (id)kCFNull) +#define RCTNullIfNil(value) ((value) ? (value) : (id)kCFNull) #define RCTNilIfNull(value) \ ({ \ __typeof__(value) t = (value); \ diff --git a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.h b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.h index 3de4c5898c1..65accd53506 100644 --- a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.h +++ b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.h @@ -60,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN * When set to `YES`, the activity indicator is not automatically hidden when the Surface stage changes. * In this scenario, users should invoke `hideActivityIndicator` to remove it. * - * @param disabled: if `YES`, the auto-hide is disabled. Otherwise the loading view will be hidden automatically + * @param disabled if `YES`, the auto-hide is disabled. Otherwise the loading view will be hidden automatically */ - (void)disableActivityIndicatorAutoHide:(BOOL)disabled; @end diff --git a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.h b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.h index d6c63d03241..cdf2248420a 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/HostAgent.h @@ -77,7 +77,7 @@ class HostAgent final { /** * Send a simple Log.entryAdded notification with the given - * \param text. You must ensure that the frontend has enabled Log + * \param text . You must ensure that the frontend has enabled Log * notifications (using Log.enable) prior to calling this function. In Chrome * DevTools, the message will appear in the Console tab along with regular * console messages. The difference between Log.entryAdded and diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index 2678b19063e..812723f646e 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -118,8 +118,8 @@ convertJSIArrayToNSArray(jsi::Runtime &runtime, const jsi::Array &value, std::sh NSMutableArray *result = [NSMutableArray new]; for (size_t i = 0; i < size; i++) { // Insert kCFNull when it's `undefined` value to preserve the indices. - [result - addObject:convertJSIValueToObjCObject(runtime, value.getValueAtIndex(runtime, i), jsInvoker) ?: (id)kCFNull]; + id convertedObject = convertJSIValueToObjCObject(runtime, value.getValueAtIndex(runtime, i), jsInvoker); + [result addObject:convertedObject ? convertedObject : (id)kCFNull]; } return [result copy]; } diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTNativeSampleTurboModuleSpec.h b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTNativeSampleTurboModuleSpec.h index e37e275e1eb..cf7919a7bbe 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTNativeSampleTurboModuleSpec.h +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTNativeSampleTurboModuleSpec.h @@ -15,6 +15,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + /** * The ObjC protocol based on the JS Flow type for SampleTurboModule. */ @@ -65,3 +67,5 @@ class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public ObjCTurboModule { }; } // namespace facebook::react + +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm index 5613f858cf4..054aa5ca8d3 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleLegacyModule.mm @@ -141,8 +141,8 @@ RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getValue : (double)x y : (NS { return @{ @"x" : @(x), - @"y" : y ?: [NSNull null], - @"z" : z ?: [NSNull null], + @"y" : y ? y : [NSNull null], + @"z" : z ? z : [NSNull null], }; } diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm index 2013c70a344..c9132b0f032 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.mm @@ -132,8 +132,8 @@ RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, getValue : (double)x y : (NS { return @{ @"x" : @(x), - @"y" : y ?: [NSNull null], - @"z" : z ?: [NSNull null], + @"y" : y ? y : [NSNull null], + @"z" : z ? z : [NSNull null], }; } diff --git a/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h b/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h index 82342767c4c..074e46a0141 100644 --- a/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h +++ b/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h @@ -108,10 +108,10 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate, * Given a `progress` between 0 and 1, a mutation and LayoutAnimation config, * return a ShadowView with mutated props and/or LayoutMetrics. * - * @param progress - * @param layoutAnimation - * @param animatedMutation - * @return + * @param progress the current progress for the animation + * @param startingView the initial configuration of the ShadowView + * @param finalView the final configuration of the ShadowView + * @return the current ShadowView */ ShadowView createInterpolatedShadowView( Float progress, diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawValue.h b/packages/react-native/ReactCommon/react/renderer/core/RawValue.h index ef136889c2f..59ea6e0124b 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawValue.h +++ b/packages/react-native/ReactCommon/react/renderer/core/RawValue.h @@ -122,51 +122,51 @@ class RawValue { folly::dynamic dynamic_; static bool checkValueType( - const folly::dynamic& dynamic, - RawValue* type) noexcept { + const folly::dynamic& /*dynamic*/, + RawValue* /*type*/) noexcept { return true; } static bool checkValueType( const folly::dynamic& dynamic, - bool* type) noexcept { + bool* /*type*/) noexcept { return dynamic.isBool(); } static bool checkValueType( const folly::dynamic& dynamic, - int* type) noexcept { + int* /*type*/) noexcept { return dynamic.isNumber(); } static bool checkValueType( const folly::dynamic& dynamic, - int64_t* type) noexcept { + int64_t* /*type*/) noexcept { return dynamic.isNumber(); } static bool checkValueType( const folly::dynamic& dynamic, - float* type) noexcept { + float* /*type*/) noexcept { return dynamic.isNumber(); } static bool checkValueType( const folly::dynamic& dynamic, - double* type) noexcept { + double* /*type*/) noexcept { return dynamic.isNumber(); } static bool checkValueType( const folly::dynamic& dynamic, - std::string* type) noexcept { + std::string* /*type*/) noexcept { return dynamic.isString(); } template static bool checkValueType( const folly::dynamic& dynamic, - std::vector* type) noexcept { + std::vector* /*type*/) noexcept { if (!dynamic.isArray()) { return false; } @@ -186,7 +186,7 @@ class RawValue { template static bool checkValueType( const folly::dynamic& dynamic, - std::unordered_map* type) noexcept { + std::unordered_map* /*type*/) noexcept { if (!dynamic.isObject()) { return false; } @@ -207,40 +207,40 @@ class RawValue { // Casts static RawValue castValue( const folly::dynamic& dynamic, - RawValue* type) noexcept { + RawValue* /*type*/) noexcept { return RawValue(dynamic); } - static bool castValue(const folly::dynamic& dynamic, bool* type) { + static bool castValue(const folly::dynamic& dynamic, bool* /*type*/) { return dynamic.getBool(); } - static int castValue(const folly::dynamic& dynamic, int* type) { + static int castValue(const folly::dynamic& dynamic, int* /*type*/) { return static_cast(dynamic.asInt()); } - static int64_t castValue(const folly::dynamic& dynamic, int64_t* type) { + static int64_t castValue(const folly::dynamic& dynamic, int64_t* /*type*/) { return dynamic.asInt(); } - static float castValue(const folly::dynamic& dynamic, float* type) { + static float castValue(const folly::dynamic& dynamic, float* /*type*/) { return static_cast(dynamic.asDouble()); } - static double castValue(const folly::dynamic& dynamic, double* type) { + static double castValue(const folly::dynamic& dynamic, double* /*type*/) { return dynamic.asDouble(); } static std::string castValue( const folly::dynamic& dynamic, - std::string* type) { + std::string* /*type*/) { return dynamic.getString(); } template static std::vector castValue( const folly::dynamic& dynamic, - std::vector* type) { + std::vector* /*type*/) { react_native_assert(dynamic.isArray()); auto result = std::vector{}; result.reserve(dynamic.size()); @@ -253,7 +253,7 @@ class RawValue { template static std::vector> castValue( const folly::dynamic& dynamic, - std::vector>* type) { + std::vector>* /*type*/) { react_native_assert(dynamic.isArray()); auto result = std::vector>{}; result.reserve(dynamic.size()); @@ -266,7 +266,7 @@ class RawValue { template static std::unordered_map castValue( const folly::dynamic& dynamic, - std::unordered_map* type) { + std::unordered_map* /*type*/) { react_native_assert(dynamic.isObject()); auto result = std::unordered_map{}; for (const auto& item : dynamic.items()) { diff --git a/packages/react-native/ReactCommon/react/renderer/debug/DebugStringConvertible.h b/packages/react-native/ReactCommon/react/renderer/debug/DebugStringConvertible.h index 80bf22fbc4d..63b27aa6f3c 100644 --- a/packages/react-native/ReactCommon/react/renderer/debug/DebugStringConvertible.h +++ b/packages/react-native/ReactCommon/react/renderer/debug/DebugStringConvertible.h @@ -140,26 +140,26 @@ std::string toString(const std::optional& value) { * types. */ template -std::string getDebugName(const T& object) { +std::string getDebugName(const T& /*object*/) { return "Node"; } template -std::string getDebugValue(const T& object) { +std::string getDebugValue(const T& /*object*/) { return ""; } template std::vector getDebugChildren( - const T& object, - DebugStringConvertibleOptions options) { + const T& /*object*/, + DebugStringConvertibleOptions /*options*/) { return {}; } template std::vector getDebugProps( - const T& object, - DebugStringConvertibleOptions options) { + const T& /*object*/, + DebugStringConvertibleOptions /*options*/) { return {}; } @@ -257,68 +257,68 @@ std::string getDebugDescription( // `int` inline std::string getDebugDescription( int number, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { return toString(number); } // `float` inline std::string getDebugDescription( float number, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { return toString(number); } // `double` inline std::string getDebugDescription( double number, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { return toString(number); } // `bool` inline std::string getDebugDescription( bool boolean, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { return toString(boolean); } // `void *` inline std::string getDebugDescription( void* pointer, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { return toString(pointer); } // `std::string` inline std::string getDebugDescription( const std::string& string, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { return string; } // `std::vector` template -std::string getDebugName(const std::vector& vector) { +std::string getDebugName(const std::vector& /*vector*/) { return "List"; } template std::vector getDebugChildren( const std::vector& vector, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { return vector; } // `std::array` template -std::string getDebugName(const std::array& array) { +std::string getDebugName(const std::array& /*array*/) { return "List"; } template std::vector getDebugChildren( const std::array& array, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { auto vector = std::vector{}; for (const auto& value : array) { vector.push_back(value); @@ -328,14 +328,14 @@ std::vector getDebugChildren( // `std::unordered_set` template -std::string getDebugName(const std::unordered_set& set) { +std::string getDebugName(const std::unordered_set& /*set*/) { return "Set"; } template std::vector getDebugChildren( const std::unordered_set& set, - DebugStringConvertibleOptions options) { + DebugStringConvertibleOptions /*options*/) { auto vector = std::vector{}; vector.insert(vector.end(), set.begin(), set.end()); return vector; diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/Transform.h b/packages/react-native/ReactCommon/react/renderer/graphics/Transform.h index 71e0a938977..5dc97aad53d 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/Transform.h +++ b/packages/react-native/ReactCommon/react/renderer/graphics/Transform.h @@ -156,10 +156,10 @@ struct Transform { * performs slerp between the two rotations, and a linear interpolation * of scale and translation. * - * @param progress - * @param lhs - * @param rhs - * @return + * @param animationProgress of the animation + * @param lhs start of the interpolation + * @param rhs end of the interpolation + * @return the Transformation */ static Transform Interpolate( Float animationProgress, diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/MountingOverrideDelegate.h b/packages/react-native/ReactCommon/react/renderer/mounting/MountingOverrideDelegate.h index 6bed003963a..c6e57993dd4 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/MountingOverrideDelegate.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/MountingOverrideDelegate.h @@ -30,10 +30,11 @@ class MountingOverrideDelegate { * - Calling * - Telemetry, if appropriate * - * @param surfaceId - * @param number - * @param mountingCoordinator - * @return + * @param surfaceId the Id of the surface to be mounted + * @param number of the transaction + * @param telemetry object associated with the transaction + * @param mutations list of the mutations from the ShadowTree + * @return the mounting transaction, if it was created */ virtual std::optional pullTransaction( SurfaceId surfaceId, diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.h b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.h index 874e31f9d5a..a24d55eff83 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.h @@ -127,7 +127,6 @@ class ShadowTree final { /** * Forces the ShadowTree to ping its delegate that an update is available. * Useful for animations on Android. - * @return */ void notifyDelegatesOfUpdates() const; diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationDelegate.h b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationDelegate.h index fad55ae309b..09c2d0661b5 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationDelegate.h +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationDelegate.h @@ -31,7 +31,7 @@ class UIManagerAnimationDelegate { /** * Set ComponentDescriptor registry. * - * @param componentDescriptorRegistry + * @param componentDescriptorRegistry the registry of componentDescriptors */ virtual void setComponentDescriptorRegistry( const SharedComponentDescriptorRegistry& componentDescriptorRegistry) = 0; diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm index 32c34d04a0f..6e3c8c4b468 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm @@ -134,7 +134,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags) { if (_valid) { _reactInstance->callFunctionOnModule( - [moduleName UTF8String], [method UTF8String], convertIdToFollyDynamic(args ?: @[])); + [moduleName UTF8String], [method UTF8String], convertIdToFollyDynamic(args ? args : @[])); } }