Skip to content

Commit 07bb38c

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
analyzer: Report INVALID_SECTION_FORMAT in 4 more places
* Invalid section (not a Map) under `analyzer: errors:` * Invalid value (not a Scalar) under `analyzer: errors:` * Invalid section (not a Map) under `analyzer: strong-mode:` * Invalid section (not a Map) under `analyzer: optional-checks:` Change-Id: Iad0b33d312f65af8a995677fe4e57389fea520c9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192600 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 706758a commit 07bb38c

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

pkg/analyzer/lib/src/task/options.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ class ErrorFilterOptionValidator extends OptionsValidator {
323323
if (analyzer is YamlMap) {
324324
var filters = analyzer.valueAt(AnalyzerOptions.errors);
325325
if (filters is YamlMap) {
326-
String? value;
327326
filters.nodes.forEach((k, v) {
327+
String? value;
328328
if (k is YamlScalar) {
329329
value = toUpperCase(k.value);
330330
if (!errorCodes.contains(value) && !lintCodes.contains(value)) {
@@ -347,8 +347,18 @@ class ErrorFilterOptionValidator extends OptionsValidator {
347347
legalValueString
348348
]);
349349
}
350+
} else {
351+
reporter.reportErrorForSpan(
352+
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT,
353+
v.span,
354+
[AnalyzerOptions.enableExperiment]);
350355
}
351356
});
357+
} else if (filters != null) {
358+
reporter.reportErrorForSpan(
359+
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT,
360+
filters.span,
361+
[AnalyzerOptions.enableExperiment]);
352362
}
353363
}
354364
}
@@ -450,6 +460,11 @@ class OptionalChecksValueValidator extends OptionsValidator {
450460
}
451461
}
452462
});
463+
} else if (v != null) {
464+
reporter.reportErrorForSpan(
465+
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT,
466+
v.span,
467+
[AnalyzerOptions.enableExperiment]);
453468
}
454469
}
455470
}
@@ -533,6 +548,11 @@ class StrongModeOptionValueValidator extends OptionsValidator {
533548
}
534549
}
535550
});
551+
} else if (v != null) {
552+
reporter.reportErrorForSpan(
553+
AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT,
554+
v.span,
555+
[AnalyzerOptions.enableExperiment]);
536556
}
537557
}
538558
}

pkg/analyzer/test/src/task/options_test.dart

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,24 @@ analyzer:
261261
''', [AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE]);
262262
}
263263

264+
test_analyzer_errors_notAMap() {
265+
validate('''
266+
analyzer:
267+
errors:
268+
- invalid_annotation
269+
- unused_import
270+
''', [AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT]);
271+
}
272+
273+
test_analyzer_errors_valueNotAScalar() {
274+
validate('''
275+
analyzer:
276+
errors:
277+
invalid_annotation: ignore
278+
unused_import: [1, 2, 3]
279+
''', [AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT]);
280+
}
281+
264282
test_analyzer_language_bad_format_list() {
265283
validate('''
266284
analyzer:
@@ -297,14 +315,14 @@ analyzer:
297315
analyzer:
298316
errors:
299317
fantastic_test_rule: ignore
300-
''', []);
318+
''', []);
301319
}
302320

303321
test_analyzer_strong_mode_deprecated() {
304322
validate('''
305323
analyzer:
306324
strong-mode: true
307-
''', [AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED]);
325+
''', [AnalysisOptionsHintCode.STRONG_MODE_SETTING_DEPRECATED]);
308326
}
309327

310328
test_analyzer_strong_mode_deprecated_key() {
@@ -327,7 +345,15 @@ analyzer:
327345
validate('''
328346
analyzer:
329347
strong-mode: false
330-
''', [AnalysisOptionsWarningCode.SPEC_MODE_REMOVED]);
348+
''', [AnalysisOptionsWarningCode.SPEC_MODE_REMOVED]);
349+
}
350+
351+
test_analyzer_strong_mode_notAMap() {
352+
validate('''
353+
analyzer:
354+
strong-mode:
355+
- implicit_casts
356+
''', [AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT]);
331357
}
332358

333359
test_analyzer_strong_mode_unsupported_key() {
@@ -351,21 +377,21 @@ analyzer:
351377
analyzer:
352378
exclude:
353379
- test/_data/p4/lib/lib1.dart
354-
''', []);
380+
''', []);
355381
}
356382

357383
test_analyzer_supported_strong_mode_supported_bad_value() {
358384
validate('''
359385
analyzer:
360386
strong-mode: w00t
361-
''', [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]);
387+
''', [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]);
362388
}
363389

364390
test_analyzer_unsupported_option() {
365391
validate('''
366392
analyzer:
367393
not_supported: true
368-
''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]);
394+
''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]);
369395
}
370396

371397
test_chromeos_manifest_checks() {
@@ -384,6 +410,14 @@ analyzer:
384410
''', [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]);
385411
}
386412

413+
test_chromeos_manifest_checks_notAMap() {
414+
validate('''
415+
analyzer:
416+
optional-checks:
417+
- chrome-os-manifest-checks
418+
''', [AnalysisOptionsWarningCode.INVALID_SECTION_FORMAT]);
419+
}
420+
387421
test_linter_supported_rules() {
388422
Registry.ruleRegistry.register(TestRule());
389423
validate('''

0 commit comments

Comments
 (0)