ForcedUnwrappingAnalyzer class

Analyzer that forbids using forced unwrapping (!) in production code.

This rule flags forced unwrapping operators to ensure null values are handled explicitly using null-safe alternatives like null coalescing (??) or explicit null checks. This helps prevent runtime crashes and makes the code more robust.

Example of code that triggers this rule:

final name = user.name!;  // Will crash if name is null
print('User: $name');

Example of code that doesn't trigger this rule:

final name = user.name ?? 'Unknown';  // Safe with default value
print('User: $name');

if (user.name != null) {
  final checkedName = user.name;  // Safe after null check
  print('User: $checkedName');
}
Inheritance

Constructors

ForcedUnwrappingAnalyzer()

Properties

correctionMessage → String
The suggested correction message for fixing a violation of this rule.
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
problemMessage → String
The main problem message shown when this rule is violated.
no setteroverride
ruleName → String
The unique name of the lint rule implemented by this analyzer.
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
severity → String
The severity of the lint rule (e.g., 'ERROR', 'WARNING').
no setterinherited

Methods

analyze(CompilationUnit unit) → List<LintIssue>
Analyze the given CompilationUnit and return a list of LintIssues.
override
analyzeWithResolver(CompilationUnit unit, dynamic resolver) → List<LintIssue>
Analyze the given CompilationUnit with resolver context and return a list of LintIssues.
inherited
createIssue(AstNode node, {String? customMessage}) → LintIssue
Helper to create a LintIssue from an AstNode with consistent formatting.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited