Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 041a6dd

Browse files
author
Dart CI
committed
Version 2.13.0-98.0.dev
Merge commit 'e7644d9a4c6f400680206f6d03135f24d0480052' into 'dev'
2 parents f527ddd + e7644d9 commit 041a6dd

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

pkg/analysis_server/lib/src/services/correction/dart/remove_unused_import.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class RemoveUnusedImport extends CorrectionProducer {
1313
@override
1414
FixKind get fixKind => DartFixKind.REMOVE_UNUSED_IMPORT;
1515

16+
@override
17+
FixKind get multiFixKind => DartFixKind.REMOVE_UNUSED_IMPORT_MULTI;
18+
1619
@override
1720
Future<void> compute(ChangeBuilder builder) async {
1821
// prepare ImportDirective

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,12 @@ class FixInFileProcessor {
287287
}
288288
}
289289
} else {
290-
// todo (pq): add support for non-lint producers and update to a new nonLintProducerMap2
291-
// var generators = FixProcessor.nonLintProducerMap[errorCode];
292-
// if (generators != null) {
293-
// if (generators != null) {
294-
// producers.addAll(generators);
295-
// }
296-
// }
290+
var fixInfos = FixProcessor.nonLintProducerMap2[errorCode] ?? [];
291+
for (var fixInfo in fixInfos) {
292+
if (fixInfo.canBeAppliedToFile) {
293+
producers.addAll(fixInfo.generators);
294+
}
295+
}
297296
// todo (pq): consider support for multiGenerators
298297
}
299298
return producers;
@@ -313,6 +312,19 @@ class FixInfo {
313312

314313
/// The computer for Dart fixes.
315314
class FixProcessor extends BaseProcessor {
315+
/// todo (pq): to replace nonLintProducerMap.
316+
static const Map<ErrorCode, List<FixInfo>> nonLintProducerMap2 = {
317+
HintCode.UNUSED_IMPORT: [
318+
FixInfo(
319+
canBeAppliedToFile: true,
320+
canBeBulkApplied: false,
321+
generators: [
322+
RemoveUnusedImport.newInstance,
323+
],
324+
),
325+
],
326+
};
327+
316328
/// todo (pq): to replace lintProducerMap.
317329
static const Map<String, List<FixInfo>> lintProducerMap2 = {
318330
LintNames.always_declare_return_types: [

pkg/analysis_server/test/src/services/correction/fix/remove_unused_import_test.dart

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import 'fix_processor.dart';
1212
void main() {
1313
defineReflectiveSuite(() {
1414
defineReflectiveTests(RemoveUnusedImportTest);
15+
defineReflectiveTests(RemoveUnusedImportMultiTest);
1516
});
1617
}
1718

1819
@reflectiveTest
19-
class RemoveUnusedImportTest extends FixProcessorTest {
20+
class RemoveUnusedImportMultiTest extends FixProcessorTest {
2021
@override
21-
FixKind get kind => DartFixKind.REMOVE_UNUSED_IMPORT;
22+
FixKind get kind => DartFixKind.REMOVE_UNUSED_IMPORT_MULTI;
2223

2324
@override
2425
void setUp() {
@@ -27,7 +28,6 @@ class RemoveUnusedImportTest extends FixProcessorTest {
2728
useLineEndingsForPlatform = false;
2829
}
2930

30-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/45026')
3131
Future<void> test_all_diverseImports() async {
3232
await resolveTestCode('''
3333
import 'dart:math';
@@ -42,7 +42,6 @@ main() {
4242
''');
4343
}
4444

45-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/45026')
4645
Future<void> test_all_diverseImports2() async {
4746
await resolveTestCode('''
4847
import 'dart:async';
@@ -64,7 +63,7 @@ main() {
6463
''');
6564
}
6665

67-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/45026')
66+
@FailingTest(reason: 'one unused import remains unremoved')
6867
Future<void> test_all_singleLine() async {
6968
await resolveTestCode('''
7069
import 'dart:math'; import 'dart:math'; import 'dart:math';
@@ -77,6 +76,33 @@ main() {
7776
''');
7877
}
7978

79+
Future<void> test_multipleOfSame_all() async {
80+
await resolveTestCode('''
81+
import 'dart:math';
82+
import 'dart:math';
83+
import 'dart:math';
84+
main() {
85+
}
86+
''');
87+
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
88+
main() {
89+
}
90+
''');
91+
}
92+
}
93+
94+
@reflectiveTest
95+
class RemoveUnusedImportTest extends FixProcessorTest {
96+
@override
97+
FixKind get kind => DartFixKind.REMOVE_UNUSED_IMPORT;
98+
99+
@override
100+
void setUp() {
101+
super.setUp();
102+
// TODO(dantup): Get these tests passing with either line ending.
103+
useLineEndingsForPlatform = false;
104+
}
105+
80106
Future<void> test_anotherImportOnLine() async {
81107
await resolveTestCode('''
82108
import 'dart:math'; import 'dart:async';
@@ -114,21 +140,6 @@ main() {
114140
''');
115141
}
116142

117-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/45026')
118-
Future<void> test_multipleOfSame_all() async {
119-
await resolveTestCode('''
120-
import 'dart:math';
121-
import 'dart:math';
122-
import 'dart:math';
123-
main() {
124-
}
125-
''');
126-
await assertHasFixAllFix(HintCode.UNUSED_IMPORT, '''
127-
main() {
128-
}
129-
''');
130-
}
131-
132143
Future<void> test_severalLines() async {
133144
await resolveTestCode('''
134145
import

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 13
2929
PATCH 0
30-
PRERELEASE 97
30+
PRERELEASE 98
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)