mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
[analysis_server] Remove unnecessary imports when organizing imports
Change-Id: I7a39a9b07adbacc7d3fd5abb3b165b47668e7938 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252420 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
71e2aee8a5
commit
5741f11f7b
|
@ -59,7 +59,8 @@ class ImportOrganizer {
|
|||
bool _isUnusedImport(UriBasedDirective directive) {
|
||||
for (var error in errors) {
|
||||
if ((error.errorCode == HintCode.DUPLICATE_IMPORT ||
|
||||
error.errorCode == HintCode.UNUSED_IMPORT) &&
|
||||
error.errorCode == HintCode.UNUSED_IMPORT ||
|
||||
error.errorCode == HintCode.UNNECESSARY_IMPORT) &&
|
||||
directive.uri.offset == error.offset) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -245,6 +245,31 @@ void f() {
|
|||
}''', removeUnused: true);
|
||||
}
|
||||
|
||||
Future<void> test_remove_unnecessaryImports() async {
|
||||
newFile(
|
||||
convertPath('$testPackageLibPath/declarations.dart'),
|
||||
'class A {} class B {}',
|
||||
);
|
||||
newFile(
|
||||
convertPath('$testPackageLibPath/exports.dart'),
|
||||
'export "a.dart" show A;',
|
||||
);
|
||||
await _computeUnitAndErrors(r'''
|
||||
import 'declarations.dart';
|
||||
import 'exports.dart';
|
||||
|
||||
A? a;
|
||||
B? b;
|
||||
''');
|
||||
// validate change
|
||||
_assertOrganize(r'''
|
||||
import 'declarations.dart';
|
||||
|
||||
A? a;
|
||||
B? b;
|
||||
''', removeUnused: true);
|
||||
}
|
||||
|
||||
Future<void> test_remove_unusedImports() async {
|
||||
await _computeUnitAndErrors(r'''
|
||||
library lib;
|
||||
|
|
Loading…
Reference in a new issue