diff --git a/.analysis_options b/.analysis_options index d4fc7fa2ed..7c1a0064ff 100644 --- a/.analysis_options +++ b/.analysis_options @@ -1,8 +1,4 @@ # Specify analysis options. -# -# Note that until there is a default "all-in" lint rule-set we need -# to opt-in to all desired lints (https://github.com/dart-lang/sdk/issues/25843). -# For a list of lints, see: http://dart-lang.github.io/linter/lints/ # This file is the .analysis_options file used by Flutter editors, such as # Atom. It is very similar to flutter_tools/flutter_analysis_options; the only @@ -23,33 +19,52 @@ analyzer: strong_mode_down_cast_composite: ignore # we allow having TODOs in the code todo: ignore + linter: rules: + # these are in the same order as http://dart-lang.github.io/linter/lints/ + # to make maintenance easier + + # error rules - avoid_empty_else + # - comment_references + - control_flow_in_finally + - hash_and_equals + # - iterable_contains_unrelated_type + - test_types_in_equals + - throw_in_finally + - unrelated_type_equality_checks + + # style rules - always_declare_return_types - always_specify_types - annotate_overrides - avoid_as - avoid_init_to_null - # - avoid_return_types_on_setters # https://github.com/dart-lang/linter/issues/202 + - avoid_return_types_on_setters + - await_only_futures - camel_case_types - # - constant_identifier_names # https://github.com/dart-lang/linter/issues/204 (and 203) + # - constant_identifier_names + - control_flow_in_finally - empty_constructor_bodies - - hash_and_equals - # - implementation_imports # https://github.com/dart-lang/linter/issues/203 + - implementation_imports - library_names - library_prefixes - non_constant_identifier_names - # - one_member_abstracts # https://github.com/dart-lang/linter/issues/203 + - one_member_abstracts + # - overriden_field - package_api_docs - - package_names - package_prefixed_library_names - prefer_is_not_empty + # - public_member_api_docs - slash_for_doc_comments - sort_constructors_first - sort_unnamed_constructors_first - super_goes_last - - type_annotate_public_apis # subset of always_specify_types + # - type_annotate_public_apis # subset of always_specify_types - type_init_formals - unnecessary_brace_in_string_interp - unnecessary_getters_setters + + # pub rules + - package_names diff --git a/packages/flutter/lib/src/foundation/assertions.dart b/packages/flutter/lib/src/foundation/assertions.dart index 7bb51dee76..79dc1a3d81 100644 --- a/packages/flutter/lib/src/foundation/assertions.dart +++ b/packages/flutter/lib/src/foundation/assertions.dart @@ -290,7 +290,7 @@ class FlutterError extends AssertionError { } result.add(line); } - if (skipped == 1) { + if (skipped.length == 1) { result.add('(elided one frame from ${skipped.single})'); } else if (skipped.length > 1) { List where = new Set.from(skipped).toList()..sort(); diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index f61d83603a..d18ec45e78 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -963,6 +963,11 @@ abstract class RenderBox extends RenderObject { int _debugActivePointers = 0; + /// Override this function to handle pointer events that hit this render object. + /// + /// For [RenderBox] objects, the `entry` argument is a [BoxHitTestEntry]. From this + /// object you can determine the [PointerDownEvent]'s position in local coordinates. + /// (This is useful because [PointerEvent.position] is in global coordinates.) @override void handleEvent(PointerEvent event, HitTestEntry entry) { super.handleEvent(event, entry); diff --git a/packages/flutter/lib/src/widgets/focus.dart b/packages/flutter/lib/src/widgets/focus.dart index 79f31304a0..3a1abd9438 100644 --- a/packages/flutter/lib/src/widgets/focus.dart +++ b/packages/flutter/lib/src/widgets/focus.dart @@ -130,8 +130,13 @@ class Focus extends StatefulWidget { if (debugOnlyFocusedKey?.currentContext == null) debugOnlyFocusedKey = context.widget.key; if (debugOnlyFocusedKey != context.widget.key) { - debugPrint('Tried to focus widgets with two different keys: $debugOnlyFocusedKey and ${context.widget.key}'); - assert('If you have more than one focusable widget, then you should put them inside a Focus.' == true); + throw new FlutterError( + 'Missing Focus scope.\n' + 'Two focusable widgets with different keys, $debugOnlyFocusedKey and ${context.widget.key}, ' + 'exist in the widget tree simultaneously, but they have no Focus widget ancestor.\n' + 'If you have more than one focusable widget, then you should put them inside a Focus. ' + 'Normally, this is done for you using a Route, via Navigator, WidgetsApp, or MaterialApp.' + ); } return true; }); diff --git a/packages/flutter/test/widget/lazy_block_viewport_test.dart b/packages/flutter/test/widget/lazy_block_viewport_test.dart index aefd7c027b..6f5bda221c 100644 --- a/packages/flutter/test/widget/lazy_block_viewport_test.dart +++ b/packages/flutter/test/widget/lazy_block_viewport_test.dart @@ -183,7 +183,7 @@ void main() { expect(callbackTracker, equals([0, 1, 2])); callbackTracker.clear(); - await tester.allWidgets.forEach(collectText); + tester.allWidgets.forEach(collectText); expect(text, equals(['0', '1', '2'])); text.clear(); @@ -191,7 +191,7 @@ void main() { expect(callbackTracker, equals([0, 1, 2])); callbackTracker.clear(); - await tester.allWidgets.forEach(collectText); + tester.allWidgets.forEach(collectText); expect(text, equals(['0', '1', '2'])); text.clear(); }); diff --git a/packages/flutter_tools/flutter_analysis_options b/packages/flutter_tools/flutter_analysis_options index bae194fa44..5721e10cb1 100644 --- a/packages/flutter_tools/flutter_analysis_options +++ b/packages/flutter_tools/flutter_analysis_options @@ -3,11 +3,13 @@ # Note that until there is a default "all-in" lint rule-set we need # to opt-in to all desired lints (https://github.com/dart-lang/sdk/issues/25843). # For a list of lints, see: http://dart-lang.github.io/linter/lints/ - +# # This file is the .analysis_options file used by "flutter analyze". # It isn't named that because otherwise editors like Atom would try # to use it, and that wouldn't work because it enables things that # need to be silenced, in particular, public_member_api_docs. +# +# When editing, make sure you keep /.analysis_options consistent. analyzer: language: @@ -23,26 +25,41 @@ analyzer: strong_mode_down_cast_composite: ignore # we allow having TODOs in the code todo: ignore + linter: rules: + # these are in the same order as http://dart-lang.github.io/linter/lints/ + # to make maintenance easier + + # # error rules - avoid_empty_else + # - comment_references # blocked on https://github.com/dart-lang/dartdoc/issues/1153 + - control_flow_in_finally + - hash_and_equals + # - iterable_contains_unrelated_type # https://github.com/dart-lang/linter/issues/245 + - test_types_in_equals + - throw_in_finally + - unrelated_type_equality_checks + + # style rules - always_declare_return_types - always_specify_types - annotate_overrides - avoid_as - avoid_init_to_null - avoid_return_types_on_setters + - await_only_futures - camel_case_types - # - constant_identifier_names # https://github.com/dart-lang/linter/issues/204 (and 203) + # - constant_identifier_names # https://github.com/dart-lang/linter/issues/204 + - control_flow_in_finally - empty_constructor_bodies - - hash_and_equals - implementation_imports - library_names - library_prefixes - non_constant_identifier_names - one_member_abstracts + # - overriden_field # the analyzer code itself violates this right now :-) - package_api_docs - - package_names - package_prefixed_library_names - prefer_is_not_empty - public_member_api_docs @@ -50,6 +67,10 @@ linter: - sort_constructors_first - sort_unnamed_constructors_first - super_goes_last + # - type_annotate_public_apis # subset of always_specify_types - type_init_formals - unnecessary_brace_in_string_interp - unnecessary_getters_setters + + # pub rules + - package_names diff --git a/packages/flutter_tools/lib/executable.dart b/packages/flutter_tools/lib/executable.dart index 5c03af96ef..c34bf14363 100644 --- a/packages/flutter_tools/lib/executable.dart +++ b/packages/flutter_tools/lib/executable.dart @@ -91,8 +91,10 @@ Future main(List args) async { if (error is UsageException) { stderr.writeln(error.message); stderr.writeln(); - stderr.writeln("Run 'flutter -h' (or 'flutter -h') for available " - "flutter commands and options."); + stderr.writeln( + "Run 'flutter -h' (or 'flutter -h') for available " + "flutter commands and options." + ); // Argument error exit code. _exit(64); } else if (error is ProcessExit) { @@ -118,7 +120,8 @@ Future main(List args) async { stderr.writeln( 'Crash report written to ${file.path};\n' - 'please let us know at https://github.com/flutter/flutter/issues.'); + 'please let us know at https://github.com/flutter/flutter/issues.' + ); } _exit(1); @@ -129,21 +132,21 @@ Future main(List args) async { File _createCrashReport(List args, dynamic error, Chain chain) { File crashFile = getUniqueFile(Directory.current, 'flutter', 'log'); - StringBuffer buf = new StringBuffer(); + StringBuffer buffer = new StringBuffer(); - buf.writeln('Flutter crash report; please file at https://github.com/flutter/flutter/issues.\n'); + buffer.writeln('Flutter crash report; please file at https://github.com/flutter/flutter/issues.\n'); - buf.writeln('## command\n'); - buf.writeln('flutter ${args.join(' ')}\n'); + buffer.writeln('## command\n'); + buffer.writeln('flutter ${args.join(' ')}\n'); - buf.writeln('## exception\n'); - buf.writeln('$error\n'); - buf.writeln('```\n${chain.terse}```\n'); + buffer.writeln('## exception\n'); + buffer.writeln('$error\n'); + buffer.writeln('```\n${chain.terse}```\n'); - buf.writeln('## flutter doctor\n'); - buf.writeln('```\n${_doctorText()}```'); + buffer.writeln('## flutter doctor\n'); + buffer.writeln('```\n${_doctorText()}```'); - crashFile.writeAsStringSync(buf.toString()); + crashFile.writeAsStringSync(buffer.toString()); return crashFile; } @@ -179,7 +182,7 @@ Future _exit(int code) async { logger.flush(); // Give the task / timer queue one cycle through before we hard exit. - await Timer.run(() { + Timer.run(() { printTrace('exiting with code $code'); exit(code); }); diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index f39f25463d..2c13a08138 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -261,7 +261,7 @@ Future startApp(DriveCommand command, BuildMode buildMode) async { printTrace('Installing application package.'); ApplicationPackage package = command.applicationPackages .getPackageForPlatform(command.device.platform); - await command.device.installApp(package); + command.device.installApp(package); printTrace('Starting application.'); LaunchResult result = await command.device.startApp( diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index e8ece07543..a97adc7e99 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -205,7 +205,7 @@ Future startApp( if (install && device is AndroidDevice) { printStatus('Installing $package to $device...'); - if (!(await installApp(device, package))) + if (!(installApp(device, package))) return 1; } @@ -345,7 +345,7 @@ class _RunAndStayResident { // TODO(devoncarew): This fails for ios devices - we haven't built yet. if (device is AndroidDevice) { printTrace('Running install command.'); - if (!(await installApp(device, package))) + if (!(installApp(device, package))) return 1; } diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index c6994ad03b..494511f5e1 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -78,7 +78,7 @@ class SimControl { bool connected = false; int attempted = 0; while (!connected && attempted < 20) { - connected = await _isAnyConnected(); + connected = _isAnyConnected(); if (!connected) { printStatus('Still waiting for iOS Simulator to boot...'); await new Future.delayed(new Duration(seconds: 1)); diff --git a/packages/flx/test/bundle_test.dart b/packages/flx/test/bundle_test.dart index fc6d2070a9..4ed3e19a2e 100644 --- a/packages/flx/test/bundle_test.dart +++ b/packages/flx/test/bundle_test.dart @@ -24,7 +24,7 @@ Future main() async { final Uint8List kTestBytes = new Uint8List.fromList([1, 2, 3]); // Create a temp dir and file for the bundle. - Directory tempDir = await Directory.systemTemp.createTempSync('bundle_test'); + Directory tempDir = Directory.systemTemp.createTempSync('bundle_test'); String bundlePath = tempDir.path + '/bundle.flx'; AsymmetricKeyPair keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER);