-
Notifications
You must be signed in to change notification settings - Fork 154
fix: prevent unchecked indexed access #1132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances TypeScript type safety by upgrading to TypeScript 5.9 and enabling strict compiler options, specifically addressing unchecked indexed access issues. The changes add optional chaining and null checks throughout the codebase to prevent potential runtime errors when accessing array elements or object properties that may not exist.
Key changes:
- Downgraded TypeScript from v5.7.2 to v5.9.3 in package.json
- Added optional chaining (
?.) operators when accessing array elements and object properties - Introduced null/undefined guards before accessing potentially non-existent values
Reviewed changes
Copilot reviewed 16 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| package.json | Downgraded TypeScript version from 5.7.2 to 5.9.3 |
| tests/test-utils.ts | Added override keyword to method signature |
| tests/rules/prefer-user-event.test.ts | Added optional chaining to prevent unchecked indexed access in test data |
| tests/rules/prefer-query-matchers.test.ts | Added optional chaining to test error data properties |
| src/rules/prefer-user-event.ts | Added optional chaining and fallback for mapping lookup |
| src/rules/prefer-find-by.ts | Added null checks for query method and source code line access |
| src/rules/prefer-query-by-disappearance.ts | Added guard clause for missing argument node |
| src/rules/no-wait-for-side-effects.ts | Added optional chaining for line access |
| src/rules/no-wait-for-multiple-assertions.ts | Added optional chaining for line access |
| src/rules/no-promise-in-fire-event.ts | Added guard clause for missing DOM element argument |
| src/rules/no-manual-cleanup.ts | Added null check before accessing declared variables |
| src/rules/no-global-regexp-flag-in-query.ts | Added conditional check before processing first argument |
| src/rules/no-container.ts | Added optional chaining for property access |
| src/node-utils/accessors.ts | Added optional chaining for quasi array access |
| src/create-testing-library-rule/detect-testing-library-utils.ts | Added null coalescing for empty array access |
| src/utils/resolve-to-testing-library-fn.ts | Added null checks for chain and def access |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (ref && ref.defs.length > 0) { | ||
| const def = ref.defs[ref.defs.length - 1]; | ||
| const importDetails = describePossibleImportDef(def); | ||
| const importDetails = def ? describePossibleImportDef(def) : null; |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null check for def is redundant. The code at line 110 already retrieves def from ref.defs[ref.defs.length - 1], and line 109 confirms ref.defs.length > 0, guaranteeing that def will always be defined at this point. The optional chaining is unnecessary here.
| const importDetails = def ? describePossibleImportDef(def) : null; | |
| const importDetails = describePossibleImportDef(def); |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1132 +/- ##
==========================================
- Coverage 97.44% 97.35% -0.10%
==========================================
Files 49 49
Lines 5979 6002 +23
Branches 1522 1536 +14
==========================================
+ Hits 5826 5843 +17
- Misses 151 157 +6
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
🎉 This PR is included in version 7.15.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Checks
Changes
Context
Closes #855