Enable and fix a number of lints, disallow implicit dynamic (dart-lang/io#65)
* also fix version
diff --git a/pkgs/io/CHANGELOG.md b/pkgs/io/CHANGELOG.md
index b8c0ff1..8e02a28 100644
--- a/pkgs/io/CHANGELOG.md
+++ b/pkgs/io/CHANGELOG.md
@@ -1,6 +1,10 @@
-## 0.3.5-dev
+## 0.3.6-dev
* Require Dart >=2.12
+
+## 0.3.5
+
+* Require Dart >=2.1
* Remove dependency on `package:charcode`.
## 0.3.4
diff --git a/pkgs/io/analysis_options.yaml b/pkgs/io/analysis_options.yaml
index d88bf2b..963fe81 100644
--- a/pkgs/io/analysis_options.yaml
+++ b/pkgs/io/analysis_options.yaml
@@ -1,33 +1,102 @@
include: package:pedantic/analysis_options.yaml
+
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
+ language:
+ strict-raw-types: true
linter:
rules:
- # Error Rules
+ - always_put_required_named_parameters_first
+ - avoid_annotating_with_dynamic
+ - avoid_bool_literals_in_conditional_expressions
+ - avoid_catches_without_on_clauses
+ - avoid_catching_errors
+ - avoid_classes_with_only_static_members
+ - avoid_double_and_int_checks
+ - avoid_dynamic_calls
+ - avoid_field_initializers_in_const_classes
+ - avoid_function_literals_in_foreach_calls
+ - avoid_implementing_value_types
+ - avoid_js_rounded_ints
+ - avoid_private_typedef_functions
+ - avoid_redundant_argument_values
+ - avoid_renaming_method_parameters
+ - avoid_returning_null_for_future
+ - avoid_returning_null_for_void
+ - avoid_returning_this
+ - avoid_setters_without_getters
+ - avoid_single_cascade_in_expression_statements
+ - avoid_slow_async_io
+ - avoid_types_on_closure_parameters
+ - avoid_unused_constructor_parameters
+ - avoid_void_async
+ - await_only_futures
+ - camel_case_types
+ - cancel_subscriptions
+ - cascade_invocations
+ - close_sinks
- comment_references
+ - constant_identifier_names
- control_flow_in_finally
+ - directives_ordering
- empty_statements
+ - file_names
- hash_and_equals
+ - implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
+ - join_return_with_assignment
+ - lines_longer_than_80_chars
- list_remove_unrelated_type
+ - literal_only_boolean_expressions
+ - missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
+ - no_runtimeType_toString
+ - non_constant_identifier_names
+ - one_member_abstracts
+ - only_throw_errors
+ - overridden_fields
+ - package_api_docs
+ - package_names
+ - package_prefixed_library_names
+ - prefer_asserts_in_initializer_lists
+ - prefer_const_constructors
+ - prefer_const_constructors_in_immutables
+ - prefer_const_declarations
+ - prefer_const_literals_to_create_immutables
+ - prefer_expression_function_bodies
+ - prefer_final_locals
+ - prefer_foreach
+ - prefer_function_declarations_over_variables
+ - prefer_initializing_formals
+ - prefer_inlined_adds
+ - prefer_int_literals
+ - prefer_interpolation_to_compose_strings
+ - prefer_is_not_operator
+ - prefer_mixin
+ - prefer_null_aware_operators
+ - prefer_relative_imports
+ - prefer_typing_uninitialized_variables
+ - prefer_void_to_null
+ - provide_deprecation_message
+ - sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
-
- # Style Rules
- - camel_case_types
- - cascade_invocations
- - constant_identifier_names
- - directives_ordering
- - implementation_imports
- - non_constant_identifier_names
- - only_throw_errors
- - prefer_const_constructors
- - prefer_final_locals
- - prefer_initializing_formals
- - prefer_interpolation_to_compose_strings
+ - type_annotate_public_apis
+ - unnecessary_await_in_return
- unnecessary_brace_in_string_interps
+ - unnecessary_getters_setters
+ - unnecessary_lambdas
+ - unnecessary_null_aware_assignments
+ - unnecessary_overrides
+ - unnecessary_parenthesis
+ - unnecessary_statements
+ - unnecessary_string_interpolations
+ - use_is_even_rather_than_modulo
+ - use_setters_to_change_properties
+ - use_string_buffers
+ - use_to_and_as_if_applicable
+ - void_checks
diff --git a/pkgs/io/example/spawn_process_example.dart b/pkgs/io/example/spawn_process_example.dart
index 0529bf3..5918057 100644
--- a/pkgs/io/example/spawn_process_example.dart
+++ b/pkgs/io/example/spawn_process_example.dart
@@ -7,7 +7,7 @@
import 'package:io/io.dart';
/// Runs `dartfmt` commands and `pub publish`.
-Future<Null> main() async {
+Future<void> main() async {
final manager = ProcessManager();
// Runs dartfmt --version and outputs the result via stdout.
diff --git a/pkgs/io/lib/src/copy_path.dart b/pkgs/io/lib/src/copy_path.dart
index b1dd5af..7906f3c 100644
--- a/pkgs/io/lib/src/copy_path.dart
+++ b/pkgs/io/lib/src/copy_path.dart
@@ -25,7 +25,7 @@
/// * If [from] and [to] are canonically the same, no operation occurs.
///
/// Returns a future that completes when complete.
-Future<Null> copyPath(String from, String to) async {
+Future<void> copyPath(String from, String to) async {
if (_doNothing(from, to)) {
return;
}
diff --git a/pkgs/io/lib/src/process_manager.dart b/pkgs/io/lib/src/process_manager.dart
index c6e96a1..069a5c4 100644
--- a/pkgs/io/lib/src/process_manager.dart
+++ b/pkgs/io/lib/src/process_manager.dart
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// ignore_for_file: close_sinks,cancel_subscriptions
+
import 'dart:async';
import 'dart:io' as io;
@@ -27,7 +29,7 @@
/// Terminates the global `stdin` listener, making future listens impossible.
///
/// This method should be invoked only at the _end_ of a program's execution.
- static Future<Null> terminateStdIn() async {
+ static Future<void> terminateStdIn() async {
await sharedStdIn.terminate();
}
@@ -131,17 +133,16 @@
bool includeParentEnvironment = true,
bool runInShell = false,
io.ProcessStartMode mode = io.ProcessStartMode.normal,
- }) async {
- return io.Process.start(
- executable,
- arguments.toList(),
- workingDirectory: workingDirectory,
- environment: environment,
- includeParentEnvironment: includeParentEnvironment,
- runInShell: runInShell,
- mode: mode,
- );
- }
+ }) async =>
+ io.Process.start(
+ executable,
+ arguments.toList(),
+ workingDirectory: workingDirectory,
+ environment: environment,
+ includeParentEnvironment: includeParentEnvironment,
+ runInShell: runInShell,
+ mode: mode,
+ );
}
/// A process instance created and managed through [ProcessManager].
@@ -180,9 +181,9 @@
/// Forwards `stdin`/`stdout`/`stderr` to/from the host.
class _ForwardingSpawn extends Spawn {
- final StreamSubscription _stdInSub;
- final StreamSubscription _stdOutSub;
- final StreamSubscription _stdErrSub;
+ final StreamSubscription<List<int>> _stdInSub;
+ final StreamSubscription<List<int>> _stdOutSub;
+ final StreamSubscription<List<int>> _stdErrSub;
final StreamController<List<int>> _stdOut;
final StreamController<List<int>> _stdErr;
diff --git a/pkgs/io/lib/src/shared_stdin.dart b/pkgs/io/lib/src/shared_stdin.dart
index fb32829..b8510fb 100644
--- a/pkgs/io/lib/src/shared_stdin.dart
+++ b/pkgs/io/lib/src/shared_stdin.dart
@@ -36,9 +36,8 @@
/// Returns a future that completes with the next line.
///
/// This is similar to the standard [Stdin.readLineSync], but asynchronous.
- Future<String> nextLine({Encoding encoding = systemEncoding}) {
- return lines(encoding: encoding).first;
- }
+ Future<String> nextLine({Encoding encoding = systemEncoding}) =>
+ lines(encoding: encoding).first;
/// Returns the stream transformed as UTF8 strings separated by line breaks.
///
@@ -51,9 +50,8 @@
/// ```
///
/// ... but asynchronous.
- Stream<String> lines({Encoding encoding = systemEncoding}) {
- return transform(utf8.decoder).transform(const LineSplitter());
- }
+ Stream<String> lines({Encoding encoding = systemEncoding}) =>
+ transform(utf8.decoder).transform(const LineSplitter());
void _onInput(List<int> event) => _getCurrent().add(event);
@@ -74,6 +72,7 @@
if (_sub == null) {
throw StateError('Stdin has already been terminated.');
}
+ // ignore: close_sinks
final controller = _getCurrent();
if (controller.hasListener) {
throw StateError(''
@@ -89,7 +88,7 @@
}
/// Terminates the connection to `stdin`, closing all subscription.
- Future<Null> terminate() async {
+ Future<void> terminate() async {
if (_sub == null) {
throw StateError('Stdin has already been terminated.');
}
diff --git a/pkgs/io/pubspec.yaml b/pkgs/io/pubspec.yaml
index 33efd3f..9f1fa32 100644
--- a/pkgs/io/pubspec.yaml
+++ b/pkgs/io/pubspec.yaml
@@ -2,8 +2,8 @@
description: >-
Utilities for the Dart VM Runtime including support for ANSI colors,
file copying, and standard exit code values.
-version: 0.3.5-dev
-homepage: https://github.com/dart-lang/io
+version: 0.3.6-dev
+repository: https://github.com/dart-lang/io
environment:
sdk: ">=2.11.99 <3.0.0"
diff --git a/pkgs/io/test/ansi_code_test.dart b/pkgs/io/test/ansi_code_test.dart
index 3b11131..5bd0cb4 100644
--- a/pkgs/io/test/ansi_code_test.dart
+++ b/pkgs/io/test/ansi_code_test.dart
@@ -31,7 +31,7 @@
});
test('forScript variaents ignore `ansiOutputEnabled`', () {
- final expected =
+ const expected =
'$_ansiEscapeForScript[34m$sampleInput$_ansiEscapeForScript[0m';
for (var override in [true, false]) {
diff --git a/pkgs/io/test/copy_path_test.dart b/pkgs/io/test/copy_path_test.dart
index 69bed59..612a516 100644
--- a/pkgs/io/test/copy_path_test.dart
+++ b/pkgs/io/test/copy_path_test.dart
@@ -33,13 +33,11 @@
});
}
-d.DirectoryDescriptor _struct() {
- return d.dir('parent', [
+d.DirectoryDescriptor _struct() => d.dir('parent', [
d.dir('child', [
d.file('foo.txt'),
]),
]);
-}
-Future _create() => _struct().create();
-Future _validate() => _struct().validate();
+Future<void> _create() => _struct().create();
+Future<void> _validate() => _struct().validate();
diff --git a/pkgs/io/test/process_manager_test.dart b/pkgs/io/test/process_manager_test.dart
index d161a9e..a865a3e 100644
--- a/pkgs/io/test/process_manager_test.dart
+++ b/pkgs/io/test/process_manager_test.dart
@@ -2,11 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// ignore_for_file: close_sinks
+
import 'dart:async';
import 'dart:convert';
import 'dart:io';
-// TODO: Change to io.dart once these features are published.
import 'package:io/io.dart' hide sharedStdIn;
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
@@ -19,7 +20,7 @@
List<String> stderrLog;
test('spawn functions should match the type definition of Process.start', () {
- final isStartProcess = const TypeMatcher<StartProcess>();
+ const isStartProcess = TypeMatcher<StartProcess>();
expect(Process.start, isStartProcess);
final manager = ProcessManager();
expect(manager.spawn, isStartProcess);
diff --git a/pkgs/io/test/shared_stdin_test.dart b/pkgs/io/test/shared_stdin_test.dart
index bdb311d..7fd2b31 100644
--- a/pkgs/io/test/shared_stdin_test.dart
+++ b/pkgs/io/test/shared_stdin_test.dart
@@ -9,6 +9,7 @@
import 'package:test/test.dart';
void main() {
+ // ignore: close_sinks
StreamController<String> fakeStdIn;
SharedStdIn sharedStdIn;
@@ -71,7 +72,7 @@
test('should allow listening for new lines multiple times', () async {
expect(sharedStdIn.nextLine(), completion('Hello World'));
fakeStdIn.add('Hello World\n');
- await Future<Null>.value();
+ await Future<void>.value();
expect(sharedStdIn.nextLine(), completion('Hello World'));
fakeStdIn.add('Hello World\n');