passsy / avoid-plain-string-widget-argsr4
Widget Parameters Instead of String Parameters
PublicGive reusable widgets Widget parameters with a DefaultTextStyle instead of String parameters for user-facing text, so callers can pass icons, rich text or their own style.
detector.tsisolate · reads files, writes none · no network · 100 ms · 32 MBEdit
import { onWrite } from "@wellactually/sdk/v3";
import { DART } from "dart-kit";
onWrite({
globs: DART,
*detect(event) {
// Only widgets take display text through their constructor.
const isWidgetFile = event.lines.some((line) => line.includes("extends StatelessWidget") || line.includes("extends StatefulWidget"));
if (!isWidgetFile) {
return;
}
for (const written of event.written) {
// Field names that carry text a user will read. Identifiers like productId or
// routeName are logic, not display, and the rule explicitly leaves them alone.
if (/final\s+String\??\s+(title|subtitle|label|message|text|caption|description|hint|heading|body)\s*;/.test(written.text)) {
yield { line: written.line };
}
}
},
});
package.jsonEdit
{
"name": "avoid-plain-string-widget-args",
"private": true,
"dependencies": {
"dart-kit": "*"
},
"tags": [
"flutter"
]
}