Skip to content

Commit e03b8f9

Browse files
authored
[stable] [flutter_tools] Fix crash when migrating flow-style exclude lists in analysis_options.yaml (#191598)
### Issue Link: #191060 ### Impact Description: When `analysis_options.yaml` uses YAML flow-style lists for `analyzer: { exclude: [...] }`, `flutter pub get` or `dart fix` crashes with a `_YamlAssertionError` when attempting to migrate and append platform exclusions. This completely blocks project preparation and tooling execution for projects using flow-style YAML syntax. ### Changelog Description: [flutter/191060] When `analysis_options.yaml` contains flow-style `exclude:` sequences, `AnalysisOptionsMigration` converts the node to block style before appending to avoid `YamlEditor` assertion crashes. ### Workaround: Manually edit `analysis_options.yaml` to convert the `exclude:` list from flow style (`[a, b]`) to standard block style (`- a\n- b`). ### Risk: ### Test Coverage: ### Validation Steps: 1. Create a Flutter project with `analysis_options.yaml` containing a flow-style `exclude:` list (e.g. `analyzer:\n exclude: [build/**]`). 2. Run `flutter pub get`. 3. Verify that `flutter pub get` succeeds without a `_YamlAssertionError` crash and correctly migrates the excluded directories.
1 parent e57eab8 commit e03b8f9

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎packages/flutter_tools/lib/src/migrations/analysis_options_migration.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ class AnalysisOptionsMigration extends ProjectMigrator {
7979
final exclude = analyzer['exclude'] as Object?;
8080
if (exclude is! YamlList) {
8181
editor.update(<String>['analyzer', 'exclude'], missingExcludes);
82+
} else if (exclude.style == CollectionStyle.FLOW) {
83+
// Workaround for https://github.com/dart-lang/tools/issues/2532.
84+
// Appending to a multiline flow-style list with a trailing comma crashes YamlEditor.
85+
// Instead, rewrite the entire exclude list as a block list.
86+
final newExcludes = <Object?>[
87+
...exclude,
88+
...missingExcludes.where((String item) => !exclude.contains(item)),
89+
];
90+
editor.update(<String>['analyzer', 'exclude'], newExcludes);
8291
} else {
8392
for (final missingExclude in missingExcludes) {
8493
if (!exclude.contains(missingExclude)) {

‎packages/flutter_tools/test/general.shard/migrations/analysis_options_migration_test.dart‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,36 @@ analyzer:
204204
expect(migratedContents, contains('linux/**'));
205205
});
206206

207+
testWithoutContext(
208+
'migrates and merges excludes when list is in flow style with newlines',
209+
() async {
210+
final _TestContext context = _createTestContext();
211+
const analysisOptionsContents = '''
212+
analyzer:
213+
exclude:
214+
[
215+
foo/**,
216+
build/**,
217+
]
218+
''';
219+
220+
context.analysisOptionsFile.writeAsStringSync(analysisOptionsContents);
221+
222+
final migration = AnalysisOptionsMigration(context.mockProject, context.testLogger);
223+
await migration.migrate();
224+
225+
final String migratedContents = context.analysisOptionsFile.readAsStringSync();
226+
expect(migratedContents, contains('foo/**'));
227+
expect(migratedContents, contains('build/**'));
228+
expect(migratedContents, contains('android/**'));
229+
expect(migratedContents, contains('ios/**'));
230+
expect(migratedContents, contains('web/**'));
231+
expect(migratedContents, contains('windows/**'));
232+
expect(migratedContents, contains('macos/**'));
233+
expect(migratedContents, contains('linux/**'));
234+
},
235+
);
236+
207237
testWithoutContext('skipped if exclusions are inherited via relative include', () async {
208238
final _TestContext context = _createTestContext();
209239
const analysisOptionsContents = '''

0 commit comments

Comments
 (0)