unnecessary-nullable

Same as check-unnecessary-nullable in Dart Code Metrics

Path
cross-file/correctness/unnecessary-nullable
Default
Off, opt in
Origin
Dart Code Metrics
Rule
466 of 512
cross-file

Cross-file rule. It runs in falcon's whole-project pass, analyzing relationships across every file rather than one file at a time. Configure it under the top-level cross-file key.

Flags private function or method parameters whose nullable type is unnecessary.

A parameter is reported when every known call argument and assignment is proven non-null. Uncertain references or values that may be null are not reported. This cross-file rule is configured under cross-file.

Invalid

bad/caller.dartdart
import 'service.dart';

void driver() {
  final s = Service();
  s._never(1);
  s._never(2);
  s._sometimes(1);
  s._sometimes(null); // makes _sometimes genuinely nullable → not flagged
  s._assigns('x');
  s._ambiguous(3);
  _topNever('hello');
  Other()._ambiguous(4);
  _viaProvenNonNull(nonNull());
  _viaNullableReturn(maybeNull());
}

void nonnullLoopCalls() {
  _nonnullLoop(1);
  _nonnullCollectionLoop(1);
  _nonnullMapLoop(1);
}

No diagnostics in this file.

Configure unnecessary-nullable

Set its severity in falcon.json under the cross-file section. See the configuration guide.

falcon.jsonjson
{
  "cross-file": {
    "rules": {
      "correctness": {
        "unnecessary-nullable": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore cross-file/correctness/unnecessary-nullable: <reason>
  • unnecessary-nullable-return-typeunnecessary_nullable_return_type

    Disallow nullable return types on functions that never return null.

  • unnecessary-statementsunnecessary_statementsrecommended

    Flags expression statements whose expression has no clear effect.

  • unrelated-type-equality-checksunrelated_type_equality_checksrecommended

    Reports ==/!= comparisons and relational ==/!= patterns whose operand types are unrelated.

  • unused-codecheck-unused-codecross-file

    Report public top-level declarations that nothing references.

  • unused-dependenciescross-file

    Report regular pubspec dependencies with no Dart import or export in the analyzed package.

  • unused-filescheck-unused-filescross-file

    Report lib/ files that no project entrypoint can reach.

  • use-build-context-synchronouslyuse_build_context_synchronouslyrecommendedflutter

    Flags BuildContext use after an asynchronous gap without a mounted guard.

  • use-closest-build-contextrecommendedflutter

    Use the nearest BuildContext parameter inside nested callbacks.