Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.

fix: remove all non-null assertions to fix noNonNullAssertion lint warnings - #21

Merged
Upd4ting merged 2 commits into
mainfrom
fix/remove-non-null-assertions
Mar 7, 2026
Merged

fix: remove all non-null assertions to fix noNonNullAssertion lint warnings#21
Upd4ting merged 2 commits into
mainfrom
fix/remove-non-null-assertions

Conversation

@Upd4ting

@Upd4ting Upd4ting commented Mar 7, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

N/A

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Eliminates all 20 lint/style/noNonNullAssertion Biome warnings across 8 files by replacing ! (non-null assertion) operators with safe alternatives:

Source files (5 fixes):

  • components.ts?? "" fallback after .has() guard; early return guard for filterValue
  • metadata.ts — local variable with undefined check for map iteration; null guard with error throw for schema lookup

Test files (15 fixes):

  • Added getSchemaInstance() helper in utils.ts that throws on missing schema
  • Replaced 8 Schema.get(...)!.instance() calls with getSchemaInstance(...) across 6 test files
  • routes.test.ts — merged into single optional chain; id ?? "" fallback
  • mandatory.test.ts — added if (!id) throw guards in 3 functions, removing 5 id! usages
  • Cleaned up unused Schema imports in 4 files

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Greptile Summary

This PR eliminates all 20 noNonNullAssertion Biome lint warnings across 8 files by replacing TypeScript ! non-null assertions with safe, explicit alternatives — either null-checks with early throws (which improves error observability), optional chaining with meaningful fallbacks, or the new getSchemaInstance test helper that centralises the Schema.get()!.instance() pattern.

The source-code changes in components.ts and metadata.ts are logically equivalent to the originals; no behavioral regressions were identified. The test-file changes are clean refactors.

Key highlights:

  • metadata.ts setForeign now throws descriptive errors (Schema "…" not found / Unable to infer foreign table name for field "…") instead of crashing with opaque null-reference errors — a genuine improvement.
  • mandatory.test.ts replaces five id! usages with explicit if (!id) throw guards, making test failures easier to diagnose.
  • parseInt(val, 10) radix added in components.ts — good practice.
  • Minor inconsistency: the new foreignSchema variable in Validation.Unlock is used in the .map() branch but the else branch still references field.foreign[1] directly; both are equivalent, but using the variable consistently would improve readability.

Confidence Score: 4/5

  • Safe to merge — all logic in production code is preserved and the null-safety improvements are correct.
  • All 20 non-null assertion replacements were traced through the code and verified to be logically equivalent to the originals. The only issue is a minor style inconsistency in Validation.Unlock where the introduced foreignSchema variable should be used consistently in both branches. No runtime regressions were identified.
  • src/interfaces/data-api/beta/components.ts (minor style inconsistency in Validation.Unlock)

Last reviewed commit: 1521c07

Greptile also left 1 inline comment on this PR.

Upd4ting added 2 commits March 7, 2026 17:37
…rnings

Replace 20 non-null assertion (!) usages across source and test files with
safe alternatives: null guards, fallback values, and optional chaining.
Add getSchemaInstance helper in test utils to centralize schema lookup.
Replace ESLint and Prettier with Biome for linting and formatting.
Remove eslint.config.mjs, .prettierrc.json, .prettierignore and
related devDependencies. Add biome.json configuration and reformat
codebase to match Biome's style (double quotes, sorted imports,
space indentation).
Comment on lines +491 to 494
const foreignSchema = field.foreign[1];
dbData[name] = Array.isArray(dbData[name])
? dbData[name].map((entry) => fromDatabase(entry, field.foreign![1]!))
? dbData[name].map((entry) => fromDatabase(entry, foreignSchema))
: fromDatabase(dbData[name], field.foreign[1]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inconsistent use of foreignSchema variable

The foreignSchema local variable was introduced to avoid the double non-null assertion field.foreign![1]! in the array branch, but the else branch still accesses field.foreign[1] directly rather than reusing the variable. For consistency, the else branch should also use foreignSchema.

Suggested change
const foreignSchema = field.foreign[1];
dbData[name] = Array.isArray(dbData[name])
? dbData[name].map((entry) => fromDatabase(entry, field.foreign![1]!))
? dbData[name].map((entry) => fromDatabase(entry, foreignSchema))
: fromDatabase(dbData[name], field.foreign[1]);
const foreignSchema = field.foreign[1];
dbData[name] = Array.isArray(dbData[name])
? dbData[name].map((entry) => fromDatabase(entry, foreignSchema))
: fromDatabase(dbData[name], foreignSchema);
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/interfaces/data-api/beta/components.ts
Line: 491-494

Comment:
**Inconsistent use of `foreignSchema` variable**

The `foreignSchema` local variable was introduced to avoid the double non-null assertion `field.foreign![1]!` in the array branch, but the `else` branch still accesses `field.foreign[1]` directly rather than reusing the variable. For consistency, the else branch should also use `foreignSchema`.

```suggestion
        const foreignSchema = field.foreign[1];
        dbData[name] = Array.isArray(dbData[name])
          ? dbData[name].map((entry) => fromDatabase(entry, foreignSchema))
          : fromDatabase(dbData[name], foreignSchema);
```

How can I resolve this? If you propose a fix, please make it concise.

@Upd4ting
Upd4ting merged commit a5e27c2 into main Mar 7, 2026
3 checks passed
@Upd4ting
Upd4ting deleted the fix/remove-non-null-assertions branch March 7, 2026 16:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant