Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions agent/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
analyzer:
language:
enableStrictCallChecks: true
enableSuperMixins: true
strong-mode: true
errors:
# allow overriding fields (if they use super, ideally...)
strong_mode_invalid_field_override: ignore
# allow type narrowing
strong_mode_invalid_method_override: ignore
strong_mode_static_type_error: ignore
strong_mode_down_cast_composite: ignore
# allow having TODOs in the code
todo: ignore
exclude:
- 'bin/**'

linter:
rules:
# these rules are documented on and in the same order as
# the Dart Lint rules page to make maintenance easier
# http://dart-lang.github.io/linter/lints/

# === error rules ===
- avoid_empty_else
# - comment_references # blocked on https://github.com/dart-lang/dartdoc/issues/1153
- cancel_subscriptions
# - close_sinks # https://github.com/flutter/flutter/issues/5789
- control_flow_in_finally
- empty_statements
- hash_and_equals
# - invariant_booleans # https://github.com/flutter/flutter/issues/5790
# - iterable_contains_unrelated_type
# - list_remove_unrelated_type
# - literal_only_boolean_expressions # https://github.com/flutter/flutter/issues/5791
- test_types_in_equals
- throw_in_finally
- unrelated_type_equality_checks
- valid_regexps

# === style rules ===
- always_declare_return_types
- annotate_overrides
- 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
- control_flow_in_finally
- empty_constructor_bodies
- implementation_imports
- library_names
- library_prefixes
- non_constant_identifier_names
- one_member_abstracts
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
# - overridden_fields
- package_api_docs
- 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_init_formals
- unawaited_futures # https://github.com/flutter/flutter/issues/5793
- unnecessary_getters_setters

# === pub rules ===
- package_names
1 change: 1 addition & 0 deletions agent/bin/agent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AuthenticatedClient extends BaseClient {
final String _authToken;
final Client _delegate = new Client();

@override
Future<StreamedResponse> send(Request request) async {
request.headers['Agent-ID'] = _agentId;
request.headers['Agent-Auth-Token'] = _authToken;
Expand Down
15 changes: 13 additions & 2 deletions agent/lib/src/adb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
}

class AndroidDevice implements Device {
AndroidDevice({@required String this.deviceId});
AndroidDevice({@required this.deviceId});

@override
final String deviceId;
Expand Down Expand Up @@ -248,7 +248,7 @@ class IosDeviceDiscovery implements DeviceDiscovery {

/// iOS device.
class IosDevice implements Device {
const IosDevice({ @required String this.deviceId });
const IosDevice({ @required this.deviceId });

@override
final String deviceId;
Expand All @@ -258,10 +258,21 @@ class IosDevice implements Device {
// devices are already unlocked. For now we'll just keep them at minimum
// screen brightness so they don't drain battery too fast.

@override
Future<bool> isAwake() async => true;

@override
Future<bool> isAsleep() async => false;

@override
Future<Null> wakeUp() async {}

@override
Future<Null> sendToSleep() async {}

@override
Future<Null> togglePower() async {}

@override
Future<Null> unlock() async {}
}
3 changes: 2 additions & 1 deletion agent/lib/src/agent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class AuthenticatedClient extends BaseClient {
final String _authToken;
final Client _delegate = new Client();

@override
Future<StreamedResponse> send(Request request) async {
request.headers['Agent-ID'] = _agentId;
request.headers['Agent-Auth-Token'] = _authToken;
Expand Down Expand Up @@ -162,7 +163,7 @@ class AgentHealth {
bool get ok => checks.isNotEmpty && checks.values.every((HealthCheckResult r) => r.succeeded);

/// Sets a health check [result] for a given [parameter].
operator []=(String parameter, HealthCheckResult result) {
void operator []=(String parameter, HealthCheckResult result) {
if (checks.containsKey(parameter)) {
print('WARNING: duplicate health check ${parameter} submitted');
}
Expand Down
3 changes: 2 additions & 1 deletion agent/lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Future<TaskResult> runTask(Agent agent, CocoonTask task) async {

bool runnerFinished = false;

// ignore: unawaited_futures
runner.exitCode.then((_) {
runnerFinished = true;
});
Expand Down Expand Up @@ -126,7 +127,7 @@ Future<TaskResult> runTask(Agent agent, CocoonTask task) async {
} finally {
await stdoutSub.cancel();
await stderrSub.cancel();
sendLog('Task execution finished', flush: true);
await sendLog('Task execution finished', flush: true);
if (!runnerFinished)
runner.kill(ProcessSignal.SIGKILL);
await forceQuitRunningProcesses();
Expand Down
3 changes: 2 additions & 1 deletion agent/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Future<Process> startProcess(String executable, List<String> arguments,
ProcessInfo procInfo = new ProcessInfo(command, proc);
_runningProcesses.add(procInfo);

// ignore: unawaited_futures
proc.exitCode.then((_) {
_runningProcesses.remove(procInfo);
});
Expand Down Expand Up @@ -351,7 +352,7 @@ String requireEnvVar(String name) {
return value;
}

dynamic/*=T*/ requireConfigProperty(Map<String, dynamic/*<T>*/> map, String propertyName) {
dynamic/*=T*/ requireConfigProperty/*<T>*/(Map<String, dynamic/*<T>*/> map, String propertyName) {
if (!map.containsKey(propertyName))
fail('Configuration property not found: $propertyName');

Expand Down
2 changes: 1 addition & 1 deletion agent/test/src/adb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class CommandArgs {
String toString() => 'CommandArgs(command: $command, arguments: $arguments, env: $env)';

@override
operator==(Object other) {
bool operator==(Object other) {
if (other.runtimeType != CommandArgs)
return false;

Expand Down
2 changes: 1 addition & 1 deletion agent/test/src/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:test/test.dart';
import 'package:cocoon_agent/src/utils.dart';

main() {
void main() {
group('grep', () {
test('greps lines', () {
expect(grep('b', from: 'ab\ncd\nba'), ['ab', 'ba']);
Expand Down
72 changes: 72 additions & 0 deletions app/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
analyzer:
language:
enableStrictCallChecks: true
enableSuperMixins: true
strong-mode: true
errors:
# allow overriding fields (if they use super, ideally...)
strong_mode_invalid_field_override: ignore
# allow type narrowing
strong_mode_invalid_method_override: ignore
strong_mode_static_type_error: ignore
strong_mode_down_cast_composite: ignore
# allow having TODOs in the code
todo: ignore
exclude:
- 'bin/**'

linter:
rules:
# these rules are documented on and in the same order as
# the Dart Lint rules page to make maintenance easier
# http://dart-lang.github.io/linter/lints/

# === error rules ===
- avoid_empty_else
# - comment_references # blocked on https://github.com/dart-lang/dartdoc/issues/1153
- cancel_subscriptions
# - close_sinks # https://github.com/flutter/flutter/issues/5789
- control_flow_in_finally
- empty_statements
- hash_and_equals
# - invariant_booleans # https://github.com/flutter/flutter/issues/5790
# - iterable_contains_unrelated_type
# - list_remove_unrelated_type
# - literal_only_boolean_expressions # https://github.com/flutter/flutter/issues/5791
- test_types_in_equals
- throw_in_finally
- unrelated_type_equality_checks
- valid_regexps

# === style rules ===
- always_declare_return_types
- annotate_overrides
- 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
- control_flow_in_finally
- empty_constructor_bodies
- implementation_imports
- library_names
- library_prefixes
- non_constant_identifier_names
- one_member_abstracts
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
# - overridden_fields
- package_api_docs
- 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_init_formals
- unawaited_futures # https://github.com/flutter/flutter/issues/5793
- unnecessary_getters_setters

# === pub rules ===
- package_names
9 changes: 5 additions & 4 deletions app/bin/dev_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const _pubServePort = 9091;

/// Runs `pub serve` and `goapp serve` such that the app can be debugged in
/// Dartium.
main(List<String> rawArgs) {
void main(List<String> rawArgs) {
ArgResults args = _parseArgs(rawArgs);

Zone.current.fork(specification: new ZoneSpecification(handleUncaughtError: _handleCatastrophy))
Expand All @@ -49,7 +49,7 @@ ArgResults _parseArgs(List<String> rawArgs) {
return argp.parse(rawArgs);
}

_start(ArgResults args) async {
Future<Null> _start(ArgResults args) async {
bool clearDatastore = args['clear-datastore'];

_streamSubscriptions.addAll(<StreamSubscription>[
Expand Down Expand Up @@ -89,7 +89,7 @@ _start(ArgResults args) async {
await _whenLocalPortIsListening(_pubServePort);
} catch(_) {
print('\n[ERROR] Timed out waiting for goapp and pub ports to become available\n');
_stop();
await _stop();
}

HttpClient http = new HttpClient();
Expand All @@ -101,7 +101,7 @@ _start(ArgResults args) async {
print('Failed redirecting ${request.uri}');
print(e);
print(s);
_stop();
await _stop();
}
}
}
Expand Down Expand Up @@ -212,6 +212,7 @@ Future<Null> _stop([ProcessSignal signal = ProcessSignal.SIGINT]) async {
_streamSubscriptions.forEach((s) => s.cancel());
await devServer.close(force: true);

// ignore: unawaited_futures
Future
.wait(_childProcesses.map((p) => p.process.exitCode))
.timeout(const Duration(seconds: 5))
Expand Down
4 changes: 2 additions & 2 deletions app/lib/components/status_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class StatusTable implements OnInit {
List<AgentStatus> agentStatuses;

@override
ngOnInit() async {
reloadData();
Future<Null> ngOnInit() async {
await reloadData();
new Timer.periodic(const Duration(seconds: 30), (_) => reloadData());
}

Expand Down
17 changes: 15 additions & 2 deletions app/lib/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Entity {
final EntitySerializer _entitySerializer;
final Map<String, dynamic> _props;

operator[](String propName) => _props[propName];
operator[]=(String propName, dynamic value) {
dynamic operator[](String propName) => _props[propName];
void operator[]=(String propName, dynamic value) {
_props[propName] = value;
}

Expand Down Expand Up @@ -53,6 +53,7 @@ class ListSerializer<E> implements JsonSerializer<List<E>> {

final JsonSerializer elementSerializer;

@override
List<E> deserialize(dynamic jsonValue) {
if (jsonValue == null)
return null;
Expand All @@ -70,6 +71,7 @@ class ListSerializer<E> implements JsonSerializer<List<E>> {
return result;
}

@override
List<dynamic> serialize(List<E> value) {
return value
.map((E elem) => elementSerializer.serialize(elem))
Expand All @@ -80,27 +82,36 @@ class ListSerializer<E> implements JsonSerializer<List<E>> {
class StringSerializer implements JsonSerializer<String> {
const StringSerializer();

@override
String deserialize(dynamic jsonValue) {
return jsonValue as String;
}

@override
dynamic serialize(String value) => value;
}

class BoolSerializer implements JsonSerializer<bool> {
const BoolSerializer();

@override
bool deserialize(dynamic jsonValue) {
return jsonValue as bool;
}

@override
dynamic serialize(bool value) => value;
}

class NumSerializer implements JsonSerializer<num> {
const NumSerializer();

@override
num deserialize(dynamic jsonValue) {
return jsonValue as num;
}

@override
dynamic serialize(num value) => value;
}

Expand Down Expand Up @@ -135,6 +146,7 @@ class EntitySerializer<T extends Entity> implements JsonSerializer<T> {
final EntityFactory<T> _entityFactory;
final Map<String, JsonSerializer> _propertyCodecs;

@override
T deserialize(dynamic jsonValue) {
Map<String, dynamic> props = <String, dynamic>{};
(jsonValue as Map).forEach((String propName, dynamic propJsonValue) {
Expand All @@ -150,6 +162,7 @@ class EntitySerializer<T extends Entity> implements JsonSerializer<T> {
return _entityFactory(props);
}

@override
dynamic serialize(T value) {
Map<String, dynamic> json = <String, dynamic>{};
value._props.forEach((String propName, dynamic propValue) {
Expand Down
Loading