@@ -69,7 +69,7 @@ List<AnalysisError> analyzeAnalysisOptions(
69
69
}
70
70
}
71
71
72
- // Validate the specified options and any included option files.
72
+ // Validates the specified options and any included option files.
73
73
void validate (Source source, YamlMap options, LintRuleProvider ? provider) {
74
74
var sourceIsOptionsForContextRoot = initialIncludeSpan == null ;
75
75
var validationErrors = OptionsFileValidator (
@@ -90,85 +90,99 @@ List<AnalysisError> analyzeAnalysisOptions(
90
90
sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot);
91
91
return ;
92
92
}
93
- var includeSpan = includeNode.span;
94
- initialIncludeSpan ?? = includeSpan;
95
- String includeUri = includeSpan.text;
96
- var includedSource = sourceFactory.resolveUri (source, includeUri);
97
- if (includedSource == initialSource) {
98
- errors.add (
99
- AnalysisError .tmp (
100
- source: initialSource,
101
- offset: initialIncludeSpan! .start.offset,
102
- length: initialIncludeSpan! .length,
103
- errorCode: AnalysisOptionsWarningCode .RECURSIVE_INCLUDE_FILE ,
104
- arguments: [includeUri, source.fullName],
105
- ),
106
- );
107
- return ;
108
- }
109
- if (includedSource == null || ! includedSource.exists ()) {
110
- errors.add (
111
- AnalysisError .tmp (
112
- source: initialSource,
113
- offset: initialIncludeSpan! .start.offset,
114
- length: initialIncludeSpan! .length,
115
- errorCode: AnalysisOptionsWarningCode .INCLUDE_FILE_NOT_FOUND ,
116
- arguments: [includeUri, source.fullName, contextRoot],
117
- ),
118
- );
119
- return ;
120
- }
121
- var spanInChain = includeChain[includedSource];
122
- if (spanInChain != null ) {
123
- errors.add (
124
- AnalysisError .tmp (
125
- source: initialSource,
126
- offset: initialIncludeSpan! .start.offset,
127
- length: initialIncludeSpan! .length,
128
- errorCode: AnalysisOptionsWarningCode .INCLUDED_FILE_WARNING ,
129
- arguments: [
130
- includedSource,
131
- spanInChain.start.offset,
132
- spanInChain.length,
133
- 'The file includes itself recursively.' ,
134
- ],
135
- ),
136
- );
137
- return ;
93
+
94
+ void validateInclude (YamlNode includeNode) {
95
+ var includeSpan = includeNode.span;
96
+ initialIncludeSpan ?? = includeSpan;
97
+ var includeUri = includeSpan.text;
98
+
99
+ var includedSource = sourceFactory.resolveUri (source, includeUri);
100
+ if (includedSource == initialSource) {
101
+ errors.add (
102
+ AnalysisError .tmp (
103
+ source: initialSource,
104
+ offset: initialIncludeSpan! .start.offset,
105
+ length: initialIncludeSpan! .length,
106
+ errorCode: AnalysisOptionsWarningCode .RECURSIVE_INCLUDE_FILE ,
107
+ arguments: [includeUri, source.fullName],
108
+ ),
109
+ );
110
+ return ;
111
+ }
112
+ if (includedSource == null || ! includedSource.exists ()) {
113
+ errors.add (
114
+ AnalysisError .tmp (
115
+ source: initialSource,
116
+ offset: initialIncludeSpan! .start.offset,
117
+ length: initialIncludeSpan! .length,
118
+ errorCode: AnalysisOptionsWarningCode .INCLUDE_FILE_NOT_FOUND ,
119
+ arguments: [includeUri, source.fullName, contextRoot],
120
+ ),
121
+ );
122
+ return ;
123
+ }
124
+ var spanInChain = includeChain[includedSource];
125
+ if (spanInChain != null ) {
126
+ errors.add (
127
+ AnalysisError .tmp (
128
+ source: initialSource,
129
+ offset: initialIncludeSpan! .start.offset,
130
+ length: initialIncludeSpan! .length,
131
+ errorCode: AnalysisOptionsWarningCode .INCLUDED_FILE_WARNING ,
132
+ arguments: [
133
+ includedSource,
134
+ spanInChain.start.offset,
135
+ spanInChain.length,
136
+ 'The file includes itself recursively.' ,
137
+ ],
138
+ ),
139
+ );
140
+ return ;
141
+ }
142
+ includeChain[includedSource] = includeSpan;
143
+
144
+ try {
145
+ var includedOptions =
146
+ optionsProvider.getOptionsFromString (includedSource.contents.data);
147
+ validate (includedSource, includedOptions, provider);
148
+ firstPluginName ?? = _firstPluginName (includedOptions);
149
+ // Validate the 'plugins' option in [options], taking into account any
150
+ // plugins enabled by [includedOptions].
151
+ addDirectErrorOrIncludedError (
152
+ _validatePluginsOption (source,
153
+ options: options, firstEnabledPluginName: firstPluginName),
154
+ source,
155
+ sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot,
156
+ );
157
+ } on OptionsFormatException catch (e) {
158
+ var args = [
159
+ includedSource.fullName,
160
+ e.span! .start.offset.toString (),
161
+ e.span! .end.offset.toString (),
162
+ e.message,
163
+ ];
164
+ // Report errors for included option files on the `include` directive
165
+ // located in the initial options file.
166
+ errors.add (
167
+ AnalysisError .tmp (
168
+ source: initialSource,
169
+ offset: initialIncludeSpan! .start.offset,
170
+ length: initialIncludeSpan! .length,
171
+ errorCode: AnalysisOptionsErrorCode .INCLUDED_FILE_PARSE_ERROR ,
172
+ arguments: args,
173
+ ),
174
+ );
175
+ }
138
176
}
139
- includeChain[includedSource] = includeSpan;
140
-
141
- try {
142
- var includedOptions =
143
- optionsProvider.getOptionsFromString (includedSource.contents.data);
144
- validate (includedSource, includedOptions, provider);
145
- firstPluginName ?? = _firstPluginName (includedOptions);
146
- // Validate the 'plugins' option in [options], taking into account any
147
- // plugins enabled by [includedOptions].
148
- addDirectErrorOrIncludedError (
149
- _validatePluginsOption (source,
150
- options: options, firstEnabledPluginName: firstPluginName),
151
- source,
152
- sourceIsOptionsForContextRoot: sourceIsOptionsForContextRoot,
153
- );
154
- } on OptionsFormatException catch (e) {
155
- var args = [
156
- includedSource.fullName,
157
- e.span! .start.offset.toString (),
158
- e.span! .end.offset.toString (),
159
- e.message,
160
- ];
161
- // Report errors for included option files on the `include` directive
162
- // located in the initial options file.
163
- errors.add (
164
- AnalysisError .tmp (
165
- source: initialSource,
166
- offset: initialIncludeSpan! .start.offset,
167
- length: initialIncludeSpan! .length,
168
- errorCode: AnalysisOptionsErrorCode .INCLUDED_FILE_PARSE_ERROR ,
169
- arguments: args,
170
- ),
171
- );
177
+
178
+ if (includeNode is YamlScalar ) {
179
+ validateInclude (includeNode);
180
+ } else if (includeNode is YamlList ) {
181
+ for (var includeValue in includeNode.nodes) {
182
+ if (includeValue is YamlScalar ) {
183
+ validateInclude (includeValue);
184
+ }
185
+ }
172
186
}
173
187
}
174
188
0 commit comments