[analysis_server] Don't produce diagnostics for empty/commented fix_data files

Previous changes to analyze the fix_data/**.yaml files failed to roll into Flutter because it has a template for these files that contains only comments.

See https://dart-review.googlesource.com/c/sdk/+/297320 and https://github.com/flutter/flutter/pull/125363.

Change-Id: I098a5b336371bab7f80ac84c556efe118c70e74f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297340
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2023-04-24 18:47:21 +00:00 committed by Commit Queue
parent 073def1334
commit d3460e0855
2 changed files with 25 additions and 3 deletions

View file

@ -154,12 +154,12 @@ class TransformSetParser {
/// Return the result of parsing the file [content] into a transform set, or
/// `null` if the content does not represent a valid transform set.
TransformSet? parse(String content) {
var map = _parseYaml(content);
if (map == null) {
var node = _parseYaml(content);
if (node == null) {
// The error has already been reported.
return null;
}
return _translateTransformSet(map);
return _translateTransformSet(node);
}
/// Convert the given [template] into a list of components. Variable
@ -1039,6 +1039,10 @@ class TransformSetParser {
set.addTransform(transform);
}
return set;
} else if (node is YamlScalar && node.value == null) {
// The file has no contents (or is only comments) and should not produce
// any diagnostics.
return null;
} else {
// TODO(brianwilkerson) Consider having a different error code for the
// top-level node (instead of using 'file' as the "key").

View file

@ -1160,6 +1160,24 @@ analyzer:
assertHasErrors(path);
}
Future<void> test_setRoots_notDartFile_fixDataYaml_empty() async {
var path = '$testPackageLibPath/fix_data.yaml';
newFile(path, '');
await setRoots(included: [workspaceRootPath], excluded: []);
assertNoErrors(path);
}
Future<void> test_setRoots_notDartFile_fixDataYaml_onlyComments() async {
var path = '$testPackageLibPath/fix_data.yaml';
newFile(path, '# one\n#two');
await setRoots(included: [workspaceRootPath], excluded: []);
assertNoErrors(path);
}
Future<void> test_setRoots_notDartFile_pubspec_excluded() async {
deleteTestPackageAnalysisOptionsFile();
var a_path = '$testPackageLibPath/a.dart';