mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:57:35 +00:00
Add a test to ensure that a single diagnostic never has multiple bulk appliable fixes
This includes an allow list for the diagnostics that we're already approved, and we can add more as needed, but I don't want us to have multiple bulk fixes without first confirming that they are mutually exclusive. This should help prevent an oversight. Change-Id: I73c4a52e36005f256b416372bfbf8bf7db38400e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214424 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
8a9a2e4066
commit
4daa1ed206
|
@ -15,12 +15,20 @@ void main() {
|
||||||
|
|
||||||
@reflectiveTest
|
@reflectiveTest
|
||||||
class FixProcessorMapTest {
|
class FixProcessorMapTest {
|
||||||
|
static const List<String> lintsAllowedToHaveMultipleBulkFixes = [
|
||||||
|
'avoid_types_on_closure_parameters',
|
||||||
|
'empty_statements',
|
||||||
|
'prefer_collection_literals',
|
||||||
|
'prefer_inlined_adds',
|
||||||
|
];
|
||||||
|
|
||||||
void test_lintProducerMap() {
|
void test_lintProducerMap() {
|
||||||
_testMap(FixProcessor.lintProducerMap.values);
|
_assertMap(FixProcessor.lintProducerMap.entries,
|
||||||
|
lintsAllowedToHaveMultipleBulkFixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_nonLintProducerMap() {
|
void test_nonLintProducerMap() {
|
||||||
_testMap(FixProcessor.nonLintProducerMap.values);
|
_assertMap(FixProcessor.nonLintProducerMap.entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_registerFixForLint() {
|
void test_registerFixForLint() {
|
||||||
|
@ -34,8 +42,36 @@ class FixProcessorMapTest {
|
||||||
FixProcessor.lintProducerMap.remove(lintName);
|
FixProcessor.lintProducerMap.remove(lintName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _testGenerator(ProducerGenerator generator) {
|
void _assertMap<K>(Iterable<MapEntry<K, List<ProducerGenerator>>> entries,
|
||||||
var producer = generator();
|
[List<String> keysAllowedToHaveMultipleBulkFixes = const []]) {
|
||||||
|
var list = <String>[];
|
||||||
|
for (var entry in entries) {
|
||||||
|
var bulkCount = 0;
|
||||||
|
for (var generator in entry.value) {
|
||||||
|
var producer = generator();
|
||||||
|
_assertValidProducer(producer);
|
||||||
|
if (producer.canBeAppliedInBulk) {
|
||||||
|
bulkCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bulkCount > 1) {
|
||||||
|
var key = entry.key.toString();
|
||||||
|
if (!keysAllowedToHaveMultipleBulkFixes.contains(key)) {
|
||||||
|
list.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (list.isNotEmpty) {
|
||||||
|
var buffer = StringBuffer();
|
||||||
|
buffer.writeln('Multiple bulk fixes for');
|
||||||
|
for (var code in list) {
|
||||||
|
buffer.writeln('- $code');
|
||||||
|
}
|
||||||
|
fail(buffer.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _assertValidProducer(CorrectionProducer producer) {
|
||||||
var className = producer.runtimeType.toString();
|
var className = producer.runtimeType.toString();
|
||||||
expect(producer.fixKind, isNotNull, reason: '$className.fixKind');
|
expect(producer.fixKind, isNotNull, reason: '$className.fixKind');
|
||||||
if (producer.canBeAppliedToFile) {
|
if (producer.canBeAppliedToFile) {
|
||||||
|
@ -43,14 +79,6 @@ class FixProcessorMapTest {
|
||||||
reason: '$className.multiFixKind');
|
reason: '$className.multiFixKind');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _testMap(Iterable<List<ProducerGenerator>> values) {
|
|
||||||
for (var generators in values) {
|
|
||||||
for (var generator in generators) {
|
|
||||||
_testGenerator(generator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockCorrectionProducer implements CorrectionProducer {
|
class MockCorrectionProducer implements CorrectionProducer {
|
||||||
|
|
Loading…
Reference in a new issue