File tree 2 files changed +27
-1
lines changed
lib/src/services/correction
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ class ImportOrganizer {
59
59
bool _isUnusedImport (UriBasedDirective directive) {
60
60
for (var error in errors) {
61
61
if ((error.errorCode == HintCode .DUPLICATE_IMPORT ||
62
- error.errorCode == HintCode .UNUSED_IMPORT ) &&
62
+ error.errorCode == HintCode .UNUSED_IMPORT ||
63
+ error.errorCode == HintCode .UNNECESSARY_IMPORT ) &&
63
64
directive.uri.offset == error.offset) {
64
65
return true ;
65
66
}
Original file line number Diff line number Diff line change @@ -245,6 +245,31 @@ void f() {
245
245
}''' , removeUnused: true );
246
246
}
247
247
248
+ Future <void > test_remove_unnecessaryImports () async {
249
+ newFile (
250
+ convertPath ('$testPackageLibPath /declarations.dart' ),
251
+ 'class A {} class B {}' ,
252
+ );
253
+ newFile (
254
+ convertPath ('$testPackageLibPath /exports.dart' ),
255
+ 'export "a.dart" show A;' ,
256
+ );
257
+ await _computeUnitAndErrors (r'''
258
+ import 'declarations.dart';
259
+ import 'exports.dart';
260
+
261
+ A? a;
262
+ B? b;
263
+ ''' );
264
+ // validate change
265
+ _assertOrganize (r'''
266
+ import 'declarations.dart';
267
+
268
+ A? a;
269
+ B? b;
270
+ ''' , removeUnused: true );
271
+ }
272
+
248
273
Future <void > test_remove_unusedImports () async {
249
274
await _computeUnitAndErrors (r'''
250
275
library lib;
You can’t perform that action at this time.
0 commit comments