refactor: simplify null checks with optional chaining#371
Merged
Conversation
This PR refactors conditional checks to use optional chaining, improving code readability and reducing boilerplate null checks.
- Logical operator can be refactored to optional chain: The original code used logical AND operators to guard property access (e.g., `if (levelEntry && levelEntry.rarity)` and `if (targetLink && targetLink.textContent.includes("Profile"))`), which can be verbose and error-prone. We replaced these with optional chaining (`if (levelEntry?.rarity)` and `if (targetLink?.textContent?.includes("Profile"))`) at the affected lines, ensuring safer and more concise null‐checks without altering runtime behavior.
> This Autofix was generated by AI. Please review the change before merging.
|
|
Overall Grade Focus Area: Complexity |
Security Reliability Complexity Hygiene |
Feedback
- Single function owns multiple responsibilities
- DOM access, calculation, state mutation and error handling are mixed in one flow, which multiplies branches; extract small, focused helpers and an orchestrator to isolate concerns and reduce branching.
- Defensive checks scattered through the main path
- Per-branch guards and early bailouts are embedded across the function, increasing cyclomatic paths; validate and normalize inputs at a single entry point so downstream logic can assume invariants and stay linear.
- Modern syntax without granular abstractions
- New language features improved clarity but were applied inside a large block, so complexity remained; naming intermediate results and splitting into tiny pure functions makes branches explicit and easier to test.
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| JavaScript | Mar 18, 2026 7:02p.m. | Review ↗ | |
| Secrets | Mar 18, 2026 7:02p.m. | Review ↗ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors conditional checks to use optional chaining, improving code readability and reducing boilerplate null checks.
if (levelEntry && levelEntry.rarity)andif (targetLink && targetLink.textContent.includes("Profile"))), which can be verbose and error-prone. We replaced these with optional chaining (if (levelEntry?.rarity)andif (targetLink?.textContent?.includes("Profile"))) at the affected lines, ensuring safer and more concise null‐checks without altering runtime behavior.