Commit 0263541
Keep original buildConsoleReplay parameter order (disable ESLint rule) (#2097)
## Summary
**REVERTED**: After analysis, the parameter reordering was reverted to
preserve better API ergonomics. The original parameter order
`(customConsoleHistory, numberOfMessagesToSkip)` is more natural for the
actual usage patterns in the codebase.
## Problem & Analysis
Initially attempted to fix ESLint `default-param-last` rule violation by
reordering parameters. However, analysis of all 6 call sites showed this
degraded API quality:
**Usage Pattern Analysis:**
- 3 call sites: Pass only `customConsoleHistory` (most common)
- 2 call sites: Use defaults
- 1 call site: Pass both parameters (rare)
**Impact of Reordering:**
```typescript
// Before reorder (natural)
consoleReplay(consoleHistory) // ✅ Clean - most common use
// After reorder (forced)
consoleReplay(0, consoleHistory) // ❌ Ugly - requires passing 0!
```
The ESLint rule optimizes for passing only `numberOfMessagesToSkip`,
which **never happens** in the codebase.
## Final Solution
**Kept original parameter order** and disabled the ESLint rule with
justification:
```typescript
// eslint-disable-next-line @typescript-eslint/default-param-last
export function consoleReplay(
customConsoleHistory: Console['history'] | undefined = undefined,
numberOfMessagesToSkip = 0
): string
```
## Changes
### Commit 1: Initial Refactor (Reverted)
- Reordered parameters to satisfy ESLint rule
- Updated all call sites
### Commit 2: Code Review Fixes
- ✅ Removed debug `console.error` statements from production code
- ✅ Added documentation explaining `consoleReplay()` vs
`buildConsoleReplay()`
- ✅ Changed `nonce` parameter to idiomatic TypeScript syntax (`nonce?:
string`)
- ✅ Added comprehensive test coverage for parameter functionality
### Commit 3: Parameter Order Reversion ⭐
- Reverted to original parameter order based on usage analysis
- Added ESLint disable comments with detailed justification
- Updated all call sites back to natural, readable forms
- See `PARAMETER_ORDER_ANALYSIS.md` for complete analysis
## Files Changed
1. **buildConsoleReplay.ts**: Kept original parameter order, added
ESLint disable
2. **serverRenderReactComponent.ts**: Clean call sites:
`buildConsoleReplay(consoleHistory)`
3. **streamingUtils.ts**: Natural order: `consoleReplay(consoleHistory,
skipCount)`
4. **buildConsoleReplay.test.js**: Added 3 new test cases, updated for
parameter order
## Testing
- ✅ All 104 tests pass
- ✅ Build passes: `yarn run build`
- ✅ RuboCop passes: `bundle exec rubocop`
- ✅ ESLint passes: `rake lint:eslint`
- ✅ Type checking passes: `yarn run type-check`
## Breaking Change?
**No** - These are internal functions. All call sites updated to use the
original, more natural parameter order.
## Key Takeaway
Sometimes lint rules don't fit the domain. This is a case where:
- **The rule is valid in general** (default params should usually be
last)
- **But doesn't match our usage** (we frequently pass only the first
param)
- **Disabling is justified** when it improves API ergonomics
See `PARAMETER_ORDER_ANALYSIS.md` for detailed analysis of all call
sites and rationale.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3f21898 commit 0263541
File tree
3 files changed
+60
-4
lines changed- packages
- react-on-rails-pro/src
- react-on-rails
- src
- tests
3 files changed
+60
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
116 | 122 | | |
117 | 123 | | |
118 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | | - | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
126 | 174 | | |
0 commit comments