Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab9010e

Browse filesBrowse files
refactor: simplify null checks with optional chaining (#371)
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. Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
1 parent 9bde5af commit ab9010e
Copy full SHA for ab9010e

File tree

Expand file treeCollapse file tree

1 file changed

+2
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+2
-2
lines changed
Open diff view settings
Collapse file

‎src/assets/js/script.js‎

Copy file name to clipboardExpand all lines: src/assets/js/script.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ function updateInventoryCounts(lvl) {
10621062
// We use i <= lvl because currentLevel is the index reached
10631063
for (let i = 0; i <= lvl; i++) {
10641064
const levelEntry = LEVELS[i];
1065-
if (levelEntry && levelEntry.rarity) {
1065+
if (levelEntry?.rarity) {
10661066
const r = levelEntry.rarity.toLowerCase();
10671067
if (counts.hasOwnProperty(r)) {
10681068
counts[r]++;
@@ -1198,7 +1198,7 @@ function initProfileTracker() {
11981198
const targetLink = e.target.closest("a");
11991199

12001200
// Only increment if the link text contains "Profile"
1201-
if (targetLink && targetLink.textContent.includes("Profile")) {
1201+
if (targetLink?.textContent?.includes("Profile")) {
12021202
let currentCount = parseInt(
12031203
localStorage.getItem("profile_view_count") || 0,
12041204
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.