From ba092bfaba9f9e1079cba2be74083972195d44aa Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 16 May 2025 18:09:09 -0700 Subject: [PATCH] RN: Add Missing `@format` Annotations (#51415) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51415 Adds the `format` annotation to all files that were missing them. Also, adds `noformat` to generated files, and removed it from files that no longer need them. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D74901034 fbshipit-source-id: 7e0b85ca8ee2de41278f3aa23cb03e9c266d9c28 --- packages/debugger-frontend/index.js | 4 +- packages/helloworld/.prettierrc.js | 2 + .../plugin-warn-on-deep-imports-test.js | 2 + .../scripts/build.js | 64 +++++++--- .../react-native.config.js | 4 +- .../scripts/prepublish-popup-menu-android.js | 11 +- .../react-native-test-library/babel.config.js | 9 +- .../react-native.config.js | 4 +- .../Components/__tests__/Button-test.js | 72 ++++++++--- .../Libraries/Core/ReactNativeVersion.js | 1 + ...tiveReactNativeFeatureFlags.js-template.js | 1 + .../js/ReactNativeFeatureFlags.js-template.js | 1 + .../featureflags/ReactNativeFeatureFlags.js | 3 +- .../specs/NativeReactNativeFeatureFlags.js | 3 +- .../ScrollViewIndicatorInsetsIOSExample.js | 118 +++++++++++------- .../ScrollViewKeyboardInsetsIOSExample.js | 85 ++++++++----- .../set-rn-artifacts-version-test.js.snap | 2 + .../ReactNativeVersion.js-template.js | 1 + 18 files changed, 268 insertions(+), 119 deletions(-) diff --git a/packages/debugger-frontend/index.js b/packages/debugger-frontend/index.js index 907eb1d74fd..ecd558a5d28 100644 --- a/packages/debugger-frontend/index.js +++ b/packages/debugger-frontend/index.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @flow strict-local - * @noformat + * @format */ const path = require('path'); @@ -33,4 +33,4 @@ if (process.env.REACT_NATIVE_DEBUGGER_FRONTEND_PATH != null) { ); } -module.exports = (frontEndPath /*: string */); +module.exports = frontEndPath /*:: as string */; diff --git a/packages/helloworld/.prettierrc.js b/packages/helloworld/.prettierrc.js index 27d8bb6e9ae..e7f500b19a6 100644 --- a/packages/helloworld/.prettierrc.js +++ b/packages/helloworld/.prettierrc.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ module.exports = { diff --git a/packages/react-native-babel-preset/src/__tests__/plugin-warn-on-deep-imports-test.js b/packages/react-native-babel-preset/src/__tests__/plugin-warn-on-deep-imports-test.js index 6858ba18d4f..97eb16d0c8f 100644 --- a/packages/react-native-babel-preset/src/__tests__/plugin-warn-on-deep-imports-test.js +++ b/packages/react-native-babel-preset/src/__tests__/plugin-warn-on-deep-imports-test.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ 'use strict'; diff --git a/packages/react-native-codegen-typescript-test/scripts/build.js b/packages/react-native-codegen-typescript-test/scripts/build.js index e52efdd0461..8148f26408d 100644 --- a/packages/react-native-codegen-typescript-test/scripts/build.js +++ b/packages/react-native-codegen-typescript-test/scripts/build.js @@ -3,25 +3,45 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format + * @lint-ignore-every LICENSELINT */ const fs = require('fs'); const path = require('path'); -const tsComponentFixturePath = path.join(__dirname, '../../react-native-codegen/src/parsers/typescript/components/__test_fixtures__/fixtures.js'); -const tsComponentSnapshotPath = path.join(__dirname, '../../react-native-codegen/src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap'); -const tsModuleFixturePath = path.join(__dirname, '../../react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/fixtures.js'); -const tsModuleSnapshotPath = path.join(__dirname, '../../react-native-codegen/src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap'); +const tsComponentFixturePath = path.join( + __dirname, + '../../react-native-codegen/src/parsers/typescript/components/__test_fixtures__/fixtures.js', +); +const tsComponentSnapshotPath = path.join( + __dirname, + '../../react-native-codegen/src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap', +); +const tsModuleFixturePath = path.join( + __dirname, + '../../react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/fixtures.js', +); +const tsModuleSnapshotPath = path.join( + __dirname, + '../../react-native-codegen/src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap', +); const snapshotOutputPath = path.join(__dirname, '../__generated__'); -function genereateSnapshotTestCases(name, fixturePath, snapshotPath, outputPath) { - const fixtures = require(fixturePath); - const snapshots = require(snapshotPath); - for (const key of Object.keys(fixtures)) { - const snapshotName = `RN Codegen TypeScript Parser can generate fixture ${key} 1`; - const snapshotString = snapshots[snapshotName]; - const snapshot = snapshotString.substring(2, snapshotString.length - 2); - const tsSourceCode = ` +function genereateSnapshotTestCases( + name, + fixturePath, + snapshotPath, + outputPath, +) { + const fixtures = require(fixturePath); + const snapshots = require(snapshotPath); + for (const key of Object.keys(fixtures)) { + const snapshotName = `RN Codegen TypeScript Parser can generate fixture ${key} 1`; + const snapshotString = snapshots[snapshotName]; + const snapshot = snapshotString.substring(2, snapshotString.length - 2); + const tsSourceCode = ` /** * Copyright (c) Meta Platforms, Inc. and affiliates. * @@ -34,9 +54,21 @@ import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema'; const snapshot : SchemaType = ${snapshot}; export default snapshot; `; - fs.writeFileSync(path.join(outputPath, `${name}_${key}.ts`), tsSourceCode, { encoding: 'utf-8' }); - } + fs.writeFileSync(path.join(outputPath, `${name}_${key}.ts`), tsSourceCode, { + encoding: 'utf-8', + }); + } } -genereateSnapshotTestCases('component', tsComponentFixturePath, tsComponentSnapshotPath, snapshotOutputPath); -genereateSnapshotTestCases('module', tsModuleFixturePath, tsModuleSnapshotPath, snapshotOutputPath); +genereateSnapshotTestCases( + 'component', + tsComponentFixturePath, + tsComponentSnapshotPath, + snapshotOutputPath, +); +genereateSnapshotTestCases( + 'module', + tsModuleFixturePath, + tsModuleSnapshotPath, + snapshotOutputPath, +); diff --git a/packages/react-native-popup-menu-android/react-native.config.js b/packages/react-native-popup-menu-android/react-native.config.js index 2fed1e155b5..a23cfdb6674 100644 --- a/packages/react-native-popup-menu-android/react-native.config.js +++ b/packages/react-native-popup-menu-android/react-native.config.js @@ -3,13 +3,15 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ module.exports = { dependency: { platforms: { android: { - 'cmakeListsPath': '../android/src/main/jni/CMakeLists.txt', + cmakeListsPath: '../android/src/main/jni/CMakeLists.txt', }, }, }, diff --git a/packages/react-native-popup-menu-android/scripts/prepublish-popup-menu-android.js b/packages/react-native-popup-menu-android/scripts/prepublish-popup-menu-android.js index b810625e774..97e9551e2b3 100644 --- a/packages/react-native-popup-menu-android/scripts/prepublish-popup-menu-android.js +++ b/packages/react-native-popup-menu-android/scripts/prepublish-popup-menu-android.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ /* @@ -26,7 +28,9 @@ const fs = require('fs'); const buildGradleKtsPath = 'android/build.gradle.kts'; const libsVersionsTomlPath = '../react-native/gradle/libs.versions.toml'; -console.log(`Updating ${buildGradleKtsPath} with versions from ${libsVersionsTomlPath}...`); +console.log( + `Updating ${buildGradleKtsPath} with versions from ${libsVersionsTomlPath}...`, +); let gradleContent = fs.readFileSync(buildGradleKtsPath, 'utf8'); const tomlContent = fs.readFileSync(libsVersionsTomlPath, 'utf8'); @@ -39,7 +43,10 @@ gradleContent = gradleContent .replace('libs.versions.compileSdk.get().toInt()', compileSdk) .replace('libs.versions.minSdk.get().toInt()', minSdk) .replace('libs.versions.buildTools.get()', `"${buildTools}"`) - .replace('project(":packages:react-native:ReactAndroid")', '"com.facebook.react:react-android"'); + .replace( + 'project(":packages:react-native:ReactAndroid")', + '"com.facebook.react:react-android"', + ); fs.writeFileSync(buildGradleKtsPath, gradleContent); diff --git a/packages/react-native-test-library/babel.config.js b/packages/react-native-test-library/babel.config.js index 3bcc1e3d56e..489b9c61277 100644 --- a/packages/react-native-test-library/babel.config.js +++ b/packages/react-native-test-library/babel.config.js @@ -3,8 +3,15 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ module.exports = { - presets: [['module:@react-native/babel-preset', {disableStaticViewConfigsCodegen: false}]], + presets: [ + [ + 'module:@react-native/babel-preset', + {disableStaticViewConfigsCodegen: false}, + ], + ], }; diff --git a/packages/react-native-test-library/react-native.config.js b/packages/react-native-test-library/react-native.config.js index 2fed1e155b5..a23cfdb6674 100644 --- a/packages/react-native-test-library/react-native.config.js +++ b/packages/react-native-test-library/react-native.config.js @@ -3,13 +3,15 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ module.exports = { dependency: { platforms: { android: { - 'cmakeListsPath': '../android/src/main/jni/CMakeLists.txt', + cmakeListsPath: '../android/src/main/jni/CMakeLists.txt', }, }, }, diff --git a/packages/react-native/Libraries/Components/__tests__/Button-test.js b/packages/react-native/Libraries/Components/__tests__/Button-test.js index f4386d93c5a..11aab60d7c2 100644 --- a/packages/react-native/Libraries/Components/__tests__/Button-test.js +++ b/packages/react-native/Libraries/Components/__tests__/Button-test.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ import {create} from '../../../jest/renderer'; @@ -14,46 +16,84 @@ describe('