From bcf2dee131d0d5386b083f4e22bd3775badd4d3c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2026 19:02:45 +0000 Subject: [PATCH] refactor: simplify null checks with optional chaining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/assets/js/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assets/js/script.js b/src/assets/js/script.js index a6d41a9..9a8ec85 100644 --- a/src/assets/js/script.js +++ b/src/assets/js/script.js @@ -1062,7 +1062,7 @@ function updateInventoryCounts(lvl) { // We use i <= lvl because currentLevel is the index reached for (let i = 0; i <= lvl; i++) { const levelEntry = LEVELS[i]; - if (levelEntry && levelEntry.rarity) { + if (levelEntry?.rarity) { const r = levelEntry.rarity.toLowerCase(); if (counts.hasOwnProperty(r)) { counts[r]++; @@ -1198,7 +1198,7 @@ function initProfileTracker() { const targetLink = e.target.closest("a"); // Only increment if the link text contains "Profile" - if (targetLink && targetLink.textContent.includes("Profile")) { + if (targetLink?.textContent?.includes("Profile")) { let currentCount = parseInt( localStorage.getItem("profile_view_count") || 0, );