[tools] verify_docs don't error on library annotations

Dartdoc code snippets should be able to have annotations before the
`library` keyword.

Bug: https://github.com/dart-lang/sdk/issues/49803#issuecomment-1287044157

Change-Id: I7ec0b6db296274a1173d10d900f7af38a1f2b552
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265321
Reviewed-by: Devon Carew <devoncarew@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
This commit is contained in:
Daco Harkes 2022-10-24 18:01:55 +00:00 committed by Commit Queue
parent 9319d07e11
commit 97eaded1ed

View file

@ -18,6 +18,7 @@ import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/overlay_file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/error/syntactic_errors.g.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/util/comment.dart';
import 'package:path/path.dart' as path;
@ -353,6 +354,10 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
return false;
});
// Don't error on annotations above library.
errors.removeWhere(
(e) => e.errorCode == ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST);
if (errors.isNotEmpty) {
print('$filePath:${sample.lineStartOffset}: ${errors.length} errors');