You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -14,16 +15,32 @@ Your job is to scan through changed files and create **inline comments** for spe
14
15
## Rules
15
16
16
17
Each rule includes:
18
+
17
19
- A unique **Rule ID**
18
20
-**Pass/Fail condition**
19
21
-**Reasoning**: Technical explanation of why the rule is important
20
22
- Examples of good and bad usage
21
23
22
24
### [PERF-1] No spread in list item's renderItem
23
-
-**Condition**: When passing data to components in renderItem functions, avoid using spread operators to extend objects. Instead, pass the base object and additional properties as separate props to prevent unnecessary object creation on each render.
25
+
26
+
-**Condition**: Flag ONLY when ALL of these are true:
27
+
28
+
- Code is inside a renderItem function (function passed to FlatList, SectionList, etc.)
29
+
- A spread operator (...) is used on an object
30
+
- That object is being passed as a prop to a component
31
+
- The spread creates a NEW object literal inline
32
+
33
+
**DO NOT flag if:**
34
+
35
+
- Spread is used outside renderItem
36
+
- Spread is on an array
37
+
- Object is created once outside renderItem and reused
38
+
- Spread is used to clone for local manipulation (not passed as prop)
39
+
24
40
-**Reasoning**: `renderItem` functions execute for every visible list item on each render. Creating new objects with spread operators forces React to treat each item as changed, preventing reconciliation optimizations and causing unnecessary re-renders of child components.
25
41
26
42
Good:
43
+
27
44
```tsx
28
45
<Component
29
46
item={item}
@@ -33,6 +50,7 @@ Good:
33
50
```
34
51
35
52
Bad:
53
+
36
54
```tsx
37
55
<Component
38
56
item={{
@@ -46,10 +64,38 @@ Bad:
46
64
---
47
65
48
66
### [PERF-2] Use early returns in array iteration methods
49
-
-**Condition**: When using `.every()`, `.some()`, or similar methods, perform simple checks first with early returns before expensive operations.
67
+
68
+
-**Condition**: Flag ONLY when ALL of these are true:
69
+
70
+
- Using .every(), .some(), .find(), .filter() or similar function
71
+
- Function contains an "expensive operation" (defined below)
72
+
- There exists a simple property check that could eliminate items earlier
73
+
- The simple check is performed AFTER the expensive operation
74
+
75
+
**Expensive operations are**:
76
+
77
+
- Function calls (except simple getters/property access)
78
+
- Regular expressions
79
+
- Object/array iterations
80
+
- Math calculations beyond basic arithmetic
81
+
82
+
**Simple checks are**:
83
+
84
+
- Property existence (!obj.prop, obj.prop === undefined)
85
+
- Boolean checks (obj.isActive)
86
+
- Primitive comparisons (obj.id === 5)
87
+
- Type checks (typeof, Array.isArray)
88
+
89
+
**DO NOT flag if**:
90
+
91
+
- No expensive operations exist
92
+
- Simple checks are already done first
93
+
- The expensive operation MUST run for all items (e.g., for side effects)
94
+
50
95
-**Reasoning**: Expensive operations can be any long-running synchronous tasks (like complex calculations) and should be avoided when simple property checks can eliminate items early. This reduces unnecessary computation and improves iteration performance, especially on large datasets.
### [PERF-3] Use OnyxListItemProvider hooks instead of useOnyx in renderItem
121
+
74
122
-**Condition**: Components rendered inside `renderItem` functions should use dedicated hooks from `OnyxListItemProvider` instead of individual `useOnyx` calls.
75
123
-**Reasoning**: Individual `useOnyx` calls in renderItem create separate subscriptions for each list item, causing memory overhead and update cascades. `OnyxListItemProvider` hooks provide optimized data access patterns specifically designed for list rendering performance.
### [PERF-4] Memoize objects and functions passed as props
140
+
90
141
-**Condition**: Objects and functions passed as props should be properly memoized or simplified to primitive values to prevent unnecessary re-renders.
91
142
-**Reasoning**: React uses referential equality to determine if props changed. New object/function instances on every render trigger unnecessary re-renders of child components, even when the actual data hasn't changed. Memoization preserves referential stability.
### [PERF-5] Use shallow comparisons instead of deep comparisons
167
+
114
168
-**Condition**: In `React.memo` and similar optimization functions, compare only specific relevant properties instead of using deep equality checks.
115
169
-**Reasoning**: Deep equality checks recursively compare all nested properties, creating performance overhead that often exceeds the re-render cost they aim to prevent. Shallow comparisons of specific relevant properties provide the same optimization benefits with minimal computational cost.
-`path`: Full file path (e.g., "src/components/ReportActionsList.tsx")
168
227
-`line`: Line number where the issue occurs
169
228
-`body`: Concise and actionable description of the violation and fix, following the below Comment Format
229
+
4.**Each comment must reference exactly one Rule ID.**
230
+
5.**Output must consist exclusively of calls to mcp__github_inline_comment__create_inline_comment in the required format.** No other text, Markdown, or prose is allowed.
231
+
6.**If no violations are found, output exactly** (with no quotes, markdown, or additional text):
232
+
LGTM :feelsgood:. Thank you for your hard work!
233
+
7.**Output LGTM if and only if**:
234
+
- You examined EVERY line of EVERY changed file
235
+
- You checked EVERY changed file against ALL rules
236
+
- You found ZERO violations matching the exact rule criteria
237
+
- You verified no false negatives by checking each rule systematically
238
+
If you found even ONE violation or have ANY uncertainty do NOT output LGTM - create inline comments instead.
239
+
8.**DO NOT invent new rules, stylistic preferences, or commentary outside the listed rules.**
240
+
9.**DO NOT describe what you are doing, output any summaries, explanations, extra content, comments on rules that are NOT violated or ANYTHING ELSE except from rules violations or LGTM message.**
241
+
EXCEPTION: If you believe something MIGHT be a Rule violation but are uncertain, err on the side of creating an inline comment with your concern rather than skipping it.
0 commit comments