Improve unnecessary_late to target variable name (#3153)
* Improve unnecessary_late to target keyword
* Report lint for every unneccesary late at the variable name
* Remove unneeded variable
diff --git a/lib/src/rules/unnecessary_late.dart b/lib/src/rules/unnecessary_late.dart
index 0074743..e4cd61d 100644
--- a/lib/src/rules/unnecessary_late.dart
+++ b/lib/src/rules/unnecessary_late.dart
@@ -77,9 +77,13 @@
}
void _visitVariableDeclarations(VariableDeclarationList node) {
+ if (node.lateKeyword == null) {
+ return;
+ }
+
for (var variable in node.variables) {
- if (variable.isLate && variable.initializer != null) {
- rule.reportLint(variable);
+ if (variable.initializer != null) {
+ rule.reportLint(variable.name);
}
}
}
diff --git a/test_data/rules/unnecessary_late.dart b/test_data/rules/unnecessary_late.dart
index 2c772c9..165bc2e 100644
--- a/test_data/rules/unnecessary_late.dart
+++ b/test_data/rules/unnecessary_late.dart
@@ -8,6 +8,12 @@
late String necessaryTopLevelLate; // OK
+late String unnecessaryListLateOne = '', // LINT
+ unnecessaryListLateTwo = ''; // LINT
+
+late String necessaryListLate, // OK
+ unnecessaryListLate = ''; // LINT
+
String unnecessaryTopLevel = ''; // OK
class Test {