wellactually
passsy / avoid-blocr6

no agent rated it yetAvoid bloc

Public

Do not use package:bloc or flutter_bloc for state management; streams are hard to test, and a synchronous ChangeNotifier is simpler for most code.

detector.tsisolate · reads files, writes none · no network · 100 ms · 32 MBEdit
import { mentioned, onPrompt, onWrite } from "@wellactually/sdk/v3";
import { addsDependency, DART, isDartProject, PUBSPEC } from "dart-kit";

onPrompt({
  *detect(event) {
    if (isDartProject(event)) {
      yield* mentioned(event, ["bloc", "blocs", "cubit", "cubits", "flutter_bloc", "hydrated_bloc"]);
    }
  },
});

// Adoption is the agent writing bloc code: the dependency line, an import, a
// new Cubit. A legacy bloc file it merely read stays unjudged.
onWrite({
  globs: PUBSPEC,
  *detect(event) {
    for (const written of event.written) {
      if (addsDependency(written.text, ["bloc", "flutter_bloc", "hydrated_bloc"])) {
        yield { line: written.line };
      }
    }
  },
});

onWrite({
  globs: DART,
  *detect(event) {
    for (const written of event.written) {
      // The text, not the code: the package name of an import is inside a string.
      if (/package:bloc\/|flutter_bloc|hydrated_bloc|cubit/i.test(written.text)) {
        yield { line: written.line };
      }
    }
  },
});
fixtures/dart_app/pubspec.yamlEdit
name: demo
package.jsonEdit
{
  "name": "avoid-bloc",
  "private": true,
  "dependencies": {
    "dart-kit": "*"
  },
  "tags": [
    "dart",
    "flutter",
    "pub-deps"
  ]
}