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): read the value of submit and button inputs in vague-button (#145) (#153)

Pure Tech25d3a029ee7c
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 126d2c9..fbf76e7 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1282,6 +1282,21 @@ const rules = [
fix: "Use a verb and an object: \"Save address\", \"Send invoice\", \"Book table\".",
find({ code }) {
const hits = [...matches(/(?:title|label|text)\s*[=:]\s*\{?\s*["'](?:Submit|Click here|Tap here)["']|>\s*(?:Submit|Click here|Tap here)\s*</i, code)].map((m) => m.index);
+ // An <input type="submit|button"> carries its label in value=. The tag is read to
+ // its real end, so `onClick={() => go()}` or `disabled={n > 0}` does not cut it, and
+ // other attributes' quoted values (`title="type=submit"`) are left out.
+ for (const m of matches(/<input\b/i, code)) {
+ const end = tagEnd(code, m.index + m[0].length);
+ const tag = code
+ .slice(m.index, end === -1 ? undefined : end)
+ .replace(/(?<![\w-])(?!type\b|value\b)[\w:@.-]+\s*=\s*(?:"[^"]*"|'[^']*')/gi, "");
+ if (
+ /(?<![\w-])type\s*=\s*\{?\s*(["']?)(?:submit|button)\1(?![\w-])/i.test(tag) &&
+ /(?<![\w-])value\s*=\s*(?:\{\s*(["'`])(?:Submit|Click here|Tap here)\1\s*\}|(["'])(?:Submit|Click here|Tap here)\2|Submit(?=\s|\/?$))/i.test(tag)
+ ) {
+ hits.push(m.index);
+ }
+ }
// Native buttons: the label only counts inside a button call, so a
// bare Text("Submit") used as a heading or field label stays quiet.
// Button("Submit") { save() } (Swift), Button(onClick = {}) {
diff --git a/test/detect.test.js b/test/detect.test.js
index d9fd94d..b014bea 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -381,6 +381,35 @@ test("vague-button catches Swift, Compose and Flutter buttons", () => {
assert.deepStrictEqual(scanSource('Text("Save address")', "a.kt"), []);
});
+test("vague-button reads the value of a submit or button input (issue #145)", () => {
+ const lines = (src, file = "form.html") => scanSource(src, file).filter((f) => f.rule === "vague-button").map((f) => f.line);
+ assert.deepStrictEqual(lines('<form>\n <input type="submit" value="Submit">\n</form>\n'), [2]);
+ assert.deepStrictEqual(lines('<input value="Click here" type="button" />\n'), [1]);
+ assert.deepStrictEqual(lines("<input type=submit value='Tap here'>\n"), [1]);
+ assert.deepStrictEqual(lines('<input type="submit" value="Submit" />\n', "Form.tsx"), [1]);
+ // Other inputs and options keep their value; a specific label is fine.
+ assert.deepStrictEqual(lines('<input type="text" value="Submit">\n'), []);
+ assert.deepStrictEqual(lines('<input value="Submit">\n'), []);
+ assert.deepStrictEqual(lines('<select><option value="Submit">Send it</option></select>\n'), []);
+ assert.deepStrictEqual(lines('<input type="submit" value="Save address">\n'), []);
+ // An arrow-function prop before value does not end the tag.
+ assert.deepStrictEqual(lines('<input type="submit" onClick={() => go()} value="Submit" />\n', "Form.tsx"), [1]);
+ // data-value and data-type are not the label or the type.
+ assert.deepStrictEqual(lines('<input type="submit" data-value="Submit" value="Send order">\n'), []);
+ assert.deepStrictEqual(lines('<input data-type="submit" value="Submit">\n'), []);
+ // A comparison in a JSX prop does not end the tag; the type must be exact.
+ assert.deepStrictEqual(lines('<input type="submit" disabled={count > 0} value="Submit" />\n', "Form.tsx"), [1]);
+ assert.deepStrictEqual(lines('<input type="button-group" value="Submit">\n'), []);
+ assert.deepStrictEqual(lines('<input type="text" title="type=submit" value="Submit">\n'), []);
+ assert.deepStrictEqual(lines("<input type=submit value=Submit>\n"), [1]);
+ assert.deepStrictEqual(lines('<input type="submit" value={"Submit"} />\n', "Form.tsx"), [1]);
+ // Only the whole value counts.
+ assert.deepStrictEqual(lines('<input type="submit" value={"Submit" + " order"} />\n', "Form.tsx"), []);
+ assert.deepStrictEqual(lines("<input type=submit value=Submit&nbsp;order>\n"), []);
+ assert.deepStrictEqual(lines("<input type=submit value=Submit/order>\n"), []);
+ assert.deepStrictEqual(lines("<input type=submit value=Submit/>\n"), [1]);
+});
+
test("transition-all stops at the quote that ends a CSS-in-JS value", () => {
// `all` in a later property of a style object is not part of the transition.
const pointerEvents = 'const s = { transition: "opacity .2s", pointerEvents: "all" };\n';