Skip to content

Conversation

@marmik-7
Copy link

@marmik-7 marmik-7 commented Dec 18, 2025

  • Fixed variable redeclarations (e.g., 'header', 'artistUri') to avoid shadowing.
  • Improved artist skipping logic to iterate safely over multiple artists without skipping unrelated tracks.
  • Added proper error handling in LocalStorage parsing.
  • Updated JSON export to include indentation for better readability.
  • Adjusted context menu return values to correctly return an object instead of modifying this.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved error handling with enhanced logging and consistent error reporting during backup operations.
  • Improvements

    • JSON backup exports now formatted with better indentation for improved readability when viewing backup files manually.

✏️ Tip: You can customize this high-level summary in your review settings.

- Fixed variable redeclarations (e.g., 'header', 'artistUri') to avoid shadowing.
- Improved artist skipping logic to iterate safely over multiple artists without skipping unrelated tracks.
- Added proper error handling in LocalStorage parsing.
- Updated JSON export to include indentation for better readability.
- Adjusted context menu return values to correctly return an object instead of modifying `this`.
@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

Walkthrough

A single-file refactoring of the trashbin extension introducing improved error handling, restructured artist URI skip logic, updated context menu object returns, and enhanced JSON export formatting for readability.

Changes

Cohort / File(s) Summary
Error handling and initialization
Extensions/trashbin.js
Enhanced error catching in initValue with console logging and default value return
Track skip logic
Extensions/trashbin.js
Refactored artist URI checking from while-loop approach to array-building with dynamic index iteration
Context menu behavior
Extensions/trashbin.js
Updated shouldAddContextMenu to return object with name field instead of boolean, for both TRACK and ARTIST types
Export and formatting
Extensions/trashbin.js
JSON backup export now formatted with indentation for readability; consistent error reporting in export path

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Artist URI skip logic refactoring: Verify the new array-building and dynamic index approach correctly identifies and skips all relevant artists in the trashArtistList
  • shouldAddContextMenu return value change: Confirm all calling code properly handles the new object return type instead of boolean
  • Error handling in initValue: Validate that console error logging doesn't introduce unintended side effects

Poem

🐰 With constants now local and errors caught tight,
The URI skip logic takes elegant flight,
Context menus return objects with grace,
JSON exports are prettily spaced in their place!
A refactor so clean, the code feels just right! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes in the pull request, focusing on refactoring for readability and improving artist skipping logic.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9017247 and 523e7cd.

📒 Files selected for processing (1)
  • Extensions/trashbin.js (5 hunks)
🧰 Additional context used
🪛 GitHub Actions: Code quality
Extensions/trashbin.js

[error] 70-71: Can't assign header because it's a constant. Unsafe fix: Replace const with let if you assign it to a new value.


[error] 266-275: File content differs from formatting output.

🔇 Additional comments (2)
Extensions/trashbin.js (2)

155-157: LGTM! Improved error handling.

The error handling now properly captures and logs parsing errors with context, making debugging easier.


391-391: LGTM! Improved JSON readability.

Adding indentation makes the exported backup file more human-readable and easier to manually inspect or edit.

Comment on lines +57 to 59
const header = document.createElement("h2");
header.innerText = "Options";
content.appendChild(header);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: const declaration breaks subsequent reassignment.

Declaring header as const at line 57 causes a runtime error at line 70, where header is reassigned. This is confirmed by the pipeline failure: "Can't assign header because it's a constant."

🔎 Apply this fix to use `let` instead of `const`:
-		const header = document.createElement("h2");
+		let header = document.createElement("h2");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const header = document.createElement("h2");
header.innerText = "Options";
content.appendChild(header);
let header = document.createElement("h2");
header.innerText = "Options";
content.appendChild(header);
🤖 Prompt for AI Agents
In Extensions/trashbin.js around lines 57 to 59, the variable header is declared
with const but later reassigned (around line 70), causing a runtime "can't
assign header because it's a constant" error; change the declaration from const
to let so the variable can be reassigned, and verify there are no other const
references or shadowing that would conflict with the updated mutable binding.

Comment on lines +265 to 274
const artistUris = [data.item.metadata.artist_uri];
let i = 1;
while (data.item.metadata[`artist_uri:${i}`]) {
artistUris.push(data.item.metadata[`artist_uri:${i}`]);
i++;
}

if (artistUris.some(uri => trashArtistList[uri])) {
Spicetify.Player.next();
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle undefined artist_uri and fix formatting.

Two concerns:

  1. Potential undefined in array: If data.item.metadata.artist_uri is undefined, line 265 initializes the array with [undefined], which could cause unexpected behavior in the .some() check.

  2. Formatting issue: The pipeline reports formatting differences at lines 266-275.

🔎 Suggested fix to handle undefined and address formatting:
-		const artistUris = [data.item.metadata.artist_uri];
-		let i = 1;
-		while (data.item.metadata[`artist_uri:${i}`]) {
-		    artistUris.push(data.item.metadata[`artist_uri:${i}`]);
-		    i++;
-		}
-		
-		if (artistUris.some(uri => trashArtistList[uri])) {
-		    Spicetify.Player.next();
-		}
+		const artistUris = [];
+		if (data.item.metadata.artist_uri) {
+			artistUris.push(data.item.metadata.artist_uri);
+		}
+		let i = 1;
+		while (data.item.metadata[`artist_uri:${i}`]) {
+			artistUris.push(data.item.metadata[`artist_uri:${i}`]);
+			i++;
+		}
+
+		if (artistUris.some((uri) => trashArtistList[uri])) {
+			Spicetify.Player.next();
+		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const artistUris = [data.item.metadata.artist_uri];
let i = 1;
while (data.item.metadata[`artist_uri:${i}`]) {
artistUris.push(data.item.metadata[`artist_uri:${i}`]);
i++;
}
if (artistUris.some(uri => trashArtistList[uri])) {
Spicetify.Player.next();
}
const artistUris = [];
if (data.item.metadata.artist_uri) {
artistUris.push(data.item.metadata.artist_uri);
}
let i = 1;
while (data.item.metadata[`artist_uri:${i}`]) {
artistUris.push(data.item.metadata[`artist_uri:${i}`]);
i++;
}
if (artistUris.some((uri) => trashArtistList[uri])) {
Spicetify.Player.next();
}
🤖 Prompt for AI Agents
In Extensions/trashbin.js around lines 265 to 274, the code initializes
artistUris with data.item.metadata.artist_uri which can be undefined, causing
[undefined] and incorrect .some() results and the block also has reported
formatting issues; change logic to start with an empty array, push
data.item.metadata.artist_uri only if it is truthy (or use optional chaining),
loop and push subsequent artist_uri:i entries only when they exist, and ensure
consistent indentation/spacing for lines 266–275 to match project formatter
(e.g., single tab/2 spaces and blank line placement).

if (uriObj.type === Spicetify.URI.Type.TRACK) {
this.name = trashSongList[uri] ? UNTHROW_TEXT : THROW_TEXT;
return true;
return { name: trashSongList[uri] ? UNTHROW_TEXT : THROW_TEXT };
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find and examine trashbin.js to see lines 344 and 348
find . -name "trashbin.js" -type f | head -5

Repository: spicetify/cli

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Read trashbin.js around lines 344 and 348
sed -n '330,360p' ./Extensions/trashbin.js | cat -n

Repository: spicetify/cli

Length of output: 1143


Fix shouldAddContextMenu to return a boolean, not an object with a name property.

Lines 344 and 348 return { name: ... } instead of a boolean value. The Spicetify API defines ShouldAddCallback as (uris: string[], uids?: string[], contextUri?: string) => boolean, which means the function must return true or false to determine whether the menu item should display. To dynamically set the menu item's label based on whether an item is in the trash, update the cntxMenu.name property directly instead of returning an object from the callback.

Also applies to: 348-348

🤖 Prompt for AI Agents
In Extensions/trashbin.js around lines 344 and 348, the shouldAddContextMenu
callback is returning an object like { name: ... } but the Spicetify
ShouldAddCallback must return a boolean; change the callback to return
true/false (e.g., return !!trashSongList[uri]) and set the menu label by
mutating cntxMenu.name directly before returning, so the function only returns a
boolean and the dynamic label is applied via cntxMenu.name.

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.

1 participant