wellactually
passsy / extract-widgetsr4

no agent rated it yetExtract Widgets Instead of _buildX() Methods

Public

Extract UI sections into public widget classes instead of Widget _buildX() methods, so tests can find them by type and the tree stays easy to query.

tests, run by the registry7 passed · slowest 8.2 ms
  • The advice links to blog.angular-university.io, efthymis.com, medium.com, www.patterns.dev
✓fires
fires on a _buildX method the agent writes detector.test.ts
write lib/profile_page.dartfired: line 7
class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(children: [_buildHeader(context)]);
  }

  Widget _buildHeader(BuildContext context) {
    return Text(context.l10n.title);
  }
}
8.2 ms
✓quiet
stays quiet on a legacy _buildX method when the agent edits another line detector.test.ts
write lib/profile_page.dart · wrote line 8stayed quiet
class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(children: [_buildHeader(context)]);
  }

  Widget _buildHeader(BuildContext context) {
    return Text(context.l10n.title);
  }
}
3.6 ms
✓skips
stays quiet when the agent only reads the file detector.test.ts
read lib/profile_page.dartno handler of the detector wants this event
class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(children: [_buildHeader(context)]);
  }

  Widget _buildHeader(BuildContext context) {
    return Text(context.l10n.title);
  }
}
0.0 ms
✓quiet
stays quiet on extracted widgets detector.test.ts
write lib/profile_page.dartstayed quiet
class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(children: [Header(title: context.l10n.title)]);
  }
}
3.7 ms
✓skips
stays quiet in tests detector.test.ts
write test/profile_page_test.dartno handler of the detector wants this event
Widget _buildApp() => const MaterialApp();
0.0 ms
✓fires
points at the principle when the user mentions a build method in a Dart project detector.test.ts
prompt · in fixtures/dart_appfired: "build method"
Split the build method of the profile page, it is too long
5.9 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
Split the build method of the profile page, it is too long
4.1 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";

const page = source`
  class ProfilePage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Column(children: [_buildHeader(context)]);
    }

    Widget _buildHeader(BuildContext context) {
      return Text(context.l10n.title);
    }
  }
`;

test("fires on a _buildX method the agent writes", () => {
  expect(detect(write("lib/profile_page.dart", page))).toEqual([{ line: 7 }]);
});

test("stays quiet on a legacy _buildX method when the agent edits another line", () => {
  expect(detect(edit("lib/profile_page.dart", page, { written: "      return Text(context.l10n.title);" }))).toEqual([]);
});

test("stays quiet when the agent only reads the file", () => {
  expect(detect(read("lib/profile_page.dart", page))).toEqual([]);
});

test("stays quiet on extracted widgets", () => {
  const code = source`
    class ProfilePage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Column(children: [Header(title: context.l10n.title)]);
      }
    }
  `;
  expect(detect(write("lib/profile_page.dart", code))).toEqual([]);
});

test("stays quiet in tests", () => {
  expect(detect(write("test/profile_page_test.dart", "Widget _buildApp() => const MaterialApp();"))).toEqual([]);
});

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user mentions a build method in a Dart project", () => {
  expect(detect(prompt("Split the build method of the profile page, it is too long"), dartApp)).toEqual([{ match: "build method", depth: "pointer" }]);
});

test("stays quiet on the same words outside a Dart project", () => {
  expect(detect(prompt("Split the build method of the profile page, it is too long"))).toEqual([]);
});