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(drawer-nav): detect Flutter's endDrawer (#329)

qwist1233-cpuab46bf5a3e3e
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index ec95db3..ebd07fc 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1192,7 +1192,7 @@ const rules = [
message: "Hamburger menu or navigation drawer. It hides the top destinations behind a tap.",
fix: "Ask first. Use tabs for three to five peer destinations; keep a drawer only for many destinations or a large-screen rail.",
find({ code }) {
- const re = /["']line\.(?:3\.horizontal|horizontal\.3)["']|\bIcons\.(?:Default\.|Filled\.|Outlined\.|Rounded\.|Sharp\.)?Menu\b|\bIcons\.menu(?:_rounded|_outlined|_sharp)?\b|\b(?:name|icon)=["']menu(?:-outline|-sharp)?["']|\bcreateDrawerNavigator\b|from\s+["']expo-router\/drawer["']|\bModalNavigationDrawer\b|\bdrawer:\s*(?:const\s+)?\w*Drawer\b|<ion-menu\b|<IonMenu(?:Button|Toggle)?\b|<(?:q-drawer|QDrawer)(?![\w-])|<(?:mat-sidenav|mat-drawer)(?![\w-])|<(?:v-navigation-drawer|VNavigationDrawer)(?![\w-])|\bBars3(?:BottomLeft|BottomRight|CenterLeft)?Icon\b|\bIconMenu2\b/;
+ const re = /["']line\.(?:3\.horizontal|horizontal\.3)["']|\bIcons\.(?:Default\.|Filled\.|Outlined\.|Rounded\.|Sharp\.)?Menu\b|\bIcons\.menu(?:_rounded|_outlined|_sharp)?\b|\b(?:name|icon)=["']menu(?:-outline|-sharp)?["']|\bcreateDrawerNavigator\b|from\s+["']expo-router\/drawer["']|\bModalNavigationDrawer\b|\b(?:drawer|endDrawer):\s*(?:const\s+)?\w*Drawer\b|<ion-menu\b|<IonMenu(?:Button|Toggle)?\b|<(?:q-drawer|QDrawer)(?![\w-])|<(?:mat-sidenav|mat-drawer)(?![\w-])|<(?:v-navigation-drawer|VNavigationDrawer)(?![\w-])|\bBars3(?:BottomLeft|BottomRight|CenterLeft)?Icon\b|\bIconMenu2\b/;
const first = matches(re, code).next();
return first.done ? [] : [first.value.index];
},
diff --git a/test/detect.test.js b/test/detect.test.js
index e2930a9..4bedb7a 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -3188,3 +3188,36 @@ test("drawer-nav catches Vuetify v-navigation-drawer and VNavigationDrawer (issu
const quiet = "<template><v-bottom-navigation><v-tabs /></v-bottom-navigation></template>\n";
assert.deepStrictEqual(drawerLines(quiet), []);
});
+
+test("drawer-nav catches Flutter's endDrawer, not a bottom navigation bar (issue #327)", () => {
+ const lines = (src, file = "home.dart") => scanSource(src, file, { platform: "mobile" }).filter((f) => f.rule === "drawer-nav").map((f) => [f.line, f.severity]);
+ // Issue #327 repro:
+ const repro = [
+ "import 'package:flutter/material.dart';",
+ "",
+ "class Home extends StatelessWidget {",
+ " @override",
+ " Widget build(BuildContext context) {",
+ " return Scaffold(",
+ " endDrawer: const Drawer(child: Text('Menu')),",
+ " body: const Text('Home'),",
+ " );",
+ " }",
+ "}",
+ ].join("\n");
+ assert.deepStrictEqual(lines(repro), [[7, "noticeable"]]);
+
+ // Both sides, with and without const, and the Material 3 NavigationDrawer
+ for (const line of [
+ "drawer: Drawer(child: menu),",
+ "drawer: const Drawer(child: menu),",
+ "endDrawer: Drawer(child: menu),",
+ "endDrawer: const Drawer(child: menu),",
+ "endDrawer: NavigationDrawer(children: items),",
+ ]) {
+ assert.deepStrictEqual(lines(`Scaffold(\n ${line}\n)\n`), [[2, "noticeable"]], line);
+ }
+
+ // Quiet case: a Scaffold with only a bottom navigation bar
+ assert.deepStrictEqual(lines("Scaffold(\n bottomNavigationBar: NavigationBar(destinations: tabs),\n body: const Text('Home'),\n)\n"), []);
+});