Skip to content

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.

fix(detect): skip package names and identifiers in buzzword-copy (#140) (#154)

Pure Techa0c180dd5aab
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index fbf76e7..abce88a 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1251,7 +1251,29 @@ const rules = [
fix: "Say what the screen does in plain words, or delete the line.",
find({ code }) {
const re = /unlock (?:your|the) (?:full )?potential|\bseamless(?:ly)?\b|\beffortless(?:ly)?\b|\bsupercharg\w*|all in one place|\bnext[- ]level\b|\belevate your\b|\bgame[- ]?changer\b|\brevolutioni[sz]\w*|\bunleash\b|\bempower(?:s|ing)? you/i;
- return [...matches(re, code)].map((m) => m.index);
+ const hits = [];
+ for (const m of matches(re, code)) {
+ // The line up to the match, at most 300 characters back.
+ const back = code.slice(Math.max(0, m.index - 300), m.index);
+ const before = back.slice(back.lastIndexOf("\n") + 1);
+ const after = code.slice(m.index + m[0].length, m.index + m[0].length + 3);
+ // A package name in a module string (`from "@unleash/..."`, `require("unleash-client")`, also
+ // with the string on the next line), a name on an import line, or a name inside a multi-line
+ // `import { ... }` clause is not copy.
+ if (/\b(?:import|export)\b[^;"'`]*\bfrom\s*["'`][^"'`\n]*$/.test(back)) continue;
+ if (/\b(?:import|require)\s*\(\s*["'`][^"'`\n]*$/.test(back)) continue;
+ // a side-effect import: `import "unleash-client";`
+ if (/(?:^|[\n;])\s*import\s+["'`][^"'`\n]*$/.test(back)) continue;
+ if (/^\s*import\b[^"'`;]*$/.test(before)) continue;
+ if (/(?:^|[\n;])\s*(?:import|export)\s+(?:type\s+)?(?:\w+\s*,\s*)?\{[^};`]*$/.test(code.slice(Math.max(0, m.index - 2000), m.index))) continue;
+ // Nor is unleash used as code: `const unleash = ...`, `new Unleash(...)`,
+ // `unleash.isEnabled(...)`, `{ unleash }`, `{ unleash: cfg }`.
+ if (/^unleash$/i.test(m[0]) && /\b(?:const|let|var|new)\s+$/.test(before)) continue;
+ // An object key or destructured name needs a brace or a key colon, so `Dream, unleash, create.` is copy.
+ if (m[0] === "unleash" && (/^\.[A-Za-z_$]/.test(after) || (/\{[^{}]*$/.test(before) && /[{,]\s*$/.test(before) && /^\s*[:,}]/.test(after)))) continue;
+ hits.push(m.index);
+ }
+ return hits;
},
},
{
diff --git a/test/detect.test.js b/test/detect.test.js
index b014bea..46e55c6 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -163,6 +163,41 @@ test("oops-error flags visible copy after a log call on the same line", () => {
assert.deepStrictEqual(scanSource('console.log("a"); console.error("Oops");\n', "a.ts"), []);
});
+test("buzzword-copy skips package names and identifiers, not copy", () => {
+ // Issue #140: the Unleash feature-flag SDK is a package, not marketing filler.
+ const buzz = (src, file) => scanSource(src, file).filter((f) => f.rule === "buzzword-copy").map((f) => f.line);
+ const checkout = 'import { useFlag } from "@unleash/proxy-client-react";\n\nexport function Checkout() {\n const enabled = useFlag("new-checkout");\n return <p>{enabled ? "New" : "Old"}</p>;\n}\n';
+ assert.deepStrictEqual(buzz(checkout, "Checkout.tsx"), []);
+ // Imports, export ... from and require
+ assert.deepStrictEqual(buzz('export { useFlag } from "@unleash/proxy-client-react";\n', "flags.ts"), []);
+ assert.deepStrictEqual(buzz('const { UnleashClient } = require("unleash-client");\n', "flags.js"), []);
+ assert.deepStrictEqual(buzz('import Unleash from "unleash-client";\n', "flags.ts"), []);
+ assert.deepStrictEqual(buzz('import {\n Unleash,\n useFlag,\n} from "@unleash/proxy-client-react";\n', "flags.ts"), []);
+ assert.deepStrictEqual(buzz('import { useFlag } from\n "@unleash/proxy-client-react";\n', "flags.ts"), []);
+ assert.deepStrictEqual(buzz('const sdk = require(\n "unleash-client");\n<h1>Unleash your team</h1>\n', "flags.ts"), [3]);
+ assert.deepStrictEqual(buzz('const m = await import(\n "@unleash/proxy-client-react");\n<h1>Unleash your team</h1>\n', "flags.ts"), [3]);
+ assert.deepStrictEqual(buzz('import "unleash-client";\n<h1>Unleash your team</h1>\n', "flags.ts"), [2]);
+ assert.deepStrictEqual(buzz('import "unleash-client"; const title = "Unleash your team";\n', "flags.ts"), [1]);
+ // Identifiers
+ assert.deepStrictEqual(buzz('const unleash = new UnleashClient({ url });\nif (unleash.isEnabled("x")) start();\n', "flags.ts"), []);
+ assert.deepStrictEqual(buzz("const client = new Unleash({ url });\n", "flags.ts"), []);
+ assert.deepStrictEqual(buzz("const { unleash } = useApp();\nconst cfg = { unleash: { url }, other: 1 };\n", "flags.ts"), []);
+ assert.deepStrictEqual(buzz("const { client, unleash } = useApp();\n", "flags.ts"), []);
+ assert.deepStrictEqual(buzz("const { client, unleash, other } = useApp();\n", "flags.ts"), []);
+ // Copy is still flagged, also next to an import or after a multi-line import clause.
+ assert.deepStrictEqual(buzz("<h1>Unleash your creativity</h1>\n", "Hero.tsx"), [1]);
+ assert.deepStrictEqual(buzz('const title = "Unleash your team";\n', "copy.ts"), [1]);
+ assert.deepStrictEqual(buzz("<p>Time to unleash. Start now.</p>\n", "Cta.tsx"), [1]);
+ assert.deepStrictEqual(buzz('import { useFlag } from "sdk"; const title = "Unleash your team";\n', "copy.ts"), [1]);
+ assert.deepStrictEqual(buzz('import type {\n Unleash,\n} from "unleash-client";\n<h1>Unleash your team</h1>\n', "Hero.tsx"), [4]);
+ assert.deepStrictEqual(buzz("<h2>Fast.Secure.Seamless.Simple.</h2>\n", "Hero.tsx"), [1]);
+ assert.deepStrictEqual(buzz("<h1>Dream, unleash, create.</h1>\n", "Hero.tsx"), [1]);
+ // `from` in copy is not an import.
+ assert.deepStrictEqual(buzz('<p>Choose from "seamless integrations"</p>\n', "Cta.tsx"), [1]);
+ assert.deepStrictEqual(buzz('<p>Choose from\n"seamless integrations"</p>\n', "Cta.tsx"), [2]);
+ assert.deepStrictEqual(buzz('import x from "y";\n<h1>Unleash your team</h1>\n', "Hero.tsx"), [2]);
+});
+
test("ignore comments from before the rename still work", () => {
const src = '// unslopovich-ignore oops-error\nconst a = "Oops";\nconst b = "Oops"; // unslopovich-ignore\nconst c = "Oops";\n';
assert.deepStrictEqual(scanSource(src, "a.ts").map((f) => f.line), [4]);