require-super-dispose

Path
lint/correctness/require-super-dispose
Default
On (recommended)
Origin
Falcon
Domain
flutter
Rule
430 of 512
recommendedflutter

Require super.dispose() in Flutter State dispose overrides. Presence is checked separately from the ordering rule; nested callbacks do not count.

Invalid

example.dartdart
import 'package:flutter/material.dart';
class S0 extends State<StatefulWidget> { void dispose() {}  }
class S1 extends State<StatefulWidget> { void dispose() => cleanup();  }
class S2 extends State<StatefulWidget> { void dispose() { cleanup(); }  }
class S3 extends State<StatefulWidget> { void dispose() { return; }  }
class S4 extends State<StatefulWidget> { void dispose() { try { cleanup(); } finally { cleanup(); } }  }
Call `super.dispose()` in this `State.dispose` override.
1import 'package:flutter/material.dart';
2class S0 extends State<StatefulWidget> { void dispose() {} }
Call `super.dispose()` in this `State.dispose` override.
2class S0 extends State<StatefulWidget> { void dispose() {} }
3class S1 extends State<StatefulWidget> { void dispose() => cleanup(); }
Call `super.dispose()` in this `State.dispose` override.
3class S1 extends State<StatefulWidget> { void dispose() => cleanup(); }
4class S2 extends State<StatefulWidget> { void dispose() { cleanup(); } }
Call `super.dispose()` in this `State.dispose` override.
4class S2 extends State<StatefulWidget> { void dispose() { cleanup(); } }
5class S3 extends State<StatefulWidget> { void dispose() { return; } }
Call `super.dispose()` in this `State.dispose` override.
5class S3 extends State<StatefulWidget> { void dispose() { return; } }
6class S4 extends State<StatefulWidget> { void dispose() { try { cleanup(); } finally { cleanup(); } } }

Valid

example.dartdart
import 'package:flutter/material.dart';
class S0 extends State<StatefulWidget> { void dispose() { super.dispose(); } }
class S1 extends State<StatefulWidget> { void dispose() => super.dispose(); }
class S2 extends State<StatefulWidget> { void dispose() { cleanup(); super.dispose(); } }
class S3 extends State<StatefulWidget> { void dispose() { try { cleanup(); } finally { super.dispose(); } } }
class Other { void dispose() {} }

Configure require-super-dispose

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "require-super-dispose": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/require-super-dispose: <reason>