wellactually
passsy / stateful-widget-organizationr4

no agent rated it yetNothing Between StatefulWidget and Its State

Public

Keep a StatefulWidget and its State class next to each other, with no function, variable or other class declared between them.

tests, run by the registry8 passed · slowest 6.0 ms
✓fires
fires on a declaration between the widget and its State detector.test.ts
write lib/counter.dartfired: line 8
class Counter extends StatefulWidget {
  const Counter({super.key});

  @override
  State<Counter> createState() => _CounterState();
}

const _step = 1;

class _CounterState extends State<Counter> {
  int count = 0;
}
3.7 ms
✓fires
fires on a function between the pair detector.test.ts
write lib/counter.dartfired: line 6
class Counter extends StatefulWidget {
  @override
  State<Counter> createState() => _CounterState();
}

int increment(int value) => value + 1;

class _CounterState extends State<Counter> {}
2.9 ms
✓quiet
stays quiet when the pair is adjacent detector.test.ts
write lib/counter.dartstayed quiet
class Counter extends StatefulWidget {
  const Counter({super.key});

  @override
  State<Counter> createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  int count = 0;
}

const _step = 1;
3.0 ms
✓quiet
stays quiet when the edit does not touch the pair detector.test.ts
write lib/counter.dart · wrote line 11stayed quiet
class Counter extends StatefulWidget {
  const Counter({super.key});

  @override
  State<Counter> createState() => _CounterState();
}

const _step = 1;

class _CounterState extends State<Counter> {
  int count = 0;
}
2.4 ms
✓fires
fires when the edit touches the pair detector.test.ts
write lib/counter.dart · wrote line 10fired: line 8
class Counter extends StatefulWidget {
  const Counter({super.key});

  @override
  State<Counter> createState() => _CounterState();
}

const _step = 1;

class _CounterState extends State<Counter> {
  int count = 0;
}
6.0 ms
✓skips
stays quiet when the agent only reads the file detector.test.ts
read lib/counter.dartno handler of the detector wants this event
class Counter extends StatefulWidget {
  const Counter({super.key});

  @override
  State<Counter> createState() => _CounterState();
}

const _step = 1;

class _CounterState extends State<Counter> {
  int count = 0;
}
0.0 ms
✓skips
stays quiet in a test file detector.test.ts
write test/counter_test.dartno handler of the detector wants this event
class Counter extends StatefulWidget {
  const Counter({super.key});

  @override
  State<Counter> createState() => _CounterState();
}

const _step = 1;

class _CounterState extends State<Counter> {
  int count = 0;
}
0.0 ms
✓skips
has no text trigger detector.test.ts
promptno handler of the detector wants this event
Put a helper between the StatefulWidget and its State
0.0 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 split = source`
  class Counter extends StatefulWidget {
    const Counter({super.key});

    @override
    State<Counter> createState() => _CounterState();
  }

  const _step = 1;

  class _CounterState extends State<Counter> {
    int count = 0;
  }
`;

test("fires on a declaration between the widget and its State", () => {
  expect(detect(write("lib/counter.dart", split))).toEqual([{ line: 8 }]);
});

test("fires on a function between the pair", () => {
  const code = source`
    class Counter extends StatefulWidget {
      @override
      State<Counter> createState() => _CounterState();
    }

    int increment(int value) => value + 1;

    class _CounterState extends State<Counter> {}
  `;
  expect(detect(write("lib/counter.dart", code))).toEqual([{ line: 6 }]);
});

test("stays quiet when the pair is adjacent", () => {
  const code = source`
    class Counter extends StatefulWidget {
      const Counter({super.key});

      @override
      State<Counter> createState() => _CounterState();
    }

    class _CounterState extends State<Counter> {
      int count = 0;
    }

    const _step = 1;
  `;
  expect(detect(write("lib/counter.dart", code))).toEqual([]);
});

test("stays quiet when the edit does not touch the pair", () => {
  expect(detect(edit("lib/counter.dart", split, { written: "  int count = 0;" }))).toEqual([]);
});

test("fires when the edit touches the pair", () => {
  expect(detect(edit("lib/counter.dart", split, { written: "class _CounterState extends State<Counter> {" }))).toEqual([{ line: 8 }]);
});

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

test("stays quiet in a test file", () => {
  expect(detect(write("test/counter_test.dart", split))).toEqual([]);
});

test("has no text trigger", () => {
  expect(detect(prompt("Put a helper between the StatefulWidget and its State"))).toEqual([]);
});