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): stop oops-error flagging log calls and thrown errors (#98)

Nguyễn Tuấn Anhb079079dc939
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index b1a3927..5666159 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -903,7 +903,16 @@ const rules = [
message: "\"Oops\" or \"Something went wrong\": no cause, no next step.",
fix: "Say what failed in the product's words and what the user can do: retry, check the connection, contact support.",
find({ code }) {
- return [...matches(/\boops\b|something went wrong/i, code)].map((m) => m.index);
+ const hits = [];
+ for (const m of matches(/\boops\b|something went wrong/i, code)) {
+ // Log calls and thrown errors never reach the user, so skip a match
+ // whose line starts as one: console.*, logger.*, Log.*, print,
+ // debugPrint, NSLog, or `throw new Error(...)`.
+ const lineStart = code.lastIndexOf("\n", m.index) + 1;
+ if (/\b(?:console|logger|log|Log)\.\w+\s*\(|\b(?:print|debugPrint|NSLog)\s*\(|throw\s+new\b/.test(code.slice(lineStart, m.index))) continue;
+ hits.push(m.index);
+ }
+ return hits;
},
},
{
diff --git a/test/detect.test.js b/test/detect.test.js
index 14823a6..80aeb55 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -105,6 +105,18 @@ test("a JSX ignore comment on its own line silences the next line", () => {
assert.deepStrictEqual(scanSource(spaced, "a.tsx"), []);
});
+test("oops-error ignores log calls and thrown errors", () => {
+ // Issue #70: none of these strings reach the user.
+ assert.deepStrictEqual(scanSource('console.error("Something went wrong", err);\nthrow new Error("Oops");\n', "a.ts"), []);
+ assert.deepStrictEqual(scanSource('Log.e(TAG, "Something went wrong")\n', "a.kt"), []);
+ assert.deepStrictEqual(scanSource('logger.warn("Something went wrong");\n', "a.ts"), []);
+ assert.deepStrictEqual(scanSource('print("Oops")\n', "a.swift"), []);
+ assert.deepStrictEqual(scanSource('debugPrint("Oops")\n', "a.dart"), []);
+ assert.deepStrictEqual(scanSource('NSLog(@"Oops");\n', "a.m"), []);
+ // Real UI text still flags.
+ assert.deepStrictEqual(scanSource('const msg = "Oops, something went wrong";\n', "a.ts").map((f) => f.rule), ["oops-error"]);
+});
+
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]);