Make expression-detection in doc verifier more discriminating.

The existing behavior treated `var x = e; // comment` as an expression,
and failed spectacularly to insert it after a `return`.
The new behavior detects a `;` anywhere in the single line, not just
at the end, as a sign that a single line is probably not an expression.

Change-Id: Ice5abc8dc802db36511dc3cdcca162dc0e8a8f13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229155
Auto-Submit: Lasse Nielsen <lrn@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
This commit is contained in:
Lasse R.H. Nielsen 2022-01-24 11:12:18 +00:00 committed by Commit Bot
parent 5106605af6
commit 225b8d3f58

View file

@ -270,8 +270,8 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
template = 'none';
} else if (hasTopDeclaration) {
template = 'top';
} else if (lines.length == 1 && !lines.first.trim().endsWith(';')) {
// If single line with no trailing `;`, assume expression.
} else if (lines.length == 1 && !lines.first.contains(';')) {
// If single line with no `;`, assume expression.
template = 'expression';
} else {
// Otherwise default to `main`.