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.

Add --fail-on to choose which severity fails the scan (#100)

Nguyễn Tuấn Anh2dce9ea2c778
diff --git a/README.md b/README.md
index 205f280..fc4ceab 100644
--- a/README.md
+++ b/README.md
@@ -145,7 +145,7 @@ On the web it adds clickable divs, removed focus rings, disabled zoom, images wi
It reads the nearest `package.json` to tell a phone app from a website, so hover is a problem in your Expo app and fine on your Next.js site. `--platform web`, `--platform mobile`, or `--platform universal` settles it when it guesses wrong. Use `universal` when the project ships to both phone and web (React Native Web, Expo web). Phone-only rules, such as hover-only, are skipped.
-Exit code `2` means findings, so it can gate a pull request. Silence one line with `// unslop-anything-ignore <rule-id>` (`<!-- unslop-anything-ignore <rule-id> -->` in XML, `/* unslop-anything-ignore <rule-id> */` in CSS), or a whole rule in `.unslop-anything/config.json`:
+Exit code `2` means findings, so it can gate a pull request. `--fail-on critical|noticeable|minor` (default `minor`) raises the bar: findings below the threshold are still printed, but only findings at or above it fail the scan, so `--fail-on critical` lets a noisy codebase through until the worst patterns are gone. Silence one line with `// unslop-anything-ignore <rule-id>` (`<!-- unslop-anything-ignore <rule-id> -->` in XML, `/* unslop-anything-ignore <rule-id> */` in CSS), or a whole rule in `.unslop-anything/config.json`:
```json
{ "ignoreRules": ["status-dot"], "ignorePaths": ["src/legacy/"] }
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index d23c477..c3f1e19 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1206,12 +1206,12 @@ function listRulesJson() {
})), null, 2);
}
-const USAGE = `Usage: unslop-anything detect [paths...] [--json] [--platform mobile|web|universal] [--ignore rule,rule] [--include-tests] [--list-rules]
+const USAGE = `Usage: unslop-anything detect [paths...] [--json] [--platform mobile|web|universal] [--fail-on critical|noticeable|minor] [--ignore rule,rule] [--include-tests] [--list-rules]
Scans mobile and web source for generated-looking UI, website-in-a-phone patterns,
and accessibility and motion defaults. The platform comes from the nearest
package.json; --platform overrides it.
-Exit code: 0 clean, 2 findings, 1 error.
+Exit code: 0 clean, 2 findings at or above --fail-on (default minor), 1 error.
Silence one line with a comment: unslop-anything-ignore <rule-id>
Project config: .unslop-anything/config.json { "ignoreRules": [], "ignorePaths": [] }`;
@@ -1228,6 +1228,7 @@ function main(argv) {
const json = args.includes("--json");
const includeTests = args.includes("--include-tests");
let platform = null;
+ let failOn = "minor";
const ignoreRules = [];
const targets = [];
for (let i = 0; i < args.length; i++) {
@@ -1242,6 +1243,16 @@ function main(argv) {
console.error(`Unknown platform: ${platform}. Choose from mobile, web, universal.`);
return 1;
}
+ } else if (a === "--fail-on") {
+ failOn = args[++i];
+ if (failOn === undefined) {
+ console.error("Missing value for --fail-on. Choose from critical, noticeable, minor.");
+ return 1;
+ }
+ if (!Object.prototype.hasOwnProperty.call(SEVERITY_RANK, failOn)) {
+ console.error(`Unknown severity: ${failOn}. Choose from critical, noticeable, minor.`);
+ return 1;
+ }
} else if (a === "--ignore") {
if (!args[i + 1]) {
console.error(USAGE);
@@ -1280,7 +1291,12 @@ function main(argv) {
console.error(result.message);
return 1;
}
- return result.findings.length ? 2 : 0;
+ // Findings below --fail-on are still printed; only findings at or above
+ // the threshold fail the scan. SEVERITY_RANK orders critical (0) above
+ // noticeable (1) above minor (2), so a finding fails when its rank is
+ // at most the threshold's rank. Default minor keeps today's behavior.
+ const failing = result.findings.some((f) => SEVERITY_RANK[f.severity] <= SEVERITY_RANK[failOn]);
+ return failing ? 2 : 0;
}
module.exports = { rules, scan, scanSource, blankComments, isSlopHue, main };
diff --git a/test/detect.test.js b/test/detect.test.js
index 1205e96..c38ffc6 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -181,6 +181,37 @@ test("exit codes and json shape", () => {
}
});
+test("--fail-on chooses which severity fails the scan", () => {
+ const log = console.log;
+ let out = "";
+ console.log = (s) => (out += s);
+ try {
+ // The slop fixture has only noticeable and minor findings today
+ // (no rule is critical yet), so --fail-on critical passes the scan
+ // while still printing every finding.
+ assert.strictEqual(main([path.join(fixtures, "slop"), "--fail-on", "critical"]), 0);
+ assert.match(out, /\d+ findings/);
+ out = "";
+ assert.strictEqual(main([path.join(fixtures, "slop"), "--fail-on", "noticeable"]), 2);
+ out = "";
+ assert.strictEqual(main([path.join(fixtures, "slop"), "--fail-on", "minor"]), 2);
+ } finally {
+ console.log = log;
+ }
+ const err = console.error;
+ let errOut = "";
+ console.error = (s) => (errOut += s);
+ try {
+ assert.strictEqual(main([path.join(fixtures, "slop"), "--fail-on", "bogus"]), 1);
+ assert.strictEqual(errOut, "Unknown severity: bogus. Choose from critical, noticeable, minor.");
+ errOut = "";
+ assert.strictEqual(main([path.join(fixtures, "slop"), "--fail-on"]), 1);
+ assert.strictEqual(errOut, "Missing value for --fail-on. Choose from critical, noticeable, minor.");
+ } finally {
+ console.error = err;
+ }
+});
+
test("--list-rules shows stacks and platforms, and --json includes them", () => {
const log = console.log;
let out = "";