Your app looks AI-generated. Vincent Van Gogh noticed. An agent skill that finds and fixes AI-looking UI and UX in mobile apps, web apps, and websites.
JavaScript accessibilityagent-skillsagent-skills-toolsagentsagentskillsai-slopclaudeclaude-codeclaude-skillsexpoflutterfrontendionicjetpack-composemobilereact-nativeswiftuiuiuxvibe-coding
fix(detect): read Tailwind arbitrary hex stops in slop-gradient (#143) (#151)
Pure Tech658a8f014379
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.jsindex 6d57287..88d52f9 100644--- a/skills/unslop-anything/scripts/detect.js+++ b/skills/unslop-anything/scripts/detect.js@@ -422,6 +422,23 @@ function closeOf(text, open) {return text.length;}+// Like closeOf() for "(", but a parenthesis inside a quoted string does not count, so+// cn("before:content-['(']", ...) still ends at its own closing parenthesis.+function callEnd(text, open) {+ let depth = 0;+ let quote = null;+ for (let i = open; i < text.length; i++) {+ const c = text[i];+ if (quote) {+ if (c === "\\") i++;+ else if (c === quote) quote = null;+ } else if (c === '"' || c === "'" || c === "`") quote = c;+ else if (c === "(") depth++;+ else if (c === ")" && --depth === 0) return i + 1;+ }+ return text.length;+}+// The part of `rest` (the text after a gradient's constructor) during which// `variable` still holds that gradient: up to the end of the enclosing block,// or up to the variable's next assignment. A declaration of the same name in a@@ -560,7 +577,21 @@ const rules = [}// Tailwind: bg-gradient-to-r from-violet-600 to-fuchsia-500for (const m of matches(/["'`][^"'`\n]*\bbg-(?:gradient|linear|radial|conic)-[^"'`\n]*["'`]/, code)) {- if (/\b(?:from|via|to)-(?:purple|violet|indigo|fuchsia|pink)-\d{2,3}\b/.test(m[0])) hits.push(m.index);+ // The stops may sit in another string of the same cn(...) / clsx(...) call.+ let scope = m[0];+ const from = Math.max(0, m.index - 400);+ for (const c of matches(/\b(?:cn|cx|clsx|classnames|classNames|twMerge|twJoin)\s*\(/, code.slice(from, m.index))) {+ const open = from + c.index + c[0].length - 1;+ const close = callEnd(code, open);+ // The outermost call that holds the string: a nested clsx(...) keeps the outer stops.+ if (close > m.index) {+ scope = code.slice(open, close);+ break;+ }+ }+ // Arbitrary stops carry the color itself: from-[#7c3aed] to-[#db2777].+ const arbitrary = [...scope.matchAll(/\b(?:from|via|to)-\[(#[0-9a-fA-F]{3,8})\]/g)].map((s) => s[1]).join(" ");+ if (/\b(?:from|via|to)-(?:purple|violet|indigo|fuchsia|pink)-\d{2,3}\b/.test(scope) || hexColors(arbitrary, stack).some(isSlopHue)) hits.push(m.index);}return hits;},diff --git a/test/detect.test.js b/test/detect.test.jsindex 04d75e2..de270cc 100644--- a/test/detect.test.js+++ b/test/detect.test.js@@ -480,6 +480,28 @@ test("slop-gradient reads Android #AARRGGBB colors", () => {assert.deepStrictEqual(scanSource(scrim, "a.css"), []);});+test("slop-gradient reads Tailwind arbitrary hex stops (issue #143)", () => {+ const lines = (src, file) => scanSource(src, file).filter((f) => f.rule === "slop-gradient").map((f) => f.line);+ assert.deepStrictEqual(lines('<div class="bg-gradient-to-r from-[#7c3aed] to-[#db2777] p-8">Hello</div>\n', "Hero.html"), [1]);+ assert.deepStrictEqual(lines('<div className="bg-linear-to-r from-[#8b5cf6] via-[#a855f7] to-[#ec4899]" />\n', "Hero.tsx"), [1]);+ // One purple stop is enough, as with named stops.+ assert.deepStrictEqual(lines('<div className="bg-gradient-to-b from-[#0ea5e9] to-[#7c3aed]" />\n', "Hero.tsx"), [1]);+ // A gradient with no purple or pink stop stays quiet.+ assert.deepStrictEqual(lines('<div class="bg-gradient-to-r from-[#0ea5e9] to-[#22c55e] p-8">Hello</div>\n', "Hero.html"), []);+ // Stops in another string of the same cn(...) call count; another call's do not.+ assert.deepStrictEqual(lines('<div className={cn("bg-gradient-to-r", "from-[#7c3aed] to-[#db2777]")} />\n', "Hero.tsx"), [1]);+ assert.deepStrictEqual(lines('<div className={clsx("bg-gradient-to-r", active && "from-violet-600", "to-pink-500")} />\n', "Hero.tsx"), [1]);+ assert.deepStrictEqual(lines('<div className={cn("bg-gradient-to-r", "from-sky-500 to-cyan-500")} />\n', "Hero.tsx"), []);+ assert.deepStrictEqual(lines('const a = cn("bg-gradient-to-r from-sky-500 to-cyan-500");\nconst b = cn("from-violet-600");\n', "Hero.tsx"), []);+ // A nested class call does not hide the outer call's stops.+ assert.deepStrictEqual(lines('<div className={cn("from-violet-600", clsx("bg-gradient-to-r", "to-cyan-500"))} />\n', "Hero.tsx"), [1]);+ // A parenthesis inside a quoted class is not part of the call's own brackets.+ assert.deepStrictEqual(lines('const a = cn("before:content-[\'(\']", "bg-gradient-to-r from-sky-500 to-cyan-500");\nconst b = cn("from-violet-600");\n', "Hero.tsx"), []);+ assert.deepStrictEqual(lines('<div className={cn("after:content-[\')\']", "bg-gradient-to-r", "from-[#7c3aed]")} />\n', "Hero.tsx"), [1]);+ // A purple outside a gradient class string is not a stop.+ assert.deepStrictEqual(lines('<div class="bg-[#7c3aed] text-white">Hello</div>\n', "Hero.html"), []);+});+test("slop-gradient reads only the gradient's own colors (issue #67)", () => {const gradientLines = (src, file) =>scanSource(src, file).filter((f) => f.rule === "slop-gradient").map((f) => f.line);