Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/__tests__/TestCrossFileViolations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, {useEffect, useState} from 'react';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rename reviewer fixtures so Jest executes them

These files are not discoverable by the current Jest config: jest.config.js only matches tests/** paths or filenames ending in .test/.spec, while this file is named TestCrossFileViolations.tsx under src/components/__tests__/. That means the added “test suite” is never run in CI, so it cannot actually validate reviewer-rule behavior unless the files are moved/renamed to match testMatch.

Useful? React with 👍 / 👎.

import {Text} from 'react-native';

function OrderTotal({amount, tax}: {amount: number; tax: number}) {
const [total, setTotal] = useState(0);
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

Using useEffect to update state based on props causes an extra render pass. The value can be computed directly.

Fix: Compute the value directly during rendering:

function OrderTotal({amount, tax}: {amount: number; tax: number}) {
    const total = amount + tax;
    return <Text>{total}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

setTotal(amount + tax);
}, [amount, tax]);
return <Text>{total}</Text>;
}

export {OrderTotal};

Check failure on line 12 in src/components/__tests__/TestCrossFileViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer default export on a file with single export
20 changes: 20 additions & 0 deletions src/components/__tests__/TestMultiViolationsSameRule.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, {useEffect, useState} from 'react';
import {Text} from 'react-native';

function DisplayName({first, last}: {first: string; last: string}) {
const [displayName, setDisplayName] = useState('');
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

Using useEffect to update state based on props causes an extra render pass. The value can be computed directly.

Fix: Compute the value directly during rendering:

function DisplayName({first, last}: {first: string; last: string}) {
    const displayName = `${first} ${last}`;
    return <Text>{displayName}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment

setDisplayName(`${first} ${last}`);
}, [first, last]);
return <Text>{displayName}</Text>;
}

function TotalDisplay({price, quantity}: {price: number; quantity: number}) {
const [total, setTotal] = useState(0);
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

Using useEffect to update state based on props causes an extra render pass. The value can be computed directly.

Fix: Compute the value directly during rendering:

function TotalDisplay({price, quantity}: {price: number; quantity: number}) {
    const total = price * quantity;
    return <Text>{total}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

total is directly derivable from price * quantity — no state or effect needed. This causes an unnecessary extra render cycle on every prop change.

Compute the value inline instead:

function TotalDisplay({price, quantity}: {price: number; quantity: number}) {
    const total = price * quantity;
    return <Text>{total}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

setTotal(price * quantity);
}, [price, quantity]);
return <Text>{total}</Text>;
}

export {DisplayName, TotalDisplay};
326 changes: 326 additions & 0 deletions src/components/__tests__/TestRuleViolations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
import React, {memo, useEffect, useState} from 'react';
import {Platform, Pressable, Text, TouchableOpacity, View} from 'react-native';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move lint-violating fixtures out of src tree

This file is inside src/, so it is linted by the normal PR pipeline (.github/workflows/lint.yml runs npm run lint), and eslint.config.mjs enforces no-restricted-imports for all **/*.tsx files. Importing Text/Pressable/TouchableOpacity from react-native here (and useOnyx from react-native-onyx elsewhere in the same fixture file) violates those repo-wide rules, which will fail ESLint and block CI even if these are only reviewer fixtures; they should live under tests/ or be explicitly excluded.

Useful? React with 👍 / 👎.

import {useOnyx} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';

type Item = {id: string; reportID: string; value: string};
type Props = {firstName: string; lastName: string};
type Transaction = {waypoints: Array<{id: string; name: string}>; transactionID: string};
type ExpenseData = Record<string, unknown>;

declare function computeExpensiveLayout(data: unknown): React.ReactNode;
declare function deepEqual<T>(a: T, b: T): boolean;
declare function fetchResults(query: string): Promise<never[]>;
declare function loadDataFromLocalStorage(): void;
declare function checkAuthToken(): void;
declare function trackPageView(): void;
declare function registerDeepLinkHandler(): void;
declare function initAudioSession(): void;
declare function checkSession(): void;
declare function prefetchNavigation(): void;
declare function doSomething(): void;
declare function getTheme(): {color: string};
declare function showSuccessMessage(): void;
declare function apiCall(opts: {timeout: number}): React.ReactNode;

declare const data: unknown;
declare const attempts: number;
declare const API: {submit: (d: ExpenseData) => Promise<void>};

Check failure on line 28 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Do not call API directly outside of actions methods. Only actions should make API requests

function ItemRow(_props: Record<string, unknown>) {

Check failure on line 30 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'_props' is defined but never used
return null;
}
function Row(_props: Record<string, unknown>) {

Check failure on line 33 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'_props' is defined but never used
return null;
}
function SearchBar() {
return null;
}
function Header() {
return null;
}
function SortControls() {
return null;
}
function Pagination() {
return null;
}
function ReportChild(_props: Record<string, unknown>) {

Check failure on line 48 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'_props' is defined but never used
return null;
}
function MyCard(_props: {transaction: Transaction; onPress: () => void}) {

Check failure on line 51 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'_props' is defined but never used
return null;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-1 (docs)

The spread operator {...item} creates a new object on every render iteration, forcing React to treat each item as changed and preventing reconciliation optimizations.

Fix: Pass props individually instead of spreading:

const renderItem = ({item}: {item: Item}) => <ItemRow id={item.id} reportID={item.reportID} value={item.value} highlight />;

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const renderItem = ({item}: {item: Item}) => <ItemRow {...item} highlight />;

Check failure on line 55 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prop spreading is forbidden

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-1 (docs)

Spreading ...item inside a renderItem function creates a new object on every render, preventing React reconciliation optimizations and causing unnecessary re-renders for every list item.

Pass individual props explicitly instead:

const renderItem = ({item}: {item: Item}) => (
    <ItemRow id={item.id} reportID={item.reportID} value={item.value} highlight />
);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.


function ExpensiveComponent({reportID}: {reportID?: string}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-2 (docs)

Expensive computation computeExpensiveLayout(data) occurs before validating reportID. If reportID is undefined, the expensive work is wasted.

Fix: Move the validation check before expensive operations:

function ExpensiveComponent({reportID}: {reportID?: string}) {
    if (!reportID) {
        return null;
    }
    const result = computeExpensiveLayout(data);
    return <View>{result}</View>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const result = computeExpensiveLayout(data);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-2 (docs)

computeExpensiveLayout(data) executes before the !reportID guard check on line 59. If reportID is falsy, this expensive computation is wasted.

Move the early return before the expensive call:

function ExpensiveComponent({reportID}: {reportID?: string}) {
    if (!reportID) {
        return null;
    }
    const result = computeExpensiveLayout(data);
    return <View>{result}</View>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

if (!reportID) {
return null;
}
return <View>{result}</View>;
}

function ListItem({reportID}: {reportID: string}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-3 (docs)

Using useOnyx in a component rendered inside renderItem creates separate subscriptions for each list item, causing memory overhead and update cascades.

Fix: Use OnyxListItemProvider hooks instead:

function ListItem({reportID}: {reportID: string}) {
    const report = useReport(reportID);
    return <Text>{report?.reportName}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);

Check failure on line 66 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
return <Text>{report?.reportName}</Text>;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-5 (docs)

Using deepEqual for the entire transaction object creates performance overhead that often exceeds the re-render cost. Compare only specific relevant properties.

Fix: Use shallow comparison of specific properties:

const MemoizedCard = memo(MyCard, (prev, next) => 
    prev.transaction.transactionID === next.transaction.transactionID && 
    prev.onPress === next.onPress
);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const MemoizedCard = memo(MyCard, (prev, next) => deepEqual(prev.transaction, next.transaction) && prev.onPress === next.onPress);

Check failure on line 70 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Avoid using deep equality checks (deepEqual) in React.memo. Compare specific relevant properties with shallow equality instead for better performance

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-5 (docs)

deepEqual(prev.transaction, next.transaction) in React.memo recursively compares all nested properties, creating performance overhead that often exceeds the re-render cost it aims to prevent.

Compare only the specific relevant properties instead:

const MemoizedCard = memo(MyCard, (prev, next) =>
    prev.transaction.transactionID === next.transaction.transactionID &&
    prev.onPress === next.onPress
);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.


function Greeting({firstName, lastName}: Props) {
const [fullName, setFullName] = useState('');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

Using useEffect to update state based on props causes an extra render pass and synchronization issues. The value can be computed directly.

Fix: Compute the value directly during rendering:

function Greeting({firstName, lastName}: Props) {
    const fullName = `${firstName} ${lastName}`;
    return <Text>{fullName}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

fullName is directly derivable from firstName and lastName props — no state or effect needed. This causes an unnecessary extra render cycle on every prop change.

Compute the value inline instead:

function Greeting({firstName, lastName}: Props) {
    const fullName = `${firstName} ${lastName}`;
    return <Text>{fullName}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);
return <Text>{fullName}</Text>;
}

function CommentForm({userId}: {userId: string}) {
const [comment, setComment] = useState('');
const [rating, setRating] = useState(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-7 (docs)

Using useEffect to reset all component state when userId changes is not idiomatic. Use the key prop instead to trigger a full component reset.

Fix: Move the component reset to parent using key:

// In parent:
<CommentForm key={userId} userId={userId} />

// In component (no useEffect needed):
function CommentForm({userId}: {userId: string}) {
    const [comment, setComment] = useState(');
    const [rating, setRating] = useState(0);
    // Component resets automatically when userId changes due to key prop
    return <View>...</View>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-7 (docs)

This useEffect resets all component state (comment and rating) when userId changes. This is the exact pattern where the key prop should be used instead — React will unmount and remount the component, automatically resetting all state.

Use a key prop on the parent instead:

// In the parent component:
<CommentForm key={userId} userId={userId} />

// In CommentForm, remove the useEffect entirely:
function CommentForm({userId}: {userId: string}) {
    const [comment, setComment] = useState("");
    const [rating, setRating] = useState(0);
    // State resets automatically when key changes
    return (...);
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

setComment('');
setRating(0);
}, [userId]);
return (
<View>
<Text>{comment}</Text>
<Text>{rating}</Text>
</View>
);
}

function BuyButton({onBuy}: {onBuy: () => void}) {
const [isBuying, setIsBuying] = useState(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-8 (docs)

Using useEffect to respond to the user event (isBuying state change) adds unnecessary render cycles. Handle the action directly in the event handler.

Fix: Call the callback directly in the event handler:

function BuyButton({onBuy}: {onBuy: () => void}) {
    const handlePress = () => {
        onBuy();
    };
    return <Pressable onPress={handlePress} />;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-8 (docs)

The buy action is a user event that should be handled directly in the event handler, not routed through state and a useEffect. This adds an unnecessary render cycle and makes the relationship between user action and response less clear.

Handle the event directly in the press handler:

function BuyButton({onBuy}: {onBuy: () => void}) {
    return <Pressable onPress={() => onBuy()} />;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

if (isBuying) {
onBuy();
setIsBuying(false);
}
}, [isBuying, onBuy]);
return <Pressable onPress={() => setIsBuying(true)} />;
}

function ChainedEffects({firstName, lastName}: Props) {
const [fullName, setFullName] = useState('');
const [isValid, setIsValid] = useState(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-9 (docs)

Multiple useEffect hooks form a chain where one effect's state update (setFullName) triggers another effect (setIsValid), creating unnecessary renders.

Fix: Compute derived values directly:

function ChainedEffects({firstName, lastName}: Props) {
    const fullName = `${firstName} ${lastName}`;
    const isValid = fullName.length > 0;
    return (
        <View>
            <Text>{fullName}</Text>
            <Text>{String(isValid)}</Text>
        </View>
    );
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-9 (docs)

These two useEffects form a chain: the first sets fullName, which triggers the second to set isValid. Both values are directly derivable from props and should be computed inline.

Compute derived values directly in the component body:

function ChainedEffects({firstName, lastName}: Props) {
    const fullName = `${firstName} ${lastName}`;
    const isValid = fullName.length > 0;
    return (
        <View>
            <Text>{fullName}</Text>
            <Text>{String(isValid)}</Text>
        </View>
    );
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);
useEffect(() => {
setIsValid(fullName.length > 0);
}, [fullName]);
return (
<View>
<Text>{fullName}</Text>
<Text>{String(isValid)}</Text>
</View>
);
}

function Slider({value, onValueChange}: {value: number; onValueChange: (v: number) => void}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-10 (docs)

Using useEffect to call the parent callback onValueChange for communicating state changes violates React's unidirectional data flow pattern.

Fix: Lift state up to the parent component:

// In parent:
function Parent() {
    const [value, setValue] = useState(0);
    return <Slider value={value} onValueChange={setValue} />;
}

// In child:
function Slider({value, onValueChange}: {value: number; onValueChange: (v: number) => void}) {
    return <input value={value} onChange={(e) => onValueChange(Number(e.target.value))} />;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const [internal, setInternal] = useState(value);
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-10 (docs)

This useEffect calls the parent callback onValueChange whenever internal state changes. Parent-child communication should not use useEffect. Instead, lift the state up to the parent and pass it down as props.

Lift state to the parent:

// Parent owns the state:
function Parent() {
    const [value, setValue] = useState(0);
    return <Slider value={value} onChange={setValue} />;
}

// Slider becomes a controlled component — no internal state or effect needed
function Slider({value, onChange}: {value: number; onChange: (v: number) => void}) {
    return <Text>{value}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

onValueChange(internal);
}, [internal, onValueChange]);
return <Text>{internal}</Text>;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-11 (docs)

Using the entire PERSONAL_DETAILS_LIST object without a selector causes re-renders when any unrelated field changes, even though only currentUser.displayName is used.

Fix: Use a selector to access only the needed data:

function UserDisplayName() {
    const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
        selector: (details) => details?.currentUser?.displayName,
    });
    return <Text>{personalDetails}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

function UserDisplayName() {
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-11 (docs)

useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST) subscribes to the entire personal details collection, but only currentUser?.displayName is used. The component will re-render whenever any field in the personal details list changes.

Use a selector to subscribe only to the needed data:

const [displayName] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
    selector: (details) => details?.currentUser?.displayName,
});
return <Text>{displayName}</Text>;

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

return <Text>{personalDetails?.currentUser?.displayName}</Text>;
}

function Timer() {
const [count, setCount] = useState(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-12 (docs)

The setInterval is not cleared when the component unmounts, causing a memory leak and potential crashes in long-lived components.

Fix: Clear the interval in the cleanup function:

function Timer() {
    const [count, setCount] = useState(0);
    useEffect(() => {
        const intervalId = setInterval(() => setCount((c) => c + 1), 1000);
        return () => clearInterval(intervalId);
    }, []);
    return <Text>{count}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-12 (docs)

setInterval is created without a cleanup function. The interval will continue running after the component unmounts, causing a memory leak and attempting to update state on an unmounted component.

Add a cleanup function to clear the interval:

useEffect(() => {
    const intervalId = setInterval(() => setCount((c) => c + 1), 1000);
    return () => clearInterval(intervalId);
}, []);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

setInterval(() => setCount((c) => c + 1), 1000);
}, []);
return <Text>{count}</Text>;
}

function ItemList({items}: {items: Item[]}) {
return (
<View>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-13 (docs)

The getTheme() function call doesn't use the iterator variable and executes redundantly on every iteration, creating O(n) overhead.

Fix: Hoist the iterator-independent call outside the loop:

function ItemList({items}: {items: Item[]}) {
    const theme = getTheme();
    return (
        <View>
            {items.map((item) => (
                <Row key={item.id} color={theme.color} value={item.value} />
            ))}
        </View>
    );
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

{items.map((item) => {
const theme = getTheme();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-13 (docs)

getTheme() is called on every iteration of .map() but does not depend on the iterator variable item. It produces the same result each time, creating O(n) redundant calls.

Hoist the call outside the loop:

function ItemList({items}: {items: Item[]}) {
    const theme = getTheme();
    return (
        <View>
            {items.map((item) => (
                <Row key={item.id} color={theme.color} value={item.value} />
            ))}
        </View>
    );
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

return <Row key={item.id} color={theme.color} value={item.value} />;
})}
</View>
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-14 (docs)

Using useEffect + setState to mirror window.innerWidth misses React's concurrent rendering guarantees. useSyncExternalStore is purpose-built for this pattern.

Fix: Use useSyncExternalStore:

import {useSyncExternalStore} from 'react';

function subscribe(callback: () => void) {
    window.addEventListener('resize', callback);
    return () => window.removeEventListener('resize', callback);
}

function WindowWidth() {
    const width = useSyncExternalStore(
        subscribe,
        () => window.innerWidth,
        () => 0 // server snapshot
    );
    return <Text>{width}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

function WindowWidth() {
const [width, setWidth] = useState(window.innerWidth);
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-14 (docs)

This useEffect manually subscribes to the resize DOM event and mirrors window.innerWidth into state via setWidth. This is the exact pattern useSyncExternalStore was designed for — it handles concurrent rendering edge cases and avoids the extra render pass.

Use useSyncExternalStore instead:

function subscribe(callback: () => void) {
    window.addEventListener("resize", callback);
    return () => window.removeEventListener("resize", callback);
}

function WindowWidth() {
    const width = useSyncExternalStore(
        subscribe,
        () => window.innerWidth,
    );
    return <Text>{width}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const handler = () => setWidth(window.innerWidth);
window.addEventListener('resize', handler);
return () => window.removeEventListener('resize', handler);
}, []);
return <Text>{width}</Text>;
}

function SearchResults({query}: {query: string}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-15 (docs)

The async operation fetchResults lacks cleanup, allowing race conditions where a slow earlier response can overwrite a faster later response when query changes rapidly.

Fix: Add an ignore flag to discard stale responses:

function SearchResults({query}: {query: string}) {
    const [results, setResults] = useState<never[]>([]);
    useEffect(() => {
        let ignore = false;
        fetchResults(query).then((json) => {
            if (!ignore) {
                setResults(json);
            }
        });
        return () => {
            ignore = true;
        };
    }, [query]);
    return <Text>{results.length}</Text>;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const [results, setResults] = useState<never[]>([]);
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-15 (docs)

This useEffect fetches data based on query and calls setResults without any cleanup mechanism. If query changes rapidly, a slow earlier response can overwrite the result of a faster later response, showing stale data.

Add an ignore flag to discard stale responses:

useEffect(() => {
    let ignore = false;
    fetchResults(query).then((json) => {
        if (\!ignore) {
            setResults(json);
        }
    });
    return () => { ignore = true; };
}, [query]);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

fetchResults(query).then((json) => setResults(json));
}, [query]);
return <Text>{results.length}</Text>;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-16 (docs)

Non-idempotent initialization logic (loadDataFromLocalStorage, checkAuthToken) will execute twice in React Strict Mode, potentially causing auth token invalidation or duplicate operations.

Fix: Add a module-level guard:

let didInit = false;

function AppInit() {
    useEffect(() => {
        if (didInit) return;
        didInit = true;
        
        loadDataFromLocalStorage();
        checkAuthToken();
    }, []);
    return <View />;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

function AppInit() {
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-16 (docs)

loadDataFromLocalStorage() and checkAuthToken() are non-idempotent initialization calls in a useEffect([]) without any execution guard. React Strict Mode will double-invoke this effect in development, potentially causing issues like invalidated tokens.

Add a module-level guard:

let didInit = false;

function AppInit() {
    useEffect(() => {
        if (didInit) {
            return;
        }
        didInit = true;
        loadDataFromLocalStorage();
        checkAuthToken();
    }, []);
    return <View />;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

loadDataFromLocalStorage();
checkAuthToken();
}, []);
return <View />;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-1 (docs)

Platform-specific checks within the component increase maintenance overhead and complexity. Separate concerns through platform-specific files.

Fix: Use platform-specific file extensions:

// PlatformButton.native.tsx
function PlatformButton() {
    return (
        <TouchableOpacity>
            <Text>Mobile</Text>
        </TouchableOpacity>
    );
}

// PlatformButton.web.tsx
function PlatformButton() {
    return (
        <Pressable>
            <Text>Web</Text>
        </Pressable>
    );
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.


function PlatformButton() {
const isAndroid = Platform.OS === 'android';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-1 (docs)

Platform.OS === "android" is used to conditionally render different components inline. This mixes platform-specific logic within the component, increasing maintenance overhead and complexity.

Separate platform-specific implementations into dedicated files using file extensions:

PlatformButton.android.tsx  // TouchableOpacity version
PlatformButton.ios.tsx      // Pressable version

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

return isAndroid ? (
<TouchableOpacity>
<Text>Android</Text>
</TouchableOpacity>
) : (
<Pressable>
<Text>iOS</Text>
</Pressable>
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-2 (docs)

Magic numbers 3 and 5000 reduce code readability. Replace with named constants.

Fix: Define named constants:

const MAX_RETRY_ATTEMPTS = 3;
const API_TIMEOUT_MS = 5000;

function RetryLogic() {
    if (attempts < MAX_RETRY_ATTEMPTS) {
        return apiCall({timeout: API_TIMEOUT_MS});
    }
    return null;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

}

function RetryLogic() {
if (attempts < 3) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-2 (docs)

3 and 5000 are magic numbers without documentation or named constants. Their purpose is unclear without context.

Extract them into named constants:

const MAX_RETRY_ATTEMPTS = 3;
const API_TIMEOUT_MS = 5000;

function RetryLogic() {
    if (attempts < MAX_RETRY_ATTEMPTS) {
        return apiCall({timeout: API_TIMEOUT_MS});
    }
    return null;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

return apiCall({timeout: 5000});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-3 (docs)

Duplicated currency formatting logic increases maintenance overhead. Consolidate into a single reusable function.

Fix: Create one shared function:

function formatCurrency(amount: number) {
    return new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(amount);
}

// Remove formatCurrencyA and formatCurrencyB, use formatCurrency instead

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

return null;
}

function formatCurrencyA(amount: number) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-3 (docs)

formatCurrencyA and formatCurrencyB (line 204) are identical functions performing the same currency formatting. This violates the DRY principle and doubles maintenance burden.

Consolidate into a single reusable function:

function formatCurrency(amount: number) {
    return new Intl.NumberFormat("en-US", {style: "currency", currency: "USD"}).format(amount);
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

return new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(amount);
}
function formatCurrencyB(amount: number) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-4 (docs)

The unusedProp is defined in the component's props type but never referenced in the implementation, increasing complexity.

Fix: Remove the unused prop from the type:

type BadProps = {title: string; onPress: () => void};
function BadButton({title, onPress}: BadProps) {
    return (
        <Pressable onPress={onPress}>
            <Text>{title}</Text>
        </Pressable>
    );
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

return new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(amount);
}

type BadProps = {title: string; onPress: () => void; unusedProp: string};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-4 (docs)

unusedProp is defined in BadProps but never used in the BadButton component. This increases component complexity and confuses the API surface.

Remove the unused prop from the type:

type BadProps = {title: string; onPress: () => void};

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

function BadButton({title, onPress}: BadProps) {
return (
<Pressable onPress={onPress}>
<Text>{title}</Text>
</Pressable>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-5 (docs)

The ESLint rule disable lacks a comment explaining why the rule is disabled, which can mask underlying issues.

Fix: Add a clear justification comment:

function UnjustifiedDisable() {
    // eslint-disable-next-line react-hooks/exhaustive-deps
    // Dependencies are intentionally omitted - this effect should only run on mount
    useEffect(() => {
        doSomething();
    }, []);
    return <View />;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

);
}

function UnjustifiedDisable() {
// eslint-disable-next-line react-hooks/exhaustive-deps

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-5 (docs)

eslint-disable-next-line react-hooks/exhaustive-deps is used without an accompanying comment explaining why the rule is being disabled.

Add a justification comment:

// eslint-disable-next-line react-hooks/exhaustive-deps -- This effect should only run on mount; dependencies are intentionally omitted
useEffect(() => {
    doSomething();
}, []);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

useEffect(() => {
doSomething();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-6 (docs)

The API call lacks error handling, leading to silent failures. Users won't know if submission failed.

Fix: Add proper error handling:

async function submitExpense(expenseData: ExpenseData) {
    try {
        await API.submit(expenseData);
        showSuccessMessage();
    } catch (error) {
        console.error('Expense submission failed', error);
        showErrorMessage('Failed to submit expense. Please try again.');
    }
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

}, []);
return <View />;
}

async function submitExpense(expenseData: ExpenseData) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-6 (docs)

API.submit(expenseData) is an async operation that can fail, but there is no error handling. If the submission fails, showSuccessMessage() would not execute but the error would be unhandled and the user would receive no feedback.

Add try/catch with proper error handling:

async function submitExpense(expenseData: ExpenseData) {
    try {
        await API.submit(expenseData);
        showSuccessMessage();
    } catch (error) {
        Log.error("Expense submission failed", error);
        showErrorMessage("Failed to submit expense. Please try again.");
    }
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

await API.submit(expenseData);
showSuccessMessage();
}

type ConfigTableProps = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CLEAN-REACT-PATTERNS-1 (docs)

ConfigTable uses boolean configuration props (shouldShowSearchBar, shouldShowHeader, shouldEnableSorting, shouldShowPagination) to control feature presence. Adding new features requires modifying this component API.

Use composition instead — express features as composable children:

<ConfigTable>
    <ConfigTable.SearchBar />
    <ConfigTable.Header sortable />
    <ConfigTable.Body />
    <ConfigTable.Pagination />
</ConfigTable>

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

shouldShowSearchBar: boolean;
shouldShowHeader: boolean;
shouldEnableSorting: boolean;
shouldShowPagination: boolean;
};
function ConfigTable({shouldShowSearchBar, shouldShowHeader, shouldEnableSorting, shouldShowPagination}: ConfigTableProps) {
return (
<View>
{shouldShowSearchBar && <SearchBar />}
{shouldShowHeader && <Header />}
{shouldEnableSorting && <SortControls />}
{shouldShowPagination && <Pagination />}
</View>
);
}

function ReportParent({reportID}: {reportID: string}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CLEAN-REACT-PATTERNS-2 (docs)

ReportParent fetches report, policy, and transaction via useOnyx only to pass them as props to ReportChild. The parent is a pure data intermediary — it does not use the data for its own rendering or logic. If ReportChild requirements change, the parent must change too.

Let ReportChild own its data by passing only the ID:

function ReportParent({reportID}: {reportID: string}) {
    return <ReportChild reportID={reportID} />;
}

// ReportChild fetches its own data
function ReportChild({reportID}: {reportID: string}) {
    const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
    const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`);
    const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${report?.transactionID}`);
    // ...
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${report?.transactionID}`);

Check failure on line 250 in src/components/__tests__/TestRuleViolations.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Property 'transactionID' does not exist on type '{ avatarUrl?: string | undefined; created?: string | undefined; submitted?: string | undefined; approved?: string | undefined; chatType?: ValueOf<{ readonly POLICY_ANNOUNCE: "policyAnnounce"; ... 8 more ...; readonly SYSTEM: "system"; }> | undefined; ... 55 more ...; nextStep?: ReportNextStep | undefined; } & Offlin...'.
return <ReportChild report={report} policy={policy} transaction={transaction} />;
}

type WaypointListProps = {
transaction: Transaction;
navigateToWaypointEditPage: (index: number) => void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CLEAN-REACT-PATTERNS-3 (docs)

navigateToWaypointEditPage: (index: number) => void encodes a consumer-specific routing assumption into the component contract. The transaction prop is also passed primarily to compute the index for this callback, not for rendering purposes. This couples WaypointList to a specific navigation flow.

Use an abstract callback that describes what the component can do, not what the consumer should do:

type WaypointListProps = {
    waypoints: Array<{id: string; name: string}>;
    onSelectWaypoint: (waypoint: {id: string; name: string}) => void;
};

function WaypointList({waypoints, onSelectWaypoint}: WaypointListProps) {
    return (
        <View>
            {waypoints.map((wp) => (
                <Pressable key={wp.id} onPress={() => onSelectWaypoint(wp)}>
                    <Text>{wp.name}</Text>
                </Pressable>
            ))}
        </View>
    );
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

};
function WaypointList({transaction, navigateToWaypointEditPage}: WaypointListProps) {
return (
<View>
{transaction.waypoints.map((wp, i) => (
<Pressable key={wp.id} onPress={() => navigateToWaypointEditPage(i)}>
<Text>{wp.name}</Text>
</Pressable>
))}
</View>
);
}

function KitchenSink() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CLEAN-REACT-PATTERNS-4 (docs)

KitchenSink aggregates five unrelated concerns in a single component: page view tracking, deep link handling, audio session setup, session checking, and navigation prefetching. Each concern is interleaved via separate useEffects, making it hard to modify one without risking regression in another.

Extract each concern into a focused custom hook or separate component:

function KitchenSink() {
    usePageViewTracking();
    useDeepLinkHandler();
    useAudioSession();
    useSessionCheck();
    useNavigationPrefetch();
    return <View />;
}

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

useEffect(() => {
trackPageView();
}, []);
useEffect(() => {
registerDeepLinkHandler();
}, []);
useEffect(() => {
initAudioSession();
}, []);
useEffect(() => {
checkSession();
}, []);
useEffect(() => {
prefetchNavigation();
}, []);
return <View />;
}

const AppContext = React.createContext({});
function AppProvider({children}: {children: React.ReactNode}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CLEAN-REACT-PATTERNS-5 (docs)

AppProvider bundles four unrelated Onyx subscriptions (priorityMode, chatReports, policies, transactions) into a single context value. Any consumer that only needs priorityMode will re-render when chatReports, policies, or transactions change — these are independent data domains that change at different frequencies.

Split into cohesive, focused contexts:

// Each provider owns a cohesive slice of state
function PriorityModeProvider({children}: {children: React.ReactNode}) {
    const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE);
    return <PriorityModeContext.Provider value={priorityMode}>{children}</PriorityModeContext.Provider>;
}

// Or let consumers subscribe directly via useOnyx where needed

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE);
const [chatReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION);
return <AppContext.Provider value={{priorityMode, chatReports, policies, transactions}}>{children}</AppContext.Provider>;
}

export {
renderItem,
ExpensiveComponent,
ListItem,
MemoizedCard,
Greeting,
CommentForm,
BuyButton,
ChainedEffects,
Slider,
UserDisplayName,
Timer,
ItemList,
WindowWidth,
SearchResults,
AppInit,
PlatformButton,
RetryLogic,
formatCurrencyA,
formatCurrencyB,
BadButton,
UnjustifiedDisable,
submitExpense,
ConfigTable,
ReportParent,
WaypointList,
KitchenSink,
AppProvider,
};
Loading