passsy / avoid-blocr6
Avoid bloc
PublicDo not use package:bloc or flutter_bloc for state management; streams are hard to test, and a synchronous ChangeNotifier is simpler for most code.
tests, run by the registry9 passed · slowest 14.0 ms
✓fires6.2 ms
fires on a bloc dependency the agent writes
write pubspec.yamlfired: line 5
namedemo
dependencies
flutter
sdkflutter
bloc^8.0.0
provider^6.0.0✓quiet4.8 ms
stays quiet on a commented out dependency
write pubspec.yamlstayed quiet
namedemo
dependencies
# bloc: ^8.0.0
# flutter_bloc: ^8.0.0
✓fires4.5 ms
fires on bloc code the agent writes
write lib/counter.dartfired: line 1, line 3, line 4
import 'package:flutter_bloc/flutter_bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
}✓quiet4.2 ms
stays quiet on legacy bloc code when the agent edits another line
write lib/counter.dart · wrote line 6stayed quiet
import 'package:flutter_bloc/flutter_bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
}
int answer = 42;
✓skips0.0 ms
stays quiet when the agent only reads a bloc file
read lib/counter.dartno handler of the detector wants this event
import 'package:flutter_bloc/flutter_bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
}✓skips0.0 ms
stays quiet in generated code
write lib/counter.g.dartno handler of the detector wants this event
class _$CounterCubit extends Cubit<int> {}✓fires10.0 ms
points at the principle when the user asks for a cubit in a Dart project
prompt · in fixtures/dart_appfired: "Cubit"
Can you move the login state into a Cubit?✓quiet4.8 ms
stays quiet on the same words outside a Dart project
promptstayed quiet
Can you move the login state into a Cubit?✓quiet14.0 ms
stays quiet on a word that only contains bloc
prompt · in fixtures/dart_appstayed quiet
The blockchain view needs a refresh buttondetector.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 pubspec = source`
name: demo
dependencies:
flutter:
sdk: flutter
bloc: ^8.0.0
provider: ^6.0.0
`;
test("fires on a bloc dependency the agent writes", () => {
expect(detect(write("pubspec.yaml", pubspec))).toEqual([{ line: 5 }]);
});
test("stays quiet on a commented out dependency", () => {
expect(detect(write("pubspec.yaml", "name: demo\ndependencies:\n # bloc: ^8.0.0\n # flutter_bloc: ^8.0.0\n"))).toEqual([]);
});
const counter = source`
import 'package:flutter_bloc/flutter_bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
}
`;
test("fires on bloc code the agent writes", () => {
expect(detect(write("lib/counter.dart", counter))).toEqual([
{ line: 1 },
{ line: 3 },
{ line: 4 },
]);
});
test("stays quiet on legacy bloc code when the agent edits another line", () => {
const code = `${counter}\nint answer = 42;\n`;
expect(detect(edit("lib/counter.dart", code, { written: "int answer = 42;" }))).toEqual([]);
});
test("stays quiet when the agent only reads a bloc file", () => {
expect(detect(read("lib/counter.dart", counter))).toEqual([]);
});
test("stays quiet in generated code", () => {
expect(detect(write("lib/counter.g.dart", "class _$CounterCubit extends Cubit<int> {}"))).toEqual([]);
});
const dartApp = { project: "fixtures/dart_app" };
test("points at the principle when the user asks for a cubit in a Dart project", () => {
expect(detect(prompt("Can you move the login state into a Cubit?"), dartApp)).toEqual([{ match: "Cubit", depth: "pointer" }]);
});
test("stays quiet on the same words outside a Dart project", () => {
expect(detect(prompt("Can you move the login state into a Cubit?"))).toEqual([]);
});
test("stays quiet on a word that only contains bloc", () => {
expect(detect(prompt("The blockchain view needs a refresh button"), dartApp)).toEqual([]);
});