Skip to content

Commit eba7f28

Browse files
javachemeta-codesync[bot]
authored andcommitted
Enable Kotlin warnings as errors (#58390)
Summary: Pull Request resolved: #58390 K2 warnings can otherwise accumulate unnoticed across React Native Android targets. Enable `warnings_as_errors_k22` by default for `rn_android_library` and clean up the warnings exposed by the RNTester dependency graph. Generated-source targets opt out where warnings cannot be fixed in checked-in source. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D119096917 fbshipit-source-id: 8604536639acb9dde817afef515be696259c1c51
1 parent fea820f commit eba7f28

75 files changed

Lines changed: 308 additions & 274 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/react-native-popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/PopupMenuPackage.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class PopupMenuPackage() : BaseReactPackage(), ViewManagerOnDemandReactPa
2626
return null
2727
}
2828

29-
protected override fun getViewManagers(reactContext: ReactApplicationContext): List<ModuleSpec> {
29+
override fun getViewManagers(reactContext: ReactApplicationContext): List<ModuleSpec> {
3030
return viewManagersMap.values.toList()
3131
}
3232

‎packages/react-native-popup-menu-android/android/src/main/java/com/facebook/react/popupmenu/ReactPopupMenuContainer.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ReactPopupMenuContainer(context: Context) : FrameLayout(context) {
2525
public fun showPopupMenu() {
2626
val view = getChildAt(0)
2727
val popupMenu = PopupMenu(context, view)
28-
var menu = popupMenu.menu
28+
val menu = popupMenu.menu
2929
val items = menuItems
3030
if (items != null) {
3131
for (i in 0 until items.size()) {

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void handleOnBackPressed() {
3838
}
3939
};
4040

41+
@SuppressWarnings("this-escape")
4142
protected ReactActivity() {
4243
mDelegate = createReactActivityDelegate();
4344
}

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ public interface ReactInstanceEventListener
175175
private final @Nullable JSExceptionHandler mJSExceptionHandler;
176176
private final @Nullable UIManagerProvider mUIManagerProvider;
177177
private final @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;
178+
179+
@SuppressWarnings("rawtypes")
178180
private List<ViewManager> mViewManagers;
181+
179182
private boolean mUseFallbackBundle = true;
180183
private volatile boolean mInstanceManagerInvalidated = false;
181184

@@ -777,7 +780,7 @@ public void destroy() {
777780
mCurrentActivity = null;
778781
}
779782

780-
ResourceDrawableIdHelper.getInstance().clear();
783+
ResourceDrawableIdHelper.clear();
781784

782785
mHasStartedDestroying = false;
783786
synchronized (mHasStartedDestroyingLock) {
@@ -940,6 +943,7 @@ public void detachRootView(ReactRoot reactRoot) {
940943
}
941944

942945
/** Uses configured {@link ReactPackage} instances to create all view managers. */
946+
@SuppressWarnings("rawtypes")
943947
public List<ViewManager> getOrCreateViewManagers(
944948
ReactApplicationContext catalystApplicationContext) {
945949
ReactMarker.logMarker(CREATE_VIEW_MANAGERS_START);
@@ -964,6 +968,7 @@ public List<ViewManager> getOrCreateViewManagers(
964968
}
965969
}
966970

971+
@SuppressWarnings("rawtypes")
967972
public @Nullable ViewManager createViewManager(String viewManagerName) {
968973
ReactApplicationContext context;
969974
synchronized (mReactContextLock) {

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,19 @@ public interface ReactRootViewEventListener {
117117
private int mLastOffsetY = Integer.MIN_VALUE;
118118
private final AtomicInteger mState = new AtomicInteger(STATE_STOPPED);
119119

120+
@SuppressWarnings("this-escape")
120121
public ReactRootView(Context context) {
121122
super(context);
122123
init();
123124
}
124125

126+
@SuppressWarnings("this-escape")
125127
public ReactRootView(Context context, AttributeSet attrs) {
126128
super(context, attrs);
127129
init();
128130
}
129131

132+
@SuppressWarnings("this-escape")
130133
public ReactRootView(Context context, AttributeSet attrs, int defStyle) {
131134
super(context, attrs, defStyle);
132135
init();

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/AnimatedNode.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public abstract class AnimatedNode {
3636
child.onAttachedToNode(this)
3737
}
3838

39-
internal fun removeChild(child: AnimatedNode): Unit {
39+
internal fun removeChild(child: AnimatedNode) {
4040
val currentChildren = children ?: return
4141
child.onDetachedFromNode(this)
4242
currentChildren.remove(child)

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,9 @@ public class NativeAnimatedModule(reactContext: ReactApplicationContext) :
903903
addUnbatchedOperation(
904904
object : UIThreadOperation() {
905905
override fun execute(animatedNodesManager: NativeAnimatedNodesManager) {
906-
val reactApplicationContext = reactApplicationContextIfActiveOrWarn
906+
// Retained for warning side-effect
907+
getReactApplicationContextIfActiveOrWarn()
907908

908-
var viewTag = -1
909909
var i = 0
910910
while (i < opBufferSize) {
911911
val command = BatchExecutionOpCodes.fromId(opsAndArgs.getInt(i++))
@@ -996,7 +996,7 @@ public class NativeAnimatedModule(reactContext: ReactApplicationContext) :
996996

997997
BatchExecutionOpCodes.OP_CODE_DISCONNECT_ANIMATED_NODE_FROM_VIEW -> {
998998
val animatedNodeTag = opsAndArgs.getInt(i++)
999-
viewTag = opsAndArgs.getInt(i++)
999+
val viewTag = opsAndArgs.getInt(i++)
10001000
animatedNodesManager.disconnectAnimatedNodeFromView(animatedNodeTag, viewTag)
10011001
}
10021002

@@ -1014,7 +1014,7 @@ public class NativeAnimatedModule(reactContext: ReactApplicationContext) :
10141014
)
10151015

10161016
BatchExecutionOpCodes.OP_CODE_REMOVE_ANIMATED_EVENT_FROM_VIEW -> {
1017-
viewTag = opsAndArgs.getInt(i++)
1017+
val viewTag = opsAndArgs.getInt(i++)
10181018
animatedNodesManager.removeAnimatedEventFromView(
10191019
viewTag,
10201020
checkNotNull(opsAndArgs.getString(i++)),

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ShakeDetector.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ constructor(private val shakeListener: ShakeListener, private val minNumShakes:
3434
private var lastShakeTimestamp: Long = 0
3535

3636
/** Start listening for shakes. */
37-
public fun start(manager: SensorManager): Unit {
37+
public fun start(manager: SensorManager) {
3838
val accelerometer = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) ?: return
3939
sensorManager = manager
4040
lastTimestamp = -1
@@ -44,7 +44,7 @@ constructor(private val shakeListener: ShakeListener, private val minNumShakes:
4444
}
4545

4646
/** Stop listening for shakes. */
47-
public fun stop(): Unit {
47+
public fun stop() {
4848
sensorManager?.unregisterListener(this)
4949
sensorManager = null
5050
}

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegate.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface SurfaceDelegate {
2222
*
2323
* @param appKey
2424
*/
25-
public fun createContentView(appKey: String): Unit
25+
public fun createContentView(appKey: String)
2626

2727
/**
2828
* Check if the content view is created and ready to be shown
@@ -32,13 +32,13 @@ public interface SurfaceDelegate {
3232
public fun isContentViewReady(): Boolean
3333

3434
/** Destroy the React content view to avoid memory leak */
35-
public fun destroyContentView(): Unit
35+
public fun destroyContentView()
3636

3737
/** Show the surface containing the React content view */
38-
public fun show(): Unit
38+
public fun show()
3939

4040
/** Hide the surface containing the React content view */
41-
public fun hide(): Unit
41+
public fun hide()
4242

4343
/** Check if the surface is currently showing */
4444
public fun isShowing(): Boolean

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public class ReactFontManager {
8383
*
8484
* ReactFontManager.getInstance().addCustomFont(this, "Srisakdi", R.font.srisakdi);
8585
*/
86-
public fun addCustomFont(context: Context, fontFamily: String, fontId: Int): Unit {
86+
public fun addCustomFont(context: Context, fontFamily: String, fontId: Int) {
8787
addCustomFont(fontFamily, ResourcesCompat.getFont(context, fontId))
8888
}
8989

9090
/**
9191
* Equivalent method to {@see addCustomFont(Context, String, int)} which accepts a Typeface
9292
* object.
9393
*/
94-
public fun addCustomFont(fontFamily: String, font: Typeface?): Unit {
94+
public fun addCustomFont(fontFamily: String, font: Typeface?) {
9595
if (font != null) {
9696
customTypefaceCache[fontFamily] = font
9797
}
@@ -105,7 +105,7 @@ public class ReactFontManager {
105105
* @see [Typeface.ITALIC]
106106
* @see [Typeface.BOLD_ITALIC]
107107
*/
108-
public fun setTypeface(fontFamilyName: String, style: Int, typeface: Typeface?): Unit {
108+
public fun setTypeface(fontFamilyName: String, style: Int, typeface: Typeface?) {
109109
if (typeface != null) {
110110
fontCache.getOrPut(fontFamilyName) { AssetFontFamily() }.setTypefaceForStyle(style, typeface)
111111
}

0 commit comments

Comments
 (0)