@@ -22,6 +22,7 @@ import 'package:analysis_server/src/services/correction/dart/inline_typedef.dart
2222import 'package:analysis_server/src/services/correction/dart/remove_dead_if_null.dart' ;
2323import 'package:analysis_server/src/services/correction/dart/remove_if_null_operator.dart' ;
2424import 'package:analysis_server/src/services/correction/dart/remove_unused.dart' ;
25+ import 'package:analysis_server/src/services/correction/dart/remove_unused_local_variable.dart' ;
2526import 'package:analysis_server/src/services/correction/dart/replace_with_eight_digit_hex.dart' ;
2627import 'package:analysis_server/src/services/correction/dart/wrap_in_future.dart' ;
2728import 'package:analysis_server/src/services/correction/fix.dart' ;
@@ -380,9 +381,6 @@ class FixProcessor extends BaseProcessor {
380381 if (errorCode == HintCode .UNUSED_LABEL ) {
381382 await _addFix_removeUnusedLabel ();
382383 }
383- if (errorCode == HintCode .UNUSED_LOCAL_VARIABLE ) {
384- await _addFix_removeUnusedLocalVariable ();
385- }
386384 if (errorCode == HintCode .UNUSED_SHOWN_NAME ) {
387385 await _addFix_removeNameFromCombinator ();
388386 }
@@ -3773,54 +3771,6 @@ class FixProcessor extends BaseProcessor {
37733771 }
37743772 }
37753773
3776- Future <void > _addFix_removeUnusedLocalVariable () async {
3777- final declaration = node.parent;
3778- if (! (declaration is VariableDeclaration && declaration.name == node)) {
3779- return ;
3780- }
3781- Element element = (declaration as VariableDeclaration ).declaredElement;
3782- if (element is ! LocalElement ) {
3783- return ;
3784- }
3785-
3786- final sourceRanges = < SourceRange > [];
3787-
3788- final functionBody = declaration.thisOrAncestorOfType <FunctionBody >();
3789- final references = findLocalElementReferences (functionBody, element);
3790- for (var reference in references) {
3791- final node = reference.thisOrAncestorMatching ((node) =>
3792- node is VariableDeclaration || node is AssignmentExpression );
3793- var sourceRange;
3794- if (node is VariableDeclaration ) {
3795- VariableDeclarationList parent = node.parent;
3796- if (parent.variables.length == 1 ) {
3797- sourceRange = utils.getLinesRange (range.node (parent.parent));
3798- } else {
3799- sourceRange = range.nodeInList (parent.variables, node);
3800- }
3801- } else if (node is AssignmentExpression ) {
3802- // todo (pq): consider node.parent is! ExpressionStatement to handle
3803- // assignments in parens, etc.
3804- if (node.parent is ArgumentList ) {
3805- sourceRange = range.startStart (node, node.operator .next);
3806- } else {
3807- sourceRange = utils.getLinesRange (range.node (node.parent));
3808- }
3809- } else {
3810- return ;
3811- }
3812- sourceRanges.add (sourceRange);
3813- }
3814-
3815- final changeBuilder = _newDartChangeBuilder ();
3816- await changeBuilder.addFileEdit (file, (DartFileEditBuilder builder) {
3817- for (var sourceRange in sourceRanges) {
3818- builder.addDeletion (sourceRange);
3819- }
3820- });
3821- _addFixFromBuilder (changeBuilder, DartFixKind .REMOVE_UNUSED_LOCAL_VARIABLE );
3822- }
3823-
38243774 Future <void > _addFix_renameToCamelCase () async {
38253775 if (node is ! SimpleIdentifier ) {
38263776 return ;
@@ -4608,6 +4558,8 @@ class FixProcessor extends BaseProcessor {
46084558 await compute (RemoveUnusedElement ());
46094559 } else if (errorCode == HintCode .UNUSED_FIELD ) {
46104560 await compute (RemoveUnusedField ());
4561+ } else if (errorCode == HintCode .UNUSED_LOCAL_VARIABLE ) {
4562+ await compute (RemoveUnusedLocalVariable ());
46114563 } else if (errorCode == StaticWarningCode .DEAD_NULL_AWARE_EXPRESSION ) {
46124564 await compute (RemoveDeadIfNull ());
46134565 } else if (errorCode is LintCode ) {
0 commit comments