Allow non-null assertions in tests; refactor two production hotspots to drop them
- eslint.config.js: disable no-non-null-assertion for *.test.ts/tsx and tests/** (fixture-driven tests routinely use arr[0]! after a length check — signal there is low). - closestFlight.ts: replace flights.legs[0]! / flights[flights.length-1]! with explicit null checks. - FlightDetailsAccordion.tsx: refactor transition + meal/service branches to use local consts narrowed by a preceding truthy check, dropping the `leg.transition!.registration!` patterns. Warning count: 190 → 65. Remaining warnings are pre-existing production-code non-null assertions spread across the codebase.
This commit is contained in:
@@ -177,4 +177,16 @@ export default [
|
||||
],
|
||||
},
|
||||
},
|
||||
// Test files get a looser ruleset: non-null assertions are idiomatic
|
||||
// when fixtures guarantee presence (`arr[0]!` after an explicit length
|
||||
// check). Production code keeps the warning; tests don't.
|
||||
{
|
||||
files: [
|
||||
"src/**/*.test.{ts,tsx}",
|
||||
"tests/**/*.{ts,tsx}",
|
||||
],
|
||||
rules: {
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user