mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:09:49 +00:00
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 <brianwilkerson@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
f274c79333
commit
d6f4640c0d
|
@ -317,7 +317,7 @@ class FixProcessor extends BaseProcessor {
|
|||
/// used to create correction producers. The generators are then used to build
|
||||
/// fixes for those diagnostics. The generators used for non-lint diagnostics
|
||||
/// are in the [nonLintProducerMap].
|
||||
static const Map<String, List<ProducerGenerator>> lintProducerMap = {
|
||||
static final Map<String, List<ProducerGenerator>> lintProducerMap = {
|
||||
LintNames.always_declare_return_types: [
|
||||
// TODO(brianwilkerson) Consider applying in bulk.
|
||||
AddReturnType.newInstance,
|
||||
|
@ -1331,6 +1331,12 @@ class FixProcessor extends BaseProcessor {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Associate the given correction producer [generator] with the lint with the
|
||||
/// given [lintName].
|
||||
static void registerFixForLint(String lintName, ProducerGenerator generator) {
|
||||
lintProducerMap.putIfAbsent(lintName, () => []).add(generator);
|
||||
}
|
||||
}
|
||||
|
||||
/// [_FixState] that is still empty.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
|
||||
import 'package:analysis_server/src/services/correction/fix_internal.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
@ -22,6 +23,17 @@ class FixProcessorMapTest {
|
|||
_testMap(FixProcessor.nonLintProducerMap.values);
|
||||
}
|
||||
|
||||
void test_registerFixForLint() {
|
||||
CorrectionProducer producer() => MockCorrectionProducer();
|
||||
|
||||
var lintName = 'not_a_lint';
|
||||
expect(FixProcessor.lintProducerMap[lintName], null);
|
||||
FixProcessor.registerFixForLint(lintName, producer);
|
||||
expect(FixProcessor.lintProducerMap[lintName], contains(producer));
|
||||
// Restore the map to it's original state so as to not impact other tests.
|
||||
FixProcessor.lintProducerMap.remove(lintName);
|
||||
}
|
||||
|
||||
void _testGenerator(ProducerGenerator generator) {
|
||||
var producer = generator();
|
||||
var className = producer.runtimeType.toString();
|
||||
|
@ -40,3 +52,10 @@ class FixProcessorMapTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MockCorrectionProducer implements CorrectionProducer {
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) {
|
||||
return super.noSuchMethod(invocation);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue