Skip to content

Conversation

@pandeymangg
Copy link
Contributor

@pandeymangg pandeymangg commented Jul 1, 2025

This PR addresses multiple SonarQube reliability and maintainability issues identified in the React Native SDK codebase. The changes focus on improving async/await handling, error management, and code quality across the entire library.
Fixes #5

Summary by CodeRabbit

  • New Features

    • Added a utility function for delayed asynchronous results.
  • Bug Fixes

    • Improved handling of asynchronous configuration loading throughout the app to prevent potential timing issues.
  • Refactor

    • Updated several internal functions and listeners to use asynchronous configuration retrieval.
    • Simplified singleton initialization logic for various components.
    • Tightened type definitions for styling and file upload configurations.
  • Tests

    • Updated tests to support asynchronous initialization and improved code readability with utility functions.
  • Chores

    • Added a new development dependency for improved development workflow.

@coderabbitai
Copy link

coderabbitai bot commented Jul 1, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change set refactors configuration initialization throughout the codebase to use asynchronous singleton retrieval (RNConfig.getInstance() now returns a Promise). All affected functions, listeners, and tests are updated to handle asynchronous config loading. Several type definitions are tightened, and minor code style, formatting, and utility improvements are made. No core business logic is altered.

Changes

File(s) Change Summary
package.json Added "rimraf" v6.0.1 to devDependencies.
packages/react-native/src/components/survey-web-view.tsx Refactored to load appConfig asynchronously within the component using hooks.
packages/react-native/src/lib/common/config.ts Refactored RNConfig to use async getInstance() and explicit async init() method; constructor is now empty.
packages/react-native/src/lib/common/setup.ts,
packages/react-native/src/lib/user/update.ts,
packages/react-native/src/lib/survey/action.ts,
packages/react-native/src/lib/user/state.ts,
packages/react-native/src/lib/environment/state.ts,
packages/react-native/src/lib/user/update-queue.ts,
packages/react-native/src/lib/user/attribute.ts,
packages/react-native/src/lib/user/user.ts,
packages/react-native/src/lib/survey/store.ts
Updated all config instance retrievals to be asynchronous (await RNConfig.getInstance()); updated related function signatures and error handling as needed.
packages/react-native/src/lib/common/api.ts,
packages/react-native/src/lib/common/file-upload.ts,
packages/react-native/src/lib/common/command-queue.ts,
packages/react-native/src/lib/common/logger.ts,
packages/react-native/src/lib/common/storage.ts
Code style and formatting improvements; added readonly modifiers to some class properties; no logic changes.
packages/react-native/src/lib/common/utils.ts Added new utility function delayedResult<T>(value, ms); added NOSONAR comment.
packages/react-native/src/types/config.ts Tightened TStylingColor.dark type from `string
packages/react-native/src/types/storage.ts Tightened optional types in TUploadFileConfig and TUploadFileResponse interfaces (removed explicit `
packages/react-native/src/lib/common/tests/command-queue.test.ts,
packages/react-native/src/lib/common/tests/config.test.ts,
packages/react-native/src/lib/common/tests/setup.test.ts,
packages/react-native/src/lib/common/tests/utils.test.ts,
packages/react-native/src/lib/environment/tests/state.test.ts,
packages/react-native/src/lib/survey/tests/action.test.ts,
packages/react-native/src/lib/user/tests/attribute.test.ts,
packages/react-native/src/lib/user/tests/state.test.ts,
packages/react-native/src/lib/user/tests/update-queue.test.ts,
packages/react-native/src/lib/user/tests/user.test.ts
Updated tests to handle async config retrieval, use new utility functions, and improve formatting; updated mocks and assertions accordingly.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Solve Sonarqube issues (#5)

Assessment against linked issues: Out-of-scope changes

No out-of-scope or unrelated code changes were identified relative to the objectives in the linked issues.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pandeymangg pandeymangg requested a review from Dhruwang July 1, 2025 07:55
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
package.json (1)

14-15: Keep devDependencies sorted alphabetically and use consistent version specifiers

rimraf is inserted after typescript, breaking the existing alphabetical order (prettier, rimraf, turbo, typescript would be the correct ordering).
Additionally, the new entry omits the caret (^) prefix that the other dependencies use, introducing an unnecessary inconsistency in version-range style.

   "prettier": "^3.5.3",
-  "turbo": "^2.5.2",
-  "typescript": "5.8.2",
-  "rimraf": "6.0.1"
+  "rimraf": "^6.0.1",
+  "turbo": "^2.5.2",
+  "typescript": "5.8.2"

Reordering and aligning the caret prefix keeps the file tidy and avoids confusion over why one dependency is pinned while the others float within the same major version.
If you intentionally want rimraf hard-pinned, add a short comment to clarify the rationale.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81d43dc and 412e5c2.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (30)
  • package.json (1 hunks)
  • packages/react-native/src/components/survey-web-view.tsx (3 hunks)
  • packages/react-native/src/lib/common/api.ts (4 hunks)
  • packages/react-native/src/lib/common/command-queue.ts (3 hunks)
  • packages/react-native/src/lib/common/config.ts (3 hunks)
  • packages/react-native/src/lib/common/file-upload.ts (5 hunks)
  • packages/react-native/src/lib/common/logger.ts (1 hunks)
  • packages/react-native/src/lib/common/setup.ts (11 hunks)
  • packages/react-native/src/lib/common/storage.ts (1 hunks)
  • packages/react-native/src/lib/common/tests/command-queue.test.ts (5 hunks)
  • packages/react-native/src/lib/common/tests/config.test.ts (4 hunks)
  • packages/react-native/src/lib/common/tests/setup.test.ts (13 hunks)
  • packages/react-native/src/lib/common/tests/utils.test.ts (5 hunks)
  • packages/react-native/src/lib/common/utils.ts (2 hunks)
  • packages/react-native/src/lib/environment/state.ts (1 hunks)
  • packages/react-native/src/lib/environment/tests/state.test.ts (9 hunks)
  • packages/react-native/src/lib/survey/action.ts (2 hunks)
  • packages/react-native/src/lib/survey/store.ts (1 hunks)
  • packages/react-native/src/lib/survey/tests/action.test.ts (3 hunks)
  • packages/react-native/src/lib/user/attribute.ts (1 hunks)
  • packages/react-native/src/lib/user/state.ts (2 hunks)
  • packages/react-native/src/lib/user/tests/attribute.test.ts (3 hunks)
  • packages/react-native/src/lib/user/tests/state.test.ts (5 hunks)
  • packages/react-native/src/lib/user/tests/update-queue.test.ts (7 hunks)
  • packages/react-native/src/lib/user/tests/user.test.ts (5 hunks)
  • packages/react-native/src/lib/user/update-queue.ts (3 hunks)
  • packages/react-native/src/lib/user/update.ts (2 hunks)
  • packages/react-native/src/lib/user/user.ts (2 hunks)
  • packages/react-native/src/types/config.ts (1 hunks)
  • packages/react-native/src/types/storage.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (12)
packages/react-native/src/lib/common/tests/command-queue.test.ts (3)
packages/react-native/src/lib/common/utils.ts (1)
  • delayedResult (192-194)
packages/react-native/src/types/error.ts (1)
  • Result (11-11)
packages/react-native/src/lib/common/setup.ts (1)
  • checkSetup (279-291)
packages/react-native/src/lib/user/update.ts (2)
packages/react-native/src/lib/common/config.ts (1)
  • RNConfig (9-96)
packages/react-native/src/lib/common/utils.ts (1)
  • filterSurveys (40-125)
packages/react-native/src/lib/common/tests/utils.test.ts (1)
packages/react-native/src/lib/common/utils.ts (2)
  • delayedResult (192-194)
  • getLanguageCode (153-179)
packages/react-native/src/lib/survey/tests/action.test.ts (3)
packages/react-native/src/lib/common/config.ts (1)
  • RNConfig (9-96)
packages/react-native/src/lib/common/utils.ts (1)
  • shouldDisplayBasedOnPercentage (181-186)
packages/react-native/src/lib/survey/action.ts (1)
  • trackAction (45-72)
packages/react-native/src/lib/common/api.ts (2)
packages/react-native/src/types/error.ts (2)
  • Result (11-11)
  • ApiErrorResponse (22-39)
packages/react-native/src/types/config.ts (1)
  • TEnvironmentState (26-33)
packages/react-native/src/lib/user/tests/update-queue.test.ts (1)
packages/react-native/src/lib/user/tests/__mocks__/update-queue.mock.ts (1)
  • mockAttributes (3-6)
packages/react-native/src/lib/user/state.ts (1)
packages/react-native/src/lib/common/config.ts (1)
  • RNConfig (9-96)
packages/react-native/src/lib/common/command-queue.ts (1)
packages/react-native/src/types/error.ts (1)
  • Result (11-11)
packages/react-native/src/lib/user/update-queue.ts (2)
packages/react-native/src/types/config.ts (1)
  • TAttributes (67-67)
packages/react-native/src/lib/common/config.ts (1)
  • RNConfig (9-96)
packages/react-native/src/lib/user/tests/user.test.ts (3)
packages/react-native/src/lib/common/config.ts (1)
  • RNConfig (9-96)
packages/react-native/src/lib/common/setup.ts (2)
  • setup (64-277)
  • tearDown (294-315)
packages/react-native/src/lib/user/user.ts (1)
  • logout (36-57)
packages/react-native/src/lib/common/tests/setup.test.ts (6)
packages/react-native/src/lib/common/config.ts (1)
  • RNConfig (9-96)
packages/react-native/src/lib/common/logger.ts (1)
  • Logger (8-48)
packages/react-native/src/lib/common/setup.ts (1)
  • setup (64-277)
packages/react-native/src/lib/common/tests/__mocks__/config.mock.ts (1)
  • mockConfig (10-125)
packages/react-native/src/lib/common/utils.ts (2)
  • isNowExpired (188-190)
  • filterSurveys (40-125)
packages/react-native/src/lib/environment/state.ts (1)
  • fetchEnvironmentState (18-49)
packages/react-native/src/components/survey-web-view.tsx (2)
packages/react-native/src/lib/common/config.ts (1)
  • RNConfig (9-96)
packages/react-native/src/lib/common/utils.ts (1)
  • getStyling (127-144)
🔇 Additional comments (97)
packages/react-native/src/lib/common/storage.ts (1)

3-6: LGTM! Formatting improvement enhances readability.

The multi-line formatting of the complex type assertion improves code readability while maintaining the same functionality.

packages/react-native/src/lib/common/utils.ts (2)

93-93: LGTM! Appropriate use of NOSONAR comment.

The NOSONAR comment correctly suppresses static analysis warnings for documented technical debt that's tracked with a TODO comment.


192-194: LGTM! Well-implemented utility function.

The delayedResult function is a clean, reusable utility that improves test code consistency by replacing manual Promise constructions with setTimeout. The generic typing makes it flexible for different value types.

packages/react-native/src/lib/common/logger.ts (1)

13-13: LGTM! Modern singleton initialization pattern.

The use of nullish assignment operator (??=) provides the same lazy initialization behavior as an explicit if check but with more concise and idiomatic syntax.

packages/react-native/src/types/config.ts (1)

76-76: LGTM! Type definition improvement enhances clarity.

Removing undefined from the union type makes the type definition cleaner and more explicit, while the optional ? marker already handles the undefined case appropriately.

packages/react-native/src/lib/user/tests/attribute.test.ts (3)

4-4: LGTM! Good use of the new utility function.

Importing delayedResult for consistent async delay handling across tests improves code reusability and maintainability.


31-33: LGTM! Formatting improvements enhance readability.

The multi-line formatting for mock method calls with complex arguments improves code readability and makes the test assertions clearer.

Also applies to: 41-43, 58-66


73-75: LGTM! Consistent use of delayedResult utility.

Replacing manual Promise construction with the delayedResult utility improves test code consistency and maintainability across the codebase.

packages/react-native/src/lib/user/attribute.ts (1)

9-9: LGTM! Proper async handling.

The addition of await ensures the asynchronous attribute update completes before proceeding. This aligns correctly with the broader refactor making updateAttributes asynchronous.

packages/react-native/src/lib/user/tests/update-queue.test.ts (3)

2-6: LGTM! Organized imports for mock objects.

The import reorganization improves readability by grouping mock-related imports together.


77-79: LGTM! Correct mock type casting.

The mock return value is properly cast as Promise<RNConfig> to match the new asynchronous getInstance() method signature.


79-81: LGTM! Consistent async test handling.

All test functions that call updateAttributes are properly updated to be async and use await. This ensures tests correctly handle the new asynchronous behavior.

Also applies to: 89-91, 102-103, 112-113, 124-125, 147-147, 160-160

packages/react-native/src/lib/user/update.ts (3)

7-13: LGTM! Improved import formatting.

The multiline import formatting enhances readability by separating different types of imports.


73-73: LGTM! Correct async config retrieval.

The addition of await for RNConfig.getInstance() properly handles the asynchronous configuration initialization pattern introduced in this refactor.


81-85: LGTM! Enhanced function call formatting.

The multiline formatting of function calls and parameters improves code readability and maintainability.

Also applies to: 89-92

packages/react-native/src/lib/common/tests/utils.test.ts (4)

8-8: LGTM! Added utility import.

The import of delayedResult supports the standardization of async testing utilities across the codebase.


58-58: LGTM! Standardized async testing utilities.

Replacing manual promise delays with delayedResult improves consistency and maintainability across test suites.

Also applies to: 73-73


359-359: LGTM! Correct function call.

The removal of the undefined second parameter aligns with the getLanguageCode function signature, which makes the language parameter optional and defaults to returning "default" when no language is provided.


422-434: LGTM! Comprehensive test coverage.

The new test suite for delayedResult ensures the utility function works correctly with different values and delays, providing proper test coverage for the newly introduced testing utility.

packages/react-native/src/lib/survey/tests/action.test.ts (2)

77-79: LGTM! Correct async mock setup.

The mock return value is properly cast as Promise<RNConfig> to match the new asynchronous getInstance() method signature.


125-125: LGTM! Consistent async test handling.

All test functions that call trackAction are properly updated to be async and use await. This ensures tests correctly handle the asynchronous behavior introduced by the config refactor.

Also applies to: 128-128, 134-134, 139-139, 148-149

packages/react-native/src/lib/common/tests/command-queue.test.ts (9)

5-5: LGTM: Good use of utility function for consistency.

The import of delayedResult from the utils module promotes code reuse and consistency across test files.


27-28: LGTM: Improved test readability with delayedResult utility.

The replacement of manual new Promise constructions with the delayedResult utility improves code consistency and readability while maintaining the same test behavior.

Also applies to: 31-32, 35-36


55-55: LGTM: Consistent use of delayedResult utility.

The change maintains the same test behavior while using the standardized utility function.


76-76: LGTM: Consistent utility usage.

Good use of the delayedResult utility for consistency across the test suite.


91-98: LGTM: Improved formatting for readability.

The multi-line formatting of the console.error spy setup improves readability, though the mock implementation returning a Result object seems unusual for a console.error spy.


105-105: LGTM: Consistent utility usage.

The use of delayedResult maintains consistency with other test cases.


113-116: LGTM: Improved formatting for readability.

The multi-line formatting of the expect call improves readability.


122-122: LGTM: Consistent utility usage.

The replacement with delayedResult maintains consistency across all test cases.

Also applies to: 125-125


43-46: LGTM: Improved formatting for readability.

The multi-line formatting of the setInterval call improves code readability.

packages/react-native/src/lib/survey/store.ts (2)

8-8: LGTM: Improved immutability with readonly modifier.

Making the listeners property readonly prevents accidental reassignment of the Set, which could break the observer pattern. This is a good defensive programming practice.


11-11: LGTM: Cleaner singleton pattern with nullish coalescing assignment.

The use of the nullish coalescing assignment operator (??=) provides a more concise and readable way to implement lazy initialization in the singleton pattern.

packages/react-native/src/lib/user/state.ts (2)

21-22: LGTM: Proper async conversion for RNConfig.getInstance().

The function signature change to async (): Promise<void> and the await of RNConfig.getInstance() correctly handles the asynchronous nature of the config singleton retrieval. This aligns with the broader refactoring across the codebase.


43-46: LGTM: Improved formatting for readability.

The multi-line formatting of the setInterval call improves code readability.

packages/react-native/src/lib/common/api.ts (4)

2-6: LGTM: Improved import formatting for readability.

The multi-line import formatting improves code readability, especially when importing multiple types from the same module.


47-49: LGTM: Improved formatting for readability.

The multi-line formatting of the conditional object spread improves code readability.


59-61: LGTM: Enhanced immutability with readonly modifiers.

Making the private properties readonly prevents accidental mutation after construction, which is a good defensive programming practice for class properties that should remain constant.


99-101: LGTM: Improved formatting for readability.

The multi-line formatting of the return type annotation improves code readability, especially for complex generic types.

packages/react-native/src/lib/user/tests/state.test.ts (6)

1-9: LGTM: Improved import formatting for readability.

The multi-line import formatting improves code readability and makes it easier to see all imported entities.

Also applies to: 11-14


28-28: LGTM: Updated type annotation for async mock.

The type annotation correctly reflects that RNConfig.getInstance() now returns a Promise<RNConfig>.


41-41: LGTM: Proper async handling in test.

The test function is correctly marked as async, the mock returns a Promise, and the function call is properly awaited to handle the asynchronous nature of RNConfig.getInstance().

Also applies to: 49-49, 51-51


73-73: LGTM: Consistent mock return type.

The mock return value is correctly typed as Promise<RNConfig> to match the new async interface.


81-81: LGTM: Proper async handling in test.

The test function is correctly marked as async, the mock returns a Promise, and both function calls are properly awaited to handle the asynchronous configuration retrieval.

Also applies to: 89-89, 91-92


105-105: LGTM: Consistent mock return type.

The mock return value is correctly typed as Promise<RNConfig> to maintain consistency with the async interface.

packages/react-native/src/lib/common/tests/config.test.ts (6)

18-18: LGTM: Proper async handling in test setup

The beforeEach correctly awaits RNConfig.getInstance() calls, ensuring proper test isolation and setup.

Also applies to: 24-24


32-35: LGTM: Singleton test properly updated for async pattern

The test correctly verifies that multiple async getInstance() calls return the same instance, maintaining singleton behavior.


40-43: LGTM: Error message formatting improved

The multi-line string formatting enhances readability while maintaining the same assertion logic.


46-49: LGTM: Consistent mock setup formatting

The multi-line formatting of AsyncStorage.getItem mocks improves readability and maintainability.

Also applies to: 67-69, 92-94, 119-121, 135-137


85-88: LGTM: Multi-line error assertion formatting

The formatting improvement makes the error message assertion more readable.


100-108: LGTM: Enhanced test coverage for config updates

The test properly verifies that updated config values can be retrieved after the update call, improving test completeness.

Also applies to: 125-127

packages/react-native/src/lib/common/command-queue.ts (4)

7-13: LGTM: Improved type safety with readonly queue

Making the queue property readonly prevents accidental reassignment while allowing array mutations through methods like push() and shift(). The multi-line function type signature improves readability.


18-24: LGTM: Consistent type signature formatting

The multi-line function type signature in the add method matches the queue property definition, maintaining consistency.


25-29: LGTM: Multi-line object formatting

The formatting improvement makes the queue item construction more readable.


63-66: LGTM: Multi-line method invocation formatting

The formatting of the command execution improves readability while maintaining the same functionality.

packages/react-native/src/lib/user/update-queue.ts (3)

18-18: LGTM: Cleaner singleton pattern implementation

Using the nullish coalescing assignment operator (??=) simplifies the singleton logic while maintaining the same behavior.


37-39: LGTM: Proper async handling for config access

Converting updateAttributes to async and awaiting RNConfig.getInstance() ensures the config is properly initialized before use.


81-81: LGTM: Consistent async config retrieval

The processUpdates method correctly awaits the asynchronous config instance, maintaining consistency with the async pattern.

packages/react-native/src/lib/common/file-upload.ts (5)

2-5: LGTM: Improved import formatting

Multi-line import statement enhances readability and makes it easier to add/remove imports in the future.


8-9: LGTM: Enhanced immutability with readonly properties

Making appUrl and environmentId readonly prevents accidental modification after construction, improving code safety.


35-44: LGTM: Improved fetch call formatting

The multi-line formatting of the fetch call and its options improves readability and maintainability.


54-60: LGTM: Enhanced destructuring readability

Multi-line destructuring assignment makes it easier to identify the extracted properties.


101-104: LGTM: Consistent multi-line string formatting

Converting single-line string constructions to multi-line format improves readability and maintainability.

Also applies to: 132-134, 139-141

packages/react-native/src/types/storage.ts (2)

4-5: LGTM: Cleaner optional property declarations

Removing the explicit | undefined from optional properties is more idiomatic TypeScript, as the ? operator already implies the property can be undefined.


18-18: LGTM: Consistent optional property style

The presignedFields property follows the same improved pattern, maintaining consistency across the interface.

packages/react-native/src/lib/user/tests/user.test.ts (4)

1-9: LGTM: Import formatting improved.

The multiline import formatting enhances readability and follows consistent code style.


53-53: Correct type update for async config retrieval.

The type change from MockInstance<() => RNConfig> to MockInstance<() => Promise<RNConfig>> properly reflects the asynchronous nature of RNConfig.getInstance().


81-83: Mock return values correctly wrapped in promises.

The mock return values are properly updated to return promises, maintaining consistency with the async RNConfig.getInstance() method.

Also applies to: 117-119, 142-144


155-156: Simplified error handling in logout test.

The error handling has been appropriately simplified by directly mocking getInstanceConfigMock to reject with an error, which is cleaner than the previous approach.

packages/react-native/src/lib/survey/action.ts (3)

45-48: Function correctly updated for async config retrieval.

The trackAction function is properly made async with the correct return type Promise<Result<void, NetworkError>> to handle the asynchronous RNConfig.getInstance() call.


50-50: Proper async handling of config instance.

The await keyword is correctly added to handle the asynchronous RNConfig.getInstance() call.


87-87: Consistent async pattern in track function.

The track function properly awaits the RNConfig.getInstance() call, maintaining consistency with the async pattern throughout the codebase.

packages/react-native/src/lib/environment/tests/state.test.ts (5)

12-21: LGTM: Import formatting improved.

The multiline import formatting enhances readability and maintains consistent code style throughout the file.


77-80: Enhanced readability with multiline object formatting.

The multiline formatting of object literals improves code readability and makes the test data structure more clear.

Also applies to: 100-104, 148-150


156-156: Correct type update for async config mock.

The type change to MockInstance<() => Promise<RNConfig>> properly reflects the asynchronous nature of the config retrieval.


180-180: Mock return values properly handle async pattern.

All mock return values are correctly wrapped as promises, ensuring compatibility with the asynchronous RNConfig.getInstance() method.

Also applies to: 209-209, 242-242, 273-273


289-289: Proper async handling in test function.

The test function is correctly made async and properly awaits the listener setup, ensuring the test accurately reflects the asynchronous behavior.

Also applies to: 292-292

packages/react-native/src/lib/common/tests/setup.test.ts (5)

2-11: LGTM: Import formatting consistency.

The multiline import statements improve readability and maintain consistent code style across the test files.

Also applies to: 19-25


89-89: Correct type annotation for async config mock.

The type change to MockInstance<() => Promise<RNConfig>> accurately reflects the asynchronous nature of RNConfig.getInstance().


103-105: Improved mock setup formatting.

The multiline formatting of the mock setup enhances readability and makes the test configuration more clear.


156-158: Mock return values consistently handle async pattern.

All mock return values are properly wrapped as promises throughout the test suite, ensuring compatibility with the asynchronous config retrieval pattern.

Also applies to: 186-188, 217-220, 282-284, 335-337, 361-363, 400-402


244-247: Enhanced test data formatting.

The multiline formatting of mock return values and test data improves readability and makes the test expectations more clear.

Also applies to: 296-298

packages/react-native/src/lib/user/user.ts (3)

3-5: Good cleanup: Removed unused imports.

The removal of unused setup and NetworkError imports improves code cleanliness and reflects the simplified logout function implementation.


8-11: Function signature correctly updated for async config.

The setUserId function is properly updated to await the asynchronous RNConfig.getInstance() call, with the function signature remaining consistent.


36-57: Well-executed refactoring of logout function.

The logout function refactoring achieves several improvements:

  • Simplified logic by removing the setup call
  • Streamlined error handling with generic error message
  • Proper async handling of config retrieval
  • Cleaner code structure while maintaining core functionality

The change aligns with the broader codebase refactoring to asynchronous configuration handling.

packages/react-native/src/lib/common/config.ts (3)

14-31: Excellent async singleton pattern implementation.

The separation of construction from initialization is a solid design improvement. The use of the null coalescing assignment operator (??=) ensures the singleton instance is created only once, and the async init() method properly handles the asynchronous loading from storage.


48-50: Improved error message for better debugging.

The updated error message clearly indicates that the init() function may not have been called, which will help developers identify the root cause more quickly.


81-84: Consistent formatting improvement.

The multiline formatting enhances readability and maintains consistency with the codebase style.

packages/react-native/src/lib/environment/state.ts (2)

54-56: Proper async conversion for config retrieval.

The function signature correctly reflects the asynchronous nature, and the config instance is properly awaited before use.


107-110: Correct handling of async interval callback.

The void operator properly handles the promise returned by the async intervalHandler, preventing unhandled promise warnings while maintaining the interval functionality.

packages/react-native/src/components/survey-web-view.tsx (4)

27-37: Excellent React pattern for async config management.

The component properly manages the asynchronous config loading with state and useEffect. The void operator correctly handles the promise without causing React warnings about unhandled promises in useEffect.


42-44: Proper guard clause prevents null reference errors.

The early return when appConfig is null ensures the component doesn't attempt to access config properties before they're loaded.


88-90: Consistent null checking pattern.

This early return maintains consistency with the earlier guard clause and prevents rendering issues when the config is not yet available.


64-64: Correct dependency array update.

Adding appConfig to the dependency array ensures the effect runs when the config becomes available, maintaining proper React hook behavior.

packages/react-native/src/lib/common/setup.ts (4)

69-69: Proper async config retrieval in setup.

The await keyword correctly handles the asynchronous config instance retrieval, ensuring the config is fully initialized before proceeding.


76-76: Consistent async pattern after config reset.

After resetting the config, the new instance is properly awaited, maintaining consistency with the async initialization pattern.


296-312: Improved tearDown function with proper async handling.

The tearDown function now properly awaits the config instance and recalculates filtered surveys, ensuring consistency in the application state during teardown.


221-223: Enhanced readability with multiline formatting.

The multiline string formatting improves code readability while maintaining the same functionality.

@pandeymangg pandeymangg requested a review from mattinannt July 2, 2025 07:27
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 2, 2025

@mattinannt mattinannt added this pull request to the merge queue Jul 2, 2025
Merged via the queue into main with commit 2b5cc02 Jul 2, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Solve Sonarqube issues

2 participants