From 188a09ef69c55d7084bed0947027165e73f52d4c Mon Sep 17 00:00:00 2001 From: Blake Friedman Date: Wed, 17 Jul 2024 10:07:00 -0700 Subject: [PATCH] fix linting noise (#45465) Summary: ## Summary: Fix linting warnings Changelog: [Internal] Pull Request resolved: https://github.com/facebook/react-native/pull/45465 Test Plan: ``` $ eslint . Done in 46.11s. $ arc f ok No lint issues. ``` Reviewed By: cipolleschi Differential Revision: D59805820 Pulled By: blakef fbshipit-source-id: f33d99a6a06607c3c3762881cc7c182804b981e1 --- .../Animated/__tests__/Animated-test.js | 2 +- .../Libraries/Animated/nodes/AnimatedValue.js | 1 + .../Components/TextInput/TextInput.js | 1 - .../ReactNative/BridgelessUIManager.js | 1 + .../Libraries/__tests__/public-api-test.js | 1 - packages/react-native/scripts/bundle.js | 2 +- .../Accessibility/AccessibilityIOSExample.js | 2 +- .../ActionSheetIOS/ActionSheetIOSExample.js | 1 + .../js/examples/Alert/AlertExample.js | 2 +- .../MixBlendMode/MixBlendModeExample.js | 10 +- .../Lists/__tests__/VirtualizedList-test.js | 220 +++++++++--------- scripts/e2e/init-template-e2e.js | 4 +- scripts/releases/utils/release-utils.js | 2 +- 13 files changed, 125 insertions(+), 124 deletions(-) diff --git a/packages/react-native/Libraries/Animated/__tests__/Animated-test.js b/packages/react-native/Libraries/Animated/__tests__/Animated-test.js index fcb1148984ce1b..53f2af95717d10 100644 --- a/packages/react-native/Libraries/Animated/__tests__/Animated-test.js +++ b/packages/react-native/Libraries/Animated/__tests__/Animated-test.js @@ -10,7 +10,7 @@ import * as React from 'react'; -const {create, update, unmount} = require('../../../jest/renderer'); +const {create, unmount, update} = require('../../../jest/renderer'); const {PlatformColor} = require('../../StyleSheet/PlatformColorValueTypes'); let Animated = require('../Animated').default; const AnimatedProps = require('../nodes/AnimatedProps').default; diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedValue.js b/packages/react-native/Libraries/Animated/nodes/AnimatedValue.js index 207dbf69c6e12b..52c8126e093b42 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedValue.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedValue.js @@ -49,6 +49,7 @@ const NativeAnimatedAPI = NativeAnimatedHelper.API; * transform which can receive values from multiple parents. */ export function flushValue(rootNode: AnimatedNode): void { + // eslint-disable-next-line func-call-spacing const leaves = new Set<{update: () => void, ...}>(); function findAnimatedStyles(node: AnimatedNode) { // $FlowFixMe[prop-missing] diff --git a/packages/react-native/Libraries/Components/TextInput/TextInput.js b/packages/react-native/Libraries/Components/TextInput/TextInput.js index 55451b9772f18c..b60ae10fa8abcf 100644 --- a/packages/react-native/Libraries/Components/TextInput/TextInput.js +++ b/packages/react-native/Libraries/Components/TextInput/TextInput.js @@ -1270,7 +1270,6 @@ function InternalTextInput(props: Props): React.Node { const inputRef = useRef>>(null); - // eslint-disable-next-line react-hooks/exhaustive-deps const selection: ?Selection = propsSelection == null ? null diff --git a/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js b/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js index adcdf0f3cbc7a2..6bed4989c535a2 100644 --- a/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js +++ b/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js @@ -382,6 +382,7 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = { shadowNode, ); + // eslint-disable-next-line no-bitwise let isAncestor = (result & DOCUMENT_POSITION_CONTAINED_BY) !== 0; callback([isAncestor]); diff --git a/packages/react-native/Libraries/__tests__/public-api-test.js b/packages/react-native/Libraries/__tests__/public-api-test.js index 88a2ab81059216..57b53f25316738 100644 --- a/packages/react-native/Libraries/__tests__/public-api-test.js +++ b/packages/react-native/Libraries/__tests__/public-api-test.js @@ -15,7 +15,6 @@ const translate = require('flow-api-translator'); const {promises: fs} = require('fs'); const glob = require('glob'); const {transform} = require('hermes-transform'); -const os = require('os'); const path = require('path'); const PACKAGE_ROOT = path.resolve(__dirname, '../../'); diff --git a/packages/react-native/scripts/bundle.js b/packages/react-native/scripts/bundle.js index 53acb055b2c0d6..83942879340a01 100644 --- a/packages/react-native/scripts/bundle.js +++ b/packages/react-native/scripts/bundle.js @@ -13,7 +13,7 @@ const {bundleCommand: bc} = require('@react-native/community-cli-plugin'); const {execSync} = require('child_process'); const program = require('commander'); -const {existsSync, readFileSync} = require('fs'); +const {readFileSync} = require('fs'); const path = require('path'); program.version( diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityIOSExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityIOSExample.js index 97f2c5fa851363..a40fb35f7ec3b1 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityIOSExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityIOSExample.js @@ -10,9 +10,9 @@ 'use strict'; +const {RNTesterThemeContext} = require('../../components/RNTesterTheme'); const React = require('react'); const {Alert, Text, View} = require('react-native'); -const {RNTesterThemeContext} = require('../../components/RNTesterTheme'); type Props = $ReadOnly<{||}>; class AccessibilityIOSExample extends React.Component { diff --git a/packages/rn-tester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js b/packages/rn-tester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js index 34c3b163b12b75..53369e0e9173b1 100644 --- a/packages/rn-tester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js +++ b/packages/rn-tester/js/examples/ActionSheetIOS/ActionSheetIOSExample.js @@ -11,6 +11,7 @@ 'use strict'; import type {NativeMethods} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes'; + import {RNTesterThemeContext} from '../../components/RNTesterTheme'; const ScreenshotManager = require('../../../NativeModuleExample/NativeScreenshotManager'); diff --git a/packages/rn-tester/js/examples/Alert/AlertExample.js b/packages/rn-tester/js/examples/Alert/AlertExample.js index b4d09721ba4b7a..329adfc9b8117d 100644 --- a/packages/rn-tester/js/examples/Alert/AlertExample.js +++ b/packages/rn-tester/js/examples/Alert/AlertExample.js @@ -10,8 +10,8 @@ import type {RNTesterModule} from '../../types/RNTesterTypes'; -import * as React from 'react'; import {RNTesterThemeContext} from '../../components/RNTesterTheme'; +import * as React from 'react'; import {Alert, Pressable, StyleSheet, Text, View} from 'react-native'; // Shows log on the screen diff --git a/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js b/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js index 79221155e01ac1..29e794738faa90 100644 --- a/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js +++ b/packages/rn-tester/js/examples/MixBlendMode/MixBlendModeExample.js @@ -13,15 +13,7 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet'; import React from 'react'; -import {useState} from 'react'; -import { - Button, - Image, - ImageBackground, - StyleSheet, - View, - Text, -} from 'react-native'; +import {Image, ImageBackground, StyleSheet, Text, View} from 'react-native'; type Props = $ReadOnly<{ style: ViewStyleProp, diff --git a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js index 83286ea3a57165..78648590d690d0 100644 --- a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js +++ b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js @@ -17,6 +17,8 @@ import {act, create} from 'react-test-renderer'; jest.useFakeTimers(); +const skipTestSilenceLinter = it.skip; + describe('VirtualizedList', () => { it('renders simple list', async () => { let component; @@ -460,77 +462,80 @@ describe('VirtualizedList', () => { }); // TODO: Revisit this test case after upgrading to React 19. - it.skip('calls onStartReached when near the start', async () => { - const ITEM_HEIGHT = 40; - const layout = {width: 300, height: 600}; - let data = Array(40) - .fill() - .map((_, index) => ({key: `key-${index}`})); - const onStartReached = jest.fn(); - const props = { - data, - initialNumToRender: 10, - onStartReachedThreshold: 1, - windowSize: 10, - renderItem: ({item}) => , - getItem: (items, index) => items[index], - getItemCount: items => items.length, - getItemLayout: (items, index) => ({ - length: ITEM_HEIGHT, - offset: ITEM_HEIGHT * index, - index, - }), - onStartReached, - initialScrollIndex: data.length - 1, - }; - let component; - await act(() => { - component = create(); - }); + skipTestSilenceLinter( + 'calls onStartReached when near the start', + async () => { + const ITEM_HEIGHT = 40; + const layout = {width: 300, height: 600}; + let data = Array(40) + .fill() + .map((_, index) => ({key: `key-${index}`})); + const onStartReached = jest.fn(); + const props = { + data, + initialNumToRender: 10, + onStartReachedThreshold: 1, + windowSize: 10, + renderItem: ({item}) => , + getItem: (items, index) => items[index], + getItemCount: items => items.length, + getItemLayout: (items, index) => ({ + length: ITEM_HEIGHT, + offset: ITEM_HEIGHT * index, + index, + }), + onStartReached, + initialScrollIndex: data.length - 1, + }; + let component; + await act(() => { + component = create(); + }); - const instance = component.getInstance(); + const instance = component.getInstance(); - await act(async () => { - instance._onLayout({nativeEvent: {layout, zoomScale: 1}}); - instance._onContentSizeChange(300, data.length * ITEM_HEIGHT); + await act(async () => { + instance._onLayout({nativeEvent: {layout, zoomScale: 1}}); + instance._onContentSizeChange(300, data.length * ITEM_HEIGHT); - // Make sure onStartReached is not called initially when initialScrollIndex is set. - await jest.runAllTimersAsync(); - }); - expect(onStartReached).not.toHaveBeenCalled(); - - await act(async () => { - // Scroll for a small amount and make sure onStartReached is not called. - instance._onScroll({ - timeStamp: 1000, - nativeEvent: { - contentOffset: {y: (data.length - 2) * ITEM_HEIGHT, x: 0}, - layoutMeasurement: layout, - contentSize: {...layout, height: data.length * ITEM_HEIGHT}, - zoomScale: 1, - contentInset: {right: 0, top: 0, left: 0, bottom: 0}, - }, + // Make sure onStartReached is not called initially when initialScrollIndex is set. + await jest.runAllTimersAsync(); }); - await jest.runAllTimersAsync(); - }); - expect(onStartReached).not.toHaveBeenCalled(); - - await act(async () => { - // Scroll to start and make sure onStartReached is called. - instance._onScroll({ - timeStamp: 1000, - nativeEvent: { - contentOffset: {y: 0, x: 0}, - layoutMeasurement: layout, - contentSize: {...layout, height: data.length * ITEM_HEIGHT}, - zoomScale: 1, - contentInset: {right: 0, top: 0, left: 0, bottom: 0}, - }, + expect(onStartReached).not.toHaveBeenCalled(); + + await act(async () => { + // Scroll for a small amount and make sure onStartReached is not called. + instance._onScroll({ + timeStamp: 1000, + nativeEvent: { + contentOffset: {y: (data.length - 2) * ITEM_HEIGHT, x: 0}, + layoutMeasurement: layout, + contentSize: {...layout, height: data.length * ITEM_HEIGHT}, + zoomScale: 1, + contentInset: {right: 0, top: 0, left: 0, bottom: 0}, + }, + }); + await jest.runAllTimersAsync(); }); - await jest.runAllTimersAsync(); - }); - expect(onStartReached).toHaveBeenCalled(); - }); + expect(onStartReached).not.toHaveBeenCalled(); + + await act(async () => { + // Scroll to start and make sure onStartReached is called. + instance._onScroll({ + timeStamp: 1000, + nativeEvent: { + contentOffset: {y: 0, x: 0}, + layoutMeasurement: layout, + contentSize: {...layout, height: data.length * ITEM_HEIGHT}, + zoomScale: 1, + contentInset: {right: 0, top: 0, left: 0, bottom: 0}, + }, + }); + await jest.runAllTimersAsync(); + }); + expect(onStartReached).toHaveBeenCalled(); + }, + ); it('calls onStartReached initially', async () => { const ITEM_HEIGHT = 40; @@ -1742,52 +1747,55 @@ it('retains initial render region when an item is appended', async () => { }); // TODO: Revisit this test case after upgrading to React 19. -it.skip('retains batch render region when an item is appended', async () => { - const items = generateItems(10); - const ITEM_HEIGHT = 10; +skipTestSilenceLinter( + 'retains batch render region when an item is appended', + async () => { + const items = generateItems(10); + const ITEM_HEIGHT = 10; - let component; - await act(() => { - component = create( - , - ); - }); + let component; + await act(() => { + component = create( + , + ); + }); - await act(() => { - simulateLayout(component, { - viewport: {width: 10, height: 50}, - content: {width: 10, height: 100}, + await act(() => { + simulateLayout(component, { + viewport: {width: 10, height: 50}, + content: {width: 10, height: 100}, + }); + performAllBatches(); }); - performAllBatches(); - }); - await act(async () => { - await jest.runAllTimersAsync(); - }); + await act(async () => { + await jest.runAllTimersAsync(); + }); - await act(() => { - component.update( - , - ); - }); + await act(() => { + component.update( + , + ); + }); - // Adding an item to the list after batch render should keep the existing - // rendered items rendered. We batch render 10 items, then add an 11th. Expect - // the first ten items to be present, with a spacer for the 11th until the - // next batch render. - expect(component).toMatchSnapshot(); -}); + // Adding an item to the list after batch render should keep the existing + // rendered items rendered. We batch render 10 items, then add an 11th. Expect + // the first ten items to be present, with a spacer for the 11th until the + // next batch render. + expect(component).toMatchSnapshot(); + }, +); it('constrains batch render region when an item is removed', async () => { const items = generateItems(10); diff --git a/scripts/e2e/init-template-e2e.js b/scripts/e2e/init-template-e2e.js index ee03d3e536bdfc..2d3d337c6ae986 100644 --- a/scripts/e2e/init-template-e2e.js +++ b/scripts/e2e/init-template-e2e.js @@ -192,12 +192,12 @@ function _updateScopedPackages( fs.readFileSync(appPackageJsonPath, 'utf8'), ); - for (const [key, _] of Object.entries(appPackageJson.dependencies)) { + for (const key of Object.keys(appPackageJson.dependencies)) { if (key.startsWith('@react-native')) { appPackageJson.dependencies[key] = version; } } - for (const [key, _] of Object.entries(appPackageJson.devDependencies)) { + for (const key of Object.keys(appPackageJson.devDependencies)) { if (key.startsWith('@react-native')) { appPackageJson.devDependencies[key] = version; } diff --git a/scripts/releases/utils/release-utils.js b/scripts/releases/utils/release-utils.js index 92af4d088e7b06..2b3af528d64aa1 100644 --- a/scripts/releases/utils/release-utils.js +++ b/scripts/releases/utils/release-utils.js @@ -14,7 +14,7 @@ const { createHermesPrebuiltArtifactsTarball, } = require('../../../packages/react-native/scripts/hermes/hermes-utils'); -const {echo, env, exec, exit, popd, pushd, test} = require('shelljs'); +const {echo, exec, exit, popd, pushd, test} = require('shelljs'); /*:: type BuildType = 'dry-run' | 'release' | 'nightly' | 'prealpha';