shadcn.io is not affiliated with official shadcn/ui
Code Refactor AI Block for Svelte
Pick the refactors you want: the original function with five numbered issues, five switches with a priority and the lines each removes, and a result recomposed from the switches with a derived line count and Copy.
Installation
Overview
Let people choose which suggested fixes go into their code, with this refactoring helper for Svelte with Ark UI. A header and a framed panel with a plus mark on each corner show Tidyloft, a refactoring helper, with one function of 35 lines. At the start the original, each of five issues marked by a numbered ring on its first line; at the end five suggestions, each a Switch with a name ("Nested ifs"), a Badge with its priority and what it does to the length ("Removes 5 lines", "Adds 1 line"); and under them the result, rebuilt from whichever switches are on. Each suggestion owns one separate segment of the code, so any combination gives valid code, and the counts ("Lines: 35 to 27") are derived. Copy result puts the real text on the clipboard. Guides draw the frame; everything moves with CSS only. On a phone the original comes first, then the switches, then the result. For linters, code assistants and any tool that proposes independent fixes.
FAQ
What stays in the page, and how do I make it real?
All of it. The function, the five issues and the code that replaces each are typed in the file, and no analysis runs; the switches only choose between the typed versions. To wire it for real, produce segments of the same shape from your linter or your model, each with the lines it covers and the lines that replace them, and keep them from overlapping.
Why must the suggestions not overlap?
Because the result is built by walking the segments in order and swapping the ones that are on. If two fixes touched the same lines, some pairs of switches would give broken code, so the data is cut into runs that never share a line.
Where do the numbers come from?
Each saving is the length of a segment's original lines minus its replacement. The total is the original length minus the result's, and the foot repeats it in words. A fix that adds a line (the named constant) says "Adds 1 line" and the result grows.
How does it work from the keyboard?
Each switch is named "Apply issue 1: Nested ifs" and works with Space. The two code regions are focusable so a keyboard can scroll them, and Copy result is an ordinary button; the status line says what changed.