Repository navigation
[DO NOT MERGE][NoQA] Test suite for "Convert code-inline-reviewer rules into proactive coding guidelines for Claude" #82206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import React, {useEffect, useState} from 'react'; | ||
| import {Text} from 'react-native'; | ||
|
|
||
| function OrderTotal({amount, tax}: {amount: number; tax: number}) { | ||
| const [total, setTotal] = useState(0); | ||
| useEffect(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-6 (docs)Using 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}; | ||
| 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-6 (docs)Using 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-6 (docs)Using 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-6 (docs)
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}; | ||
| 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'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This file is inside 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>}; | ||
|
|
||
| function ItemRow(_props: Record<string, unknown>) { | ||
| return null; | ||
| } | ||
| function Row(_props: Record<string, unknown>) { | ||
| return null; | ||
| } | ||
| function SearchBar() { | ||
| return null; | ||
| } | ||
| function Header() { | ||
| return null; | ||
| } | ||
| function SortControls() { | ||
| return null; | ||
| } | ||
| function Pagination() { | ||
| return null; | ||
| } | ||
| function ReportChild(_props: Record<string, unknown>) { | ||
| return null; | ||
| } | ||
| function MyCard(_props: {transaction: Transaction; onPress: () => void}) { | ||
| return null; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-1 (docs)The spread operator 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 />; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-1 (docs)Spreading 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}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-2 (docs)Expensive computation 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-2 (docs)
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}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-3 (docs)Using Fix: Use 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}`); | ||
| return <Text>{report?.reportName}</Text>; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-5 (docs)Using 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
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-5 (docs)
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(''); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-6 (docs)Using 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-6 (docs)
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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-7 (docs)Using Fix: Move the component reset to parent using // 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-7 (docs)This useEffect resets all component state ( Use a // 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-8 (docs)Using 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-9 (docs)Multiple 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-9 (docs)These two useEffects form a chain: the first sets 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}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-10 (docs)Using 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-10 (docs)This useEffect calls the parent callback 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>; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-11 (docs)Using the entire 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-11 (docs)
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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-12 (docs)The 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-12 (docs)
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> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-13 (docs)The 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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-13 (docs)
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> | ||
| ); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-14 (docs)Using Fix: Use 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-14 (docs)This useEffect manually subscribes to the Use 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}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-15 (docs)The async operation Fix: Add an 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-15 (docs)This useEffect fetches data based on 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>; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-16 (docs)Non-idempotent initialization logic ( 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(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-16 (docs)
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 />; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-1 (docs)
Separate platform-specific implementations into dedicated files using file extensions: 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> | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-2 (docs)Magic numbers 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-2 (docs)
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}); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 insteadPlease rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency. |
||
| return null; | ||
| } | ||
|
|
||
| function formatCurrencyA(amount: number) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-3 (docs)
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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-4 (docs)The 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}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-4 (docs)
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> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-5 (docs)
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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-6 (docs)
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 = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CLEAN-REACT-PATTERNS-1 (docs)
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}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CLEAN-REACT-PATTERNS-2 (docs)
Let 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
|
||
| return <ReportChild report={report} policy={policy} transaction={transaction} />; | ||
| } | ||
|
|
||
| type WaypointListProps = { | ||
| transaction: Transaction; | ||
| navigateToWaypointEditPage: (index: number) => void; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CLEAN-REACT-PATTERNS-3 (docs)
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() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CLEAN-REACT-PATTERNS-4 (docs)
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}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CLEAN-REACT-PATTERNS-5 (docs)
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 neededPlease 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, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files are not discoverable by the current Jest config:
jest.config.jsonly matchestests/**paths or filenames ending in.test/.spec, while this file is namedTestCrossFileViolations.tsxundersrc/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 matchtestMatch.Useful? React with 👍 / 👎.