- 
                Notifications
    You must be signed in to change notification settings 
- Fork 151
chore: enable noUncheckedIndexedAccess #285
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 enables TypeScript's noUncheckedIndexedAccess by adding optional chaining and default fallbacks across tests and source files to avoid undefined index accesses.
- Added ?.or??guards for array indexing in tests and parsing logic.
- Introduced null checks and default values in application code (tools, atlas helpers, scripts).
- Updated logging and error handling for missing tool registrations and Atlas project creation.
Reviewed Changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description | 
|---|---|
| tests/integration/tools/mongodb/.../*.test.ts | Added ?.guards to array index accesses in assertions | 
| tests/integration/tools/mongodb/metadata/dbStats.test.ts | Defaulted JSON.parseinput with?? "{}" | 
| tests/integration/tools/atlas/atlasHelpers.ts | Guarded header indexing in parseTable | 
| src/tools/tool.ts | Logged and early-returned on missing existingTool | 
| src/tools/atlas/read/listProjects.ts | Filtered out empty org IDs and defaulted orgName | 
| src/tools/atlas/create/createProject.ts | Checked firstOrg.idbefore assignment | 
| src/common/atlas/cluster.ts | Refactored instanceSizefallback logic | 
| scripts/apply.ts | Cast OpenAPI refs and null-checked response content | 
Comments suppressed due to low confidence (2)
tests/integration/tools/mongodb/metadata/explain.test.ts:92
- Since you've already asserted that contenthas length ≥ 2, use the non-null assertion (content[0]!.text) instead of optional chaining to avoid masking indexing errors.
expect(content[0]?.text).toEqual(
tests/integration/tools/mongodb/metadata/dbStats.test.ts:33
- Prefer using a non-null assertion (elements[1]!.text) here sinceelementsis asserted to have length 2; this makes test failures more explicit if the element is missing.
const stats = JSON.parse(elements[1]?.text ?? "{}") as {
| if (headers) { | ||
| row[headers[index] ?? ""] = cell; | ||
| } | 
    
      
    
      Copilot
AI
    
    
    
      Jun 4, 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 headers array is always defined here; you can remove the runtime if check and use row[headers[index]!] = cell; to simplify the code.
| if (headers) { | |
| row[headers[index] ?? ""] = cell; | |
| } | |
| row[headers[index]!] = cell; | 
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.
'headers' is possibly 'undefined'.ts(18048)
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
closes #184