Skip to content
Open
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
54 changes: 54 additions & 0 deletions lib/utils/result_formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,57 @@ describe('ResultFormatter timestamp family NaN guards', () => {
expect(dr.formatted.items[0].value).toBe('02:08:00');
});
});

describe('ResultFormatter numeric formatters NaN guards', () => {
// Non-numeric ACARS fields ('---', '***', whitespace) become NaN via
// Number()/parseInt(); these must disappear from formatted.items rather
// 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'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 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

['airspeed', (dr) => ResultFormatter.airspeed(dr, NaN), 'airspeed'],
['mach', (dr) => ResultFormatter.mach(dr, NaN), 'mach'],
['day', (dr) => ResultFormatter.day(dr, NaN), 'day'],
['month', (dr) => ResultFormatter.month(dr, NaN), 'month'],
['departureDay', (dr) => ResultFormatter.departureDay(dr, NaN), 'departure_day'],
['arrivalDay', (dr) => ResultFormatter.arrivalDay(dr, NaN), 'arrival_day'],
];

test.each(cases)(
'%s skips NaN instead of pushing a "NaN" item',
(_name, invoke, rawKey) => {
const dr = makeDecodeResult();
invoke(dr);
expect(dr.formatted.items.length).toBe(0);
expect((dr.raw as Record<string, unknown>)[rawKey]).toBeUndefined();
},
);

test('heading still formats a valid value', () => {
const dr = makeDecodeResult();
ResultFormatter.heading(dr, 270);
expect(dr.raw.heading).toBe(270);
expect(dr.formatted.items[0].value).toBe('270');
});

test('groundspeed still formats a valid value', () => {
const dr = makeDecodeResult();
ResultFormatter.groundspeed(dr, 420);
expect(dr.raw.groundspeed).toBe(420);
expect(dr.formatted.items[0].value).toBe('420 knots');
});

test('mach still formats a valid value', () => {
const dr = makeDecodeResult();
ResultFormatter.mach(dr, 0.84);
expect(dr.raw.mach).toBe(0.84);
expect(dr.formatted.items[0].value).toBe('0.84 mach');
});

test('day still formats a valid value', () => {
const dr = makeDecodeResult();
ResultFormatter.day(dr, 12);
expect(dr.raw.day).toBe(12);
expect(dr.formatted.items[0].value).toBe('12');
});
});
24 changes: 24 additions & 0 deletions lib/utils/result_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ export class ResultFormatter {
}

static groundspeed(decodeResult: DecodeResult, value: number) {
if (isNaN(value)) {
return;
}
decodeResult.raw.groundspeed = value;
decodeResult.formatted.items.push({
type: 'aircraft_groundspeed',
Expand All @@ -313,6 +316,9 @@ export class ResultFormatter {
}

static airspeed(decodeResult: DecodeResult, value: number) {
if (isNaN(value)) {
return;
}
decodeResult.raw.airspeed = value;
decodeResult.formatted.items.push({
type: 'airspeed',
Expand All @@ -323,6 +329,9 @@ export class ResultFormatter {
}

static mach(decodeResult: DecodeResult, value: number) {
if (isNaN(value)) {
return;
}
decodeResult.raw.mach = value;
decodeResult.formatted.items.push({
type: 'mach',
Expand Down Expand Up @@ -363,6 +372,9 @@ export class ResultFormatter {
}

static heading(decodeResult: DecodeResult, value: number) {
if (isNaN(value)) {
return;
}
decodeResult.raw.heading = value;
decodeResult.formatted.items.push({
type: 'heading',
Expand Down Expand Up @@ -460,6 +472,9 @@ export class ResultFormatter {
}

static day(decodeResult: DecodeResult, day: number) {
if (isNaN(day)) {
return;
}
decodeResult.raw.day = day;
decodeResult.formatted.items.push({
type: 'day',
Expand All @@ -470,6 +485,9 @@ export class ResultFormatter {
}

static month(decodeResult: DecodeResult, month: number) {
if (isNaN(month)) {
return;
}
decodeResult.raw.month = month;
decodeResult.formatted.items.push({
type: 'month',
Expand All @@ -480,6 +498,9 @@ export class ResultFormatter {
}

static departureDay(decodeResult: DecodeResult, day: number) {
if (isNaN(day)) {
return;
}
decodeResult.raw.departure_day = day;
decodeResult.formatted.items.push({
type: 'day',
Expand All @@ -490,6 +511,9 @@ export class ResultFormatter {
}

static arrivalDay(decodeResult: DecodeResult, day: number) {
if (isNaN(day)) {
return;
}
decodeResult.raw.arrival_day = day;
decodeResult.formatted.items.push({
type: 'day',
Expand Down