From 1053a6bf0c159c6b57a95f479de19382448f62b1 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 9 Jun 2025 20:26:05 -0700 Subject: [PATCH 1/6] sort-imports: Update Rule Definition (#51880) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51880 Updates the `sort-imports` lint rule. The main change is that it enforces newlines after the last import statement. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D76149902 --- .../src/generators/__tests__/RNCodegen-test.js | 1 + .../src/generators/components/GenerateViewConfigJs.js | 1 + packages/react-native-codegen/src/parsers/errors.js | 1 + .../flow/components/__tests__/component-parser-test.js | 1 + .../components/__tests__/typescript-component-parser-test.js | 1 + .../src/parsers/typescript/components/events.js | 1 + packages/react-native-test-library/index.js | 1 + .../Libraries/ActionSheetIOS/NativeActionSheetManager.js | 1 + packages/react-native/Libraries/Alert/NativeAlertManager.js | 1 + .../react-native/Libraries/Animated/NativeAnimatedModule.js | 1 + .../Libraries/Animated/NativeAnimatedTurboModule.js | 1 + .../react-native/Libraries/Animated/__tests__/Easing-test.js | 1 + packages/react-native/Libraries/AppState/NativeAppState.js | 1 + packages/react-native/Libraries/Blob/NativeBlobModule.js | 1 + .../react-native/Libraries/Blob/NativeFileReaderModule.js | 1 + .../react-native/Libraries/BugReporting/NativeBugReporting.js | 1 + .../RefreshControl/PullToRefreshViewNativeComponent.js | 1 + .../react-native/Libraries/Core/NativeExceptionsManager.js | 1 + .../Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js | 1 + packages/react-native/Libraries/Core/Timers/NativeTiming.js | 1 + packages/react-native/Libraries/Core/checkNativeVersion.js | 1 + .../Libraries/Debugging/DebuggingOverlayNativeComponent.js | 1 + packages/react-native/Libraries/Image/NativeImageEditor.js | 1 + .../react-native/Libraries/Image/NativeImageLoaderAndroid.js | 1 + packages/react-native/Libraries/Image/NativeImageLoaderIOS.js | 1 + .../react-native/Libraries/Image/NativeImageStoreAndroid.js | 1 + packages/react-native/Libraries/Image/NativeImageStoreIOS.js | 1 + .../Libraries/Interaction/NativeFrameRateLogger.js | 1 + .../react-native/Libraries/Linking/NativeIntentAndroid.js | 1 + .../react-native/Libraries/Linking/NativeLinkingManager.js | 1 + packages/react-native/Libraries/Modal/NativeModalManager.js | 1 + .../Libraries/Modal/RCTModalHostViewNativeComponent.js | 1 + .../Libraries/NativeModules/specs/NativeDevMenu.js | 1 + .../Libraries/NativeModules/specs/NativeDevSettings.js | 1 + .../Libraries/NativeModules/specs/NativeDeviceEventManager.js | 1 + .../NativeModules/specs/NativeDialogManagerAndroid.js | 1 + .../Libraries/NativeModules/specs/NativeLogBox.js | 1 + .../Libraries/NativeModules/specs/NativeRedBox.js | 1 + .../Libraries/NativeModules/specs/NativeSourceCode.js | 1 + .../react-native/Libraries/Network/NativeNetworkingAndroid.js | 1 + .../react-native/Libraries/Network/NativeNetworkingIOS.js | 1 + .../Libraries/PermissionsAndroid/NativePermissionsAndroid.js | 1 + .../PushNotificationIOS/NativePushNotificationManagerIOS.js | 1 + .../Libraries/ReactNative/NativeHeadlessJsTaskSupport.js | 1 + .../react-native/Libraries/ReactNative/NativeI18nManager.js | 1 + .../react-native/Libraries/ReactNative/NativeUIManager.js | 1 + .../react-native/Libraries/Settings/NativeSettingsManager.js | 1 + packages/react-native/Libraries/Share/NativeShareModule.js | 1 + packages/react-native/Libraries/StyleSheet/StyleSheet.js | 1 + .../Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js | 1 + .../Libraries/TurboModule/samples/NativeSampleTurboModule.js | 1 + .../react-native/Libraries/Types/CodegenTypesNamespace.js | 1 + packages/react-native/Libraries/Utilities/NativeAppearance.js | 1 + .../react-native/Libraries/Utilities/NativeDevLoadingView.js | 1 + packages/react-native/Libraries/Utilities/NativeDeviceInfo.js | 1 + .../Libraries/Utilities/NativePlatformConstantsAndroid.js | 1 + .../Libraries/Utilities/NativePlatformConstantsIOS.js | 1 + packages/react-native/Libraries/Vibration/NativeVibration.js | 1 + .../react-native/Libraries/WebSocket/NativeWebSocketModule.js | 1 + packages/react-native/react-native.config.js | 1 + .../generate-artifacts-executor/generateCustomURLHandlers.js | 1 + .../scripts/ios-prebuild/reactNativeDependencies.js | 1 + packages/rn-tester/IntegrationTests/IntegrationTestsApp.js | 1 + packages/rn-tester/IntegrationTests/TimersTest.js | 1 + packages/rn-tester/IntegrationTests/WebSocketTest.js | 1 + packages/rn-tester/NativeComponentExample/js/MyNativeView.js | 1 + packages/rn-tester/js/examples/Image/ImageCapInsetsExample.js | 1 + .../js/examples/ScrollView/ScrollViewAnimatedExample.js | 1 + tools/eslint/rules/sort-imports.js | 4 ++-- 69 files changed, 70 insertions(+), 2 deletions(-) diff --git a/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js b/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js index b99c038a2554..4949a94d780c 100644 --- a/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js +++ b/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js @@ -12,6 +12,7 @@ const fixture = require('../__test_fixtures__/fixtures.js'); const rnCodegen = require('../RNCodegen.js'); + const packageName = 'na'; describe('RNCodegen.generate', () => { diff --git a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js index 407216f32fbe..5a200a21da60 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js @@ -17,6 +17,7 @@ import type { import type {SchemaType} from '../../CodegenSchema'; const core = require('@babel/core'); + const t = core.types; // File path -> contents diff --git a/packages/react-native-codegen/src/parsers/errors.js b/packages/react-native-codegen/src/parsers/errors.js index 5fa37f58afba..d86cc1d9ae2c 100644 --- a/packages/react-native-codegen/src/parsers/errors.js +++ b/packages/react-native-codegen/src/parsers/errors.js @@ -12,6 +12,7 @@ import type {UnionTypeAnnotationMemberType} from '../CodegenSchema'; import type {Parser} from './parser'; + export type ParserType = 'Flow' | 'TypeScript'; class ParserError extends Error { diff --git a/packages/react-native-codegen/src/parsers/flow/components/__tests__/component-parser-test.js b/packages/react-native-codegen/src/parsers/flow/components/__tests__/component-parser-test.js index da084290cb7c..5abe85fd7656 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/__tests__/component-parser-test.js +++ b/packages/react-native-codegen/src/parsers/flow/components/__tests__/component-parser-test.js @@ -13,6 +13,7 @@ const failureFixtures = require('../__test_fixtures__/failures.js'); const fixtures = require('../__test_fixtures__/fixtures.js'); const {FlowParser} = require('../../parser'); + jest.mock('fs', () => ({ readFileSync: filename => { // Jest in the OSS does not allow to capture variables in closures. diff --git a/packages/react-native-codegen/src/parsers/typescript/components/__tests__/typescript-component-parser-test.js b/packages/react-native-codegen/src/parsers/typescript/components/__tests__/typescript-component-parser-test.js index cbc531ec6e0b..c96953a0c4fb 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/__tests__/typescript-component-parser-test.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/__tests__/typescript-component-parser-test.js @@ -13,6 +13,7 @@ const failureFixtures = require('../__test_fixtures__/failures.js'); const fixtures = require('../__test_fixtures__/fixtures.js'); const {TypeScriptParser} = require('../../parser'); + jest.mock('fs', () => ({ readFileSync: filename => { // Jest in the OSS does not allow to capture variables in closures. diff --git a/packages/react-native-codegen/src/parsers/typescript/components/events.js b/packages/react-native-codegen/src/parsers/typescript/components/events.js index af0ac9fc4ae2..1a2e038756bd 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/events.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/events.js @@ -41,6 +41,7 @@ const { } = require('../../parsers-primitives'); const {parseTopLevelType} = require('../parseTopLevelType'); const {flattenProperties} = require('./componentsUtils'); + function getPropertyType( /* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's * LTI update could not be added via codemod */ diff --git a/packages/react-native-test-library/index.js b/packages/react-native-test-library/index.js index a623cdc1ef00..7e033cab5a6d 100644 --- a/packages/react-native-test-library/index.js +++ b/packages/react-native-test-library/index.js @@ -11,5 +11,6 @@ export {default as SampleNativeComponent} from './src/SampleNativeComponent'; export type {NativeComponentType} from './src/SampleNativeComponent'; import {Commands as SampleNativeComponentCommands} from './src/SampleNativeComponent'; + export {SampleNativeComponentCommands}; export {default as NativeSampleModule} from './src/NativeSampleModule'; diff --git a/packages/react-native/Libraries/ActionSheetIOS/NativeActionSheetManager.js b/packages/react-native/Libraries/ActionSheetIOS/NativeActionSheetManager.js index 95309e4f6d67..99e87f3fcf58 100644 --- a/packages/react-native/Libraries/ActionSheetIOS/NativeActionSheetManager.js +++ b/packages/react-native/Libraries/ActionSheetIOS/NativeActionSheetManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeActionSheetManager'; import NativeActionSheetManager from '../../src/private/specs_DEPRECATED/modules/NativeActionSheetManager'; + export default NativeActionSheetManager; diff --git a/packages/react-native/Libraries/Alert/NativeAlertManager.js b/packages/react-native/Libraries/Alert/NativeAlertManager.js index 64ae1208277e..383a4f5e771b 100644 --- a/packages/react-native/Libraries/Alert/NativeAlertManager.js +++ b/packages/react-native/Libraries/Alert/NativeAlertManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeAlertManager'; import NativeAlertManager from '../../src/private/specs_DEPRECATED/modules/NativeAlertManager'; + export default NativeAlertManager; diff --git a/packages/react-native/Libraries/Animated/NativeAnimatedModule.js b/packages/react-native/Libraries/Animated/NativeAnimatedModule.js index 9b4c3233055b..d17b629e1827 100644 --- a/packages/react-native/Libraries/Animated/NativeAnimatedModule.js +++ b/packages/react-native/Libraries/Animated/NativeAnimatedModule.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeAnimatedModule'; import NativeAnimatedModule from '../../src/private/specs_DEPRECATED/modules/NativeAnimatedModule'; + export default NativeAnimatedModule; diff --git a/packages/react-native/Libraries/Animated/NativeAnimatedTurboModule.js b/packages/react-native/Libraries/Animated/NativeAnimatedTurboModule.js index 12c342d2cdf2..2e424edc555a 100644 --- a/packages/react-native/Libraries/Animated/NativeAnimatedTurboModule.js +++ b/packages/react-native/Libraries/Animated/NativeAnimatedTurboModule.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeAnimatedTurboModule'; import NativeAnimatedTurboModule from '../../src/private/specs_DEPRECATED/modules/NativeAnimatedTurboModule'; + export default NativeAnimatedTurboModule; diff --git a/packages/react-native/Libraries/Animated/__tests__/Easing-test.js b/packages/react-native/Libraries/Animated/__tests__/Easing-test.js index a247a613238c..9581ae1310b4 100644 --- a/packages/react-native/Libraries/Animated/__tests__/Easing-test.js +++ b/packages/react-native/Libraries/Animated/__tests__/Easing-test.js @@ -11,6 +11,7 @@ 'use strict'; import Easing from '../Easing'; + describe('Easing', () => { it('should work with linear', () => { const easing = Easing.linear; diff --git a/packages/react-native/Libraries/AppState/NativeAppState.js b/packages/react-native/Libraries/AppState/NativeAppState.js index 43c99eebf0d2..616b507f1801 100644 --- a/packages/react-native/Libraries/AppState/NativeAppState.js +++ b/packages/react-native/Libraries/AppState/NativeAppState.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeAppState'; import NativeAppState from '../../src/private/specs_DEPRECATED/modules/NativeAppState'; + export default NativeAppState; diff --git a/packages/react-native/Libraries/Blob/NativeBlobModule.js b/packages/react-native/Libraries/Blob/NativeBlobModule.js index 10a58cb059fd..b0b180a188c2 100644 --- a/packages/react-native/Libraries/Blob/NativeBlobModule.js +++ b/packages/react-native/Libraries/Blob/NativeBlobModule.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeBlobModule'; import NativeBlobModule from '../../src/private/specs_DEPRECATED/modules/NativeBlobModule'; + export default NativeBlobModule; diff --git a/packages/react-native/Libraries/Blob/NativeFileReaderModule.js b/packages/react-native/Libraries/Blob/NativeFileReaderModule.js index 028770e8072d..c130992ad1f4 100644 --- a/packages/react-native/Libraries/Blob/NativeFileReaderModule.js +++ b/packages/react-native/Libraries/Blob/NativeFileReaderModule.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeFileReaderModule'; import NativeFileReaderModule from '../../src/private/specs_DEPRECATED/modules/NativeFileReaderModule'; + export default NativeFileReaderModule; diff --git a/packages/react-native/Libraries/BugReporting/NativeBugReporting.js b/packages/react-native/Libraries/BugReporting/NativeBugReporting.js index 831ffc1b187a..382398d24be1 100644 --- a/packages/react-native/Libraries/BugReporting/NativeBugReporting.js +++ b/packages/react-native/Libraries/BugReporting/NativeBugReporting.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeBugReporting'; import NativeBugReporting from '../../src/private/specs_DEPRECATED/modules/NativeBugReporting'; + export default NativeBugReporting; diff --git a/packages/react-native/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js b/packages/react-native/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js index ead7bf1c4797..8dfc8b4be86b 100644 --- a/packages/react-native/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js +++ b/packages/react-native/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/components/PullToRefreshViewNativeComponent'; import PullToRefreshViewNativeComponent from '../../../src/private/specs_DEPRECATED/components/PullToRefreshViewNativeComponent'; + export default PullToRefreshViewNativeComponent; diff --git a/packages/react-native/Libraries/Core/NativeExceptionsManager.js b/packages/react-native/Libraries/Core/NativeExceptionsManager.js index 1f903c8129e3..df4340147268 100644 --- a/packages/react-native/Libraries/Core/NativeExceptionsManager.js +++ b/packages/react-native/Libraries/Core/NativeExceptionsManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeExceptionsManager'; import NativeExceptionsManager from '../../src/private/specs_DEPRECATED/modules/NativeExceptionsManager'; + export default NativeExceptionsManager; diff --git a/packages/react-native/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js b/packages/react-native/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js index cd00e93fe299..9d9739fde13a 100644 --- a/packages/react-native/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js +++ b/packages/react-native/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeSegmentFetcher'; import NativeSegmentFetcher from '../../../src/private/specs_DEPRECATED/modules/NativeSegmentFetcher'; + export default NativeSegmentFetcher; diff --git a/packages/react-native/Libraries/Core/Timers/NativeTiming.js b/packages/react-native/Libraries/Core/Timers/NativeTiming.js index 1fb2335eff1c..89dc56bd63e1 100644 --- a/packages/react-native/Libraries/Core/Timers/NativeTiming.js +++ b/packages/react-native/Libraries/Core/Timers/NativeTiming.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeTiming'; import NativeTiming from '../../../src/private/specs_DEPRECATED/modules/NativeTiming'; + export default NativeTiming; diff --git a/packages/react-native/Libraries/Core/checkNativeVersion.js b/packages/react-native/Libraries/Core/checkNativeVersion.js index 789dd15015e9..8d558bac309b 100644 --- a/packages/react-native/Libraries/Core/checkNativeVersion.js +++ b/packages/react-native/Libraries/Core/checkNativeVersion.js @@ -15,4 +15,5 @@ * You can use this module directly, or just require InitializeCore. */ const ReactNativeVersionCheck = require('./ReactNativeVersionCheck'); + ReactNativeVersionCheck.checkVersions(); diff --git a/packages/react-native/Libraries/Debugging/DebuggingOverlayNativeComponent.js b/packages/react-native/Libraries/Debugging/DebuggingOverlayNativeComponent.js index d66b9fbb9520..d2caa647bc4d 100644 --- a/packages/react-native/Libraries/Debugging/DebuggingOverlayNativeComponent.js +++ b/packages/react-native/Libraries/Debugging/DebuggingOverlayNativeComponent.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/components/DebuggingOverlayNativeComponent'; import DebuggingOverlayNativeComponent from '../../src/private/specs_DEPRECATED/components/DebuggingOverlayNativeComponent'; + export default DebuggingOverlayNativeComponent; diff --git a/packages/react-native/Libraries/Image/NativeImageEditor.js b/packages/react-native/Libraries/Image/NativeImageEditor.js index a77808d78d76..1402e6efc685 100644 --- a/packages/react-native/Libraries/Image/NativeImageEditor.js +++ b/packages/react-native/Libraries/Image/NativeImageEditor.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeImageEditor'; import NativeImageEditor from '../../src/private/specs_DEPRECATED/modules/NativeImageEditor'; + export default NativeImageEditor; diff --git a/packages/react-native/Libraries/Image/NativeImageLoaderAndroid.js b/packages/react-native/Libraries/Image/NativeImageLoaderAndroid.js index 6208715b2d16..7226b9b47633 100644 --- a/packages/react-native/Libraries/Image/NativeImageLoaderAndroid.js +++ b/packages/react-native/Libraries/Image/NativeImageLoaderAndroid.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeImageLoaderAndroid'; import NativeImageLoaderAndroid from '../../src/private/specs_DEPRECATED/modules/NativeImageLoaderAndroid'; + export default NativeImageLoaderAndroid; diff --git a/packages/react-native/Libraries/Image/NativeImageLoaderIOS.js b/packages/react-native/Libraries/Image/NativeImageLoaderIOS.js index 377bfa402576..443daf2e5f0e 100644 --- a/packages/react-native/Libraries/Image/NativeImageLoaderIOS.js +++ b/packages/react-native/Libraries/Image/NativeImageLoaderIOS.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeImageLoaderIOS'; import NativeImageLoaderIOS from '../../src/private/specs_DEPRECATED/modules/NativeImageLoaderIOS'; + export default NativeImageLoaderIOS; diff --git a/packages/react-native/Libraries/Image/NativeImageStoreAndroid.js b/packages/react-native/Libraries/Image/NativeImageStoreAndroid.js index cb0b91388f68..1d692d0f07dd 100644 --- a/packages/react-native/Libraries/Image/NativeImageStoreAndroid.js +++ b/packages/react-native/Libraries/Image/NativeImageStoreAndroid.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeImageStoreAndroid'; import NativeImageStoreAndroid from '../../src/private/specs_DEPRECATED/modules/NativeImageStoreAndroid'; + export default NativeImageStoreAndroid; diff --git a/packages/react-native/Libraries/Image/NativeImageStoreIOS.js b/packages/react-native/Libraries/Image/NativeImageStoreIOS.js index 624fa62bfef1..ef4f6967d83a 100644 --- a/packages/react-native/Libraries/Image/NativeImageStoreIOS.js +++ b/packages/react-native/Libraries/Image/NativeImageStoreIOS.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeImageStoreIOS'; import NativeImageStoreIOS from '../../src/private/specs_DEPRECATED/modules/NativeImageStoreIOS'; + export default NativeImageStoreIOS; diff --git a/packages/react-native/Libraries/Interaction/NativeFrameRateLogger.js b/packages/react-native/Libraries/Interaction/NativeFrameRateLogger.js index 0175269d92ee..25ac100a3bc4 100644 --- a/packages/react-native/Libraries/Interaction/NativeFrameRateLogger.js +++ b/packages/react-native/Libraries/Interaction/NativeFrameRateLogger.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeFrameRateLogger'; import NativeFrameRateLogger from '../../src/private/specs_DEPRECATED/modules/NativeFrameRateLogger'; + export default NativeFrameRateLogger; diff --git a/packages/react-native/Libraries/Linking/NativeIntentAndroid.js b/packages/react-native/Libraries/Linking/NativeIntentAndroid.js index 9920b4736947..b57ef0bac0b9 100644 --- a/packages/react-native/Libraries/Linking/NativeIntentAndroid.js +++ b/packages/react-native/Libraries/Linking/NativeIntentAndroid.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeIntentAndroid'; import NativeIntentAndroid from '../../src/private/specs_DEPRECATED/modules/NativeIntentAndroid'; + export default NativeIntentAndroid; diff --git a/packages/react-native/Libraries/Linking/NativeLinkingManager.js b/packages/react-native/Libraries/Linking/NativeLinkingManager.js index e888635bda5a..9d54248e0267 100644 --- a/packages/react-native/Libraries/Linking/NativeLinkingManager.js +++ b/packages/react-native/Libraries/Linking/NativeLinkingManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeLinkingManager'; import NativeLinkingManager from '../../src/private/specs_DEPRECATED/modules/NativeLinkingManager'; + export default NativeLinkingManager; diff --git a/packages/react-native/Libraries/Modal/NativeModalManager.js b/packages/react-native/Libraries/Modal/NativeModalManager.js index f0cfbeddc988..0d6b730aaaac 100644 --- a/packages/react-native/Libraries/Modal/NativeModalManager.js +++ b/packages/react-native/Libraries/Modal/NativeModalManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeModalManager'; import NativeModalManager from '../../src/private/specs_DEPRECATED/modules/NativeModalManager'; + export default NativeModalManager; diff --git a/packages/react-native/Libraries/Modal/RCTModalHostViewNativeComponent.js b/packages/react-native/Libraries/Modal/RCTModalHostViewNativeComponent.js index 4661178e007c..5adaf223364a 100644 --- a/packages/react-native/Libraries/Modal/RCTModalHostViewNativeComponent.js +++ b/packages/react-native/Libraries/Modal/RCTModalHostViewNativeComponent.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/components/RCTModalHostViewNativeComponent'; import RCTModalHostViewNativeComponent from '../../src/private/specs_DEPRECATED/components/RCTModalHostViewNativeComponent'; + export default RCTModalHostViewNativeComponent; diff --git a/packages/react-native/Libraries/NativeModules/specs/NativeDevMenu.js b/packages/react-native/Libraries/NativeModules/specs/NativeDevMenu.js index f134112e2ac2..a4f9e92bc316 100644 --- a/packages/react-native/Libraries/NativeModules/specs/NativeDevMenu.js +++ b/packages/react-native/Libraries/NativeModules/specs/NativeDevMenu.js @@ -10,4 +10,5 @@ export * from '../../../src/private/devsupport/devmenu/specs/NativeDevMenu'; import NativeDevMenu from '../../../src/private/devsupport/devmenu/specs/NativeDevMenu'; + export default NativeDevMenu; diff --git a/packages/react-native/Libraries/NativeModules/specs/NativeDevSettings.js b/packages/react-native/Libraries/NativeModules/specs/NativeDevSettings.js index 6f0f75fc012f..f589626ec279 100644 --- a/packages/react-native/Libraries/NativeModules/specs/NativeDevSettings.js +++ b/packages/react-native/Libraries/NativeModules/specs/NativeDevSettings.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeDevSettings'; import NativeDevSettings from '../../../src/private/specs_DEPRECATED/modules/NativeDevSettings'; + export default NativeDevSettings; diff --git a/packages/react-native/Libraries/NativeModules/specs/NativeDeviceEventManager.js b/packages/react-native/Libraries/NativeModules/specs/NativeDeviceEventManager.js index d81212ee798d..b1d08beaf242 100644 --- a/packages/react-native/Libraries/NativeModules/specs/NativeDeviceEventManager.js +++ b/packages/react-native/Libraries/NativeModules/specs/NativeDeviceEventManager.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeDeviceEventManager'; import NativeDeviceEventManager from '../../../src/private/specs_DEPRECATED/modules/NativeDeviceEventManager'; + export default NativeDeviceEventManager; diff --git a/packages/react-native/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js b/packages/react-native/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js index 84c318753524..415f6ba4935e 100644 --- a/packages/react-native/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js +++ b/packages/react-native/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeDialogManagerAndroid'; import NativeDialogManagerAndroid from '../../../src/private/specs_DEPRECATED/modules/NativeDialogManagerAndroid'; + export default NativeDialogManagerAndroid; diff --git a/packages/react-native/Libraries/NativeModules/specs/NativeLogBox.js b/packages/react-native/Libraries/NativeModules/specs/NativeLogBox.js index cdefa2258b07..dc050ae093c4 100644 --- a/packages/react-native/Libraries/NativeModules/specs/NativeLogBox.js +++ b/packages/react-native/Libraries/NativeModules/specs/NativeLogBox.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeLogBox'; import NativeLogBox from '../../../src/private/specs_DEPRECATED/modules/NativeLogBox'; + export default NativeLogBox; diff --git a/packages/react-native/Libraries/NativeModules/specs/NativeRedBox.js b/packages/react-native/Libraries/NativeModules/specs/NativeRedBox.js index ad75f6c54782..e94cc6ca39bd 100644 --- a/packages/react-native/Libraries/NativeModules/specs/NativeRedBox.js +++ b/packages/react-native/Libraries/NativeModules/specs/NativeRedBox.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeRedBox'; import NativeRedBox from '../../../src/private/specs_DEPRECATED/modules/NativeRedBox'; + export default NativeRedBox; diff --git a/packages/react-native/Libraries/NativeModules/specs/NativeSourceCode.js b/packages/react-native/Libraries/NativeModules/specs/NativeSourceCode.js index deab9d935995..aaea2480ab83 100644 --- a/packages/react-native/Libraries/NativeModules/specs/NativeSourceCode.js +++ b/packages/react-native/Libraries/NativeModules/specs/NativeSourceCode.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeSourceCode'; import NativeSourceCode from '../../../src/private/specs_DEPRECATED/modules/NativeSourceCode'; + export default NativeSourceCode; diff --git a/packages/react-native/Libraries/Network/NativeNetworkingAndroid.js b/packages/react-native/Libraries/Network/NativeNetworkingAndroid.js index 9343748b6664..94aa9cb0e14a 100644 --- a/packages/react-native/Libraries/Network/NativeNetworkingAndroid.js +++ b/packages/react-native/Libraries/Network/NativeNetworkingAndroid.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeNetworkingAndroid'; import NativeNetworkingAndroid from '../../src/private/specs_DEPRECATED/modules/NativeNetworkingAndroid'; + export default NativeNetworkingAndroid; diff --git a/packages/react-native/Libraries/Network/NativeNetworkingIOS.js b/packages/react-native/Libraries/Network/NativeNetworkingIOS.js index 372b3faed867..47438fac99dc 100644 --- a/packages/react-native/Libraries/Network/NativeNetworkingIOS.js +++ b/packages/react-native/Libraries/Network/NativeNetworkingIOS.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeNetworkingIOS'; import NativeNetworkingIOS from '../../src/private/specs_DEPRECATED/modules/NativeNetworkingIOS'; + export default NativeNetworkingIOS; diff --git a/packages/react-native/Libraries/PermissionsAndroid/NativePermissionsAndroid.js b/packages/react-native/Libraries/PermissionsAndroid/NativePermissionsAndroid.js index eacd8a3d127a..0cad7c529bad 100644 --- a/packages/react-native/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +++ b/packages/react-native/Libraries/PermissionsAndroid/NativePermissionsAndroid.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativePermissionsAndroid'; import NativePermissionsAndroid from '../../src/private/specs_DEPRECATED/modules/NativePermissionsAndroid'; + export default NativePermissionsAndroid; diff --git a/packages/react-native/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js b/packages/react-native/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js index 23b72b424fb9..c47a4b86db11 100644 --- a/packages/react-native/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js +++ b/packages/react-native/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativePushNotificationManagerIOS'; import NativePushNotificationManagerIOS from '../../src/private/specs_DEPRECATED/modules/NativePushNotificationManagerIOS'; + export default NativePushNotificationManagerIOS; diff --git a/packages/react-native/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js b/packages/react-native/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js index 8d9082f7342d..41dd52270d32 100644 --- a/packages/react-native/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js +++ b/packages/react-native/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeHeadlessJsTaskSupport'; import NativeHeadlessJsTaskSupport from '../../src/private/specs_DEPRECATED/modules/NativeHeadlessJsTaskSupport'; + export default NativeHeadlessJsTaskSupport; diff --git a/packages/react-native/Libraries/ReactNative/NativeI18nManager.js b/packages/react-native/Libraries/ReactNative/NativeI18nManager.js index 99126d36817c..f6d7bdbe1d9d 100644 --- a/packages/react-native/Libraries/ReactNative/NativeI18nManager.js +++ b/packages/react-native/Libraries/ReactNative/NativeI18nManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeI18nManager'; import NativeI18nManager from '../../src/private/specs_DEPRECATED/modules/NativeI18nManager'; + export default NativeI18nManager; diff --git a/packages/react-native/Libraries/ReactNative/NativeUIManager.js b/packages/react-native/Libraries/ReactNative/NativeUIManager.js index 8af1a68a87a0..f34b4cf37d69 100644 --- a/packages/react-native/Libraries/ReactNative/NativeUIManager.js +++ b/packages/react-native/Libraries/ReactNative/NativeUIManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeUIManager'; import NativeUIManager from '../../src/private/specs_DEPRECATED/modules/NativeUIManager'; + export default NativeUIManager; diff --git a/packages/react-native/Libraries/Settings/NativeSettingsManager.js b/packages/react-native/Libraries/Settings/NativeSettingsManager.js index e5bac41a5576..68984a4bf1e0 100644 --- a/packages/react-native/Libraries/Settings/NativeSettingsManager.js +++ b/packages/react-native/Libraries/Settings/NativeSettingsManager.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeSettingsManager'; import NativeSettingsManager from '../../src/private/specs_DEPRECATED/modules/NativeSettingsManager'; + export default NativeSettingsManager; diff --git a/packages/react-native/Libraries/Share/NativeShareModule.js b/packages/react-native/Libraries/Share/NativeShareModule.js index d725c5211c79..5bac7314e12e 100644 --- a/packages/react-native/Libraries/Share/NativeShareModule.js +++ b/packages/react-native/Libraries/Share/NativeShareModule.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeShareModule'; import NativeShareModule from '../../src/private/specs_DEPRECATED/modules/NativeShareModule'; + export default NativeShareModule; diff --git a/packages/react-native/Libraries/StyleSheet/StyleSheet.js b/packages/react-native/Libraries/StyleSheet/StyleSheet.js index 6bc121ade9d3..3bbfa9031f30 100644 --- a/packages/react-native/Libraries/StyleSheet/StyleSheet.js +++ b/packages/react-native/Libraries/StyleSheet/StyleSheet.js @@ -25,6 +25,7 @@ import type { ____ViewStyleProp_Internal, NativeColorValue, } from './StyleSheetTypes'; + const StyleSheet: StyleSheetExports = ( require('./StyleSheetExports') as $FlowFixMe ).default; diff --git a/packages/react-native/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js b/packages/react-native/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js index 7f41f0a069c6..9ec8c2efa3fd 100644 --- a/packages/react-native/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js +++ b/packages/react-native/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js @@ -11,6 +11,7 @@ import type {ImageStyleProp, TextStyleProp} from '../StyleSheet'; const StyleSheet = require('../StyleSheet').default; + const imageStyle = {tintColor: 'rgb(0, 0, 0)'}; const textStyle = {color: 'rgb(0, 0, 0)'}; diff --git a/packages/react-native/Libraries/TurboModule/samples/NativeSampleTurboModule.js b/packages/react-native/Libraries/TurboModule/samples/NativeSampleTurboModule.js index cb342c14969f..1a5daa1511ff 100644 --- a/packages/react-native/Libraries/TurboModule/samples/NativeSampleTurboModule.js +++ b/packages/react-native/Libraries/TurboModule/samples/NativeSampleTurboModule.js @@ -10,4 +10,5 @@ export * from '../../../src/private/specs_DEPRECATED/modules/NativeSampleTurboModule'; import NativeSampleTurboModule from '../../../src/private/specs_DEPRECATED/modules/NativeSampleTurboModule'; + export default NativeSampleTurboModule; diff --git a/packages/react-native/Libraries/Types/CodegenTypesNamespace.js b/packages/react-native/Libraries/Types/CodegenTypesNamespace.js index aae6f7ae3c23..28067da45e54 100644 --- a/packages/react-native/Libraries/Types/CodegenTypesNamespace.js +++ b/packages/react-native/Libraries/Types/CodegenTypesNamespace.js @@ -11,4 +11,5 @@ // This module exists to fit CodegenTypes into a namespace under Flow import * as CodegenTypes from './CodegenTypes'; + export type {CodegenTypes}; diff --git a/packages/react-native/Libraries/Utilities/NativeAppearance.js b/packages/react-native/Libraries/Utilities/NativeAppearance.js index a5e5c78ad09b..37a52b4d795b 100644 --- a/packages/react-native/Libraries/Utilities/NativeAppearance.js +++ b/packages/react-native/Libraries/Utilities/NativeAppearance.js @@ -10,4 +10,5 @@ export type * from '../../src/private/specs_DEPRECATED/modules/NativeAppearance'; import NativeAppearance from '../../src/private/specs_DEPRECATED/modules/NativeAppearance'; + export default NativeAppearance; diff --git a/packages/react-native/Libraries/Utilities/NativeDevLoadingView.js b/packages/react-native/Libraries/Utilities/NativeDevLoadingView.js index a7eef92fa427..678f1d14edf0 100644 --- a/packages/react-native/Libraries/Utilities/NativeDevLoadingView.js +++ b/packages/react-native/Libraries/Utilities/NativeDevLoadingView.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeDevLoadingView'; import NativeDevLoadingView from '../../src/private/specs_DEPRECATED/modules/NativeDevLoadingView'; + export default NativeDevLoadingView; diff --git a/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js b/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js index 9070cf694e47..172f4201d2ba 100644 --- a/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js +++ b/packages/react-native/Libraries/Utilities/NativeDeviceInfo.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeDeviceInfo'; import NativeDeviceInfo from '../../src/private/specs_DEPRECATED/modules/NativeDeviceInfo'; + export default NativeDeviceInfo; diff --git a/packages/react-native/Libraries/Utilities/NativePlatformConstantsAndroid.js b/packages/react-native/Libraries/Utilities/NativePlatformConstantsAndroid.js index 5c1c7c687d37..1f17e373f47f 100644 --- a/packages/react-native/Libraries/Utilities/NativePlatformConstantsAndroid.js +++ b/packages/react-native/Libraries/Utilities/NativePlatformConstantsAndroid.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativePlatformConstantsAndroid'; import NativePlatformConstantsAndroid from '../../src/private/specs_DEPRECATED/modules/NativePlatformConstantsAndroid'; + export default NativePlatformConstantsAndroid; diff --git a/packages/react-native/Libraries/Utilities/NativePlatformConstantsIOS.js b/packages/react-native/Libraries/Utilities/NativePlatformConstantsIOS.js index 3a4733139577..739c0f0d10c6 100644 --- a/packages/react-native/Libraries/Utilities/NativePlatformConstantsIOS.js +++ b/packages/react-native/Libraries/Utilities/NativePlatformConstantsIOS.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativePlatformConstantsIOS'; import NativePlatformConstantsIOS from '../../src/private/specs_DEPRECATED/modules/NativePlatformConstantsIOS'; + export default NativePlatformConstantsIOS; diff --git a/packages/react-native/Libraries/Vibration/NativeVibration.js b/packages/react-native/Libraries/Vibration/NativeVibration.js index bd7b7bbf3466..f381708723db 100644 --- a/packages/react-native/Libraries/Vibration/NativeVibration.js +++ b/packages/react-native/Libraries/Vibration/NativeVibration.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeVibration'; import NativeVibration from '../../src/private/specs_DEPRECATED/modules/NativeVibration'; + export default NativeVibration; diff --git a/packages/react-native/Libraries/WebSocket/NativeWebSocketModule.js b/packages/react-native/Libraries/WebSocket/NativeWebSocketModule.js index 48df59c75616..5f1a00f0cdf9 100644 --- a/packages/react-native/Libraries/WebSocket/NativeWebSocketModule.js +++ b/packages/react-native/Libraries/WebSocket/NativeWebSocketModule.js @@ -10,4 +10,5 @@ export * from '../../src/private/specs_DEPRECATED/modules/NativeWebSocketModule'; import NativeWebSocketModule from '../../src/private/specs_DEPRECATED/modules/NativeWebSocketModule'; + export default NativeWebSocketModule; diff --git a/packages/react-native/react-native.config.js b/packages/react-native/react-native.config.js index e28864fadef3..d505b0c5ffcf 100644 --- a/packages/react-native/react-native.config.js +++ b/packages/react-native/react-native.config.js @@ -74,6 +74,7 @@ const { bundleCommand, startCommand, } = require('@react-native/community-cli-plugin'); + commands.push(bundleCommand, startCommand); const codegenCommand /*: Command */ = { diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js index 85e1b3e7e06f..a81c00faaa18 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateCustomURLHandlers.js @@ -14,6 +14,7 @@ const {TEMPLATES_FOLDER_PATH} = require('./constants'); const {parseiOSAnnotations} = require('./utils'); const fs = require('fs'); const path = require('path'); + const MODULES_PROTOCOLS_H_TEMPLATE_PATH = path.join( TEMPLATES_FOLDER_PATH, 'RCTModulesConformingToProtocolsProviderH.template', diff --git a/packages/react-native/scripts/ios-prebuild/reactNativeDependencies.js b/packages/react-native/scripts/ios-prebuild/reactNativeDependencies.js index be0b99a5f9cf..bcc3d2d3d517 100644 --- a/packages/react-native/scripts/ios-prebuild/reactNativeDependencies.js +++ b/packages/react-native/scripts/ios-prebuild/reactNativeDependencies.js @@ -14,6 +14,7 @@ const fs = require('fs'); const path = require('path'); const stream = require('stream'); const {promisify} = require('util'); + const pipeline = promisify(stream.pipeline); const dependencyLog = createLogger('ReactNativeDependencies'); diff --git a/packages/rn-tester/IntegrationTests/IntegrationTestsApp.js b/packages/rn-tester/IntegrationTests/IntegrationTestsApp.js index f9f4fbce2bc8..7f0194e4d933 100644 --- a/packages/rn-tester/IntegrationTests/IntegrationTestsApp.js +++ b/packages/rn-tester/IntegrationTests/IntegrationTestsApp.js @@ -13,6 +13,7 @@ require('react-native/Libraries/Core/InitializeCore'); const React = require('react'); const ReactNative = require('react-native'); + const {AppRegistry, ScrollView, StyleSheet, Text, TouchableOpacity, View} = ReactNative; diff --git a/packages/rn-tester/IntegrationTests/TimersTest.js b/packages/rn-tester/IntegrationTests/TimersTest.js index 6be88a9824e5..7040a3fe6abb 100644 --- a/packages/rn-tester/IntegrationTests/TimersTest.js +++ b/packages/rn-tester/IntegrationTests/TimersTest.js @@ -12,6 +12,7 @@ const React = require('react'); const ReactNative = require('react-native'); + const {StyleSheet, Text, View} = ReactNative; const {TestModule} = ReactNative.NativeModules; diff --git a/packages/rn-tester/IntegrationTests/WebSocketTest.js b/packages/rn-tester/IntegrationTests/WebSocketTest.js index ce5c19db7bfb..1198e8b0e657 100644 --- a/packages/rn-tester/IntegrationTests/WebSocketTest.js +++ b/packages/rn-tester/IntegrationTests/WebSocketTest.js @@ -12,6 +12,7 @@ const React = require('react'); const ReactNative = require('react-native'); + const {View} = ReactNative; const {TestModule} = ReactNative.NativeModules; diff --git a/packages/rn-tester/NativeComponentExample/js/MyNativeView.js b/packages/rn-tester/NativeComponentExample/js/MyNativeView.js index 11126e00222f..2fed427bb6c7 100644 --- a/packages/rn-tester/NativeComponentExample/js/MyNativeView.js +++ b/packages/rn-tester/NativeComponentExample/js/MyNativeView.js @@ -23,6 +23,7 @@ import RNTMyNativeView, { import * as React from 'react'; import {useRef, useState} from 'react'; import {Button, Platform, Text, UIManager, View} from 'react-native'; + const colors = [ '#0000FF', '#FF0000', diff --git a/packages/rn-tester/js/examples/Image/ImageCapInsetsExample.js b/packages/rn-tester/js/examples/Image/ImageCapInsetsExample.js index 0df78c3b3f32..a2e84272a602 100644 --- a/packages/rn-tester/js/examples/Image/ImageCapInsetsExample.js +++ b/packages/rn-tester/js/examples/Image/ImageCapInsetsExample.js @@ -14,6 +14,7 @@ const React = require('react'); const ReactNative = require('react-native'); const nativeImageSource = require('react-native/Libraries/Image/nativeImageSource').default; + const {Image, StyleSheet, Text, View} = ReactNative; type Props = $ReadOnly<{}>; diff --git a/packages/rn-tester/js/examples/ScrollView/ScrollViewAnimatedExample.js b/packages/rn-tester/js/examples/ScrollView/ScrollViewAnimatedExample.js index 80336b67b427..35f15cf801b7 100644 --- a/packages/rn-tester/js/examples/ScrollView/ScrollViewAnimatedExample.js +++ b/packages/rn-tester/js/examples/ScrollView/ScrollViewAnimatedExample.js @@ -14,6 +14,7 @@ import type AnimatedValue from 'react-native/Libraries/Animated/nodes/AnimatedVa const React = require('react'); const ReactNative = require('react-native'); + const {Component} = React; const {StyleSheet, Text, View, Animated, Easing, TouchableOpacity, Dimensions} = ReactNative; diff --git a/tools/eslint/rules/sort-imports.js b/tools/eslint/rules/sort-imports.js index 6f52515b75af..a061c4e1dea9 100644 --- a/tools/eslint/rules/sort-imports.js +++ b/tools/eslint/rules/sort-imports.js @@ -6,7 +6,7 @@ * * To regenerate this file, please run this command on Meta's monorepo: * @codegen-command : xplat/js/tools/sort-imports/scripts/build.sh - * @generated SignedSource<<165e00cb24cdaa9e47306c8384d4355f>> + * @generated SignedSource<<374df066e2e1e673cc452314636d8dd8>> * @nolint */ -"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function t(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}const n=e(require("path")).default,r=__dirname.split(n.sep).includes("xplat");function i(e){if(("Literal"===e.type||"JSXText"===e.type)&&"string"==typeof e.value)return e.value;if("BinaryExpression"===e.type&&"+"===e.operator){const t=i(e.left),n=i(e.right);if(null!=t&&null!=n)return t+n}return null}function o(e){if("Identifier"===e.type)return e.name;if("ThisExpression"===e.type)return"this";if("MemberExpression"===e.type){const t=o(e.object),n=e.computed?i(e.property):o(e.property);if(null!=t&&null!=n)return t+"."+n}else if("TypeCastExpression"===e.type||"AsExpression"===e.type)return o(e.expression);return null}function a(e){return e.callee?o(e.callee):null}function l(e,t,n){const r=e.getSourceCode().getText(),i=function(e,t){if(t.line<1)throw new RangeError("Line number "+t.line+" is before the start of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r={index:0};for(let i=1;i=e.length)throw new RangeError("computed offset "+t+" is past the end of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r,i={index:0},o=0;do{r=i,i=n.exec(e),++o}while(i&&i.index"string"==typeof e&&e.charCodeAt(0)>=97,c=e=>"string"==typeof e&&e.charCodeAt(0)<=90;function p(e){return null!=e&&"VariableDeclaration"===e.type&&"Program"===e.parent.type&&1===e.declarations.length&&null!=e.declarations[0].init&&m(e.declarations[0].init)}function f(e){return null!=e&&"VariableDeclarator"===e.type&&"VariableDeclaration"===e.parent.type&&"Program"===e.parent.parent.type&&1===e.parent.declarations.length&&m(e.init)}function m(e){return null!=e&&(g(e)||y(e)||h(e))}function d(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"requireNUX"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function g(e){return"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"require"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function y(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferred"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function h(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferredForDisplay"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function x(e){return"ImportDeclaration"===e.type&&(null==e.importKind||"value"===e.importKind)}function b(e){return"ImportDeclaration"===e.type&&("type"===e.importKind||"typeof"===e.importKind)}function C(e){return x(e)||b(e)}function v(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function S(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResourceForInteraction"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function E(e){return null!=e&&"CallExpression"===e.type&&"Identifier"===e.callee.type&&"ClientJSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function I(e){if(null==e||"CallExpression"!==e.type||null==e.callee)return!1;let t;return"Identifier"===e.callee.type&&(t=e.callee),"MemberExpression"===e.callee.type&&"Identifier"===e.callee.object.type&&(t=e.callee.object),null!=t&&"requireCond"===t.name&&e.arguments.length>0}function T(e){return 0===e.indexOf("m#")?e.substring(2):e}function D(e,t,n=1){return"CallExpression"!==e.type||e.arguments.length!==n||null!=t&&"string"==typeof t&&a(e)!==t||"Literal"!==e.arguments[0].type||"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value)}function R(e,t,n){const r=e.arguments;return I(e)?3!==r.length?null:(null==t||r[0]&&"Literal"===r[0].type&&r[0].value===t)&&(null==n||r[1]&&"Literal"===r[1].type&&r[1].value===n)?r[2]&&"ObjectExpression"===r[2].type?r[2].properties.reduce(((e,t)=>{if("Property"===t.type&&"Literal"===t.value.type){let n;if("Identifier"===t.key.type)n=t.key.name;else{if("Literal"!==t.key.type)return e;n=String(t.key.value)}e[n]="string"==typeof t.value.value?T(t.value.value):null}return e}),{}):r[2]&&"Literal"===r[2].type&&"string"==typeof r[2].value?T(r[2].value):null:null:null}function w(e){return D(e,"JSResource")}function N(e){return D(e,"JSResourceForInteraction",2)}function k(e){return null==e?null:m(e)?"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value):null}function q(e){return d(e)?2!==e.arguments.length||"string"!=typeof e.arguments[1].value?null:T(e.arguments[1].value):null}function L(e,t){const n=e.getSourceCode().ast.body.find((e=>"VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&null!=e.declarations[0].init&&k(e.declarations[0].init)===t));return n||null}function O(e){let t=e;for(;"TypeCastExpression"===t.type||"AsExpression"===t.type;)t=t.expression;return t}function P(e){if("value"!==e.importKind)return!0;return e.specifiers.every((e=>"ImportSpecifier"===e.type&&("type"===e.importKind||"typeof"===e.importKind)))}function j(e,t){const n=e.getSourceCode().ast.body.find((e=>"ImportDeclaration"===e.type&&e.source.value===t&&!P(e)));return n||null}var B={asAnyKindOfRequireCall:function(e){return m(e)?e:null},asAnyKindOfRequireVariableDeclaration:function(e){return p(e)?e:null},asAnyKindOfRequireVariableDeclarator:function(e){return f(e)?e:null},getAnyRequiredModuleName:function(e,t=Object.freeze({})){const n=k(e)||w(e)||N(e)||q(e);return null!=n?n:R(e,t.condType,t.condition)},getBaseNode:function(e){let t=e;for(;"MemberExpression"===t.type;)t=t.object;return t},getBinding:s,getBootloadedModuleNames:function(e){return"ExpressionStatement"===e.type&&e.expression&&"CallExpression"===e.expression.type&&e.expression.callee&&"MemberExpression"===e.expression.callee.type&&e.expression.callee.object&&"Bootloader"===e.expression.callee.object.name&&e.expression.callee.property&&"loadModules"===e.expression.callee.property.name&&e.expression.arguments.length>0&&"ArrayExpression"===e.expression.arguments[0].type&&e.expression.arguments[0].elements.length>0?e.expression.arguments[0].elements.map((e=>"Literal"===e.type&&"string"==typeof e.value?T(e.value):null)).filter(Boolean):null},getCalleeName:a,getConstantStringExpression:i,getCurrentClassName:function(e){const t=e.getAncestors().find((e=>"ClassDeclaration"===e.type));return t&&"ClassDeclaration"===t.type&&null!=t.id?t.id.name:null},getEnglishForNth:function(e){return["first","second","third","fourth","fifth","sixth"][e]},getFullyQualifiedIdentifier:o,getJSResourceModuleName:w,getJSXMemberOrNamespaceRoot:function(e){let t=e;for(;"JSXIdentifier"!==t.type;)if("JSXMemberExpression"===t.type)t=t.object;else{if("JSXNamespacedName"!==t.type)throw new Error("unexpected "+t.type);t=t.namespace}return t},getLocOffset:function(e,t,n){return l(e,t.loc.start,n)},getLocOffsetOfLoc:l,getName:function(e){const t=O(e);return"Identifier"===t.type?t.name:"Literal"===t.type?String(t.value):null},getObjectPropertyName:function(e){if("Property"!==e.type&&"PropertyDefinition"!==e.type&&"MethodDefinition"!==e.type)return null;const t=e.key;return"Identifier"!==t.type||e.computed?function(e){switch(e.type){case"Literal":switch(e.literalType){case"bigint":return e.bigint;case"null":return"null";case"regexp":return`/${e.regex.pattern}/${e.regex.flags}`;default:return String(e.value)}case"TemplateLiteral":if(0===e.expressions.length&&1===e.quasis.length)return e.quasis[0].value.cooked}return null}(t):t.name},getParamComments:function(e,t){return t.params.map((function(t){const n=e.getSourceCode().getCommentsBefore(t);return n[n.length-1]}))},getPropertyName:function(e){return"MemberExpression"!==e.type?null:e.computed?i(e.property):"Identifier"!==e.property.type?null:e.property.name},getPropTokens:function(e,t){const n=e.getSourceCode().getTokens(t),r=[];return n.forEach(((e,t,n)=>{"JSXIdentifier"===e.type&&"Punctuator"===n[t+1].type&&"="===n[t+1].value&&r.push(e)})),r},getRequireCondModules:R,getRequireModuleName:k,getRequireModuleNode:L,getReturnComment:function(e,t){return e.getSourceCode().getCommentsBefore(t.body)[0]},getValueImportNode:j,getValueImportVariables:function(e,t){const n=[];for(const r of e.getSourceCode().ast.body)"ImportDeclaration"!==r.type||r.source.value!==t||P(r)||r.specifiers.filter((e=>{null!=e.importKind&&"value"!==e.importKind||n.push(e.local.name)}));return n},hasValueImport:function(e){return e.getSourceCode().ast.body.some((e=>"ImportDeclaration"===e.type&&!P(e)))},getVariable:function(e,t){let n=t;for(;n;){const t=n.set.get(e);if(t)return t;n=n.upper}return null},insertRequireStatement:function(e,t,n,r=""){if(""===n)throw new Error("Name must be a string with length larger than 0");const i=`const ${n} = require('${n}${r}');`,o=[];e.getSourceCode().ast.body.forEach((e=>{if("VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&e.declarations[0].init){const t=k(e.declarations[0].init);null!=t&&o.push({name:t,node:e})}}));const a=o.find((e=>e.name>=n));if(a){if(a.name.replace(r,"")===n)return[];const e=o[0];if(u(a.name)&&c(n)){if(e!==a){const e=a.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(a.node,i+"\n\n")]}return[t.insertTextBefore(a.node,i+"\n\n")]}return[t.insertTextBefore(a.node,i+"\n")]}if(o.length>0){const e=o[o.length-1],r=c(e.name)&&u(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+i+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],i+"\n")]:[t.insertTextBefore(n[0],i+"\n")]}},insertValueImportStatement:function(e,t,n,r="",i){if(""===n)throw new Error("Name must be a string with length larger than 0");const o=`import ${i??n} from '${n}${r}';`,a=[];e.getSourceCode().ast.body.forEach((e=>{if(x(e)){const t=function(e){if(m(e))return"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value);if(C(e))return e.source.value;return null}(e);null!=t&&a.push({name:t,node:e})}}));const l=a.find((e=>e.name>=n));if(l){if(l.name.replace(r,"")===n)return[];const e=a[0];if(u(l.name)&&c(n)){if(e!==l){const e=l.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(l.node,o+"\n\n")]}return[t.insertTextBefore(l.node,o+"\n\n")]}return[t.insertTextBefore(l.node,o+"\n")]}if(a.length>0){const e=a[a.length-1],r=c(e.name)&&u(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+o+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],o+"\n")]:[t.insertTextBefore(n[0],o+"\n")]}},isAnyKindOfImport:C,isAnyKindOfModuleCall:function(e){return m(e)||I(e)||v(e)||S(e)||E(e)||d(e)},isAnyKindOfRequireCall:m,isAnyKindOfRequireVariableDeclaration:p,isAnyKindOfRequireVariableDeclarator:f,isClientJSResource:E,isFbSourceRepo:r,isGraphQLTemplate:function(e){return"Identifier"===e.tag.type&&"graphql"===e.tag.name&&1===e.quasi.quasis.length},isInsideMethod:function(e,t){return e.getAncestors().some((e=>"MethodDefinition"===e.type&&"Identifier"===e.key.type&&e.key.name===t))},isJSResource:v,isJSResourceForInteraction:S,isModuleRef:function(e){return"Literal"===e.type&&"string"==typeof e.value&&e.value.startsWith("m#")},isOnlyTypeImport:P,isOnlyTypeExport:function(e){return"type"===e.exportKind},isReferenced:function(e){const t=e.parent;switch(t.type){case"MemberExpression":case"JSXMemberExpression":return t.property===e&&!0===t.computed||t.object===e;case"MetaProperty":case"ImportDefaultSpecifier":case"ImportNamespaceSpecifier":case"ImportSpecifier":case"LabeledStatement":case"RestElement":case"ObjectPattern":case"ArrayPattern":return!1;case"Property":case"MethodDefinition":return t.key===e&&t.computed;case"VariableDeclarator":case"ClassDeclaration":case"ClassExpression":return t.id!==e;case"ArrowFunctionExpression":case"FunctionDeclaration":case"HookDeclaration":case"FunctionExpression":for(let n=0;ne.writeExpr));return null!=i?i.writeExpr:null},resolveModuleSource:function(e,t){const n=s(e.getScope(),t);if(null==n)return null;const r=n.defs[0];switch(r.node.type){case"VariableDeclarator":{const e=r.node.init;if(null!=e)return k(e)||w(e)||N(e)||q(e);break}case"ImportNamespaceSpecifier":case"ImportSpecifier":case"ImportDefaultSpecifier":return r.node.parent.source.value}return null},stripModuleRef:T,uncast:O};var F=t(Object.freeze({__proto__:null,isCommaOrSemiToken:function(e){return"Punctuator"===e.type&&(","===e.value||";"===e.value)}}));const{isCommaOrSemiToken:M}=F;var A={getInlineComments:function(e,t,n=M){const r=e.ast.comments.filter((e=>e.loc.start.line===t.loc.end.line&&e.range[0]>t.range[1])).sort(((e,t)=>e.range[0]-t.range[0])),i=[];let o=t;for(const t of r){const r=e.getTokensBetween(o,t);if(r.length>0){if(!n)break;if(!r.every(n))break}i.push(t),o=t}return i},getLeadingComments:function(e,t,n){const r=e.getCommentsBefore(t),i=[];let o=t;for(let t=r.length-1;t>=0;t-=1){const a=r[t];if(a===n)break;if(a.loc.end.line===o.loc.start.line){i.unshift(a),o=a;continue}if(a.loc.end.line!==o.loc.start.line-1)break;const l=e.getTokenBefore(a);if(l&&l.loc.end.line===a.loc.start.line)break;i.unshift(a),o=a}return i}};var V=function(e){return e.getSourceCode().ast.docblock?.comment};const{getInlineComments:$,getLeadingComments:K}=A,{isCommaOrSemiToken:_}=F;function J(e){return"@"===e[0]||":"===e[0]}const X=/\d{1,3}(\.\d+)?%/;function U(e){switch(typeof e){case"number":return{isSafeNumericString:!0,isPercentage:!1};case"boolean":return{isSafeNumericString:!1,isPercentage:!1}}return isNaN(e)||isNaN(parseFloat(e))?X.test(e)?{isSafeNumericString:!0,isPercentage:!0}:{isSafeNumericString:!1,isPercentage:!1}:{isSafeNumericString:!0,isPercentage:!1}}function z(e){return e.reduce((([e,t],[n,r])=>[Math.min(e,n),Math.max(t,r)]),[Number.MAX_SAFE_INTEGER,0])}var G={compareNames:function(e,t,n=!1){if("number"==typeof e&&"number"==typeof t)return e-t;const r=String(e),i=String(t);if(""===r&&""!==i)return-1;if(""!==r&&""===i)return 1;if(""===r&&""===i)return 0;const{isSafeNumericString:o,isPercentage:a}=U(r),{isSafeNumericString:l,isPercentage:s}=U(i);if(o&&l){const e=Number.parseFloat(r),t=Number.parseFloat(i);if(e===t){if(!a&&s)return-1;if(a&&!s)return 1}return e-t}if(n){const e=J(r),t=J(i);if(!e&&t)return-1;if(e&&!t)return 1}const u=o||r[0].toLowerCase()===r[0].toUpperCase(),c=l||i[0].toLowerCase()===i[0].toUpperCase();if(!u&&c)return 1;if(u&&!c)return-1;if(!u&&!c){const e=r[0].toLowerCase()===r[0],t=i[0].toLowerCase()===i[0];if(!e&&t)return-1;if(e&&!t)return 1}return r.localeCompare(i,"en",{caseFirst:"upper",sensitivity:"base"})},getEncompassingRange:z,getNodeTextWithComments:function(e,t,n,{shouldIncludeNextTokenInRange:r=_,ensureTextFollowsNode:i,inlineCommentIgnoreToken:o}={}){const a=$(e,t,o),l=[...K(e,t,n).map((({range:e})=>e)),t.range,...a.map((({range:e})=>e))],s=e.getTokenAfter(t);s&&!0===r?.(s)&&l.push(s.range);const u=z(l);let c=e.text.slice(u[0],u[1]);const p=t.range[1]-u[0];if(null!=i){e.getTokenAfter(t)?.value!==i&&(c=c.slice(0,p)+i+c.slice(p))}return{range:u,text:c}},isComma:function(e){return"Punctuator"===e.type&&","===e.value}};const Q=B,{getInlineComments:W,getLeadingComments:H}=A,Y=V,{compareNames:Z}=G,ee=0,te={default:1,namespace:2,named:3},ne={default:4,namespace:5,named:6},re={default:7,namespace:8,named:9},ie=0,oe=1,ae=2,le=3,se=99;var ue={meta:{fixable:"code",messages:{incorrectOrder:"Requires should be sorted alphabetically"}},create(e){const t=e.getSourceCode(),n=function(e){const t=Y(e);if(null!=t)return t;const n=e.getSourceCode().ast,r=n.body.length>0?n.body[0]:n,i=e.getSourceCode().getCommentsBefore(r)[0];return i&&"Block"===i.type?i:null}(e);if(n&&(n.value.includes("* @generated")||n.value.includes("* @partially-generated"))&&!n.value.includes("* @xpr_allow_generated_lint"))return{};const r=Object.freeze({typeImport:{priority:10,uppercase:[],lowercase:[],tiebreakFunction:s},valueImport:{priority:20,uppercase:[],lowercase:[],tiebreakFunction:s},requiresUsedByOtherRequires:{priority:30,uppercase:[],lowercase:[],tiebreakFunction:u},require:{priority:40,uppercase:[],lowercase:[],tiebreakFunction:u}}),i=[];let o=null,a=null;const l=new Set;return{Program(n){for(const e of n.body)switch(e.type){case"ImportDeclaration":if("type"===e.importKind||"typeof"===e.importKind)d(r.typeImport,e,e.source.value,!0);else{const n=t.getLastToken(e.source,(e=>"from"===e.value));0===e.specifiers.length&&null==n?g(e):d(r.valueImport,e,e.source.value)}break;case"VariableDeclaration":{const t=e.declarations[0]?.init;if(1!==e.declarations.length||null==t){g(e);break}f(t,e);break}default:g(e)}const s=[];for(const e of Object.keys(r)){const t=r[e];s.push({priority:t.priority,nodes:t.uppercase.sort(((e,n)=>c(e,n,t.tiebreakFunction)))}),s.push({priority:t.priority+5,nodes:t.lowercase.sort(((e,n)=>c(e,n,t.tiebreakFunction)))})}function u(e){return[e.leadingComments.length?e.leadingComments.map((e=>t.getText(e))).join("\n")+"\n":"",e.inlineComments.length?" "+e.inlineComments.map((e=>t.getText(e))).join(" "):""]}const p=s.filter((e=>0!==e.nodes.length)).sort(((e,t)=>e.priority-t.priority)).map((e=>e.nodes.map((e=>{const[n,r]=u(e),i=function(e,t){const n=t.node,r=e.getText(n),i=(()=>{if("ImportDeclaration"===n.type&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const t=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"{"===e.value)),r=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"}"===e.value));return null==t||null==r?null:e.getText().substring(t.range[0],r.range[1])}if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const t=n.declarations[0].id.typeAnnotation,r=e.getText(n.declarations[0].id);return t?r.substr(0,t.range[0]-n.declarations[0].id.range[0]):r}return null})();if(null==i)return r;let o=[],a=null;"ImportDeclaration"===n.type?o=n.specifiers.map((t=>"ImportDefaultSpecifier"===t.type||"ImportNamespaceSpecifier"===t.type?null:{leadingComments:e.getCommentsBefore(t),name:t.imported.name,node:t})).filter(Boolean):"VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type&&(o=n.declarations[0].id.properties.map((t=>{if("ExperimentalRestProperty"===t.type||"RestElement"===t.type)return a=t,null;const n=t.key,r="Literal"===n.type?String(n.value):"Identifier"===n.type?t.computed?null:n.name:null;return null==r?null:{leadingComments:e.getCommentsBefore(t),name:r,node:t}})).filter(Boolean));if(o.length<=1)return r;const l=i.indexOf("\n")>=0,s=o.sort(((e,t)=>Z(e.name,t.name))).map((e=>e.node));null!=a&&s.push(a);const u=s.map((t=>{const n=e.getCommentsBefore(t).map((t=>e.getText(t))),r=n.length?n.join(""):"";return l?(r?" "+r+"\n":"")+" "+e.getText(t):(r?r+" ":"")+e.getText(t)})),c=(()=>{const t=[];if("ImportDeclaration"===n.type){if(t.push(...e.getCommentsBefore(n.source)),l&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const r=e.getTokenBefore(n.source,(e=>"Punctuator"===e.type&&"}"===e.value));null!=r&&t.push(...e.getCommentsBefore(r))}}else if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const r=e.getLastToken(n.declarations[0].id);null!=r&&t.push(...e.getCommentsBefore(r))}return t})(),p=l&&c.length?c.map((t=>" "+e.getText(t))).join("\n")+"\n":"",f=l?"\n"+u.map((e=>e.includes("...")?`${e}\n`:`${e},\n`)).join("")+p:u.join(", ");return r.replace(i,(()=>`{${f}}`))}(t,e);return n+i+r})).join("\n"))).join("\n\n"),m=o;if(null==m||null==a)return;const y=m.leadingComments.length?m.leadingComments[0].range[0]:m.node.range[0],h=a.inlineComments.length>0?a.inlineComments[a.inlineComments.length-1].range[1]:a.node.range[1];t.getText(m.node,m.node.range[0]-y,h-m.node.range[1])!==p&&e.report({node:m.node,messageId:"incorrectOrder",fix(e){const n=i.filter((({node:e})=>e.range[0]>=y&&e.range[1]<=h)).map((e=>{const[n,r]=u(e),i=t.getText(e.node);return{range:e.node.range,text:n+i+r}})).flat().concat(t.getAllComments().filter((e=>e.range[0]>=y&&e.range[1]<=h&&!l.has(e))).map((e=>({range:e.range,text:t.getText(e)})))).sort(((e,t)=>e.range[0]-t.range[0]||e.range[1]-t.range[1])).map((({text:e})=>e)).join("\n");return e.replaceTextRange([y,h],[p,n].filter(Boolean).join("\n\n"))}})}};function s(e){if(0===e.specifiers.length)return ee;const t=(()=>{switch(e.importKind){default:case"value":return te;case"type":return ne;case"typeof":return re}})();return e.specifiers.find((e=>"ImportDefaultSpecifier"===e.type))?t.default:e.specifiers.find((e=>"ImportNamespaceSpecifier"===e.type))?t.namespace:t.named}function u(e){if("ExpressionStatement"===e.type)return ie;switch(e.declarations[0].id.type){case"Identifier":return oe;case"ObjectPattern":return ae;case"ArrayPattern":return le}return se}function c(e,t,n){const r=Z(e.moduleName,t.moduleName);if(0!==r)return r;const i=n(e.node)-n(t.node);return 0!==i?i:e.node.loc.start.line-t.node.loc.start.line}function p(e,t){if(null==e)throw new Error("Missing required module name");return null!=t?`${e}_${t}`:e}function f(e,n,i){const o=Q.getRequireModuleName(e);if(Q.isRequire(e)){const e=p(o,i);d("requireCond"===e||"requireDeferred"===e||"requireDeferredForDisplay"===e?r.requiresUsedByOtherRequires:r.require,n,p(o,i))}else if(Q.isRequireDeferred(e)||Q.isRequireDeferredForDisplay(e))d(r.require,n,p(o,i));else{if(Q.isRequireCond(e)){if("VariableDeclaration"===n.type){const e=t.getText(n.declarations[0].id);return void d(r.require,n,p(e,i))}}else{if("MemberExpression"===e.type)return void f(e.object,n,p(t.getText(e.property),i));if("CallExpression"===e.type)return void f(e.callee,n,i)}g(n)}}function m(e){e.leadingComments.forEach((e=>l.add(e))),e.inlineComments.forEach((e=>l.add(e)));t.getCommentsInside(e.node).forEach((e=>l.add(e)))}function d(e,r,i,l=!1){const s={inlineComments:W(t,r),leadingComments:H(t,r,n),moduleName:i,node:r};if(l)e.uppercase.push(s);else{const t=i[0]||"";t.toLowerCase()===t?e.lowercase.push(s):e.uppercase.push(s)}null==o&&(o=s),a=s,m(s)}function g(e){const r={inlineComments:W(t,e),leadingComments:H(t,e,n),node:e};i.push(r),m(r)}}};var ce=ue;module.exports=ce; +"use strict";var e,t,n=require("path");function r(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}function o(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function a(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function l(){if(t)return e;t=1;const r=n,o=__dirname.split(r.sep).includes("xplat");function i(e){if(("Literal"===e.type||"JSXText"===e.type)&&"string"==typeof e.value)return e.value;if("BinaryExpression"===e.type&&"+"===e.operator){const t=i(e.left),n=i(e.right);if(null!=t&&null!=n)return t+n}return null}function a(e){if("Identifier"===e.type)return e.name;if("ThisExpression"===e.type)return"this";if("MemberExpression"===e.type){const t=a(e.object),n=e.computed?i(e.property):a(e.property);if(null!=t&&null!=n)return t+"."+n}else if("TypeCastExpression"===e.type||"AsExpression"===e.type)return a(e.expression);return null}function l(e){return e.callee?a(e.callee):null}function s(e,t,n){const r=e.getSourceCode().getText(),o=function(e,t){if(t.line<1)throw new RangeError("Line number "+t.line+" is before the start of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r={index:0};for(let o=1;o=e.length)throw new RangeError("computed offset "+t+" is past the end of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r,o={index:0},i=0;do{r=o,o=n.exec(e),++i}while(o&&o.index"string"==typeof e&&e.charCodeAt(0)>=97,p=e=>"string"==typeof e&&e.charCodeAt(0)<=90;function f(e){return null!=e&&"VariableDeclaration"===e.type&&"Program"===e.parent.type&&1===e.declarations.length&&null!=e.declarations[0].init&&d(e.declarations[0].init)}function m(e){return null!=e&&"VariableDeclarator"===e.type&&"VariableDeclaration"===e.parent.type&&"Program"===e.parent.parent.type&&1===e.parent.declarations.length&&d(e.init)}function d(e){return null!=e&&(y(e)||h(e)||x(e))}function g(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"requireNUX"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function y(e){return"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"require"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function h(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferred"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function x(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferredForDisplay"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function b(e){return"ImportDeclaration"===e.type&&(null==e.importKind||"value"===e.importKind)}function C(e){return"ImportDeclaration"===e.type&&("type"===e.importKind||"typeof"===e.importKind)}function S(e){return b(e)||C(e)}function v(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function E(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResourceForInteraction"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function I(e){return null!=e&&"CallExpression"===e.type&&"Identifier"===e.callee.type&&"ClientJSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function D(e){if(null==e||"CallExpression"!==e.type||null==e.callee)return!1;let t;return"Identifier"===e.callee.type&&(t=e.callee),"MemberExpression"===e.callee.type&&"Identifier"===e.callee.object.type&&(t=e.callee.object),null!=t&&"requireCond"===t.name&&e.arguments.length>0}function T(e){return 0===e.indexOf("m#")?e.substring(2):e}function R(e,t,n=1){return"CallExpression"!==e.type||e.arguments.length!==n||null!=t&&"string"==typeof t&&l(e)!==t||"Literal"!==e.arguments[0].type||"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value)}function w(e,t,n){const r=e.arguments;return D(e)?3!==r.length?null:(null==t||r[0]&&"Literal"===r[0].type&&r[0].value===t)&&(null==n||r[1]&&"Literal"===r[1].type&&r[1].value===n)?r[2]&&"ObjectExpression"===r[2].type?r[2].properties.reduce(((e,t)=>{if("Property"===t.type&&"Literal"===t.value.type){let n;if("Identifier"===t.key.type)n=t.key.name;else{if("Literal"!==t.key.type)return e;n=String(t.key.value)}e[n]="string"==typeof t.value.value?T(t.value.value):null}return e}),{}):r[2]&&"Literal"===r[2].type&&"string"==typeof r[2].value?T(r[2].value):null:null:null}function O(e){return R(e,"JSResource")}function N(e){return R(e,"JSResourceForInteraction",2)}function k(e){return null==e?null:d(e)?"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value):null}function q(e){return g(e)?2!==e.arguments.length||"string"!=typeof e.arguments[1].value?null:T(e.arguments[1].value):null}function j(e,t){const n=e.getSourceCode().ast.body.find((e=>"VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&null!=e.declarations[0].init&&k(e.declarations[0].init)===t));return n||null}function P(e){let t=e;for(;"TypeCastExpression"===t.type||"AsExpression"===t.type;)t=t.expression;return t}function L(e){if(0===e.specifiers.length)return!1;if("value"!==e.importKind)return!0;return e.specifiers.every((e=>"ImportSpecifier"===e.type&&("type"===e.importKind||"typeof"===e.importKind)))}function F(e,t){const n=e.getSourceCode().ast.body.find((e=>"ImportDeclaration"===e.type&&e.source.value===t&&!L(e)));return n||null}return e={asAnyKindOfRequireCall:function(e){return d(e)?e:null},asAnyKindOfRequireVariableDeclaration:function(e){return f(e)?e:null},asAnyKindOfRequireVariableDeclarator:function(e){return m(e)?e:null},getAnyRequiredModuleName:function(e,t=Object.freeze({})){const n=k(e)||O(e)||N(e)||q(e);return null!=n?n:w(e,t.condType,t.condition)},getBaseNode:function(e){let t=e;for(;"MemberExpression"===t.type;)t=t.object;return t},getBinding:u,getBootloadedModuleNames:function(e){return"ExpressionStatement"===e.type&&e.expression&&"CallExpression"===e.expression.type&&e.expression.callee&&"MemberExpression"===e.expression.callee.type&&e.expression.callee.object&&"Bootloader"===e.expression.callee.object.name&&e.expression.callee.property&&"loadModules"===e.expression.callee.property.name&&e.expression.arguments.length>0&&"ArrayExpression"===e.expression.arguments[0].type&&e.expression.arguments[0].elements.length>0?e.expression.arguments[0].elements.map((e=>"Literal"===e.type&&"string"==typeof e.value?T(e.value):null)).filter(Boolean):null},getCalleeName:l,getConstantStringExpression:i,getCurrentClassName:function(e){const t=e.getAncestors().find((e=>"ClassDeclaration"===e.type));return t&&"ClassDeclaration"===t.type&&null!=t.id?t.id.name:null},getEnglishForNth:function(e){return["first","second","third","fourth","fifth","sixth"][e]},getFullyQualifiedIdentifier:a,getJSResourceModuleName:O,getJSXMemberOrNamespaceRoot:function(e){let t=e;for(;"JSXIdentifier"!==t.type;)if("JSXMemberExpression"===t.type)t=t.object;else{if("JSXNamespacedName"!==t.type)throw new Error("unexpected "+t.type);t=t.namespace}return t},getLocOffset:function(e,t,n){return s(e,t.loc.start,n)},getLocOffsetOfLoc:s,getName:function(e){const t=P(e);return"Identifier"===t.type?t.name:"Literal"===t.type?String(t.value):null},getObjectPropertyName:function(e){if("Property"!==e.type&&"PropertyDefinition"!==e.type&&"MethodDefinition"!==e.type)return null;const t=e.key;return"Identifier"!==t.type||e.computed?function(e){switch(e.type){case"Literal":switch(e.literalType){case"bigint":return e.bigint;case"null":return"null";case"regexp":return`/${e.regex.pattern}/${e.regex.flags}`;default:return String(e.value)}case"TemplateLiteral":if(0===e.expressions.length&&1===e.quasis.length)return e.quasis[0].value.cooked}return null}(t):t.name},getParamComments:function(e,t){return t.params.map((function(t){const n=e.getSourceCode().getCommentsBefore(t);return n[n.length-1]}))},getPropertyName:function(e){return"MemberExpression"!==e.type?null:e.computed?i(e.property):"Identifier"!==e.property.type?null:e.property.name},getPropTokens:function(e,t){const n=e.getSourceCode().getTokens(t),r=[];return n.forEach(((e,t,n)=>{"JSXIdentifier"===e.type&&"Punctuator"===n[t+1].type&&"="===n[t+1].value&&r.push(e)})),r},getRequireCondModules:w,getRequireModuleName:k,getRequireModuleNode:j,getReturnComment:function(e,t){return e.getSourceCode().getCommentsBefore(t.body)[0]},getValueImportNode:F,getValueImportVariables:function(e,t){const n=[];for(const r of e.getSourceCode().ast.body)"ImportDeclaration"!==r.type||r.source.value!==t||L(r)||r.specifiers.filter((e=>{null!=e.importKind&&"value"!==e.importKind||n.push(e.local.name)}));return n},hasValueImport:function(e){return e.getSourceCode().ast.body.some((e=>"ImportDeclaration"===e.type&&!L(e)))},getVariable:function(e,t){let n=t;for(;n;){const t=n.set.get(e);if(t)return t;n=n.upper}return null},insertRequireStatement:function(e,t,n,r=""){if(""===n)throw new Error("Name must be a string with length larger than 0");const o=`const ${n} = require('${n}${r}');`,i=[];e.getSourceCode().ast.body.forEach((e=>{if("VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&e.declarations[0].init){const t=k(e.declarations[0].init);null!=t&&i.push({name:t,node:e})}}));const a=i.find((e=>e.name>=n));if(a){if(a.name.replace(r,"")===n)return[];const e=i[0];if(c(a.name)&&p(n)){if(e!==a){const e=a.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(a.node,o+"\n\n")]}return[t.insertTextBefore(a.node,o+"\n\n")]}return[t.insertTextBefore(a.node,o+"\n")]}if(i.length>0){const e=i[i.length-1],r=p(e.name)&&c(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+o+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],o+"\n")]:[t.insertTextBefore(n[0],o+"\n")]}},insertValueImportStatement:function(e,t,n,r="",o){if(""===n)throw new Error("Name must be a string with length larger than 0");const i=`import ${o??n} from '${n}${r}';`,a=[];e.getSourceCode().ast.body.forEach((e=>{if(b(e)){const t=function(e){if(d(e))return"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value);if(S(e))return e.source.value;return null}(e);null!=t&&a.push({name:t,node:e})}}));const l=a.find((e=>e.name>=n));if(l){if(l.name.replace(r,"")===n)return[];const e=a[0];if(c(l.name)&&p(n)){if(e!==l){const e=l.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(l.node,i+"\n\n")]}return[t.insertTextBefore(l.node,i+"\n\n")]}return[t.insertTextBefore(l.node,i+"\n")]}if(a.length>0){const e=a[a.length-1],r=p(e.name)&&c(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+i+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],i+"\n")]:[t.insertTextBefore(n[0],i+"\n")]}},isAnyKindOfImport:S,isAnyKindOfModuleCall:function(e){return d(e)||D(e)||v(e)||E(e)||I(e)||g(e)},isAnyKindOfRequireCall:d,isAnyKindOfRequireVariableDeclaration:f,isAnyKindOfRequireVariableDeclarator:m,isClientJSResource:I,isFbSourceRepo:o,isGraphQLTemplate:function(e){return"Identifier"===e.tag.type&&"graphql"===e.tag.name&&1===e.quasi.quasis.length},isInsideMethod:function(e,t){return e.getAncestors().some((e=>"MethodDefinition"===e.type&&"Identifier"===e.key.type&&e.key.name===t))},isJSResource:v,isJSResourceForInteraction:E,isModuleRef:function(e){return"Literal"===e.type&&"string"==typeof e.value&&e.value.startsWith("m#")},isNodeInsideFunctionBody:function e(t){return null!=t.parent&&("ArrowFunctionExpression"===t.parent.type||"FunctionDeclaration"===t.parent.type||"FunctionExpression"===t.parent.type||"HookDeclaration"===t.parent.type||"ComponentDeclaration"===t.parent.type||e(t.parent))},isNodeInsideNode:function(e,t){return e.range[0]>=t.range[0]&&e.range[1]<=t.range[1]},isOnlyTypeImport:L,isOnlyTypeExport:function(e){return"type"===e.exportKind},isReferenced:function(e){const t=e.parent;switch(t.type){case"MemberExpression":case"JSXMemberExpression":return t.property===e&&!0===t.computed||t.object===e;case"MetaProperty":case"ImportDefaultSpecifier":case"ImportNamespaceSpecifier":case"ImportSpecifier":case"LabeledStatement":case"RestElement":case"ObjectPattern":case"ArrayPattern":return!1;case"Property":case"MethodDefinition":return t.key===e&&t.computed;case"VariableDeclarator":case"ClassDeclaration":case"ClassExpression":return t.id!==e;case"ArrowFunctionExpression":case"FunctionDeclaration":case"HookDeclaration":case"FunctionExpression":for(let n=0;ne.writeExpr));return null!=o?o.writeExpr:null},resolveModuleSource:function(e,t){const n=u(e.getScope(),t);if(null==n)return null;const r=n.defs[0];switch(r.node.type){case"VariableDeclarator":{const e=r.node.init;if(null!=e)return k(e)||O(e)||N(e)||q(e);break}case"ImportNamespaceSpecifier":case"ImportSpecifier":case"ImportDefaultSpecifier":return r.node.parent.source.value}return null},stripModuleRef:T,uncast:P},e}var s,u,c,p,f,m,d,g,y,h,x=a(o({__proto__:null,isCommaOrSemiToken:function(e){return"Punctuator"===e.type&&(","===e.value||";"===e.value)}},[r(require("hermes-estree"))]));function b(){if(u)return s;u=1;const{isCommaOrSemiToken:e}=x;return s={getInlineComments:function(t,n,r=e){const o=t.ast.comments.filter((e=>e.loc.start.line===n.loc.end.line&&e.range[0]>n.range[1])).sort(((e,t)=>e.range[0]-t.range[0])),i=[];let a=n;for(const e of o){const n=t.getTokensBetween(a,e);if(n.length>0){if(!r)break;if(!n.every(r))break}i.push(e),a=e}return i},getLeadingComments:function(e,t,n){const r=e.getCommentsBefore(t),o=[];let i=t;for(let t=r.length-1;t>=0;t-=1){const a=r[t];if(a===n)break;if(a.loc.end.line===i.loc.start.line){o.unshift(a),i=a;continue}if(a.loc.end.line!==i.loc.start.line-1)break;const l=e.getTokenBefore(a);if(l&&l.loc.end.line===a.loc.start.line)break;o.unshift(a),i=a}return o}}}function C(){if(g)return d;g=1;const e=l(),{getInlineComments:t,getLeadingComments:n}=b(),r=p?c:(p=1,c=function(e){const t=e.getSourceCode().ast;return t.docblock?.comment}),{compareNames:o}=function(){if(m)return f;m=1;const{getInlineComments:e,getLeadingComments:t}=b(),{isCommaOrSemiToken:n}=x;function r(e){return"@"===e[0]||":"===e[0]}const o=/\d{1,3}(\.\d+)?%/;function i(e){switch(typeof e){case"number":return{isSafeNumericString:!0,isPercentage:!1};case"boolean":return{isSafeNumericString:!1,isPercentage:!1}}return isNaN(e)||isNaN(parseFloat(e))?o.test(e)?{isSafeNumericString:!0,isPercentage:!0}:{isSafeNumericString:!1,isPercentage:!1}:{isSafeNumericString:!0,isPercentage:!1}}function a(e){return e.reduce((([e,t],[n,r])=>[Math.min(e,n),Math.max(t,r)]),[Number.MAX_SAFE_INTEGER,0])}return f={compareNames:function(e,t,n=!1){if("number"==typeof e&&"number"==typeof t)return e-t;const o=String(e),a=String(t);if(""===o&&""!==a)return-1;if(""!==o&&""===a)return 1;if(""===o&&""===a)return 0;const{isSafeNumericString:l,isPercentage:s}=i(o),{isSafeNumericString:u,isPercentage:c}=i(a);if(l&&u){const e=Number.parseFloat(o),t=Number.parseFloat(a);if(e===t){if(!s&&c)return-1;if(s&&!c)return 1}return e-t}if(n){const e=r(o),t=r(a);if(!e&&t)return-1;if(e&&!t)return 1}const p=l||o[0].toLowerCase()===o[0].toUpperCase(),f=u||a[0].toLowerCase()===a[0].toUpperCase();if(!p&&f)return 1;if(p&&!f)return-1;if(!p&&!f){const e=o[0].toLowerCase()===o[0],t=a[0].toLowerCase()===a[0];if(!e&&t)return-1;if(e&&!t)return 1}return o.localeCompare(a,"en",{caseFirst:"upper",sensitivity:"base"})},getEncompassingRange:a,getNodeTextWithComments:function(r,o,i,{shouldIncludeNextTokenInRange:l=n,ensureTextFollowsNode:s,inlineCommentIgnoreToken:u}={}){const c=e(r,o,u),p=[...t(r,o,i).map((({range:e})=>e)),o.range,...c.map((({range:e})=>e))],f=r.getTokenAfter(o);f&&!0===l?.(f)&&p.push(f.range);const m=a(p);let d=r.text.slice(m[0],m[1]);const g=o.range[1]-m[0];if(null!=s){const e=r.getTokenAfter(o);e?.value!==s&&(d=d.slice(0,g)+s+d.slice(g))}return{range:m,text:d}},isComma:function(e){return"Punctuator"===e.type&&","===e.value}}}(),i=0,a={default:1,namespace:2,named:3},s={default:4,namespace:5,named:6},u={default:7,namespace:8,named:9},y=0,h=1,C=2,S=3,v=99;return d={meta:{fixable:"code",messages:{incorrectOrder:"Requires should be sorted alphabetically, with at least one line between imports/requires and code"}},create(l){const c=l.getSourceCode(),p=function(e){const t=r(e);if(null!=t)return t;const n=e.getSourceCode().ast,o=n.body.length>0?n.body[0]:n,i=e.getSourceCode().getCommentsBefore(o)[0];return i&&"Block"===i.type?i:null}(l);if(p&&(p.value.includes("* @generated")||p.value.includes("* @partially-generated")))return{};const f=Object.freeze({typeImport:{priority:10,uppercase:[],lowercase:[],tiebreakFunction:b},valueImport:{priority:20,uppercase:[],lowercase:[],tiebreakFunction:b},requiresUsedByOtherRequires:{priority:30,uppercase:[],lowercase:[],tiebreakFunction:E},require:{priority:40,uppercase:[],lowercase:[],tiebreakFunction:E}}),m=[];let d=null,g=null;const x=new Set;return{Program(e){for(const t of e.body)switch(t.type){case"ImportDeclaration":if("type"===t.importKind||"typeof"===t.importKind)w(f.typeImport,t,t.source.value,!0);else{const e=c.getLastToken(t.source,(e=>"from"===e.value));0===t.specifiers.length&&null==e?O(t):w(f.valueImport,t,t.source.value)}break;case"VariableDeclaration":{const e=t.declarations[0]?.init;if(1!==t.declarations.length||null==e){O(t);break}T(e,t);break}default:O(t)}const t=[];for(const e of Object.keys(f)){const n=f[e];t.push({priority:n.priority,nodes:n.uppercase.sort(((e,t)=>I(e,t,n.tiebreakFunction)))}),t.push({priority:n.priority+5,nodes:n.lowercase.sort(((e,t)=>I(e,t,n.tiebreakFunction)))})}function n(e){return[e.leadingComments.length?e.leadingComments.map((e=>c.getText(e))).join("\n")+"\n":"",e.inlineComments.length?" "+e.inlineComments.map((e=>c.getText(e))).join(" "):""]}let r=t.filter((e=>0!==e.nodes.length)).sort(((e,t)=>e.priority-t.priority)).map((e=>e.nodes.map((e=>{const[t,r]=n(e),i=function(e,t){const n=t.node,r=e.getText(n),i=(()=>{if("ImportDeclaration"===n.type&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const t=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"{"===e.value)),r=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"}"===e.value));return null==t||null==r?null:e.getText().substring(t.range[0],r.range[1])}if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const t=n.declarations[0].id.typeAnnotation,r=e.getText(n.declarations[0].id);return t?r.substr(0,t.range[0]-n.declarations[0].id.range[0]):r}return null})();if(null==i)return r;let a=[],l=null;"ImportDeclaration"===n.type?a=n.specifiers.map((t=>"ImportDefaultSpecifier"===t.type||"ImportNamespaceSpecifier"===t.type?null:{leadingComments:e.getCommentsBefore(t),name:t.imported.name,node:t})).filter(Boolean):"VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type&&(a=n.declarations[0].id.properties.map((t=>{if("ExperimentalRestProperty"===t.type||"RestElement"===t.type)return l=t,null;const n=t.key,r="Literal"===n.type?String(n.value):"Identifier"===n.type?t.computed?null:n.name:null;return null==r?null:{leadingComments:e.getCommentsBefore(t),name:r,node:t}})).filter(Boolean));if(a.length<=1)return r;const s=i.indexOf("\n")>=0,u=a.sort(((e,t)=>o(e.name,t.name))).map((e=>e.node));null!=l&&u.push(l);const c=u.map((t=>{const n=e.getCommentsBefore(t).map((t=>e.getText(t))),r=n.length?n.join(""):"";return s?(r?" "+r+"\n":"")+" "+e.getText(t):(r?r+" ":"")+e.getText(t)})),p=(()=>{const t=[];if("ImportDeclaration"===n.type){if(t.push(...e.getCommentsBefore(n.source)),s&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const r=e.getTokenBefore(n.source,(e=>"Punctuator"===e.type&&"}"===e.value));null!=r&&t.push(...e.getCommentsBefore(r))}}else if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const r=e.getLastToken(n.declarations[0].id);null!=r&&t.push(...e.getCommentsBefore(r))}return t})(),f=s&&p.length?p.map((t=>" "+e.getText(t))).join("\n")+"\n":"",m=s?"\n"+c.map((e=>e.includes("...")?`${e}\n`:`${e},\n`)).join("")+f:c.join(", ");return r.replace(i,(()=>`{${m}}`))}(c,e);return t+i+r})).join("\n"))).join("\n\n");const i=d;if(null==i||null==g)return;const a=i.leadingComments.length?i.leadingComments[0].range[0]:i.node.range[0],s=g.inlineComments.length>0?g.inlineComments[g.inlineComments.length-1].range[1]:g.node.range[1],u=c.getText(i.node,i.node.range[0]-a,s-i.node.range[1]),p=g?.node;if(null!=p){const t=e.body.indexOf(p),n=e.body[t+1];null!=n&&n.loc.start.line-p.loc.end.line===1&&(r+="\n")}u!==r&&l.report({node:i.node,messageId:"incorrectOrder",fix(e){const t=m.filter((({node:e})=>e.range[0]>=a&&e.range[1]<=s)).map((e=>{const[t,r]=n(e),o=c.getText(e.node);return{range:e.node.range,text:t+o+r}})).flat().concat(c.getAllComments().filter((e=>e.range[0]>=a&&e.range[1]<=s&&!x.has(e))).map((e=>({range:e.range,text:c.getText(e)})))).sort(((e,t)=>e.range[0]-t.range[0]||e.range[1]-t.range[1])).map((({text:e})=>e)).join("\n");return e.replaceTextRange([a,s],[r,t].filter(Boolean).join("\n\n"))}})}};function b(e){if(0===e.specifiers.length)return i;const t=(()=>{switch(e.importKind){default:case"value":return a;case"type":return s;case"typeof":return u}})();return e.specifiers.find((e=>"ImportDefaultSpecifier"===e.type))?t.default:e.specifiers.find((e=>"ImportNamespaceSpecifier"===e.type))?t.namespace:t.named}function E(e){if("ExpressionStatement"===e.type)return y;switch(e.declarations[0].id.type){case"Identifier":return h;case"ObjectPattern":return C;case"ArrayPattern":return S}return v}function I(e,t,n){const r=o(e.moduleName,t.moduleName);if(0!==r)return r;const i=n(e.node)-n(t.node);return 0!==i?i:e.node.loc.start.line-t.node.loc.start.line}function D(e,t){if(null==e)throw new Error("Missing required module name");return null!=t?`${e}_${t}`:e}function T(t,n,r){const o=e.getRequireModuleName(t);if(e.isRequire(t)){const e=D(o,r);w("requireCond"===e||"requireDeferred"===e||"requireDeferredForDisplay"===e?f.requiresUsedByOtherRequires:f.require,n,D(o,r))}else if(e.isRequireDeferred(t)||e.isRequireDeferredForDisplay(t))w(f.require,n,D(o,r));else{if(e.isRequireCond(t)){if("VariableDeclaration"===n.type){const e=c.getText(n.declarations[0].id);return void w(f.require,n,D(e,r))}}else{if("MemberExpression"===t.type)return void T(t.object,n,D(c.getText(t.property),r));if("CallExpression"===t.type)return void T(t.callee,n,r)}O(n)}}function R(e){e.leadingComments.forEach((e=>x.add(e))),e.inlineComments.forEach((e=>x.add(e)));c.getCommentsInside(e.node).forEach((e=>x.add(e)))}function w(e,r,o,i=!1){const a={inlineComments:t(c,r),leadingComments:n(c,r,p),moduleName:o,node:r};if(i)e.uppercase.push(a);else{const t=o[0]||"";t.toLowerCase()===t?e.lowercase.push(a):e.uppercase.push(a)}null==d&&(d=a),g=a,R(a)}function O(e){const r={inlineComments:t(c,e),leadingComments:n(c,e,p),node:e};m.push(r),R(r)}}},d}var S=i(function(){if(h)return y;h=1;const e=C();return y=e}());module.exports=S; From e4f4f6b4312485ee0f225363af3e963f91366e97 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 9 Jun 2025 20:26:05 -0700 Subject: [PATCH 2/6] sort-imports: ESLint Suppression Comments (#51881) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51881 Switches the suppression of ESLint for the generated `sort-imports` lint rule definition to using in-file comments instead of `.eslintignore`. This makes the suppression more portable. If the path to the lint rule definition changes, we don't have to remember to update `.eslintignore`. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D76152973 --- .eslintignore | 1 - .eslintrc.js | 1 + tools/eslint/rules/sort-imports.js | 5 ++++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.eslintignore b/.eslintignore index ca22506f6c8c..e16e0140326a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -13,7 +13,6 @@ packages/*/dist packages/*/types_generated packages/debugger-frontend/dist/**/* packages/react-native-codegen/lib -tools/eslint/rules/sort-imports.js **/Pods/* **/*.macos.js **/*.windows.js diff --git a/.eslintrc.js b/.eslintrc.js index 6c1f336d2685..829535a3520e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,6 +28,7 @@ module.exports = { files: ['*.js', '*.js.flow', '*.jsx'], parser: 'hermes-eslint', rules: { + 'eslint-comments/no-unlimited-disable': 0, 'ft-flow/require-valid-file-annotation': [2, 'always'], 'no-extra-boolean-cast': 0, 'no-void': 0, diff --git a/tools/eslint/rules/sort-imports.js b/tools/eslint/rules/sort-imports.js index a061c4e1dea9..618bf01efd1e 100644 --- a/tools/eslint/rules/sort-imports.js +++ b/tools/eslint/rules/sort-imports.js @@ -6,7 +6,10 @@ * * To regenerate this file, please run this command on Meta's monorepo: * @codegen-command : xplat/js/tools/sort-imports/scripts/build.sh - * @generated SignedSource<<374df066e2e1e673cc452314636d8dd8>> + * @generated SignedSource<<7b842f046d041c0d5d44b62d0f8244e1>> * @nolint */ + +/* eslint-disable */ + "use strict";var e,t,n=require("path");function r(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}function o(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}function i(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function a(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function l(){if(t)return e;t=1;const r=n,o=__dirname.split(r.sep).includes("xplat");function i(e){if(("Literal"===e.type||"JSXText"===e.type)&&"string"==typeof e.value)return e.value;if("BinaryExpression"===e.type&&"+"===e.operator){const t=i(e.left),n=i(e.right);if(null!=t&&null!=n)return t+n}return null}function a(e){if("Identifier"===e.type)return e.name;if("ThisExpression"===e.type)return"this";if("MemberExpression"===e.type){const t=a(e.object),n=e.computed?i(e.property):a(e.property);if(null!=t&&null!=n)return t+"."+n}else if("TypeCastExpression"===e.type||"AsExpression"===e.type)return a(e.expression);return null}function l(e){return e.callee?a(e.callee):null}function s(e,t,n){const r=e.getSourceCode().getText(),o=function(e,t){if(t.line<1)throw new RangeError("Line number "+t.line+" is before the start of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r={index:0};for(let o=1;o=e.length)throw new RangeError("computed offset "+t+" is past the end of file");const n=/\r\n|\r|\n|\u2028|\u2029/g;let r,o={index:0},i=0;do{r=o,o=n.exec(e),++i}while(o&&o.index"string"==typeof e&&e.charCodeAt(0)>=97,p=e=>"string"==typeof e&&e.charCodeAt(0)<=90;function f(e){return null!=e&&"VariableDeclaration"===e.type&&"Program"===e.parent.type&&1===e.declarations.length&&null!=e.declarations[0].init&&d(e.declarations[0].init)}function m(e){return null!=e&&"VariableDeclarator"===e.type&&"VariableDeclaration"===e.parent.type&&"Program"===e.parent.parent.type&&1===e.parent.declarations.length&&d(e.init)}function d(e){return null!=e&&(y(e)||h(e)||x(e))}function g(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"requireNUX"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function y(e){return"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"require"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function h(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferred"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function x(e){return"CallExpression"===e.type&&"Identifier"===e.callee.type&&"requireDeferredForDisplay"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function b(e){return"ImportDeclaration"===e.type&&(null==e.importKind||"value"===e.importKind)}function C(e){return"ImportDeclaration"===e.type&&("type"===e.importKind||"typeof"===e.importKind)}function S(e){return b(e)||C(e)}function v(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type}function E(e){return null!=e&&"CallExpression"===e.type&&e.callee&&"Identifier"===e.callee.type&&"JSResourceForInteraction"===e.callee.name&&2===e.arguments.length&&"Literal"===e.arguments[0].type}function I(e){return null!=e&&"CallExpression"===e.type&&"Identifier"===e.callee.type&&"ClientJSResource"===e.callee.name&&1===e.arguments.length&&"Literal"===e.arguments[0].type&&"string"==typeof e.arguments[0].value}function D(e){if(null==e||"CallExpression"!==e.type||null==e.callee)return!1;let t;return"Identifier"===e.callee.type&&(t=e.callee),"MemberExpression"===e.callee.type&&"Identifier"===e.callee.object.type&&(t=e.callee.object),null!=t&&"requireCond"===t.name&&e.arguments.length>0}function T(e){return 0===e.indexOf("m#")?e.substring(2):e}function R(e,t,n=1){return"CallExpression"!==e.type||e.arguments.length!==n||null!=t&&"string"==typeof t&&l(e)!==t||"Literal"!==e.arguments[0].type||"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value)}function w(e,t,n){const r=e.arguments;return D(e)?3!==r.length?null:(null==t||r[0]&&"Literal"===r[0].type&&r[0].value===t)&&(null==n||r[1]&&"Literal"===r[1].type&&r[1].value===n)?r[2]&&"ObjectExpression"===r[2].type?r[2].properties.reduce(((e,t)=>{if("Property"===t.type&&"Literal"===t.value.type){let n;if("Identifier"===t.key.type)n=t.key.name;else{if("Literal"!==t.key.type)return e;n=String(t.key.value)}e[n]="string"==typeof t.value.value?T(t.value.value):null}return e}),{}):r[2]&&"Literal"===r[2].type&&"string"==typeof r[2].value?T(r[2].value):null:null:null}function O(e){return R(e,"JSResource")}function N(e){return R(e,"JSResourceForInteraction",2)}function k(e){return null==e?null:d(e)?"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value):null}function q(e){return g(e)?2!==e.arguments.length||"string"!=typeof e.arguments[1].value?null:T(e.arguments[1].value):null}function j(e,t){const n=e.getSourceCode().ast.body.find((e=>"VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&null!=e.declarations[0].init&&k(e.declarations[0].init)===t));return n||null}function P(e){let t=e;for(;"TypeCastExpression"===t.type||"AsExpression"===t.type;)t=t.expression;return t}function L(e){if(0===e.specifiers.length)return!1;if("value"!==e.importKind)return!0;return e.specifiers.every((e=>"ImportSpecifier"===e.type&&("type"===e.importKind||"typeof"===e.importKind)))}function F(e,t){const n=e.getSourceCode().ast.body.find((e=>"ImportDeclaration"===e.type&&e.source.value===t&&!L(e)));return n||null}return e={asAnyKindOfRequireCall:function(e){return d(e)?e:null},asAnyKindOfRequireVariableDeclaration:function(e){return f(e)?e:null},asAnyKindOfRequireVariableDeclarator:function(e){return m(e)?e:null},getAnyRequiredModuleName:function(e,t=Object.freeze({})){const n=k(e)||O(e)||N(e)||q(e);return null!=n?n:w(e,t.condType,t.condition)},getBaseNode:function(e){let t=e;for(;"MemberExpression"===t.type;)t=t.object;return t},getBinding:u,getBootloadedModuleNames:function(e){return"ExpressionStatement"===e.type&&e.expression&&"CallExpression"===e.expression.type&&e.expression.callee&&"MemberExpression"===e.expression.callee.type&&e.expression.callee.object&&"Bootloader"===e.expression.callee.object.name&&e.expression.callee.property&&"loadModules"===e.expression.callee.property.name&&e.expression.arguments.length>0&&"ArrayExpression"===e.expression.arguments[0].type&&e.expression.arguments[0].elements.length>0?e.expression.arguments[0].elements.map((e=>"Literal"===e.type&&"string"==typeof e.value?T(e.value):null)).filter(Boolean):null},getCalleeName:l,getConstantStringExpression:i,getCurrentClassName:function(e){const t=e.getAncestors().find((e=>"ClassDeclaration"===e.type));return t&&"ClassDeclaration"===t.type&&null!=t.id?t.id.name:null},getEnglishForNth:function(e){return["first","second","third","fourth","fifth","sixth"][e]},getFullyQualifiedIdentifier:a,getJSResourceModuleName:O,getJSXMemberOrNamespaceRoot:function(e){let t=e;for(;"JSXIdentifier"!==t.type;)if("JSXMemberExpression"===t.type)t=t.object;else{if("JSXNamespacedName"!==t.type)throw new Error("unexpected "+t.type);t=t.namespace}return t},getLocOffset:function(e,t,n){return s(e,t.loc.start,n)},getLocOffsetOfLoc:s,getName:function(e){const t=P(e);return"Identifier"===t.type?t.name:"Literal"===t.type?String(t.value):null},getObjectPropertyName:function(e){if("Property"!==e.type&&"PropertyDefinition"!==e.type&&"MethodDefinition"!==e.type)return null;const t=e.key;return"Identifier"!==t.type||e.computed?function(e){switch(e.type){case"Literal":switch(e.literalType){case"bigint":return e.bigint;case"null":return"null";case"regexp":return`/${e.regex.pattern}/${e.regex.flags}`;default:return String(e.value)}case"TemplateLiteral":if(0===e.expressions.length&&1===e.quasis.length)return e.quasis[0].value.cooked}return null}(t):t.name},getParamComments:function(e,t){return t.params.map((function(t){const n=e.getSourceCode().getCommentsBefore(t);return n[n.length-1]}))},getPropertyName:function(e){return"MemberExpression"!==e.type?null:e.computed?i(e.property):"Identifier"!==e.property.type?null:e.property.name},getPropTokens:function(e,t){const n=e.getSourceCode().getTokens(t),r=[];return n.forEach(((e,t,n)=>{"JSXIdentifier"===e.type&&"Punctuator"===n[t+1].type&&"="===n[t+1].value&&r.push(e)})),r},getRequireCondModules:w,getRequireModuleName:k,getRequireModuleNode:j,getReturnComment:function(e,t){return e.getSourceCode().getCommentsBefore(t.body)[0]},getValueImportNode:F,getValueImportVariables:function(e,t){const n=[];for(const r of e.getSourceCode().ast.body)"ImportDeclaration"!==r.type||r.source.value!==t||L(r)||r.specifiers.filter((e=>{null!=e.importKind&&"value"!==e.importKind||n.push(e.local.name)}));return n},hasValueImport:function(e){return e.getSourceCode().ast.body.some((e=>"ImportDeclaration"===e.type&&!L(e)))},getVariable:function(e,t){let n=t;for(;n;){const t=n.set.get(e);if(t)return t;n=n.upper}return null},insertRequireStatement:function(e,t,n,r=""){if(""===n)throw new Error("Name must be a string with length larger than 0");const o=`const ${n} = require('${n}${r}');`,i=[];e.getSourceCode().ast.body.forEach((e=>{if("VariableDeclaration"===e.type&&1===e.declarations.length&&"VariableDeclarator"===e.declarations[0].type&&e.declarations[0].init){const t=k(e.declarations[0].init);null!=t&&i.push({name:t,node:e})}}));const a=i.find((e=>e.name>=n));if(a){if(a.name.replace(r,"")===n)return[];const e=i[0];if(c(a.name)&&p(n)){if(e!==a){const e=a.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(a.node,o+"\n\n")]}return[t.insertTextBefore(a.node,o+"\n\n")]}return[t.insertTextBefore(a.node,o+"\n")]}if(i.length>0){const e=i[i.length-1],r=p(e.name)&&c(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+o+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],o+"\n")]:[t.insertTextBefore(n[0],o+"\n")]}},insertValueImportStatement:function(e,t,n,r="",o){if(""===n)throw new Error("Name must be a string with length larger than 0");const i=`import ${o??n} from '${n}${r}';`,a=[];e.getSourceCode().ast.body.forEach((e=>{if(b(e)){const t=function(e){if(d(e))return"string"!=typeof e.arguments[0].value?null:T(e.arguments[0].value);if(S(e))return e.source.value;return null}(e);null!=t&&a.push({name:t,node:e})}}));const l=a.find((e=>e.name>=n));if(l){if(l.name.replace(r,"")===n)return[];const e=a[0];if(c(l.name)&&p(n)){if(e!==l){const e=l.node.range[0];return[t.removeRange([e-1,e-1]),t.insertTextBefore(l.node,i+"\n\n")]}return[t.insertTextBefore(l.node,i+"\n\n")]}return[t.insertTextBefore(l.node,i+"\n")]}if(a.length>0){const e=a[a.length-1],r=p(e.name)&&c(n)?"\n":"";return[t.insertTextAfter(e.node,"\n"+i+r)]}{const n=e.getSourceCode().ast.body,r=n[0];return"ExpressionStatement"===r.type&&"Literal"===r.expression.type&&"use strict"===r.expression.value?[t.insertTextBefore(n[1],i+"\n")]:[t.insertTextBefore(n[0],i+"\n")]}},isAnyKindOfImport:S,isAnyKindOfModuleCall:function(e){return d(e)||D(e)||v(e)||E(e)||I(e)||g(e)},isAnyKindOfRequireCall:d,isAnyKindOfRequireVariableDeclaration:f,isAnyKindOfRequireVariableDeclarator:m,isClientJSResource:I,isFbSourceRepo:o,isGraphQLTemplate:function(e){return"Identifier"===e.tag.type&&"graphql"===e.tag.name&&1===e.quasi.quasis.length},isInsideMethod:function(e,t){return e.getAncestors().some((e=>"MethodDefinition"===e.type&&"Identifier"===e.key.type&&e.key.name===t))},isJSResource:v,isJSResourceForInteraction:E,isModuleRef:function(e){return"Literal"===e.type&&"string"==typeof e.value&&e.value.startsWith("m#")},isNodeInsideFunctionBody:function e(t){return null!=t.parent&&("ArrowFunctionExpression"===t.parent.type||"FunctionDeclaration"===t.parent.type||"FunctionExpression"===t.parent.type||"HookDeclaration"===t.parent.type||"ComponentDeclaration"===t.parent.type||e(t.parent))},isNodeInsideNode:function(e,t){return e.range[0]>=t.range[0]&&e.range[1]<=t.range[1]},isOnlyTypeImport:L,isOnlyTypeExport:function(e){return"type"===e.exportKind},isReferenced:function(e){const t=e.parent;switch(t.type){case"MemberExpression":case"JSXMemberExpression":return t.property===e&&!0===t.computed||t.object===e;case"MetaProperty":case"ImportDefaultSpecifier":case"ImportNamespaceSpecifier":case"ImportSpecifier":case"LabeledStatement":case"RestElement":case"ObjectPattern":case"ArrayPattern":return!1;case"Property":case"MethodDefinition":return t.key===e&&t.computed;case"VariableDeclarator":case"ClassDeclaration":case"ClassExpression":return t.id!==e;case"ArrowFunctionExpression":case"FunctionDeclaration":case"HookDeclaration":case"FunctionExpression":for(let n=0;ne.writeExpr));return null!=o?o.writeExpr:null},resolveModuleSource:function(e,t){const n=u(e.getScope(),t);if(null==n)return null;const r=n.defs[0];switch(r.node.type){case"VariableDeclarator":{const e=r.node.init;if(null!=e)return k(e)||O(e)||N(e)||q(e);break}case"ImportNamespaceSpecifier":case"ImportSpecifier":case"ImportDefaultSpecifier":return r.node.parent.source.value}return null},stripModuleRef:T,uncast:P},e}var s,u,c,p,f,m,d,g,y,h,x=a(o({__proto__:null,isCommaOrSemiToken:function(e){return"Punctuator"===e.type&&(","===e.value||";"===e.value)}},[r(require("hermes-estree"))]));function b(){if(u)return s;u=1;const{isCommaOrSemiToken:e}=x;return s={getInlineComments:function(t,n,r=e){const o=t.ast.comments.filter((e=>e.loc.start.line===n.loc.end.line&&e.range[0]>n.range[1])).sort(((e,t)=>e.range[0]-t.range[0])),i=[];let a=n;for(const e of o){const n=t.getTokensBetween(a,e);if(n.length>0){if(!r)break;if(!n.every(r))break}i.push(e),a=e}return i},getLeadingComments:function(e,t,n){const r=e.getCommentsBefore(t),o=[];let i=t;for(let t=r.length-1;t>=0;t-=1){const a=r[t];if(a===n)break;if(a.loc.end.line===i.loc.start.line){o.unshift(a),i=a;continue}if(a.loc.end.line!==i.loc.start.line-1)break;const l=e.getTokenBefore(a);if(l&&l.loc.end.line===a.loc.start.line)break;o.unshift(a),i=a}return o}}}function C(){if(g)return d;g=1;const e=l(),{getInlineComments:t,getLeadingComments:n}=b(),r=p?c:(p=1,c=function(e){const t=e.getSourceCode().ast;return t.docblock?.comment}),{compareNames:o}=function(){if(m)return f;m=1;const{getInlineComments:e,getLeadingComments:t}=b(),{isCommaOrSemiToken:n}=x;function r(e){return"@"===e[0]||":"===e[0]}const o=/\d{1,3}(\.\d+)?%/;function i(e){switch(typeof e){case"number":return{isSafeNumericString:!0,isPercentage:!1};case"boolean":return{isSafeNumericString:!1,isPercentage:!1}}return isNaN(e)||isNaN(parseFloat(e))?o.test(e)?{isSafeNumericString:!0,isPercentage:!0}:{isSafeNumericString:!1,isPercentage:!1}:{isSafeNumericString:!0,isPercentage:!1}}function a(e){return e.reduce((([e,t],[n,r])=>[Math.min(e,n),Math.max(t,r)]),[Number.MAX_SAFE_INTEGER,0])}return f={compareNames:function(e,t,n=!1){if("number"==typeof e&&"number"==typeof t)return e-t;const o=String(e),a=String(t);if(""===o&&""!==a)return-1;if(""!==o&&""===a)return 1;if(""===o&&""===a)return 0;const{isSafeNumericString:l,isPercentage:s}=i(o),{isSafeNumericString:u,isPercentage:c}=i(a);if(l&&u){const e=Number.parseFloat(o),t=Number.parseFloat(a);if(e===t){if(!s&&c)return-1;if(s&&!c)return 1}return e-t}if(n){const e=r(o),t=r(a);if(!e&&t)return-1;if(e&&!t)return 1}const p=l||o[0].toLowerCase()===o[0].toUpperCase(),f=u||a[0].toLowerCase()===a[0].toUpperCase();if(!p&&f)return 1;if(p&&!f)return-1;if(!p&&!f){const e=o[0].toLowerCase()===o[0],t=a[0].toLowerCase()===a[0];if(!e&&t)return-1;if(e&&!t)return 1}return o.localeCompare(a,"en",{caseFirst:"upper",sensitivity:"base"})},getEncompassingRange:a,getNodeTextWithComments:function(r,o,i,{shouldIncludeNextTokenInRange:l=n,ensureTextFollowsNode:s,inlineCommentIgnoreToken:u}={}){const c=e(r,o,u),p=[...t(r,o,i).map((({range:e})=>e)),o.range,...c.map((({range:e})=>e))],f=r.getTokenAfter(o);f&&!0===l?.(f)&&p.push(f.range);const m=a(p);let d=r.text.slice(m[0],m[1]);const g=o.range[1]-m[0];if(null!=s){const e=r.getTokenAfter(o);e?.value!==s&&(d=d.slice(0,g)+s+d.slice(g))}return{range:m,text:d}},isComma:function(e){return"Punctuator"===e.type&&","===e.value}}}(),i=0,a={default:1,namespace:2,named:3},s={default:4,namespace:5,named:6},u={default:7,namespace:8,named:9},y=0,h=1,C=2,S=3,v=99;return d={meta:{fixable:"code",messages:{incorrectOrder:"Requires should be sorted alphabetically, with at least one line between imports/requires and code"}},create(l){const c=l.getSourceCode(),p=function(e){const t=r(e);if(null!=t)return t;const n=e.getSourceCode().ast,o=n.body.length>0?n.body[0]:n,i=e.getSourceCode().getCommentsBefore(o)[0];return i&&"Block"===i.type?i:null}(l);if(p&&(p.value.includes("* @generated")||p.value.includes("* @partially-generated")))return{};const f=Object.freeze({typeImport:{priority:10,uppercase:[],lowercase:[],tiebreakFunction:b},valueImport:{priority:20,uppercase:[],lowercase:[],tiebreakFunction:b},requiresUsedByOtherRequires:{priority:30,uppercase:[],lowercase:[],tiebreakFunction:E},require:{priority:40,uppercase:[],lowercase:[],tiebreakFunction:E}}),m=[];let d=null,g=null;const x=new Set;return{Program(e){for(const t of e.body)switch(t.type){case"ImportDeclaration":if("type"===t.importKind||"typeof"===t.importKind)w(f.typeImport,t,t.source.value,!0);else{const e=c.getLastToken(t.source,(e=>"from"===e.value));0===t.specifiers.length&&null==e?O(t):w(f.valueImport,t,t.source.value)}break;case"VariableDeclaration":{const e=t.declarations[0]?.init;if(1!==t.declarations.length||null==e){O(t);break}T(e,t);break}default:O(t)}const t=[];for(const e of Object.keys(f)){const n=f[e];t.push({priority:n.priority,nodes:n.uppercase.sort(((e,t)=>I(e,t,n.tiebreakFunction)))}),t.push({priority:n.priority+5,nodes:n.lowercase.sort(((e,t)=>I(e,t,n.tiebreakFunction)))})}function n(e){return[e.leadingComments.length?e.leadingComments.map((e=>c.getText(e))).join("\n")+"\n":"",e.inlineComments.length?" "+e.inlineComments.map((e=>c.getText(e))).join(" "):""]}let r=t.filter((e=>0!==e.nodes.length)).sort(((e,t)=>e.priority-t.priority)).map((e=>e.nodes.map((e=>{const[t,r]=n(e),i=function(e,t){const n=t.node,r=e.getText(n),i=(()=>{if("ImportDeclaration"===n.type&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const t=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"{"===e.value)),r=e.getFirstToken(n,(e=>"Punctuator"===e.type&&"}"===e.value));return null==t||null==r?null:e.getText().substring(t.range[0],r.range[1])}if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const t=n.declarations[0].id.typeAnnotation,r=e.getText(n.declarations[0].id);return t?r.substr(0,t.range[0]-n.declarations[0].id.range[0]):r}return null})();if(null==i)return r;let a=[],l=null;"ImportDeclaration"===n.type?a=n.specifiers.map((t=>"ImportDefaultSpecifier"===t.type||"ImportNamespaceSpecifier"===t.type?null:{leadingComments:e.getCommentsBefore(t),name:t.imported.name,node:t})).filter(Boolean):"VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type&&(a=n.declarations[0].id.properties.map((t=>{if("ExperimentalRestProperty"===t.type||"RestElement"===t.type)return l=t,null;const n=t.key,r="Literal"===n.type?String(n.value):"Identifier"===n.type?t.computed?null:n.name:null;return null==r?null:{leadingComments:e.getCommentsBefore(t),name:r,node:t}})).filter(Boolean));if(a.length<=1)return r;const s=i.indexOf("\n")>=0,u=a.sort(((e,t)=>o(e.name,t.name))).map((e=>e.node));null!=l&&u.push(l);const c=u.map((t=>{const n=e.getCommentsBefore(t).map((t=>e.getText(t))),r=n.length?n.join(""):"";return s?(r?" "+r+"\n":"")+" "+e.getText(t):(r?r+" ":"")+e.getText(t)})),p=(()=>{const t=[];if("ImportDeclaration"===n.type){if(t.push(...e.getCommentsBefore(n.source)),s&&null!=n.specifiers.find((e=>"ImportSpecifier"===e.type))){const r=e.getTokenBefore(n.source,(e=>"Punctuator"===e.type&&"}"===e.value));null!=r&&t.push(...e.getCommentsBefore(r))}}else if("VariableDeclaration"===n.type&&"ObjectPattern"===n.declarations[0].id.type){const r=e.getLastToken(n.declarations[0].id);null!=r&&t.push(...e.getCommentsBefore(r))}return t})(),f=s&&p.length?p.map((t=>" "+e.getText(t))).join("\n")+"\n":"",m=s?"\n"+c.map((e=>e.includes("...")?`${e}\n`:`${e},\n`)).join("")+f:c.join(", ");return r.replace(i,(()=>`{${m}}`))}(c,e);return t+i+r})).join("\n"))).join("\n\n");const i=d;if(null==i||null==g)return;const a=i.leadingComments.length?i.leadingComments[0].range[0]:i.node.range[0],s=g.inlineComments.length>0?g.inlineComments[g.inlineComments.length-1].range[1]:g.node.range[1],u=c.getText(i.node,i.node.range[0]-a,s-i.node.range[1]),p=g?.node;if(null!=p){const t=e.body.indexOf(p),n=e.body[t+1];null!=n&&n.loc.start.line-p.loc.end.line===1&&(r+="\n")}u!==r&&l.report({node:i.node,messageId:"incorrectOrder",fix(e){const t=m.filter((({node:e})=>e.range[0]>=a&&e.range[1]<=s)).map((e=>{const[t,r]=n(e),o=c.getText(e.node);return{range:e.node.range,text:t+o+r}})).flat().concat(c.getAllComments().filter((e=>e.range[0]>=a&&e.range[1]<=s&&!x.has(e))).map((e=>({range:e.range,text:c.getText(e)})))).sort(((e,t)=>e.range[0]-t.range[0]||e.range[1]-t.range[1])).map((({text:e})=>e)).join("\n");return e.replaceTextRange([a,s],[r,t].filter(Boolean).join("\n\n"))}})}};function b(e){if(0===e.specifiers.length)return i;const t=(()=>{switch(e.importKind){default:case"value":return a;case"type":return s;case"typeof":return u}})();return e.specifiers.find((e=>"ImportDefaultSpecifier"===e.type))?t.default:e.specifiers.find((e=>"ImportNamespaceSpecifier"===e.type))?t.namespace:t.named}function E(e){if("ExpressionStatement"===e.type)return y;switch(e.declarations[0].id.type){case"Identifier":return h;case"ObjectPattern":return C;case"ArrayPattern":return S}return v}function I(e,t,n){const r=o(e.moduleName,t.moduleName);if(0!==r)return r;const i=n(e.node)-n(t.node);return 0!==i?i:e.node.loc.start.line-t.node.loc.start.line}function D(e,t){if(null==e)throw new Error("Missing required module name");return null!=t?`${e}_${t}`:e}function T(t,n,r){const o=e.getRequireModuleName(t);if(e.isRequire(t)){const e=D(o,r);w("requireCond"===e||"requireDeferred"===e||"requireDeferredForDisplay"===e?f.requiresUsedByOtherRequires:f.require,n,D(o,r))}else if(e.isRequireDeferred(t)||e.isRequireDeferredForDisplay(t))w(f.require,n,D(o,r));else{if(e.isRequireCond(t)){if("VariableDeclaration"===n.type){const e=c.getText(n.declarations[0].id);return void w(f.require,n,D(e,r))}}else{if("MemberExpression"===t.type)return void T(t.object,n,D(c.getText(t.property),r));if("CallExpression"===t.type)return void T(t.callee,n,r)}O(n)}}function R(e){e.leadingComments.forEach((e=>x.add(e))),e.inlineComments.forEach((e=>x.add(e)));c.getCommentsInside(e.node).forEach((e=>x.add(e)))}function w(e,r,o,i=!1){const a={inlineComments:t(c,r),leadingComments:n(c,r,p),moduleName:o,node:r};if(i)e.uppercase.push(a);else{const t=o[0]||"";t.toLowerCase()===t?e.lowercase.push(a):e.uppercase.push(a)}null==d&&(d=a),g=a,R(a)}function O(e){const r={inlineComments:t(c,e),leadingComments:n(c,e,p),node:e};m.push(r),R(r)}}},d}var S=i(function(){if(h)return y;h=1;const e=C();return y=e}());module.exports=S; From ac19bd12ffb9286f78fd70cffe8686fa0ca1454e Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 9 Jun 2025 20:26:05 -0700 Subject: [PATCH 3/6] RN: Private Package for Monorepo ESLint Rules (#51858) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51858 Creates a new private package for the ESLint rules that are defined in the `facebook/react-native` repository for linting the monorepo itself: `react-native/eslint-plugin-monorepo` It resides in a new `private/` directory that will be used for all private packages. I plan to move private packages over from `packages/` and `tools/`. This also eliminates the need for the `eslint-plugin-lint` dependency in open source. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D76088698 --- .eslintrc.js | 28 ++++++++----------- jest/preprocessor.js | 2 +- package.json | 2 +- packages/assets/registry.js | 2 +- packages/helloworld/cli.js | 2 +- .../__mocks__/MessageQueueTestConfig.js | 4 +-- .../__mocks__/MessageQueueTestModule.js | 2 +- .../Libraries/Image/RelativeImageStub.js | 2 +- .../ReactNativePrivateInterface.js | 2 +- .../private/webapis/errors/DOMException.js | 2 +- .../performance/__tests__/Performance-test.js | 3 +- packages/rn-tester/cli.js | 2 +- private/eslint-plugin-monorepo/README.md | 7 +++++ .../__tests__/eslintrc-test.js | 4 +-- private/eslint-plugin-monorepo/index.js | 22 +++++++++++++++ .../eslint-plugin-monorepo}/package.json | 3 +- .../__tests__/no-commonjs-exports-test.js | 0 .../rules/__tests__/no-haste-imports-test.js | 0 .../__tests__/no-react-default-imports.js | 0 .../__tests__/no-react-named-type-imports.js | 0 .../__tests__/no-react-native-imports-test.js | 0 .../__tests__/no-react-node-imports-test.js | 0 .../__tests__/react-native-manifest-test.js | 0 .../__tests__/require-extends-error-test.js | 0 .../valid-flow-typed-signature-test.js | 0 .../rules/no-commonjs-exports.js | 0 .../rules/no-haste-imports.js | 0 .../rules/no-react-default-imports.js | 0 .../rules/no-react-named-type-imports.js | 0 .../rules/no-react-native-imports.js | 0 .../rules/no-react-node-imports.js | 0 .../rules/react-native-manifest.js | 0 .../rules/require-extends-error.js | 0 .../rules/sort-imports.js | 0 .../rules/valid-flow-typed-signature.js | 0 tools/eslint/README.md | 7 ----- yarn.lock | 5 ---- 37 files changed, 57 insertions(+), 44 deletions(-) create mode 100644 private/eslint-plugin-monorepo/README.md rename {tools/eslint => private/eslint-plugin-monorepo}/__tests__/eslintrc-test.js (89%) create mode 100644 private/eslint-plugin-monorepo/index.js rename {tools/eslint => private/eslint-plugin-monorepo}/package.json (59%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/no-commonjs-exports-test.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/no-haste-imports-test.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/no-react-default-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/no-react-named-type-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/no-react-native-imports-test.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/no-react-node-imports-test.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/react-native-manifest-test.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/require-extends-error-test.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/__tests__/valid-flow-typed-signature-test.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/no-commonjs-exports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/no-haste-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/no-react-default-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/no-react-named-type-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/no-react-native-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/no-react-node-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/react-native-manifest.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/require-extends-error.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/sort-imports.js (100%) rename {tools/eslint => private/eslint-plugin-monorepo}/rules/valid-flow-typed-signature.js (100%) delete mode 100644 tools/eslint/README.md diff --git a/.eslintrc.js b/.eslintrc.js index 829535a3520e..8d4f88b4931c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,16 +10,12 @@ 'use strict'; -const path = require('node:path'); - -require('eslint-plugin-lint').load(path.join(__dirname, 'tools/eslint/rules')); - module.exports = { root: true, extends: ['@react-native'], - plugins: ['@react-native/eslint-plugin-specs', 'lint'], + plugins: ['@react-native/monorepo', '@react-native/specs'], overrides: [ // overriding the JS config from @react-native/eslint-config to ensure @@ -28,6 +24,7 @@ module.exports = { files: ['*.js', '*.js.flow', '*.jsx'], parser: 'hermes-eslint', rules: { + '@react-native/monorepo/sort-imports': 1, 'eslint-comments/no-unlimited-disable': 0, 'ft-flow/require-valid-file-annotation': [2, 'always'], 'no-extra-boolean-cast': 0, @@ -35,7 +32,6 @@ module.exports = { // These rules are not required with hermes-eslint 'ft-flow/define-flow-type': 0, 'ft-flow/use-flow-type': 0, - 'lint/sort-imports': 1, // Flow handles these checks for us, so they aren't required 'no-undef': 0, 'no-unreachable': 0, @@ -55,7 +51,7 @@ module.exports = { ], parser: 'hermes-eslint', rules: { - 'lint/no-commonjs-exports': 1, + '@react-native/monorepo/no-commonjs-exports': 1, }, }, { @@ -65,14 +61,14 @@ module.exports = { { files: ['package.json'], rules: { - 'lint/react-native-manifest': 2, + '@react-native/monorepo/react-native-manifest': 2, }, }, { files: ['flow-typed/**/*.js', 'packages/react-native/flow/**/*'], rules: { + '@react-native/monorepo/valid-flow-typed-signature': 2, 'ft-flow/require-valid-file-annotation': 0, - 'lint/valid-flow-typed-signature': 2, 'no-shadow': 0, 'no-unused-vars': 0, quotes: 0, @@ -84,14 +80,14 @@ module.exports = { 'packages/react-native/src/**/*.js', ], rules: { + '@react-native/monorepo/no-haste-imports': 2, + '@react-native/monorepo/no-react-default-imports': 2, + '@react-native/monorepo/no-react-named-type-imports': 2, + '@react-native/monorepo/no-react-native-imports': 2, + '@react-native/monorepo/no-react-node-imports': 2, + '@react-native/monorepo/require-extends-error': 2, '@react-native/platform-colors': 2, '@react-native/specs/react-native-modules': 2, - 'lint/no-haste-imports': 2, - 'lint/no-react-native-imports': 2, - 'lint/require-extends-error': 2, - 'lint/no-react-node-imports': 2, - 'lint/no-react-default-imports': 2, - 'lint/no-react-named-type-imports': 2, }, }, { @@ -145,7 +141,7 @@ module.exports = { { files: ['**/__tests__/**'], rules: { - 'lint/no-react-native-imports': 'off', + '@react-native/monorepo/no-react-native-imports': 'off', }, }, ], diff --git a/jest/preprocessor.js b/jest/preprocessor.js index e1084b1972a2..7436bac2d092 100644 --- a/jest/preprocessor.js +++ b/jest/preprocessor.js @@ -12,7 +12,7 @@ 'use strict'; -// eslint-disable-next-line lint/sort-imports +// eslint-disable-next-line @react-native/monorepo/sort-imports const { transformFromAstSync: babelTransformFromAstSync, transformSync: babelTransformSync, diff --git a/package.json b/package.json index 3e34e5985dd4..da64b27fd679 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "workspaces": [ "packages/*", + "private/*", "tools/*", "!packages/helloworld" ], @@ -73,7 +74,6 @@ "eslint-plugin-ft-flow": "^2.0.1", "eslint-plugin-jest": "^27.9.0", "eslint-plugin-jsx-a11y": "^6.6.0", - "eslint-plugin-lint": "^1.0.0", "eslint-plugin-react": "^7.30.1", "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-native": "^4.0.0", diff --git a/packages/assets/registry.js b/packages/assets/registry.js index f4f1a722eb51..435bd519411f 100644 --- a/packages/assets/registry.js +++ b/packages/assets/registry.js @@ -40,5 +40,5 @@ function getAssetByID(assetId /*: number */) /*: PackagerAsset */ { return assets[assetId - 1]; } -// eslint-disable-next-line lint/no-commonjs-exports +// eslint-disable-next-line @react-native/monorepo/no-commonjs-exports module.exports = {registerAsset, getAssetByID}; diff --git a/packages/helloworld/cli.js b/packages/helloworld/cli.js index 130210dd9a8b..3dfd0fbc8533 100644 --- a/packages/helloworld/cli.js +++ b/packages/helloworld/cli.js @@ -12,7 +12,7 @@ import {Command} from 'commander'; */ -// eslint-disable-next-line lint/sort-imports +// eslint-disable-next-line @react-native/monorepo/sort-imports const {patchCoreCLIUtilsPackageJSON} = require('./scripts/monorepo'); function injectCoreCLIUtilsRuntimePatch() { diff --git a/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js b/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js index 7ec2c962ecd5..92b6b07beb22 100644 --- a/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js +++ b/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js @@ -8,8 +8,6 @@ * @format */ -// These don't actually exist anywhere in the code. - 'use strict'; import type {ModuleConfig} from '../NativeModules'; @@ -35,5 +33,5 @@ const MessageQueueTestConfig = { remoteModuleConfig: remoteModulesConfig, }; -// eslint-disable-next-line lint/no-commonjs-exports +// eslint-disable-next-line @react-native/monorepo/no-commonjs-exports module.exports = MessageQueueTestConfig; diff --git a/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js b/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js index f015faeac65f..fa691273e51d 100644 --- a/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js +++ b/packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js @@ -20,5 +20,5 @@ const MessageQueueTestModule = { testHook2: function () {}, }; -// eslint-disable-next-line lint/no-commonjs-exports +// eslint-disable-next-line @react-native/monorepo/no-commonjs-exports module.exports = MessageQueueTestModule; diff --git a/packages/react-native/Libraries/Image/RelativeImageStub.js b/packages/react-native/Libraries/Image/RelativeImageStub.js index b31526af5422..ba1f050a0f8e 100644 --- a/packages/react-native/Libraries/Image/RelativeImageStub.js +++ b/packages/react-native/Libraries/Image/RelativeImageStub.js @@ -27,5 +27,5 @@ const RelativeImageStub = (AssetRegistry.registerAsset({ type: 'png', }): number); -// eslint-disable-next-line lint/no-commonjs-exports +// eslint-disable-next-line @react-native/monorepo/no-commonjs-exports module.exports = RelativeImageStub; diff --git a/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js b/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js index adaa496047d0..3caf81f8c06c 100644 --- a/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js +++ b/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js @@ -51,7 +51,7 @@ export type {PublicRootInstance} from '../ReactNative/ReactFabricPublicInstance/ export type PublicTextInstance = ReturnType; // flowlint unsafe-getters-setters:off -// eslint-disable-next-line lint/no-commonjs-exports +// eslint-disable-next-line @react-native/monorepo/no-commonjs-exports module.exports = { get BatchedBridge(): BatchedBridge { return require('../BatchedBridge/BatchedBridge').default; diff --git a/packages/react-native/src/private/webapis/errors/DOMException.js b/packages/react-native/src/private/webapis/errors/DOMException.js index 3dbb0469f12e..b759632d0a9e 100644 --- a/packages/react-native/src/private/webapis/errors/DOMException.js +++ b/packages/react-native/src/private/webapis/errors/DOMException.js @@ -70,7 +70,7 @@ const ERROR_CODES: {[string]: number} = { DATA_CLONE_ERR: 25, }; -/* eslint-disable lint/require-extends-error */ +/* eslint-disable @react-native/monorepo/require-extends-error */ // $FlowExpectedError[incompatible-variance] name is writable in Error but not in DOMException, but this is how it works on Web. export default class DOMException extends Error { static +INDEX_SIZE_ERR: 1; diff --git a/packages/react-native/src/private/webapis/performance/__tests__/Performance-test.js b/packages/react-native/src/private/webapis/performance/__tests__/Performance-test.js index 606e6ee26155..292ee6674cec 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/Performance-test.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/Performance-test.js @@ -8,8 +8,9 @@ * @format */ -// eslint-disable-next-line lint/sort-imports +// eslint-disable-next-line @react-native/monorepo/sort-imports import type Performance from '../Performance'; + import {performanceEntryTypeToRaw} from '../internals/RawPerformanceEntry'; import {reportEntry} from '../specs/__mocks__/NativePerformanceMock'; diff --git a/packages/rn-tester/cli.js b/packages/rn-tester/cli.js index 130210dd9a8b..3dfd0fbc8533 100644 --- a/packages/rn-tester/cli.js +++ b/packages/rn-tester/cli.js @@ -12,7 +12,7 @@ import {Command} from 'commander'; */ -// eslint-disable-next-line lint/sort-imports +// eslint-disable-next-line @react-native/monorepo/sort-imports const {patchCoreCLIUtilsPackageJSON} = require('./scripts/monorepo'); function injectCoreCLIUtilsRuntimePatch() { diff --git a/private/eslint-plugin-monorepo/README.md b/private/eslint-plugin-monorepo/README.md new file mode 100644 index 000000000000..8b6f2ed7f32e --- /dev/null +++ b/private/eslint-plugin-monorepo/README.md @@ -0,0 +1,7 @@ +# @react-native/eslint-plugin-monorepo + +This is a private package that contains ESLint rules for `react-native` itself. +They are configured in the `.eslintrc.js` at the repository root. + +For ESLint rules intended for projects that consume React Native, add them to +the `@react-native-community/eslint-plugin` package instead. diff --git a/tools/eslint/__tests__/eslintrc-test.js b/private/eslint-plugin-monorepo/__tests__/eslintrc-test.js similarity index 89% rename from tools/eslint/__tests__/eslintrc-test.js rename to private/eslint-plugin-monorepo/__tests__/eslintrc-test.js index 8037b65e5e1a..9cf50d6dd572 100644 --- a/tools/eslint/__tests__/eslintrc-test.js +++ b/private/eslint-plugin-monorepo/__tests__/eslintrc-test.js @@ -15,7 +15,7 @@ import path from 'path'; const REPO_DIR = path.resolve(__dirname, '..', '..', '..'); describe('react-native/.eslintrc.js', () => { - describe('lint/sort-imports', () => { + describe('@react-native/monorepo/sort-imports', () => { const testDirectories = [ '.', 'packages/react-native', @@ -35,7 +35,7 @@ describe('react-native/.eslintrc.js', () => { expect(config).toHaveProperty( 'rules', expect.objectContaining({ - 'lint/sort-imports': expect.arrayContaining([1]), + '@react-native/monorepo/sort-imports': expect.arrayContaining([1]), }), ); }); diff --git a/private/eslint-plugin-monorepo/index.js b/private/eslint-plugin-monorepo/index.js new file mode 100644 index 000000000000..6b34791bc03b --- /dev/null +++ b/private/eslint-plugin-monorepo/index.js @@ -0,0 +1,22 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +exports.rules = { + 'no-commonjs-exports': require('./rules/no-commonjs-exports'), + 'no-haste-imports': require('./rules/no-haste-imports'), + 'no-react-default-imports': require('./rules/no-react-default-imports'), + 'no-react-named-type-imports': require('./rules/no-react-named-type-imports'), + 'no-react-native-imports': require('./rules/no-react-native-imports'), + 'no-react-node-imports': require('./rules/no-react-node-imports'), + 'react-native-manifest': require('./rules/react-native-manifest'), + 'require-extends-error': require('./rules/require-extends-error'), + 'sort-imports': require('./rules/sort-imports'), + 'valid-flow-typed-signature': require('./rules/valid-flow-typed-signature'), +}; diff --git a/tools/eslint/package.json b/private/eslint-plugin-monorepo/package.json similarity index 59% rename from tools/eslint/package.json rename to private/eslint-plugin-monorepo/package.json index 8a45d1133bbc..ed92f37d19ca 100644 --- a/tools/eslint/package.json +++ b/private/eslint-plugin-monorepo/package.json @@ -1,7 +1,8 @@ { - "name": "@react-native/eslint", + "name": "@react-native/eslint-plugin-monorepo", "private": true, "version": "0.0.0", + "main": "index.js", "dependencies": { "jsonc-eslint-parser": "^2.3.0" } diff --git a/tools/eslint/rules/__tests__/no-commonjs-exports-test.js b/private/eslint-plugin-monorepo/rules/__tests__/no-commonjs-exports-test.js similarity index 100% rename from tools/eslint/rules/__tests__/no-commonjs-exports-test.js rename to private/eslint-plugin-monorepo/rules/__tests__/no-commonjs-exports-test.js diff --git a/tools/eslint/rules/__tests__/no-haste-imports-test.js b/private/eslint-plugin-monorepo/rules/__tests__/no-haste-imports-test.js similarity index 100% rename from tools/eslint/rules/__tests__/no-haste-imports-test.js rename to private/eslint-plugin-monorepo/rules/__tests__/no-haste-imports-test.js diff --git a/tools/eslint/rules/__tests__/no-react-default-imports.js b/private/eslint-plugin-monorepo/rules/__tests__/no-react-default-imports.js similarity index 100% rename from tools/eslint/rules/__tests__/no-react-default-imports.js rename to private/eslint-plugin-monorepo/rules/__tests__/no-react-default-imports.js diff --git a/tools/eslint/rules/__tests__/no-react-named-type-imports.js b/private/eslint-plugin-monorepo/rules/__tests__/no-react-named-type-imports.js similarity index 100% rename from tools/eslint/rules/__tests__/no-react-named-type-imports.js rename to private/eslint-plugin-monorepo/rules/__tests__/no-react-named-type-imports.js diff --git a/tools/eslint/rules/__tests__/no-react-native-imports-test.js b/private/eslint-plugin-monorepo/rules/__tests__/no-react-native-imports-test.js similarity index 100% rename from tools/eslint/rules/__tests__/no-react-native-imports-test.js rename to private/eslint-plugin-monorepo/rules/__tests__/no-react-native-imports-test.js diff --git a/tools/eslint/rules/__tests__/no-react-node-imports-test.js b/private/eslint-plugin-monorepo/rules/__tests__/no-react-node-imports-test.js similarity index 100% rename from tools/eslint/rules/__tests__/no-react-node-imports-test.js rename to private/eslint-plugin-monorepo/rules/__tests__/no-react-node-imports-test.js diff --git a/tools/eslint/rules/__tests__/react-native-manifest-test.js b/private/eslint-plugin-monorepo/rules/__tests__/react-native-manifest-test.js similarity index 100% rename from tools/eslint/rules/__tests__/react-native-manifest-test.js rename to private/eslint-plugin-monorepo/rules/__tests__/react-native-manifest-test.js diff --git a/tools/eslint/rules/__tests__/require-extends-error-test.js b/private/eslint-plugin-monorepo/rules/__tests__/require-extends-error-test.js similarity index 100% rename from tools/eslint/rules/__tests__/require-extends-error-test.js rename to private/eslint-plugin-monorepo/rules/__tests__/require-extends-error-test.js diff --git a/tools/eslint/rules/__tests__/valid-flow-typed-signature-test.js b/private/eslint-plugin-monorepo/rules/__tests__/valid-flow-typed-signature-test.js similarity index 100% rename from tools/eslint/rules/__tests__/valid-flow-typed-signature-test.js rename to private/eslint-plugin-monorepo/rules/__tests__/valid-flow-typed-signature-test.js diff --git a/tools/eslint/rules/no-commonjs-exports.js b/private/eslint-plugin-monorepo/rules/no-commonjs-exports.js similarity index 100% rename from tools/eslint/rules/no-commonjs-exports.js rename to private/eslint-plugin-monorepo/rules/no-commonjs-exports.js diff --git a/tools/eslint/rules/no-haste-imports.js b/private/eslint-plugin-monorepo/rules/no-haste-imports.js similarity index 100% rename from tools/eslint/rules/no-haste-imports.js rename to private/eslint-plugin-monorepo/rules/no-haste-imports.js diff --git a/tools/eslint/rules/no-react-default-imports.js b/private/eslint-plugin-monorepo/rules/no-react-default-imports.js similarity index 100% rename from tools/eslint/rules/no-react-default-imports.js rename to private/eslint-plugin-monorepo/rules/no-react-default-imports.js diff --git a/tools/eslint/rules/no-react-named-type-imports.js b/private/eslint-plugin-monorepo/rules/no-react-named-type-imports.js similarity index 100% rename from tools/eslint/rules/no-react-named-type-imports.js rename to private/eslint-plugin-monorepo/rules/no-react-named-type-imports.js diff --git a/tools/eslint/rules/no-react-native-imports.js b/private/eslint-plugin-monorepo/rules/no-react-native-imports.js similarity index 100% rename from tools/eslint/rules/no-react-native-imports.js rename to private/eslint-plugin-monorepo/rules/no-react-native-imports.js diff --git a/tools/eslint/rules/no-react-node-imports.js b/private/eslint-plugin-monorepo/rules/no-react-node-imports.js similarity index 100% rename from tools/eslint/rules/no-react-node-imports.js rename to private/eslint-plugin-monorepo/rules/no-react-node-imports.js diff --git a/tools/eslint/rules/react-native-manifest.js b/private/eslint-plugin-monorepo/rules/react-native-manifest.js similarity index 100% rename from tools/eslint/rules/react-native-manifest.js rename to private/eslint-plugin-monorepo/rules/react-native-manifest.js diff --git a/tools/eslint/rules/require-extends-error.js b/private/eslint-plugin-monorepo/rules/require-extends-error.js similarity index 100% rename from tools/eslint/rules/require-extends-error.js rename to private/eslint-plugin-monorepo/rules/require-extends-error.js diff --git a/tools/eslint/rules/sort-imports.js b/private/eslint-plugin-monorepo/rules/sort-imports.js similarity index 100% rename from tools/eslint/rules/sort-imports.js rename to private/eslint-plugin-monorepo/rules/sort-imports.js diff --git a/tools/eslint/rules/valid-flow-typed-signature.js b/private/eslint-plugin-monorepo/rules/valid-flow-typed-signature.js similarity index 100% rename from tools/eslint/rules/valid-flow-typed-signature.js rename to private/eslint-plugin-monorepo/rules/valid-flow-typed-signature.js diff --git a/tools/eslint/README.md b/tools/eslint/README.md deleted file mode 100644 index 116e749329df..000000000000 --- a/tools/eslint/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# react-native/tools/eslint - -This directory contains ESLint rules for the `react-native` repository itself. -They are configured in `.eslintrc.js` using the `eslint-plugin-lint` package. - -For ESLint rules intended for projects that consume React Native, add them to -the `@react-native-community/eslint-plugin` package instead. diff --git a/yarn.lock b/yarn.lock index 23b8950d5577..092522edcffa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4027,11 +4027,6 @@ eslint-plugin-jsx-a11y@^6.6.0: safe-regex-test "^1.0.3" string.prototype.includes "^2.0.0" -eslint-plugin-lint@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-lint/-/eslint-plugin-lint-1.0.0.tgz#bfc98ad0d1b5ea437b0072ec735c459df4d084b5" - integrity sha512-hYl6F/lYLjycZmHYnpTk3dlliNxjy9breG/9URhdQmPZibmENjM378EPKvSdIDBOV+Zw/Z0d3EaJhLTjcWTovA== - eslint-plugin-react-hooks@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-5.2.0.tgz#1be0080901e6ac31ce7971beed3d3ec0a423d9e3" From c849299bb23d8459cec583b678e2fdbeaa88df28 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 9 Jun 2025 20:26:05 -0700 Subject: [PATCH 4/6] RN: Standardize ESLint Severity Levels (#51863) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51863 Standardizes lint severity in `.eslintrc.js` to use the string format. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D76098593 --- .eslintrc.js | 50 +++++++++---------- .../__tests__/eslintrc-test.js | 4 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8d4f88b4931c..a6d2c177a278 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,23 +24,23 @@ module.exports = { files: ['*.js', '*.js.flow', '*.jsx'], parser: 'hermes-eslint', rules: { - '@react-native/monorepo/sort-imports': 1, - 'eslint-comments/no-unlimited-disable': 0, - 'ft-flow/require-valid-file-annotation': [2, 'always'], - 'no-extra-boolean-cast': 0, - 'no-void': 0, + '@react-native/monorepo/sort-imports': 'warn', + 'eslint-comments/no-unlimited-disable': 'off', + 'ft-flow/require-valid-file-annotation': ['error', 'always'], + 'no-extra-boolean-cast': 'off', + 'no-void': 'off', // These rules are not required with hermes-eslint - 'ft-flow/define-flow-type': 0, - 'ft-flow/use-flow-type': 0, + 'ft-flow/define-flow-type': 'off', + 'ft-flow/use-flow-type': 'off', // Flow handles these checks for us, so they aren't required - 'no-undef': 0, - 'no-unreachable': 0, + 'no-undef': 'off', + 'no-unreachable': 'off', }, }, { files: ['*.js', '*.jsx', '*.ts', '*.tsx'], rules: { - '@react-native/no-deep-imports': 0, + '@react-native/no-deep-imports': 'off', }, }, { @@ -51,7 +51,7 @@ module.exports = { ], parser: 'hermes-eslint', rules: { - '@react-native/monorepo/no-commonjs-exports': 1, + '@react-native/monorepo/no-commonjs-exports': 'warn', }, }, { @@ -61,17 +61,17 @@ module.exports = { { files: ['package.json'], rules: { - '@react-native/monorepo/react-native-manifest': 2, + '@react-native/monorepo/react-native-manifest': 'error', }, }, { files: ['flow-typed/**/*.js', 'packages/react-native/flow/**/*'], rules: { - '@react-native/monorepo/valid-flow-typed-signature': 2, - 'ft-flow/require-valid-file-annotation': 0, - 'no-shadow': 0, - 'no-unused-vars': 0, - quotes: 0, + '@react-native/monorepo/valid-flow-typed-signature': 'error', + 'ft-flow/require-valid-file-annotation': 'off', + 'no-shadow': 'off', + 'no-unused-vars': 'off', + quotes: 'off', }, }, { @@ -80,14 +80,14 @@ module.exports = { 'packages/react-native/src/**/*.js', ], rules: { - '@react-native/monorepo/no-haste-imports': 2, - '@react-native/monorepo/no-react-default-imports': 2, - '@react-native/monorepo/no-react-named-type-imports': 2, - '@react-native/monorepo/no-react-native-imports': 2, - '@react-native/monorepo/no-react-node-imports': 2, - '@react-native/monorepo/require-extends-error': 2, - '@react-native/platform-colors': 2, - '@react-native/specs/react-native-modules': 2, + '@react-native/monorepo/no-haste-imports': 'error', + '@react-native/monorepo/no-react-default-imports': 'error', + '@react-native/monorepo/no-react-named-type-imports': 'error', + '@react-native/monorepo/no-react-native-imports': 'error', + '@react-native/monorepo/no-react-node-imports': 'error', + '@react-native/monorepo/require-extends-error': 'error', + '@react-native/platform-colors': 'error', + '@react-native/specs/react-native-modules': 'error', }, }, { diff --git a/private/eslint-plugin-monorepo/__tests__/eslintrc-test.js b/private/eslint-plugin-monorepo/__tests__/eslintrc-test.js index 9cf50d6dd572..3430d857310a 100644 --- a/private/eslint-plugin-monorepo/__tests__/eslintrc-test.js +++ b/private/eslint-plugin-monorepo/__tests__/eslintrc-test.js @@ -35,7 +35,9 @@ describe('react-native/.eslintrc.js', () => { expect(config).toHaveProperty( 'rules', expect.objectContaining({ - '@react-native/monorepo/sort-imports': expect.arrayContaining([1]), + '@react-native/monorepo/sort-imports': expect.arrayContaining([ + 'warn', + ]), }), ); }); From ce6c41600a64abaea3df9086ab119ead4b4dfe7d Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 9 Jun 2025 20:26:05 -0700 Subject: [PATCH 5/6] RN: Move `tools/api` to `private/cxx-public-api` (#51859) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51859 Moves `tools/apis` to `private/cxx-public-api` and cleans up a few things: - Clean up the `BUCK` file a bit. - Deduplicate relative paths in scripts. - Prefix the private package name with `react-native/`. Changelog: [Internal] Reviewed By: huntie Differential Revision: D76091765 --- package.json | 1 - {tools/api => private/cxx-public-api}/ReactNativeCPP.api | 0 {tools/api => private/cxx-public-api}/check-api.sh | 9 +++++---- {tools/api => private/cxx-public-api}/package.json | 2 +- {tools/api => private/cxx-public-api}/public-api.conf | 2 +- {tools/api => private/cxx-public-api}/public-api.js | 0 6 files changed, 7 insertions(+), 7 deletions(-) rename {tools/api => private/cxx-public-api}/ReactNativeCPP.api (100%) rename {tools/api => private/cxx-public-api}/check-api.sh (91%) rename {tools/api => private/cxx-public-api}/package.json (89%) rename {tools/api => private/cxx-public-api}/public-api.conf (94%) rename {tools/api => private/cxx-public-api}/public-api.js (100%) diff --git a/package.json b/package.json index da64b27fd679..e4e32d0abae7 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "workspaces": [ "packages/*", "private/*", - "tools/*", "!packages/helloworld" ], "devDependencies": { diff --git a/tools/api/ReactNativeCPP.api b/private/cxx-public-api/ReactNativeCPP.api similarity index 100% rename from tools/api/ReactNativeCPP.api rename to private/cxx-public-api/ReactNativeCPP.api diff --git a/tools/api/check-api.sh b/private/cxx-public-api/check-api.sh similarity index 91% rename from tools/api/check-api.sh rename to private/cxx-public-api/check-api.sh index 02f79634006e..3bf419aa7a9e 100755 --- a/tools/api/check-api.sh +++ b/private/cxx-public-api/check-api.sh @@ -73,12 +73,13 @@ pushd "$FBSOURCE_ROOT/xplat/js/react-native-github" || exit $ERR_CODE_CANT_FIND_ trap cleanup EXIT # TODO: This operates in the sandbox and can't modify files in the repository, which we need for change detection -# buck2 run //xplat/js/react-native-github/tools/api:public-api -(cd tools/api && $YARN_BINARY install) -$NODE_BINARY tools/api/public-api.js +# buck2 run //xplat/js/react-native-github/private/cxx-public-api:public-api +REPO_RELATIVE_DIR="private/cxx-public-api" +(cd "$REPO_RELATIVE_DIR" && $YARN_BINARY install) +$NODE_BINARY "$REPO_RELATIVE_DIR/public-api.js" echo -API_FILE=$(grep -oP '(?<=output=)[^ \n]+' tools/api/public-api.conf) +API_FILE=$(grep -oP '(?<=output=)[^ \n]+' "$REPO_RELATIVE_DIR/public-api.conf") API_STATUS=$(hg status --no-status "$API_FILE") if [ -z "$API_STATUS" ]; then diff --git a/tools/api/package.json b/private/cxx-public-api/package.json similarity index 89% rename from tools/api/package.json rename to private/cxx-public-api/package.json index e0e092d23386..11e3c5cb75ea 100644 --- a/tools/api/package.json +++ b/private/cxx-public-api/package.json @@ -1,5 +1,5 @@ { - "name": "public-api", + "name": "@react-native/cxx-public-api", "version": "0.0.1", "description": "Captures the Objective-C / C++ public API of React Native", "main": "public-api.js", diff --git a/tools/api/public-api.conf b/private/cxx-public-api/public-api.conf similarity index 94% rename from tools/api/public-api.conf rename to private/cxx-public-api/public-api.conf index cc34a11319cb..1abb1b3ef23d 100644 --- a/tools/api/public-api.conf +++ b/private/cxx-public-api/public-api.conf @@ -22,6 +22,6 @@ packages/react-native/Libraries/WebSocket/* packages/react-native/Libraries/Wrapper/Example/* [settings] -output=tools/api/ReactNativeCPP.api +output=private/cxx-public-api/ReactNativeCPP.api ; clang=$HOME/some/path/to/clang ; clang-format=$HOME/some/path/to/clang-format diff --git a/tools/api/public-api.js b/private/cxx-public-api/public-api.js similarity index 100% rename from tools/api/public-api.js rename to private/cxx-public-api/public-api.js From a02e8681dde3e9d10a160edb559a596b8f099acb Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Mon, 9 Jun 2025 20:30:45 -0700 Subject: [PATCH 6/6] RN: Move `{tools => private/monorepo-tests}/__tests__ (#51862) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51862 Moves the dependency tests in `tools/__tests__` to `private/monorepo-tests/__tests__`, allowing us to delete the now-vacant `tools/` directory. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D76098157 --- .../__tests__/no-dependencies-in-root-package-test.js | 1 + .../no-dev-dependencies-in-react-native-package-test.js | 1 + .../__tests__/no-dev-dependencies-in-tester-package.js | 1 + private/monorepo-tests/package.json | 5 +++++ 4 files changed, 8 insertions(+) rename {tools => private/monorepo-tests}/__tests__/no-dependencies-in-root-package-test.js (98%) rename {tools => private/monorepo-tests}/__tests__/no-dev-dependencies-in-react-native-package-test.js (98%) rename {tools => private/monorepo-tests}/__tests__/no-dev-dependencies-in-tester-package.js (98%) create mode 100644 private/monorepo-tests/package.json diff --git a/tools/__tests__/no-dependencies-in-root-package-test.js b/private/monorepo-tests/__tests__/no-dependencies-in-root-package-test.js similarity index 98% rename from tools/__tests__/no-dependencies-in-root-package-test.js rename to private/monorepo-tests/__tests__/no-dependencies-in-root-package-test.js index ca6fe3157983..9bc646c0dbbe 100644 --- a/tools/__tests__/no-dependencies-in-root-package-test.js +++ b/private/monorepo-tests/__tests__/no-dependencies-in-root-package-test.js @@ -16,6 +16,7 @@ const PATH_TO_ROOT_PACKAGE_MANIFEST = path.join( CURRENT_DIR, '..', '..', + '..', 'package.json', ); diff --git a/tools/__tests__/no-dev-dependencies-in-react-native-package-test.js b/private/monorepo-tests/__tests__/no-dev-dependencies-in-react-native-package-test.js similarity index 98% rename from tools/__tests__/no-dev-dependencies-in-react-native-package-test.js rename to private/monorepo-tests/__tests__/no-dev-dependencies-in-react-native-package-test.js index fdb8e13737dc..0ce252a19469 100644 --- a/tools/__tests__/no-dev-dependencies-in-react-native-package-test.js +++ b/private/monorepo-tests/__tests__/no-dev-dependencies-in-react-native-package-test.js @@ -16,6 +16,7 @@ const PATH_TO_REACT_NATIVE_PACKAGE_MANIFEST = path.join( CURRENT_DIR, '..', '..', + '..', 'packages', 'react-native', 'package.json', diff --git a/tools/__tests__/no-dev-dependencies-in-tester-package.js b/private/monorepo-tests/__tests__/no-dev-dependencies-in-tester-package.js similarity index 98% rename from tools/__tests__/no-dev-dependencies-in-tester-package.js rename to private/monorepo-tests/__tests__/no-dev-dependencies-in-tester-package.js index 44248788aad4..3a3e48430c13 100644 --- a/tools/__tests__/no-dev-dependencies-in-tester-package.js +++ b/private/monorepo-tests/__tests__/no-dev-dependencies-in-tester-package.js @@ -16,6 +16,7 @@ const PATH_TO_TESTER_PACKAGE_MANIFEST = path.join( CURRENT_DIR, '..', '..', + '..', 'packages', 'rn-tester', 'package.json', diff --git a/private/monorepo-tests/package.json b/private/monorepo-tests/package.json new file mode 100644 index 000000000000..10725c529541 --- /dev/null +++ b/private/monorepo-tests/package.json @@ -0,0 +1,5 @@ +{ + "name": "@react-native/monorepo-tests", + "private": true, + "version": "0.0.0" +}