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): match sparkle-derived SF Symbols (#110)
rva.creates972ead550c73
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.jsindex 7809eed..e57392c 100644--- a/skills/unslop-anything/scripts/detect.js+++ b/skills/unslop-anything/scripts/detect.js@@ -139,6 +139,18 @@ function blankComments(text, stack) {i = skipRegex(text, i);continue;}+ if (stack === "swift" && c === '"') {+ // Swift raw strings use #"..."# (or more hashes). Quotes and // inside+ // them are literal text, not delimiters or comments.+ let hashes = 0;+ while (text[i - 1 - hashes] === "#") hashes++;+ if (hashes > 0) {+ const closing = '"' + "#".repeat(hashes);+ const end = text.indexOf(closing, i + 1);+ i = end === -1 ? text.length : end + closing.length;+ continue;+ }+ }if (c === '"' || c === "`" || (c === "'" && stack !== "swift")) {// An apostrophe between letters is prose (JSX text such as Don't), not a string.if (c === "'" && /[A-Za-z]/.test(text[i - 1] || "") && /[A-Za-z]/.test(next || "")) { i++; continue; }@@ -149,6 +161,94 @@ function blankComments(text, stack) {return out.join("");}+// Collect string literal contents with their starting offsets. This is used by+// rules that care about a whole literal rather than text inside it. It keeps+// JSX prose apostrophes, Swift interpolation and Swift raw strings from being+// mistaken for ordinary quote delimiters.+function stringLiterals(code, stack) {+ const literals = [];+ const proseApostrophe = (i) =>+ code[i] === "'" && /[A-Za-z]/.test(code[i - 1] || "") && /[A-Za-z]/.test(code[i + 1] || "");+ const quoteStart = (i) =>+ !proseApostrophe(i) && (code[i] === '"' || code[i] === "'" || code[i] === "`");++ const rawHashes = (i) => {+ if (stack !== "swift" || code[i] !== '"') return 0;+ let count = 0;+ while (code[i - 1 - count] === "#") count++;+ return count;+ };++ // `i` points at the backslash in a Swift \(...) interpolation. Nested+ // literals are collected here so the outer literal can resume after the+ // matching parenthesis instead of closing at the nested quote.+ const scanInterpolation = (i) => {+ let depth = 0;+ let j = i + 2;+ while (j < code.length) {+ if (code[j] === "\\" && code[j + 1] === "(") {+ j = scanInterpolation(j);+ continue;+ }+ if (quoteStart(j)) {+ j = readLiteral(j);+ continue;+ }+ if (code[j] === "(") depth++;+ else if (code[j] === ")") {+ if (depth === 0) return j + 1;+ depth--;+ }+ j++;+ }+ return j;+ };++ function readLiteral(start) {+ const quote = code[start];+ const hashes = rawHashes(start);+ const from = start + 1;+ let j = from;+ while (j < code.length) {+ const c = code[j];+ if (hashes > 0) {+ // In a raw string, quotes are literal and backslashes do not escape.+ // Only the closing quote followed by the same number of # ends it.+ if (c === '"' && code.slice(j + 1, j + 1 + hashes) === "#".repeat(hashes)) {+ literals.push({ start, contents: code.slice(from, j) });+ return j + 1 + hashes;+ }+ j++;+ continue;+ }+ if (c === "\\") {+ if (quote === '"' && code[j + 1] === "(") {+ j = scanInterpolation(j);+ } else {+ j += 2;+ }+ continue;+ }+ if (c === quote) {+ literals.push({ start, contents: code.slice(from, j) });+ return j + 1;+ }+ j++;+ }+ literals.push({ start, contents: code.slice(from, j) });+ return j;+ }++ for (let i = 0; i < code.length; ) {+ if (quoteStart(i)) {+ i = readLiteral(i);+ } else {+ i++;+ }+ }+ return literals;+}+// A slash starts a regex literal when it follows an operator, an opening// bracket, a keyword such as return, or the start of the text.function isRegexStart(text, i) {@@ -535,9 +635,22 @@ const rules = [stacks: null,message: "Sparkle icon. It usually marks an AI feature or stands in for meaning.",fix: "Use an icon that names the action, or a text label. If it marks an AI feature, make sure that feature is not in the way of the core task.",- find({ code }) {- const re = /["']sparkles?["']|["']wand\.and\.stars|\bauto_awesome\b|\bAutoAwesome\b|\bSparkles\b|\bSparklesIcon\b|\bSparkle\b|\bSparkleIcon\b|\bWandSparkles\b|\bWandSparklesIcon\b|✨/;- return [...matches(re, code)].map((m) => m.index);+ find({ code, stack }) {+ // SF Symbols are often derived from "sparkle"/"sparkles" or+ // "wand.and.stars"/"wand.and.sparkles", for example+ // "sparkles.rectangle.stack" and "wand.and.stars.inverse". Check the+ // complete string literal so a quoted symbol is only flagged when the+ // literal is exactly that symbol; substrings and apostrophes inside+ // longer text stay quiet.+ const symbol = /^(?:sparkles?(?:\.[a-z0-9._-]+)?|wand\.and\.(?:stars|sparkles)(?:\.[a-z0-9._-]+)?)$/;+ const re = /\bauto_awesome\b|\bAutoAwesome\b|\bSparkles\b|\bSparklesIcon\b|\bSparkle\b|\bSparkleIcon\b|\bWandSparkles\b|\bWandSparklesIcon\b|✨/;+ const hits = [...matches(re, code)].map((m) => m.index);++ for (const literal of stringLiterals(code, stack)) {+ if (symbol.test(literal.contents)) hits.push(literal.start);+ }++ return hits.sort((a, b) => a - b);},},{diff --git a/test/detect.test.js b/test/detect.test.jsindex 7c4c891..1e43b2a 100644--- a/test/detect.test.js+++ b/test/detect.test.js@@ -3,7 +3,7 @@const test = require("node:test");const assert = require("node:assert");const path = require("path");-const { scan, scanSource, rules, isSlopHue, main } = require("../skills/unslop-anything/scripts/detect.js");+const { scan, scanSource, rules, isSlopHue, main, blankComments } = require("../skills/unslop-anything/scripts/detect.js");const fixtures = path.join(__dirname, "fixtures");@@ -980,6 +980,60 @@ test("sparkle-icon flags the singular and combined icon names", () => {assert.deepStrictEqual(rulesFor("<SparkleCounter />\n"), []);});+test("sparkle-icon flags sparkle-derived SF Symbols but not words containing sparkles", () => {+ const src = [+ "import SwiftUI",+ "struct A: View {",+ " var body: some View {",+ " VStack {",+ ' Image(systemName: "wand.and.sparkles")',+ ' Label("Summarize", systemImage: "sparkles.rectangle.stack")',+ ' Image(systemName: "sparkle")',+ ' Image(systemName: "sparkles")',+ ' Image(systemName: "wand.and.stars")',+ ' Image(systemName: "wand.and.stars.inverse")',+ ' Image(systemName: "wand.and.sparkles.inverse")',+ ' Text("sparkles.rectangle.stack\'s label")',+ ' Text("\'sparkles\'")',+ ' Text("not \\"sparkles\\" here")',+ " }",+ " }",+ "}",+ 'let quietSymbols = ["sparkles_count", "no sparkles here"]',+ ].join("\n");++ const findings = scanSource(src, "a.swift").filter((f) => f.rule === "sparkle-icon");+ assert.deepStrictEqual(findings.map((f) => f.line), [5, 6, 7, 8, 9, 10, 11]);+});++test("sparkle-icon ignores prose apostrophes but still scans later literals", () => {+ const doubleQuote = 'const view = <><p>Don\'t forget</p><Icon name="sparkles" /></>;';+ const singleQuote = "const view = <><p>Don't forget</p><Icon name='sparkles' /></>;";+ for (const src of [doubleQuote, singleQuote]) {+ assert.deepStrictEqual(scanSource(src, "a.tsx").map((f) => f.rule), ["sparkle-icon"]);+ }+});++test("sparkle-icon scans nested Swift interpolation and raw strings", () => {+ const interpolation = "let label = \"Icon: \\(Image(systemName: \"sparkles\"))\"";+ assert.deepStrictEqual(scanSource(interpolation, "a.swift").map((f) => f.rule), ["sparkle-icon"]);++ assert.deepStrictEqual(scanSource('let icon = #"sparkles"#', "a.swift").map((f) => f.rule), ["sparkle-icon"]);++ const prose = "let label = #\"Use \"'sparkles'\" as text\"#";+ assert.deepStrictEqual(scanSource(prose, "a.swift"), []);+});++test("blankComments keeps slashes inside Swift raw strings and still finds later symbols", () => {+ const src = [+ 'let label = #"A "// B"#',+ 'let icon = Image(systemName: "sparkles")',+ ].join("\n");++ assert.ok(blankComments(src, "swift").includes("// B"));+ assert.deepStrictEqual(scanSource(src, "a.swift").map((f) => f.rule), ["sparkle-icon"]);+});+test("glow-shadow flags #0000ff and a saturated second color in a shadow list, but not whole-black or neutral-only lists", () => {const flagged = ['<div className="shadow-[0_0_40px_#0000ff]">x</div>',