Unverified Commit bf602914 authored by Dan Field's avatar Dan Field Committed by GitHub

Improve sync*/async* opt outs (#95286)

parent aa599358
...@@ -163,8 +163,8 @@ Future<void> run(List<String> arguments) async { ...@@ -163,8 +163,8 @@ Future<void> run(List<String> arguments) async {
Future<void> verifyNoSyncAsyncStar(String workingDirectory, {int minimumMatches = 2000 }) async { Future<void> verifyNoSyncAsyncStar(String workingDirectory, {int minimumMatches = 2000 }) async {
final RegExp syncPattern = RegExp(r'\s*?a?sync\*\s*?{'); final RegExp syncPattern = RegExp(r'\s*?a?sync\*\s*?{');
const String ignorePattern = 'no_sync_async_star'; final RegExp ignorePattern = RegExp(r'^\s*?// The following uses a?sync\* because:? ');
final RegExp commentPattern = RegExp(r'^\s*?///?'); final RegExp commentPattern = RegExp(r'^\s*?//');
final List<String> errors = <String>[]; final List<String> errors = <String>[];
await for (final File file in _allFiles(workingDirectory, 'dart', minimumMatches: minimumMatches)) { await for (final File file in _allFiles(workingDirectory, 'dart', minimumMatches: minimumMatches)) {
if (file.path.contains('test')) { if (file.path.contains('test')) {
...@@ -176,8 +176,19 @@ Future<void> verifyNoSyncAsyncStar(String workingDirectory, {int minimumMatches ...@@ -176,8 +176,19 @@ Future<void> verifyNoSyncAsyncStar(String workingDirectory, {int minimumMatches
if (line.startsWith(commentPattern)) { if (line.startsWith(commentPattern)) {
continue; continue;
} }
if (line.contains(syncPattern) && !line.contains(ignorePattern) && (index == 0 || !lines[index - 1].contains(ignorePattern))) { if (line.contains(syncPattern)) {
errors.add('${file.path}:$index: sync*/async* without an ignore (no_sync_async_star).'); int lookBehindIndex = index - 1;
bool hasExplanation = false;
while (lookBehindIndex >= 0 && lines[lookBehindIndex].startsWith(commentPattern)) {
if (lines[lookBehindIndex].startsWith(ignorePattern)) {
hasExplanation = true;
break;
}
lookBehindIndex -= 1;
}
if (!hasExplanation) {
errors.add('${file.path}:$index: sync*/async* without an explanation.');
}
} }
} }
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// Flutter code sample for StreamBuilder // Flutter code sample for StreamBuilder
import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() => runApp(const MyApp()); void main() => runApp(const MyApp());
...@@ -30,11 +32,17 @@ class MyStatefulWidget extends StatefulWidget { ...@@ -30,11 +32,17 @@ class MyStatefulWidget extends StatefulWidget {
} }
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _MyStatefulWidgetState extends State<MyStatefulWidget> {
// ignore: no_sync_async_star final Stream<int> _bids = (() {
final Stream<int> _bids = (() async* { late final StreamController<int> controller;
await Future<void>.delayed(const Duration(seconds: 1)); controller = StreamController<int>(
yield 1; onListen: () async {
await Future<void>.delayed(const Duration(seconds: 1)); await Future<void>.delayed(const Duration(seconds: 1));
controller.add(1);
await Future<void>.delayed(const Duration(seconds: 1));
await controller.close();
},
);
return controller.stream;
})(); })();
@override @override
......
...@@ -795,7 +795,8 @@ class RenderTable extends RenderBox { ...@@ -795,7 +795,8 @@ class RenderTable extends RenderBox {
/// column, in row order, starting from the first row. /// column, in row order, starting from the first row.
/// ///
/// This is a lazily-evaluated iterable. /// This is a lazily-evaluated iterable.
// flutter_ignore: no_sync_async_star // The following uses sync* because it is public API documented to return a
// lazy iterable.
Iterable<RenderBox> column(int x) sync* { Iterable<RenderBox> column(int x) sync* {
for (int y = 0; y < rows; y += 1) { for (int y = 0; y < rows; y += 1) {
final int xy = x + y * columns; final int xy = x + y * columns;
...@@ -809,7 +810,8 @@ class RenderTable extends RenderBox { ...@@ -809,7 +810,8 @@ class RenderTable extends RenderBox {
/// row, in column order, starting with the first column. /// row, in column order, starting with the first column.
/// ///
/// This is a lazily-evaluated iterable. /// This is a lazily-evaluated iterable.
// flutter_ignore: no_sync_async_star // The following uses sync* because it is public API documented to return a
// lazy iterable.
Iterable<RenderBox> row(int y) sync* { Iterable<RenderBox> row(int y) sync* {
final int start = y * columns; final int start = y * columns;
final int end = (y + 1) * columns; final int end = (y + 1) * columns;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment