-
Notifications
You must be signed in to change notification settings - Fork 169
Conversation
…nter into nnbd_auto_migration
…nter into nnbd_auto_migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought you were ready for a review, but I've had to refresh several times since I started, and now I have no idea what I have and haven't looked at.
It probably doesn't matter, though, because there's way too much to do a decent review, so I'll just have to trust that you'll clean it up after you commit it. I made a couple of specific requests near the beginning, but in general here's a list of the kinds of issues I saw that I think should be cleaned up:
-
Every use of the null check operator (
!
) should be removed. There are lots of different ways to do that depending on the context, every single one should be removed, or there should be a comment explaining why it isn't possible to get rid of it. -
Every question mark that can be removed should be. There are lots of places where there are nullable types that I think we can get rid of. One common pattern before was to check for null argument values in every method, but the code is much cleaner in a null safe world if we check at every call site.
-
Every local variable that was created in order to hold a casted value should be removed.
@@ -268,7 +268,7 @@ bool _checkForSimpleSetter(MethodDeclaration setter, Expression expression) { | |||
if (expression is! AssignmentExpression) { | |||
return false; | |||
} | |||
final assignment = expression as AssignmentExpression; | |||
final assignment = expression; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment is unlikely to be necessary now.
@@ -14,15 +14,15 @@ import 'util/score_utils.dart'; | |||
// Number of times to perform linting to get stable benchmarks. | |||
const benchmarkRuns = 10; | |||
|
|||
String getLineContents(int lineNumber, AnalysisError error) { | |||
String getLineContents(int? lineNumber, AnalysisError error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lineNumber
should not be nullable.
@@ -14,15 +14,15 @@ import 'util/score_utils.dart'; | |||
// Number of times to perform linting to get stable benchmarks. | |||
const benchmarkRuns = 10; | |||
|
|||
String getLineContents(int lineNumber, AnalysisError error) { | |||
String getLineContents(int? lineNumber, AnalysisError error) { | |||
final path = error.source.fullName; | |||
final file = File(path); | |||
String failureDetails; | |||
if (!file.existsSync()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't part of the migration, but there's no value in testing whether the file exists. Just read the content and catch the exception if the file doesn't exist.
final bool machineOutput; | ||
final bool quiet; | ||
final bool? machineOutput; | ||
final bool? quiet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool?
is a strong signal that there's a bug in the code. Consider making these non-nullable and clean up the code.
@@ -322,10 +322,10 @@ class SimpleFormatter implements ReportFormatter { | |||
|
|||
class _Stat implements Comparable<_Stat> { | |||
final String name; | |||
final int elapsed; | |||
final int? elapsed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be non-nullable.
@@ -93,14 +93,14 @@ class _Visitor extends SimpleAstVisitor<void> { | |||
_checkNodeOnNextLine(node.body, node.rightParenthesis.end); | |||
} | |||
|
|||
void _checkNodeOnNextLine(AstNode node, int controlEnd) { | |||
void _checkNodeOnNextLine(AstNode? node, int controlEnd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node
should be non-nullable.
@@ -82,7 +82,7 @@ class _Visitor extends SimpleAstVisitor<void> { | |||
return; | |||
} | |||
|
|||
final classElement = parentElement as ClassElement; | |||
final classElement = parentElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is unnecessary now.
_visitFunctionBody(node.body); | ||
} | ||
} | ||
|
||
void _visitFunctionBody(FunctionBody node) { | ||
void _visitFunctionBody(FunctionBody? node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node
should be non-nullable. The analyzer APIs have been updated to disallow any function from having a null body. The compiler won't catch the change when you update to the next version of analyzer.
As described in dart-lang/sdk#58322, landing this as-is with tidying to follow. |
First cut at migration using the migration tool.
As discussed, I'd like to land this (if green) and iterate on improvements.
See: dart-lang/sdk#58322