diff --git a/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart b/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart index 6e27913c31a..83e66a2bfef 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart @@ -15,12 +15,20 @@ void main() { @reflectiveTest class FixProcessorMapTest { + static const List lintsAllowedToHaveMultipleBulkFixes = [ + 'avoid_types_on_closure_parameters', + 'empty_statements', + 'prefer_collection_literals', + 'prefer_inlined_adds', + ]; + void test_lintProducerMap() { - _testMap(FixProcessor.lintProducerMap.values); + _assertMap(FixProcessor.lintProducerMap.entries, + lintsAllowedToHaveMultipleBulkFixes); } void test_nonLintProducerMap() { - _testMap(FixProcessor.nonLintProducerMap.values); + _assertMap(FixProcessor.nonLintProducerMap.entries); } void test_registerFixForLint() { @@ -34,8 +42,36 @@ class FixProcessorMapTest { FixProcessor.lintProducerMap.remove(lintName); } - void _testGenerator(ProducerGenerator generator) { - var producer = generator(); + void _assertMap(Iterable>> entries, + [List keysAllowedToHaveMultipleBulkFixes = const []]) { + var list = []; + 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(); expect(producer.fixKind, isNotNull, reason: '$className.fixKind'); if (producer.canBeAppliedToFile) { @@ -43,14 +79,6 @@ class FixProcessorMapTest { reason: '$className.multiFixKind'); } } - - void _testMap(Iterable> values) { - for (var generators in values) { - for (var generator in generators) { - _testGenerator(generator); - } - } - } } class MockCorrectionProducer implements CorrectionProducer {