@@ -68,11 +68,7 @@ Future<AnalysisOptions> readAnalysisOptions(
6868 // Lower the YAML to a regular map.
6969 var options = {...yaml};
7070
71- // If there is an `include:` key, then load that and merge it with these
72- // options.
73- if (options['include' ] case String include) {
74- options.remove ('include' );
75-
71+ Future <Map <Object ?, Object ?>> optionsFromInclude (String include) async {
7672 // If the include path is "package:", resolve it to a file path first.
7773 var includeUri = Uri .tryParse (include);
7874 if (includeUri != null && includeUri.scheme == 'package' ) {
@@ -95,9 +91,39 @@ Future<AnalysisOptions> readAnalysisOptions(
9591 // options file.
9692 var includePath = await fileSystem.join (
9793 (await fileSystem.parentDirectory (optionsPath))! , include);
98- var includeFile = await readAnalysisOptions (fileSystem, includePath,
94+ return await readAnalysisOptions (fileSystem, includePath,
9995 resolvePackageUri: resolvePackageUri);
100- options = merge (includeFile, options) as AnalysisOptions ;
96+ }
97+
98+ // If there is an `include:` key with a String value, then load that and merge
99+ // it with these options. If there is an `include:` key with a List value,
100+ // then load each value, merging successive included options, overriding
101+ // previous results with each set of included options, finally merging with
102+ // these options.
103+ switch (options['include' ]) {
104+ case String include:
105+ options.remove ('include' );
106+ var includeOptions = await optionsFromInclude (include);
107+ options = merge (includeOptions, options) as AnalysisOptions ;
108+ case List <Object ?> includeList:
109+ options.remove ('include' );
110+ var mergedIncludeOptions = AnalysisOptions ();
111+ for (var include in includeList) {
112+ if (include is ! String ) {
113+ throw PackageResolutionException (
114+ 'Unsupported "include" value in analysis options include list: '
115+ '"$include ".' );
116+ }
117+ var includeOptions = await optionsFromInclude (include);
118+ mergedIncludeOptions =
119+ merge (mergedIncludeOptions, includeOptions) as AnalysisOptions ;
120+ }
121+ options = merge (mergedIncludeOptions, options) as AnalysisOptions ;
122+ case null :
123+ break ;
124+ case Object include:
125+ throw PackageResolutionException (
126+ 'Unsupported "include" value in analysis options: "$include ".' );
101127 }
102128
103129 return options;
0 commit comments