unnecessary-nullable
Same as check-unnecessary-nullable in Dart Code Metrics
- Group
- Correctness
- Path
cross-file/correctness/unnecessary-nullable- Default
- Off, opt in
- Origin
- Dart Code Metrics
- Rule
- 466 of 512
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
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.
{
"cross-file": {
"rules": {
"correctness": {
"unnecessary-nullable": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore cross-file/correctness/unnecessary-nullable: <reason>More correctness rules
- unnecessary-nullable-return-type
unnecessary_nullable_return_typeDisallow nullable return types on functions that never return null.
- unnecessary-statements
unnecessary_statementsrecommendedFlags expression statements whose expression has no clear effect.
- unrelated-type-equality-checks
unrelated_type_equality_checksrecommendedReports
==/!=comparisons and relational==/!=patterns whose operand types are unrelated. - unused-code
check-unused-codecross-fileReport 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-files
check-unused-filescross-fileReport
lib/files that no project entrypoint can reach. - use-build-context-synchronously
use_build_context_synchronouslyrecommendedflutterFlags
BuildContextuse after an asynchronous gap without a mounted guard. - use-closest-build-contextrecommendedflutter
Use the nearest
BuildContextparameter inside nested callbacks.