-
Notifications
You must be signed in to change notification settings - Fork 2
fix: sonarqube reliability and maintainability issues #7
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
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the WalkthroughThis change set refactors configuration initialization throughout the codebase to use asynchronous singleton retrieval ( Changes
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
package.json (1)
14-15: KeepdevDependenciessorted alphabetically and use consistent version specifiers
rimrafis inserted aftertypescript, breaking the existing alphabetical order (prettier,rimraf,turbo,typescriptwould 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 wantrimrafhard-pinned, add a short comment to clarify the rationale.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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
delayedResultfunction 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
undefinedfrom 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
delayedResultfor 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
delayedResultutility 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
awaitensures the asynchronous attribute update completes before proceeding. This aligns correctly with the broader refactor makingupdateAttributesasynchronous.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 asynchronousgetInstance()method signature.
79-81: LGTM! Consistent async test handling.All test functions that call
updateAttributesare properly updated to be async and useawait. 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
awaitforRNConfig.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
delayedResultsupports the standardization of async testing utilities across the codebase.
58-58: LGTM! Standardized async testing utilities.Replacing manual promise delays with
delayedResultimproves consistency and maintainability across test suites.Also applies to: 73-73
359-359: LGTM! Correct function call.The removal of the
undefinedsecond parameter aligns with thegetLanguageCodefunction signature, which makes thelanguageparameter optional and defaults to returning"default"when no language is provided.
422-434: LGTM! Comprehensive test coverage.The new test suite for
delayedResultensures 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 asynchronousgetInstance()method signature.
125-125: LGTM! Consistent async test handling.All test functions that call
trackActionare properly updated to be async and useawait. 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
delayedResultfrom 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 Promiseconstructions with thedelayedResultutility 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
delayedResultutility 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
delayedResultmaintains 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
delayedResultmaintains 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
listenersproperty 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 ofRNConfig.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 aPromise<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 setupThe
beforeEachcorrectly awaitsRNConfig.getInstance()calls, ensuring proper test isolation and setup.Also applies to: 24-24
32-35: LGTM: Singleton test properly updated for async patternThe test correctly verifies that multiple async
getInstance()calls return the same instance, maintaining singleton behavior.
40-43: LGTM: Error message formatting improvedThe multi-line string formatting enhances readability while maintaining the same assertion logic.
46-49: LGTM: Consistent mock setup formattingThe multi-line formatting of
AsyncStorage.getItemmocks improves readability and maintainability.Also applies to: 67-69, 92-94, 119-121, 135-137
85-88: LGTM: Multi-line error assertion formattingThe formatting improvement makes the error message assertion more readable.
100-108: LGTM: Enhanced test coverage for config updatesThe 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 queueMaking the
queuepropertyreadonlyprevents accidental reassignment while allowing array mutations through methods likepush()andshift(). The multi-line function type signature improves readability.
18-24: LGTM: Consistent type signature formattingThe multi-line function type signature in the
addmethod matches the queue property definition, maintaining consistency.
25-29: LGTM: Multi-line object formattingThe formatting improvement makes the queue item construction more readable.
63-66: LGTM: Multi-line method invocation formattingThe 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 implementationUsing the nullish coalescing assignment operator (
??=) simplifies the singleton logic while maintaining the same behavior.
37-39: LGTM: Proper async handling for config accessConverting
updateAttributesto async and awaitingRNConfig.getInstance()ensures the config is properly initialized before use.
81-81: LGTM: Consistent async config retrievalThe
processUpdatesmethod 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 formattingMulti-line import statement enhances readability and makes it easier to add/remove imports in the future.
8-9: LGTM: Enhanced immutability with readonly propertiesMaking
appUrlandenvironmentIdreadonly prevents accidental modification after construction, improving code safety.
35-44: LGTM: Improved fetch call formattingThe multi-line formatting of the fetch call and its options improves readability and maintainability.
54-60: LGTM: Enhanced destructuring readabilityMulti-line destructuring assignment makes it easier to identify the extracted properties.
101-104: LGTM: Consistent multi-line string formattingConverting 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 declarationsRemoving the explicit
| undefinedfrom optional properties is more idiomatic TypeScript, as the?operator already implies the property can be undefined.
18-18: LGTM: Consistent optional property styleThe
presignedFieldsproperty 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>toMockInstance<() => Promise<RNConfig>>properly reflects the asynchronous nature ofRNConfig.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
getInstanceConfigMockto 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
trackActionfunction is properly made async with the correct return typePromise<Result<void, NetworkError>>to handle the asynchronousRNConfig.getInstance()call.
50-50: Proper async handling of config instance.The
awaitkeyword is correctly added to handle the asynchronousRNConfig.getInstance()call.
87-87: Consistent async pattern in track function.The
trackfunction properly awaits theRNConfig.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 ofRNConfig.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
setupandNetworkErrorimports improves code cleanliness and reflects the simplified logout function implementation.
8-11: Function signature correctly updated for async config.The
setUserIdfunction is properly updated to await the asynchronousRNConfig.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
setupcall- 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 asyncinit()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
voidoperator properly handles the promise returned by the asyncintervalHandler, 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
voidoperator 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
appConfigis 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
appConfigto 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
awaitkeyword 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.
|



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
Bug Fixes
Refactor
Tests
Chores