Skip to content

Commit d6f4640

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Make the set of fixes for lints extensible
Change-Id: I70ba8737f91aa2d3728ae67d656de26d3619579e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210840 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent f274c79 commit d6f4640

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class FixProcessor extends BaseProcessor {
317317
/// used to create correction producers. The generators are then used to build
318318
/// fixes for those diagnostics. The generators used for non-lint diagnostics
319319
/// are in the [nonLintProducerMap].
320-
static const Map<String, List<ProducerGenerator>> lintProducerMap = {
320+
static final Map<String, List<ProducerGenerator>> lintProducerMap = {
321321
LintNames.always_declare_return_types: [
322322
// TODO(brianwilkerson) Consider applying in bulk.
323323
AddReturnType.newInstance,
@@ -1331,6 +1331,12 @@ class FixProcessor extends BaseProcessor {
13311331
}
13321332
}
13331333
}
1334+
1335+
/// Associate the given correction producer [generator] with the lint with the
1336+
/// given [lintName].
1337+
static void registerFixForLint(String lintName, ProducerGenerator generator) {
1338+
lintProducerMap.putIfAbsent(lintName, () => []).add(generator);
1339+
}
13341340
}
13351341

13361342
/// [_FixState] that is still empty.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
56
import 'package:analysis_server/src/services/correction/fix_internal.dart';
67
import 'package:test/test.dart';
78
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -22,6 +23,17 @@ class FixProcessorMapTest {
2223
_testMap(FixProcessor.nonLintProducerMap.values);
2324
}
2425

26+
void test_registerFixForLint() {
27+
CorrectionProducer producer() => MockCorrectionProducer();
28+
29+
var lintName = 'not_a_lint';
30+
expect(FixProcessor.lintProducerMap[lintName], null);
31+
FixProcessor.registerFixForLint(lintName, producer);
32+
expect(FixProcessor.lintProducerMap[lintName], contains(producer));
33+
// Restore the map to it's original state so as to not impact other tests.
34+
FixProcessor.lintProducerMap.remove(lintName);
35+
}
36+
2537
void _testGenerator(ProducerGenerator generator) {
2638
var producer = generator();
2739
var className = producer.runtimeType.toString();
@@ -40,3 +52,10 @@ class FixProcessorMapTest {
4052
}
4153
}
4254
}
55+
56+
class MockCorrectionProducer implements CorrectionProducer {
57+
@override
58+
dynamic noSuchMethod(Invocation invocation) {
59+
return super.noSuchMethod(invocation);
60+
}
61+
}

0 commit comments

Comments
 (0)