no_late 0.2.0 copy "no_late: ^0.2.0" to clipboard
no_late: ^0.2.0 copied to clipboard

Dart analyzer plugin that prevents LateInitializationError by enforcing safe late keyword usage for lazy initialization only.

no_late #

Stop LateInitializationError at compile time.

Dart analyzer plugin that bans unsafe late usage. Only allows late for lazy initialization. Everything else is a compile error.

The Problem #

late without immediate initialization causes runtime exceptions:

late String name;  // πŸ’£ Bomb waiting to explode
String greet() => 'Hello $name';  // πŸ’₯ LateInitializationError!

The Solution #

This plugin makes unsafe late usage a compile-time error:

late String name;  // ❌ ERROR: Uninitialized late variable

Quick Start #

Just add the package and put this in your analysis_options

analyzer:
  plugins:
    - custom_lint

What's Blocked #

// ❌ Uninitialized late
late String userName;

// ❌ Simple literals (no lazy benefit)
late String title = "Hello";
late int count = 42;

// ❌ Simple identifiers
late var copy = originalValue;

What's Allowed #

// βœ… Expensive computations
late final primes = calculatePrimes(1000000);

// βœ… Method/constructor calls
late final db = Database.connect();
late final timestamp = DateTime.now();

// βœ… Complex expressions
late final sum = numbers.fold(0, (a, b) => a + b);

Real Example: Flutter #

❌ Dangerous Pattern #

class _MyWidgetState extends State<MyWidget> {
  late AnimationController controller;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(vsync: this);
  }
  // If initState fails, controller.dispose() crashes
}

βœ… Safe Pattern #

class _MyWidgetState extends State<MyWidget> {
  AnimationController? controller;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    controller?.dispose();  // Null-safe
    super.dispose();
  }
}

Migration #

Pattern Before After
Uninitialized late T value; T? value;
Simple literal late T value = literal; T value = literal;
Lazy computation late T value = compute(); Keep as-is βœ…
8
likes
40
points
117
downloads

Publisher

unverified uploader

Weekly Downloads

Dart analyzer plugin that prevents LateInitializationError by enforcing safe late keyword usage for lazy initialization only.

Repository (GitHub)
View/report issues

Topics

#dart #analyzer #lint #late #safety

License

BSD-3-Clause (license)

Dependencies

analyzer, analyzer_plugin, custom_lint_builder

More

Packages that depend on no_late