diff --git a/analysis_options.yaml b/analysis_options.yaml index 7b00ff6132..1390906a4e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -80,7 +80,7 @@ linter: # - avoid_catches_without_on_clauses # not yet tested # - avoid_catching_errors # not yet tested # - avoid_classes_with_only_static_members # not yet tested - # - avoid_function_literals_in_foreach_calls # not yet tested + - avoid_function_literals_in_foreach_calls - avoid_init_to_null - avoid_null_checks_in_equality_operators # - avoid_positional_boolean_parameters # not yet tested diff --git a/analysis_options_repo.yaml b/analysis_options_repo.yaml index bfeef2cd86..31ba513305 100644 --- a/analysis_options_repo.yaml +++ b/analysis_options_repo.yaml @@ -74,7 +74,7 @@ linter: # - avoid_catches_without_on_clauses # not yet tested # - avoid_catching_errors # not yet tested # - avoid_classes_with_only_static_members # not yet tested - # - avoid_function_literals_in_foreach_calls # not yet tested + - avoid_function_literals_in_foreach_calls - avoid_init_to_null - avoid_null_checks_in_equality_operators # - avoid_positional_boolean_parameters # not yet tested diff --git a/dev/devicelab/lib/tasks/save_catalog_screenshots.dart b/dev/devicelab/lib/tasks/save_catalog_screenshots.dart index bee740a5c1..4c9a062c3f 100644 --- a/dev/devicelab/lib/tasks/save_catalog_screenshots.dart +++ b/dev/devicelab/lib/tasks/save_catalog_screenshots.dart @@ -120,12 +120,12 @@ Future saveCatalogScreenshots({ String prefix, // Prefix for all file names. }) async { final List screenshots = []; - directory.listSync().forEach((FileSystemEntity entity) { + for (FileSystemEntity entity in directory.listSync()) { if (entity is File && entity.path.endsWith('.png')) { final File file = entity; screenshots.add(file.path); } - }); + } final List largeNames = []; // Cloud storage names for the full res screenshots. final List smallNames = []; // Likewise for the scaled down screenshots. diff --git a/examples/catalog/bin/sample_page.dart b/examples/catalog/bin/sample_page.dart index 5096376e8a..6efa4c4732 100644 --- a/examples/catalog/bin/sample_page.dart +++ b/examples/catalog/bin/sample_page.dart @@ -146,13 +146,13 @@ void generate(String commit) { initialize(); final List samples = []; - sampleDirectory.listSync().forEach((FileSystemEntity entity) { + for (FileSystemEntity entity in sampleDirectory.listSync()) { if (entity is File && entity.path.endsWith('.dart')) { final SampleInfo sample = new SampleInfo(entity, commit); if (sample.initialize()) // skip files that lack the Sample Catalog comment samples.add(sample); } - }); + } // Causes the generated imports to appear in alphabetical order. // Avoid complaints from flutter lint. diff --git a/packages/flutter/test/widgets/routes_test.dart b/packages/flutter/test/widgets/routes_test.dart index 70dbf73046..c93a831a85 100644 --- a/packages/flutter/test/widgets/routes_test.dart +++ b/packages/flutter/test/widgets/routes_test.dart @@ -74,7 +74,8 @@ class TestRoute extends LocalHistoryRoute { @override void dispose() { log('dispose'); - _entries.forEach((OverlayEntry entry) { entry.remove(); }); + for (OverlayEntry entry in _entries) + entry.remove(); _entries.clear(); routes.remove(this); super.dispose(); diff --git a/packages/flutter_localizations/test/date_picker_test.dart b/packages/flutter_localizations/test/date_picker_test.dart index 123ffaf928..88f8ddff8d 100644 --- a/packages/flutter_localizations/test/date_picker_test.dart +++ b/packages/flutter_localizations/test/date_picker_test.dart @@ -64,12 +64,12 @@ void main() { expect(find.text(expectedMonthYearHeader), findsOneWidget); - expectedDaysOfWeek.forEach((String dayOfWeek) { + for (String dayOfWeek in expectedDaysOfWeek) { expect(find.text(dayOfWeek), findsWidgets); - }); + } Offset previousCellOffset; - expectedDaysOfMonth.forEach((String dayOfMonth) { + for (String dayOfMonth in expectedDaysOfMonth) { final Finder dayCell = find.descendant(of: find.byType(GridView), matching: find.text(dayOfMonth)); expect(dayCell, findsOneWidget); @@ -84,7 +84,7 @@ void main() { } } previousCellOffset = offset; - }); + } }); } }); diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index 6a867c6a6c..9efadfe293 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -100,7 +100,7 @@ Future _readGradleProject() async { if (flutterPluginVersion == FlutterPluginVersion.managed) { // Handle known exceptions. This will exit if handled. handleKnownGradleExceptions(e); - + // Print a general Gradle error and exit. printError('* Error running Gradle:\n$e\n'); throwToolExit('Please review your Gradle project setup in the android/ folder.'); @@ -355,14 +355,14 @@ class GradleProject { // Extract build types and product flavors. final Set variants = new Set(); - properties.split('\n').forEach((String s) { + for (String s in properties.split('\n')) { final Match match = _assembleTaskPattern.matchAsPrefix(s); if (match != null) { final String variant = match.group(1).toLowerCase(); if (!variant.endsWith('test')) variants.add(variant); } - }); + } final Set buildTypes = new Set(); final Set productFlavors = new Set(); for (final String variant1 in variants) { diff --git a/packages/flutter_tools/lib/src/base/file_system.dart b/packages/flutter_tools/lib/src/base/file_system.dart index 6baeecf37f..556c8feaa4 100644 --- a/packages/flutter_tools/lib/src/base/file_system.dart +++ b/packages/flutter_tools/lib/src/base/file_system.dart @@ -82,7 +82,7 @@ void copyDirectorySync(Directory srcDir, Directory destDir, [void onFileCopied(F if (!destDir.existsSync()) destDir.createSync(recursive: true); - srcDir.listSync().forEach((FileSystemEntity entity) { + for (FileSystemEntity entity in srcDir.listSync()) { final String newPath = destDir.fileSystem.path.join(destDir.path, entity.basename); if (entity is File) { final File newFile = destDir.fileSystem.file(newPath); @@ -94,7 +94,7 @@ void copyDirectorySync(Directory srcDir, Directory destDir, [void onFileCopied(F } else { throw new Exception('${entity.path} is neither File nor Directory'); } - }); + } } /// Gets a directory to act as a recording destination, creating the directory diff --git a/packages/flutter_tools/lib/src/commands/analyze_base.dart b/packages/flutter_tools/lib/src/commands/analyze_base.dart index daebe970ad..1661242290 100644 --- a/packages/flutter_tools/lib/src/commands/analyze_base.dart +++ b/packages/flutter_tools/lib/src/commands/analyze_base.dart @@ -132,22 +132,22 @@ class PackageDependencyTracker { final File dotPackages = fs.file(dotPackagesPath); if (dotPackages.existsSync()) { // this directory has opinions about what we should be using - dotPackages + final Iterable lines = dotPackages .readAsStringSync() .split('\n') - .where((String line) => !line.startsWith(new RegExp(r'^ *#'))) - .forEach((String line) { - final int colon = line.indexOf(':'); - if (colon > 0) { - final String packageName = line.substring(0, colon); - final String packagePath = fs.path.fromUri(line.substring(colon+1)); - // Ensure that we only add `analyzer` and dependent packages defined in the vended SDK (and referred to with a local - // fs.path. directive). Analyzer package versions reached via transitive dependencies (e.g., via `test`) are ignored - // since they would produce spurious conflicts. - if (!_vendedSdkPackages.contains(packageName) || packagePath.startsWith('..')) - add(packageName, fs.path.normalize(fs.path.absolute(directory.path, packagePath)), dotPackagesPath); - } - }); + .where((String line) => !line.startsWith(new RegExp(r'^ *#'))); + for (String line in lines) { + final int colon = line.indexOf(':'); + if (colon > 0) { + final String packageName = line.substring(0, colon); + final String packagePath = fs.path.fromUri(line.substring(colon+1)); + // Ensure that we only add `analyzer` and dependent packages defined in the vended SDK (and referred to with a local + // fs.path. directive). Analyzer package versions reached via transitive dependencies (e.g., via `test`) are ignored + // since they would produce spurious conflicts. + if (!_vendedSdkPackages.contains(packageName) || packagePath.startsWith('..')) + add(packageName, fs.path.normalize(fs.path.absolute(directory.path, packagePath)), dotPackagesPath); + } + } } } diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 605876df17..0af8a08863 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -143,7 +143,8 @@ class Daemon { void shutdown({dynamic error}) { _commandSubscription?.cancel(); - _domainMap.values.forEach((Domain domain) => domain.dispose()); + for (Domain domain in _domainMap.values) + domain.dispose(); if (!_onExitCompleter.isCompleted) { if (error == null) _onExitCompleter.complete(0); diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index 40db37da9a..1ac521d3d5 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -636,7 +636,8 @@ class VM extends ServiceObjectOwner { void _removeDeadIsolates(List newIsolates) { // Build a set of new isolates. final Set newIsolateSet = new Set(); - newIsolates.forEach((Isolate iso) => newIsolateSet.add(iso.id)); + for (Isolate iso in newIsolates) + newIsolateSet.add(iso.id); // Remove any old isolates which no longer exist. final List toRemove = []; diff --git a/packages/flutter_tools/test/forbidden_imports_test.dart b/packages/flutter_tools/test/forbidden_imports_test.dart index 8383201005..05a2f49bf0 100644 --- a/packages/flutter_tools/test/forbidden_imports_test.dart +++ b/packages/flutter_tools/test/forbidden_imports_test.dart @@ -15,39 +15,37 @@ void main() { bool _isNotWhitelisted(FileSystemEntity entity) => entity.path != whitelistedPath; for (String dirName in ['lib', 'bin']) { - fs.directory(fs.path.join(flutterTools, dirName)) + final Iterable files = fs.directory(fs.path.join(flutterTools, dirName)) .listSync(recursive: true) .where(_isDartFile) .where(_isNotWhitelisted) - .map(_asFile) - .forEach((File file) { - for (String line in file.readAsLinesSync()) { - if (line.startsWith(new RegExp(r'import.*dart:io')) && - !line.contains('ignore: dart_io_import')) { - final String relativePath = fs.path.relative(file.path, from:flutterTools); - fail("$relativePath imports 'dart:io'; import 'lib/src/base/io.dart' instead"); - } + .map(_asFile); + for (File file in files) { + for (String line in file.readAsLinesSync()) { + if (line.startsWith(new RegExp(r'import.*dart:io')) && + !line.contains('ignore: dart_io_import')) { + final String relativePath = fs.path.relative(file.path, from:flutterTools); + fail("$relativePath imports 'dart:io'; import 'lib/src/base/io.dart' instead"); } } - ); + } } }); test('no unauthorized imports of package:path', () { for (String dirName in ['lib', 'bin', 'test']) { - fs.directory(fs.path.join(flutterTools, dirName)) + final Iterable files = fs.directory(fs.path.join(flutterTools, dirName)) .listSync(recursive: true) .where(_isDartFile) - .map(_asFile) - .forEach((File file) { - for (String line in file.readAsLinesSync()) { - if (line.startsWith(new RegExp(r'import.*package:path/path.dart'))) { - final String relativePath = fs.path.relative(file.path, from:flutterTools); - fail("$relativePath imports 'package:path/path.dart'; use 'fs.path' instead"); - } + .map(_asFile); + for (File file in files) { + for (String line in file.readAsLinesSync()) { + if (line.startsWith(new RegExp(r'import.*package:path/path.dart'))) { + final String relativePath = fs.path.relative(file.path, from:flutterTools); + fail("$relativePath imports 'package:path/path.dart'; use 'fs.path' instead"); } } - ); + } } }); }