Skip to content

Commit

Permalink
[DAS] Adds quick-fix for extension name
Browse files Browse the repository at this point in the history
[email protected]

Fixes: #59723
Change-Id: I3679146ac70dd6bcb936c151cb93dacf8273d4b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401040
Auto-Submit: Felipe Morschel <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
  • Loading branch information
FMorschel authored and Commit Queue committed Dec 18, 2024
1 parent 302315c commit 4e719de
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ import 'package:analyzer/src/generated/parser.dart';
import 'package:linter/src/lint_codes.dart';

final _builtInLintMultiProducers = {
LinterLintCode.comment_references: [ImportLibrary.forType],
LinterLintCode.comment_references: [
ImportLibrary.forType,
ImportLibrary.forExtension,
],
LinterLintCode.deprecated_member_use_from_same_package_without_message: [
DataDriven.new,
],
Expand Down Expand Up @@ -1094,8 +1097,8 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
// updated so that only the appropriate subset is generated.
QualifyReference.new,
],
CompileTimeErrorCode.UNQUALIFIED_REFERENCE_TO_STATIC_MEMBER_OF_EXTENDED_TYPE:
[
CompileTimeErrorCode
.UNQUALIFIED_REFERENCE_TO_STATIC_MEMBER_OF_EXTENDED_TYPE: [
// TODO(brianwilkerson): Consider adding fixes to create a field, getter,
// method or setter. The existing producers would need to be updated so
// that only the appropriate subset is generated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,23 @@ void f() {
await assertNoFix();
}

Future<void> test_extension_name() async {
createAnalysisOptionsFile(lints: [LintNames.comment_references]);
newFile('$testPackageLibPath/lib.dart', '''
extension Ext on int {}
''');
await resolveTestCode('''
/// This should import [Ext].
void f() {}
''');
await assertHasFix('''
import 'package:test/lib.dart';
/// This should import [Ext].
void f() {}
''');
}

Future<void> test_extension_notImported_binaryOperator() async {
newFile('$testPackageLibPath/lib.dart', '''
extension E on String {
Expand Down Expand Up @@ -2164,6 +2181,25 @@ class ImportLibraryProject2Test extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.IMPORT_LIBRARY_PROJECT2;

Future<void> test_extension_name() async {
createAnalysisOptionsFile(lints: [LintNames.comment_references]);
newFile('$testPackageLibPath/lib1.dart', '''
extension Ext on int {}
''');
newFile('$testPackageLibPath/lib2.dart', '''
export 'package:test/lib1.dart';''');
await resolveTestCode('''
/// This should import [Ext].
void f() {}
''');
await assertHasFix('''
import 'package:test/lib2.dart';
/// This should import [Ext].
void f() {}
''');
}

Future<void> test_lib() async {
newFile('$packagesRootPath/my_pkg/lib/a.dart', '''
export 'b.dart';
Expand Down Expand Up @@ -2540,6 +2576,23 @@ class ImportLibraryProject3Test extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.IMPORT_LIBRARY_PROJECT3;

Future<void> test_extension_name() async {
createAnalysisOptionsFile(lints: [LintNames.comment_references]);
newFile('$testPackageLibPath/src/lib1.dart', '''
extension Ext on int {}
''');
await resolveTestCode('''
/// This should import [Ext].
void f() {}
''');
await assertHasFix('''
import 'package:test/src/lib1.dart';
/// This should import [Ext].
void f() {}
''');
}

Future<void> test_inLibSrc_thisContextRoot_extension() async {
newFile('$testPackageLibPath/src/lib.dart', '''
extension E on int {
Expand Down

0 comments on commit 4e719de

Please sign in to comment.