-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add quick fix to avoid_final_with_getter
- Loading branch information
Showing
4 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
lib/src/lints/avoid_final_with_getter/avoid_final_with_getter_fix.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
part of 'avoid_final_with_getter_rule.dart'; | ||
|
||
class _FinalWithGetterFix extends DartFix { | ||
@override | ||
void run( | ||
CustomLintResolver resolver, | ||
ChangeReporter reporter, | ||
CustomLintContext context, | ||
AnalysisError analysisError, | ||
List<AnalysisError> others, | ||
) { | ||
context.registry.addMethodDeclaration((node) { | ||
if (analysisError.sourceRange.intersects(node.sourceRange)) { | ||
final info = analysisError.data as FinalWithGetterInfo?; | ||
if (info == null) return; | ||
|
||
_addReplacement(reporter, info); | ||
} | ||
}); | ||
} | ||
|
||
void _addReplacement( | ||
ChangeReporter reporter, | ||
FinalWithGetterInfo info, | ||
) { | ||
final changeBuilder = reporter.createChangeBuilder( | ||
message: "Remove getter and make variable public.", | ||
priority: 1, | ||
); | ||
|
||
changeBuilder.addDartFileEdit((builder) { | ||
builder.addDeletion(info.getter.sourceRange); | ||
builder.addDeletion(SourceRange(info.variable.name.offset, 1)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters