Skip to content

Commit d9be807

Browse files
authored
Updated the analyze.dart deprecation check to only look for beta branch versions. (#105290)
1 parent 81df638 commit d9be807

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

dev/bots/analyze.dart

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ Future<void> verifyNoSyncAsyncStar(String workingDirectory, {int minimumMatches
368368

369369
final RegExp _findGoldenTestPattern = RegExp(r'matchesGoldenFile\(');
370370
final RegExp _findGoldenDefinitionPattern = RegExp(r'matchesGoldenFile\(Object');
371-
final RegExp _leadingComment = RegExp(r'\/\/');
371+
final RegExp _leadingComment = RegExp(r'//');
372372
final RegExp _goldenTagPattern1 = RegExp(r'@Tags\(');
373373
final RegExp _goldenTagPattern2 = RegExp(r"'reduced-test-set'");
374374

@@ -433,10 +433,10 @@ Future<void> verifyGoldenTags(String workingDirectory, { int minimumMatches = 20
433433
}
434434

435435
final RegExp _findDeprecationPattern = RegExp(r'@[Dd]eprecated');
436-
final RegExp _deprecationPattern1 = RegExp(r'^( *)@Deprecated\($'); // flutter_ignore: deprecation_syntax (see analyze.dart)
437-
final RegExp _deprecationPattern2 = RegExp(r"^ *'(.+) '$");
438-
final RegExp _deprecationPattern3 = RegExp(r"^ *'This feature was deprecated after v([0-9]+)\.([0-9]+)\.([0-9]+)(\-[0-9]+\.[0-9]+\.pre)?\.',?$");
439-
final RegExp _deprecationPattern4 = RegExp(r'^ *\)$');
436+
final RegExp _deprecationStartPattern = RegExp(r'^(?<indent> *)@Deprecated\($'); // flutter_ignore: deprecation_syntax (see analyze.dart)
437+
final RegExp _deprecationMessagePattern = RegExp(r"^ *'(?<message>.+) '$");
438+
final RegExp _deprecationVersionPattern = RegExp(r"^ *'This feature was deprecated after v(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?<build>-\d+\.\d+\.pre)?\.',?$");
439+
final RegExp _deprecationEndPattern = RegExp(r'^ *\)$');
440440

441441
/// Some deprecation notices are special, for example they're used to annotate members that
442442
/// will never go away and were never allowed but which we are trying to show messages for.
@@ -446,7 +446,7 @@ final RegExp _deprecationPattern4 = RegExp(r'^ *\)$');
446446
const String _ignoreDeprecation = ' // flutter_ignore: deprecation_syntax (see analyze.dart)';
447447

448448
/// Some deprecation notices are exempt for historical reasons. They must have an issue listed.
449-
final RegExp _legacyDeprecation = RegExp(r' // flutter_ignore: deprecation_syntax, https://github.com/flutter/flutter/issues/[0-9]+$');
449+
final RegExp _legacyDeprecation = RegExp(r' // flutter_ignore: deprecation_syntax, https://github.com/flutter/flutter/issues/\d+$');
450450

451451
Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches = 2000 }) async {
452452
final List<String> errors = <String>[];
@@ -464,18 +464,18 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
464464
}
465465
for (int lineNumber in linesWithDeprecations) {
466466
try {
467-
final Match? match1 = _deprecationPattern1.firstMatch(lines[lineNumber]);
468-
if (match1 == null)
467+
final RegExpMatch? startMatch = _deprecationStartPattern.firstMatch(lines[lineNumber]);
468+
if (startMatch == null)
469469
throw 'Deprecation notice does not match required pattern.';
470-
final String indent = match1[1]!;
470+
final String indent = startMatch.namedGroup('indent')!;
471471
lineNumber += 1;
472472
if (lineNumber >= lines.length)
473473
throw 'Incomplete deprecation notice.';
474-
Match? match3;
474+
RegExpMatch? versionMatch;
475475
String? message;
476476
do {
477-
final Match? match2 = _deprecationPattern2.firstMatch(lines[lineNumber]);
478-
if (match2 == null) {
477+
final RegExpMatch? messageMatch = _deprecationMessagePattern.firstMatch(lines[lineNumber]);
478+
if (messageMatch == null) {
479479
String possibleReason = '';
480480
if (lines[lineNumber].trimLeft().startsWith('"')) {
481481
possibleReason = ' You might have used double quotes (") for the string instead of single quotes (\').';
@@ -485,31 +485,34 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
485485
if (!lines[lineNumber].startsWith("$indent '"))
486486
throw 'Unexpected deprecation notice indent.';
487487
if (message == null) {
488-
final String firstChar = String.fromCharCode(match2[1]!.runes.first);
488+
message = messageMatch.namedGroup('message');
489+
final String firstChar = String.fromCharCode(message!.runes.first);
489490
if (firstChar.toUpperCase() != firstChar)
490491
throw 'Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo';
491492
}
492-
message = match2[1];
493493
lineNumber += 1;
494494
if (lineNumber >= lines.length)
495495
throw 'Incomplete deprecation notice.';
496-
match3 = _deprecationPattern3.firstMatch(lines[lineNumber]);
497-
} while (match3 == null);
498-
final int v1 = int.parse(match3[1]!);
499-
final int v2 = int.parse(match3[2]!);
500-
final bool hasV4 = match3[4] != null;
501-
if (v1 > 1 || (v1 == 1 && v2 >= 20)) {
502-
if (!hasV4)
503-
throw 'Deprecation notice does not accurately indicate a dev branch version number; please see https://flutter.dev/docs/development/tools/sdk/releases to find the latest dev build version number.';
496+
versionMatch = _deprecationVersionPattern.firstMatch(lines[lineNumber]);
497+
} while (versionMatch == null);
498+
final int major = int.parse(versionMatch.namedGroup('major')!);
499+
final int minor = int.parse(versionMatch.namedGroup('minor')!);
500+
final int patch = int.parse(versionMatch.namedGroup('patch')!);
501+
final bool hasBuild = versionMatch.namedGroup('build') != null;
502+
// There was a beta release that was mistakenly labeled 3.1.0 without a build.
503+
final bool specialBeta = major == 3 && minor == 1 && patch == 0;
504+
if (!specialBeta && (major > 1 || (major == 1 && minor >= 20))) {
505+
if (!hasBuild)
506+
throw 'Deprecation notice does not accurately indicate a beta branch version number; please see https://flutter.dev/docs/development/tools/sdk/releases to find the latest beta build version number.';
504507
}
505-
if (!message!.endsWith('.') && !message.endsWith('!') && !message.endsWith('?'))
508+
if (!message.endsWith('.') && !message.endsWith('!') && !message.endsWith('?'))
506509
throw 'Deprecation notice should be a grammatically correct sentence and end with a period.';
507510
if (!lines[lineNumber].startsWith("$indent '"))
508511
throw 'Unexpected deprecation notice indent.';
509512
lineNumber += 1;
510513
if (lineNumber >= lines.length)
511514
throw 'Incomplete deprecation notice.';
512-
if (!lines[lineNumber].contains(_deprecationPattern4))
515+
if (!lines[lineNumber].contains(_deprecationEndPattern))
513516
throw 'End of deprecation notice does not match required pattern.';
514517
if (!lines[lineNumber].startsWith('$indent)'))
515518
throw 'Unexpected deprecation notice indent.';
@@ -637,7 +640,7 @@ class _TestSkipLinesVisitor<T> extends RecursiveAstVisitor<T> {
637640

638641
final RegExp _skipTestCommentPattern = RegExp(r'//(.*)$');
639642
const Pattern _skipTestIntentionalPattern = '[intended]';
640-
final Pattern _skipTestTrackingBugPattern = RegExp(r'https+?://github.com/.*/issues/[0-9]+');
643+
final Pattern _skipTestTrackingBugPattern = RegExp(r'https+?://github.com/.*/issues/\d+');
641644

642645
Future<void> verifySkipTestComments(String workingDirectory) async {
643646
final List<String> errors = <String>[];
@@ -1721,7 +1724,7 @@ Future<void> _checkConsumerDependencies() async {
17211724
}
17221725

17231726
const String _kDebugOnlyAnnotation = '@_debugOnly';
1724-
final RegExp _nullInitializedField = RegExp(r'kDebugMode \? [\w\<\> ,{}()]+ : null;');
1727+
final RegExp _nullInitializedField = RegExp(r'kDebugMode \? [\w<> ,{}()]+ : null;');
17251728

17261729
Future<void> verifyNullInitializedDebugExpensiveFields(String workingDirectory, {int minimumMatches = 400}) async {
17271730
final String flutterLib = path.join(workingDirectory, 'packages', 'flutter', 'lib');

dev/bots/test/analyze-test-input/root/packages/foo/deprecation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void test13() { }
7878
void test14() { }
7979

8080
@Deprecated(
81-
'Version number test (should fail). '
81+
'Version number test (special beta should pass). '
8282
'This feature was deprecated after v3.1.0.'
8383
)
8484
void test15() { }

dev/bots/test/analyze_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ void main() {
5353
'test/analyze-test-input/root/packages/foo/deprecation.dart:41: Deprecation notice does not match required pattern.',
5454
'test/analyze-test-input/root/packages/foo/deprecation.dart:48: End of deprecation notice does not match required pattern.',
5555
'test/analyze-test-input/root/packages/foo/deprecation.dart:51: Unexpected deprecation notice indent.',
56-
'test/analyze-test-input/root/packages/foo/deprecation.dart:70: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.',
57-
'test/analyze-test-input/root/packages/foo/deprecation.dart:76: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.',
58-
'test/analyze-test-input/root/packages/foo/deprecation.dart:82: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.',
56+
'test/analyze-test-input/root/packages/foo/deprecation.dart:70: Deprecation notice does not accurately indicate a beta branch version number; please see RELEASES_URL to find the latest beta build version number.',
57+
'test/analyze-test-input/root/packages/foo/deprecation.dart:76: Deprecation notice does not accurately indicate a beta branch version number; please see RELEASES_URL to find the latest beta build version number.',
5958
'test/analyze-test-input/root/packages/foo/deprecation.dart:99: Deprecation notice does not match required pattern. You might have used double quotes (") for the string instead of single quotes (\').',
6059
]
6160
.map((String line) {

0 commit comments

Comments
 (0)