fix(ResultFormatter): guard heading/airspeed/groundspeed/mach/day/month/departureDay/arrivalDay against NaN (#494) - #521
Conversation
…th/departureDay/arrivalDay against NaN (issue airframesio#494)
Walkthrough
ChangesResultFormatter NaN handling
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/utils/result_formatter.test.ts`:
- Line 105: Format the `groundspeed` and `departureDay` entries in the result
formatter test using Prettier’s multiline tuple layout, keeping each tuple’s
existing callback and label unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: eda52a60-7147-4c36-9e72-4ca4d127c97d
📒 Files selected for processing (2)
lib/utils/result_formatter.test.tslib/utils/result_formatter.ts
| // than surfacing as literal "NaN" strings (issue #494). | ||
| const cases: Array<[string, (dr: DecodeResult) => void, string]> = [ | ||
| ['heading', (dr) => ResultFormatter.heading(dr, NaN), 'heading'], | ||
| ['groundspeed', (dr) => ResultFormatter.groundspeed(dr, NaN), 'groundspeed'], |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix the Prettier errors on Line 105 and Line 110.
ESLint reports formatting errors for the groundspeed and departureDay entries. Apply the multiline tuple layout before merging.
Proposed formatting fix
- ['groundspeed', (dr) => ResultFormatter.groundspeed(dr, NaN), 'groundspeed'],
+ [
+ 'groundspeed',
+ (dr) => ResultFormatter.groundspeed(dr, NaN),
+ 'groundspeed',
+ ],
- ['departureDay', (dr) => ResultFormatter.departureDay(dr, NaN), 'departure_day'],
+ [
+ 'departureDay',
+ (dr) => ResultFormatter.departureDay(dr, NaN),
+ 'departure_day',
+ ],Also applies to: 110-110
🧰 Tools
🪛 ESLint
[error] 105-105: Replace 'groundspeed',·(dr)·=>·ResultFormatter.groundspeed(dr,·NaN),·'groundspeed' with ⏎······'groundspeed',⏎······(dr)·=>·ResultFormatter.groundspeed(dr,·NaN),⏎······'groundspeed',⏎····
(prettier/prettier)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@lib/utils/result_formatter.test.ts` at line 105, Format the `groundspeed` and
`departureDay` entries in the result formatter test using Prettier’s multiline
tuple layout, keeping each tuple’s existing callback and label unchanged.
Source: Linters/SAST tools
Fixes #494.
heading,airspeed,groundspeed,mach,day,month,departureDay, andarrivalDaystored whatever number they received and interpolated it into the formatted string, soNumber('---')/Number('***')/ non-numeric fields surfaced as literal"NaN","NaN knots","NaN mach"items informatted.items(andNaNinraw).This adds the same early
isNaNguard thataltitude,position,flightNumber,temperature, and the timestamp-family formatters already use: NaN input now returns without pushing an item or touchingraw, so unknown values simply disappear from the output instead of rendering as"NaN".Changes:
lib/utils/result_formatter.ts—if (isNaN(...)) return;guard at the top of the eight affected formatters.lib/utils/result_formatter.test.ts— table test covering NaN input for all eight formatters (no item pushed,rawfield left unset), plus valid-value sanity checks forheading,groundspeed,mach, andday.Out of scope (per the issue): the fuel formatters and the
Number('')silent-zero class (#487) are untouched.Tested: full suite 493 passed / 9 skipped (100 suites), formatter tests 27/27.
Summary by CodeRabbit
Bug Fixes
Tests