Commit 94636bd2 authored by Ian Hickson's avatar Ian Hickson

Cleanup based on new lints (#4052)

parent 4052aa71
# Specify analysis options. # 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 # 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 # Atom. It is very similar to flutter_tools/flutter_analysis_options; the only
...@@ -23,33 +19,52 @@ analyzer: ...@@ -23,33 +19,52 @@ analyzer:
strong_mode_down_cast_composite: ignore strong_mode_down_cast_composite: ignore
# we allow having TODOs in the code # we allow having TODOs in the code
todo: ignore todo: ignore
linter: linter:
rules: rules:
# these are in the same order as http://dart-lang.github.io/linter/lints/
# to make maintenance easier
# error rules
- avoid_empty_else - 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_declare_return_types
- always_specify_types - always_specify_types
- annotate_overrides - annotate_overrides
- avoid_as - avoid_as
- avoid_init_to_null - 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 - 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 - empty_constructor_bodies
- hash_and_equals - implementation_imports
# - implementation_imports # https://github.com/dart-lang/linter/issues/203
- library_names - library_names
- library_prefixes - library_prefixes
- non_constant_identifier_names - non_constant_identifier_names
# - one_member_abstracts # https://github.com/dart-lang/linter/issues/203 - one_member_abstracts
# - overriden_field
- package_api_docs - package_api_docs
- package_names
- package_prefixed_library_names - package_prefixed_library_names
- prefer_is_not_empty - prefer_is_not_empty
# - public_member_api_docs
- slash_for_doc_comments - slash_for_doc_comments
- sort_constructors_first - sort_constructors_first
- sort_unnamed_constructors_first - sort_unnamed_constructors_first
- super_goes_last - super_goes_last
- type_annotate_public_apis # subset of always_specify_types # - type_annotate_public_apis # subset of always_specify_types
- type_init_formals - type_init_formals
- unnecessary_brace_in_string_interp - unnecessary_brace_in_string_interp
- unnecessary_getters_setters - unnecessary_getters_setters
# pub rules
- package_names
...@@ -290,7 +290,7 @@ class FlutterError extends AssertionError { ...@@ -290,7 +290,7 @@ class FlutterError extends AssertionError {
} }
result.add(line); result.add(line);
} }
if (skipped == 1) { if (skipped.length == 1) {
result.add('(elided one frame from ${skipped.single})'); result.add('(elided one frame from ${skipped.single})');
} else if (skipped.length > 1) { } else if (skipped.length > 1) {
List<String> where = new Set<String>.from(skipped).toList()..sort(); List<String> where = new Set<String>.from(skipped).toList()..sort();
......
...@@ -963,6 +963,11 @@ abstract class RenderBox extends RenderObject { ...@@ -963,6 +963,11 @@ abstract class RenderBox extends RenderObject {
int _debugActivePointers = 0; 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 @override
void handleEvent(PointerEvent event, HitTestEntry entry) { void handleEvent(PointerEvent event, HitTestEntry entry) {
super.handleEvent(event, entry); super.handleEvent(event, entry);
......
...@@ -130,8 +130,13 @@ class Focus extends StatefulWidget { ...@@ -130,8 +130,13 @@ class Focus extends StatefulWidget {
if (debugOnlyFocusedKey?.currentContext == null) if (debugOnlyFocusedKey?.currentContext == null)
debugOnlyFocusedKey = context.widget.key; debugOnlyFocusedKey = context.widget.key;
if (debugOnlyFocusedKey != context.widget.key) { if (debugOnlyFocusedKey != context.widget.key) {
debugPrint('Tried to focus widgets with two different keys: $debugOnlyFocusedKey and ${context.widget.key}'); throw new FlutterError(
assert('If you have more than one focusable widget, then you should put them inside a Focus.' == true); '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; return true;
}); });
......
...@@ -183,7 +183,7 @@ void main() { ...@@ -183,7 +183,7 @@ void main() {
expect(callbackTracker, equals(<int>[0, 1, 2])); expect(callbackTracker, equals(<int>[0, 1, 2]));
callbackTracker.clear(); callbackTracker.clear();
await tester.allWidgets.forEach(collectText); tester.allWidgets.forEach(collectText);
expect(text, equals(<String>['0', '1', '2'])); expect(text, equals(<String>['0', '1', '2']));
text.clear(); text.clear();
...@@ -191,7 +191,7 @@ void main() { ...@@ -191,7 +191,7 @@ void main() {
expect(callbackTracker, equals(<int>[0, 1, 2])); expect(callbackTracker, equals(<int>[0, 1, 2]));
callbackTracker.clear(); callbackTracker.clear();
await tester.allWidgets.forEach(collectText); tester.allWidgets.forEach(collectText);
expect(text, equals(<String>['0', '1', '2'])); expect(text, equals(<String>['0', '1', '2']));
text.clear(); text.clear();
}); });
......
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
# Note that until there is a default "all-in" lint rule-set we need # 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). # 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/ # For a list of lints, see: http://dart-lang.github.io/linter/lints/
#
# This file is the .analysis_options file used by "flutter analyze". # This file is the .analysis_options file used by "flutter analyze".
# It isn't named that because otherwise editors like Atom would try # 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 # to use it, and that wouldn't work because it enables things that
# need to be silenced, in particular, public_member_api_docs. # need to be silenced, in particular, public_member_api_docs.
#
# When editing, make sure you keep /.analysis_options consistent.
analyzer: analyzer:
language: language:
...@@ -23,26 +25,41 @@ analyzer: ...@@ -23,26 +25,41 @@ analyzer:
strong_mode_down_cast_composite: ignore strong_mode_down_cast_composite: ignore
# we allow having TODOs in the code # we allow having TODOs in the code
todo: ignore todo: ignore
linter: linter:
rules: rules:
# these are in the same order as http://dart-lang.github.io/linter/lints/
# to make maintenance easier
# # error rules
- avoid_empty_else - 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_declare_return_types
- always_specify_types - always_specify_types
- annotate_overrides - annotate_overrides
- avoid_as - avoid_as
- avoid_init_to_null - avoid_init_to_null
- avoid_return_types_on_setters - avoid_return_types_on_setters
- await_only_futures
- camel_case_types - 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 - empty_constructor_bodies
- hash_and_equals
- implementation_imports - implementation_imports
- library_names - library_names
- library_prefixes - library_prefixes
- non_constant_identifier_names - non_constant_identifier_names
- one_member_abstracts - one_member_abstracts
# - overriden_field # the analyzer code itself violates this right now :-)
- package_api_docs - package_api_docs
- package_names
- package_prefixed_library_names - package_prefixed_library_names
- prefer_is_not_empty - prefer_is_not_empty
- public_member_api_docs - public_member_api_docs
...@@ -50,6 +67,10 @@ linter: ...@@ -50,6 +67,10 @@ linter:
- sort_constructors_first - sort_constructors_first
- sort_unnamed_constructors_first - sort_unnamed_constructors_first
- super_goes_last - super_goes_last
# - type_annotate_public_apis # subset of always_specify_types
- type_init_formals - type_init_formals
- unnecessary_brace_in_string_interp - unnecessary_brace_in_string_interp
- unnecessary_getters_setters - unnecessary_getters_setters
# pub rules
- package_names
...@@ -91,8 +91,10 @@ Future<Null> main(List<String> args) async { ...@@ -91,8 +91,10 @@ Future<Null> main(List<String> args) async {
if (error is UsageException) { if (error is UsageException) {
stderr.writeln(error.message); stderr.writeln(error.message);
stderr.writeln(); stderr.writeln();
stderr.writeln("Run 'flutter -h' (or 'flutter <command> -h') for available " stderr.writeln(
"flutter commands and options."); "Run 'flutter -h' (or 'flutter <command> -h') for available "
"flutter commands and options."
);
// Argument error exit code. // Argument error exit code.
_exit(64); _exit(64);
} else if (error is ProcessExit) { } else if (error is ProcessExit) {
...@@ -118,7 +120,8 @@ Future<Null> main(List<String> args) async { ...@@ -118,7 +120,8 @@ Future<Null> main(List<String> args) async {
stderr.writeln( stderr.writeln(
'Crash report written to ${file.path};\n' '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); _exit(1);
...@@ -129,21 +132,21 @@ Future<Null> main(List<String> args) async { ...@@ -129,21 +132,21 @@ Future<Null> main(List<String> args) async {
File _createCrashReport(List<String> args, dynamic error, Chain chain) { File _createCrashReport(List<String> args, dynamic error, Chain chain) {
File crashFile = getUniqueFile(Directory.current, 'flutter', 'log'); 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'); buffer.writeln('## command\n');
buf.writeln('flutter ${args.join(' ')}\n'); buffer.writeln('flutter ${args.join(' ')}\n');
buf.writeln('## exception\n'); buffer.writeln('## exception\n');
buf.writeln('$error\n'); buffer.writeln('$error\n');
buf.writeln('```\n${chain.terse}```\n'); buffer.writeln('```\n${chain.terse}```\n');
buf.writeln('## flutter doctor\n'); buffer.writeln('## flutter doctor\n');
buf.writeln('```\n${_doctorText()}```'); buffer.writeln('```\n${_doctorText()}```');
crashFile.writeAsStringSync(buf.toString()); crashFile.writeAsStringSync(buffer.toString());
return crashFile; return crashFile;
} }
...@@ -179,7 +182,7 @@ Future<Null> _exit(int code) async { ...@@ -179,7 +182,7 @@ Future<Null> _exit(int code) async {
logger.flush(); logger.flush();
// Give the task / timer queue one cycle through before we hard exit. // Give the task / timer queue one cycle through before we hard exit.
await Timer.run(() { Timer.run(() {
printTrace('exiting with code $code'); printTrace('exiting with code $code');
exit(code); exit(code);
}); });
......
...@@ -261,7 +261,7 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async { ...@@ -261,7 +261,7 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async {
printTrace('Installing application package.'); printTrace('Installing application package.');
ApplicationPackage package = command.applicationPackages ApplicationPackage package = command.applicationPackages
.getPackageForPlatform(command.device.platform); .getPackageForPlatform(command.device.platform);
await command.device.installApp(package); command.device.installApp(package);
printTrace('Starting application.'); printTrace('Starting application.');
LaunchResult result = await command.device.startApp( LaunchResult result = await command.device.startApp(
......
...@@ -205,7 +205,7 @@ Future<int> startApp( ...@@ -205,7 +205,7 @@ Future<int> startApp(
if (install && device is AndroidDevice) { if (install && device is AndroidDevice) {
printStatus('Installing $package to $device...'); printStatus('Installing $package to $device...');
if (!(await installApp(device, package))) if (!(installApp(device, package)))
return 1; return 1;
} }
...@@ -345,7 +345,7 @@ class _RunAndStayResident { ...@@ -345,7 +345,7 @@ class _RunAndStayResident {
// TODO(devoncarew): This fails for ios devices - we haven't built yet. // TODO(devoncarew): This fails for ios devices - we haven't built yet.
if (device is AndroidDevice) { if (device is AndroidDevice) {
printTrace('Running install command.'); printTrace('Running install command.');
if (!(await installApp(device, package))) if (!(installApp(device, package)))
return 1; return 1;
} }
......
...@@ -78,7 +78,7 @@ class SimControl { ...@@ -78,7 +78,7 @@ class SimControl {
bool connected = false; bool connected = false;
int attempted = 0; int attempted = 0;
while (!connected && attempted < 20) { while (!connected && attempted < 20) {
connected = await _isAnyConnected(); connected = _isAnyConnected();
if (!connected) { if (!connected) {
printStatus('Still waiting for iOS Simulator to boot...'); printStatus('Still waiting for iOS Simulator to boot...');
await new Future<Null>.delayed(new Duration(seconds: 1)); await new Future<Null>.delayed(new Duration(seconds: 1));
......
...@@ -24,7 +24,7 @@ Future<Null> main() async { ...@@ -24,7 +24,7 @@ Future<Null> main() async {
final Uint8List kTestBytes = new Uint8List.fromList(<int>[1, 2, 3]); final Uint8List kTestBytes = new Uint8List.fromList(<int>[1, 2, 3]);
// Create a temp dir and file for the bundle. // 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'; String bundlePath = tempDir.path + '/bundle.flx';
AsymmetricKeyPair<PublicKey, PrivateKey> keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER); AsymmetricKeyPair<PublicKey, PrivateKey> keyPair = keyPairFromPrivateKeyBytes(kPrivateKeyDER);
......
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