enable and fix lints
diff --git a/.travis.yml b/.travis.yml index 9c21886..8d6eeea 100644 --- a/.travis.yml +++ b/.travis.yml
@@ -1,13 +1,12 @@ language: dart dart: - - stable + - 2.0.0 - dev - - 1.24.3 dart_task: - test: - - dartanalyzer + - dartanalyzer: --fatal-infos --fatal-warnings . matrix: include:
diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..ee63c14 --- /dev/null +++ b/analysis_options.yaml
@@ -0,0 +1,98 @@ +include: package:pedantic/analysis_options.yaml +analyzer: + strong-mode: + implicit-casts: false + errors: + dead_code: error + override_on_non_overriding_method: error + unused_element: error + unused_import: error + unused_local_variable: error +linter: + rules: + - always_declare_return_types + - annotate_overrides + - avoid_bool_literals_in_conditional_expressions + - avoid_classes_with_only_static_members + - avoid_empty_else + - avoid_function_literals_in_foreach_calls + - avoid_init_to_null + - avoid_null_checks_in_equality_operators + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - avoid_returning_null + - avoid_returning_null_for_future + - avoid_returning_null_for_void + - avoid_returning_this + - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements + - avoid_types_as_parameter_names + - avoid_unused_constructor_parameters + - await_only_futures + - camel_case_types + - cancel_subscriptions + - cascade_invocations + - comment_references + - constant_identifier_names + - control_flow_in_finally + - directives_ordering + - empty_catches + - empty_constructor_bodies + - empty_statements + - file_names + - hash_and_equals + - implementation_imports + - invariant_booleans + - iterable_contains_unrelated_type + - join_return_with_assignment + - library_names + - library_prefixes + - list_remove_unrelated_type + - literal_only_boolean_expressions + - no_adjacent_strings_in_list + - no_duplicate_case_values + - non_constant_identifier_names + - null_closures + - omit_local_variable_types + - only_throw_errors + - overridden_fields + - package_api_docs + - package_names + - package_prefixed_library_names + - prefer_adjacent_string_concatenation + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_contains + - prefer_equal_for_default_values + - prefer_final_fields + - prefer_final_locals + - prefer_generic_function_type_aliases + - prefer_initializing_formals + - prefer_interpolation_to_compose_strings + - prefer_is_empty + - prefer_is_not_empty + - prefer_null_aware_operators + - prefer_single_quotes + - prefer_typing_uninitialized_variables + - recursive_getters + - slash_for_doc_comments + - test_types_in_equals + - throw_in_finally + - type_init_formals + - unawaited_futures + - unnecessary_await_in_return + - unnecessary_brace_in_string_interps + - unnecessary_const + - unnecessary_getters_setters + - unnecessary_lambdas + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_parenthesis + - unnecessary_statements + - unnecessary_this + - unrelated_type_equality_checks + - use_function_type_syntax_for_parameters + - use_rethrow_when_possible + - valid_regexps + - void_checks
diff --git a/lib/tuple.dart b/lib/tuple.dart index 21d2578..82edd2b 100644 --- a/lib/tuple.dart +++ b/lib/tuple.dart
@@ -38,20 +38,20 @@ /// Create a new tuple value with the specified list [items]. factory Tuple2.fromList(List items) { if (items.length != 2) { - throw new ArgumentError('items must have length 2'); + throw ArgumentError('items must have length 2'); } - return new Tuple2<T1, T2>(items[0] as T1, items[1] as T2); + return Tuple2<T1, T2>(items[0] as T1, items[1] as T2); } /// Returns a tuple with the first item set to the specified value. Tuple2<T1, T2> withItem1(T1 v) { - return new Tuple2<T1, T2>(v, item2); + return Tuple2<T1, T2>(v, item2); } /// Returns a tuple with the second item set to the specified value. Tuple2<T1, T2> withItem2(T2 v) { - return new Tuple2<T1, T2>(item1, v); + return Tuple2<T1, T2>(item1, v); } /// Creates a [List] containing the items of this [Tuple2]. @@ -59,13 +59,14 @@ /// The elements are in item order. The list is variable-length /// if [growable] is true. List toList({bool growable = false}) => - new List.from([item1, item2], growable: growable); + List.from([item1, item2], growable: growable); @override String toString() => '[$item1, $item2]'; @override - bool operator ==(o) => o is Tuple2 && o.item1 == item1 && o.item2 == item2; + bool operator ==(other) => + other is Tuple2 && other.item1 == item1 && other.item2 == item2; @override int get hashCode => hash2(item1.hashCode, item2.hashCode); @@ -88,26 +89,25 @@ /// Create a new tuple value with the specified list [items]. factory Tuple3.fromList(List items) { if (items.length != 3) { - throw new ArgumentError('items must have length 3'); + throw ArgumentError('items must have length 3'); } - return new Tuple3<T1, T2, T3>( - items[0] as T1, items[1] as T2, items[2] as T3); + return Tuple3<T1, T2, T3>(items[0] as T1, items[1] as T2, items[2] as T3); } /// Returns a tuple with the first item set to the specified value. Tuple3<T1, T2, T3> withItem1(T1 v) { - return new Tuple3<T1, T2, T3>(v, item2, item3); + return Tuple3<T1, T2, T3>(v, item2, item3); } /// Returns a tuple with the second item set to the specified value. Tuple3<T1, T2, T3> withItem2(T2 v) { - return new Tuple3<T1, T2, T3>(item1, v, item3); + return Tuple3<T1, T2, T3>(item1, v, item3); } /// Returns a tuple with the third item set to the specified value. Tuple3<T1, T2, T3> withItem3(T3 v) { - return new Tuple3<T1, T2, T3>(item1, item2, v); + return Tuple3<T1, T2, T3>(item1, item2, v); } /// Creates a [List] containing the items of this [Tuple3]. @@ -115,14 +115,17 @@ /// The elements are in item order. The list is variable-length /// if [growable] is true. List toList({bool growable = false}) => - new List.from([item1, item2, item3], growable: growable); + List.from([item1, item2, item3], growable: growable); @override String toString() => '[$item1, $item2, $item3]'; @override - bool operator ==(o) => - o is Tuple3 && o.item1 == item1 && o.item2 == item2 && o.item3 == item3; + bool operator ==(other) => + other is Tuple3 && + other.item1 == item1 && + other.item2 == item2 && + other.item3 == item3; @override int get hashCode => hash3(item1.hashCode, item2.hashCode, item3.hashCode); @@ -148,31 +151,31 @@ /// Create a new tuple value with the specified list [items]. factory Tuple4.fromList(List items) { if (items.length != 4) { - throw new ArgumentError('items must have length 4'); + throw ArgumentError('items must have length 4'); } - return new Tuple4<T1, T2, T3, T4>( + return Tuple4<T1, T2, T3, T4>( items[0] as T1, items[1] as T2, items[2] as T3, items[3] as T4); } /// Returns a tuple with the first item set to the specified value. Tuple4<T1, T2, T3, T4> withItem1(T1 v) { - return new Tuple4<T1, T2, T3, T4>(v, item2, item3, item4); + return Tuple4<T1, T2, T3, T4>(v, item2, item3, item4); } /// Returns a tuple with the second item set to the specified value. Tuple4<T1, T2, T3, T4> withItem2(T2 v) { - return new Tuple4<T1, T2, T3, T4>(item1, v, item3, item4); + return Tuple4<T1, T2, T3, T4>(item1, v, item3, item4); } /// Returns a tuple with the third item set to the specified value. Tuple4<T1, T2, T3, T4> withItem3(T3 v) { - return new Tuple4<T1, T2, T3, T4>(item1, item2, v, item4); + return Tuple4<T1, T2, T3, T4>(item1, item2, v, item4); } /// Returns a tuple with the fourth item set to the specified value. Tuple4<T1, T2, T3, T4> withItem4(T4 v) { - return new Tuple4<T1, T2, T3, T4>(item1, item2, item3, v); + return Tuple4<T1, T2, T3, T4>(item1, item2, item3, v); } /// Creates a [List] containing the items of this [Tuple4]. @@ -180,18 +183,18 @@ /// The elements are in item order. The list is variable-length /// if [growable] is true. List toList({bool growable = false}) => - new List.from([item1, item2, item3, item4], growable: growable); + List.from([item1, item2, item3, item4], growable: growable); @override String toString() => '[$item1, $item2, $item3, $item4]'; @override - bool operator ==(o) => - o is Tuple4 && - o.item1 == item1 && - o.item2 == item2 && - o.item3 == item3 && - o.item4 == item4; + bool operator ==(other) => + other is Tuple4 && + other.item1 == item1 && + other.item2 == item2 && + other.item3 == item3 && + other.item4 == item4; @override int get hashCode => @@ -221,36 +224,36 @@ /// Create a new tuple value with the specified list [items]. factory Tuple5.fromList(List items) { if (items.length != 5) { - throw new ArgumentError('items must have length 5'); + throw ArgumentError('items must have length 5'); } - return new Tuple5<T1, T2, T3, T4, T5>(items[0] as T1, items[1] as T2, + return Tuple5<T1, T2, T3, T4, T5>(items[0] as T1, items[1] as T2, items[2] as T3, items[3] as T4, items[4] as T5); } /// Returns a tuple with the first item set to the specified value. Tuple5<T1, T2, T3, T4, T5> withItem1(T1 v) { - return new Tuple5<T1, T2, T3, T4, T5>(v, item2, item3, item4, item5); + return Tuple5<T1, T2, T3, T4, T5>(v, item2, item3, item4, item5); } /// Returns a tuple with the second item set to the specified value. Tuple5<T1, T2, T3, T4, T5> withItem2(T2 v) { - return new Tuple5<T1, T2, T3, T4, T5>(item1, v, item3, item4, item5); + return Tuple5<T1, T2, T3, T4, T5>(item1, v, item3, item4, item5); } /// Returns a tuple with the third item set to the specified value. Tuple5<T1, T2, T3, T4, T5> withItem3(T3 v) { - return new Tuple5<T1, T2, T3, T4, T5>(item1, item2, v, item4, item5); + return Tuple5<T1, T2, T3, T4, T5>(item1, item2, v, item4, item5); } /// Returns a tuple with the fourth item set to the specified value. Tuple5<T1, T2, T3, T4, T5> withItem4(T4 v) { - return new Tuple5<T1, T2, T3, T4, T5>(item1, item2, item3, v, item5); + return Tuple5<T1, T2, T3, T4, T5>(item1, item2, item3, v, item5); } /// Returns a tuple with the fifth item set to the specified value. Tuple5<T1, T2, T3, T4, T5> withItem5(T5 v) { - return new Tuple5<T1, T2, T3, T4, T5>(item1, item2, item3, item4, v); + return Tuple5<T1, T2, T3, T4, T5>(item1, item2, item3, item4, v); } /// Creates a [List] containing the items of this [Tuple5]. @@ -258,19 +261,19 @@ /// The elements are in item order. The list is variable-length /// if [growable] is true. List toList({bool growable = false}) => - new List.from([item1, item2, item3, item4, item5], growable: growable); + List.from([item1, item2, item3, item4, item5], growable: growable); @override String toString() => '[$item1, $item2, $item3, $item4, $item5]'; @override - bool operator ==(o) => - o is Tuple5 && - o.item1 == item1 && - o.item2 == item2 && - o.item3 == item3 && - o.item4 == item4 && - o.item5 == item5; + bool operator ==(other) => + other is Tuple5 && + other.item1 == item1 && + other.item2 == item2 && + other.item3 == item3 && + other.item4 == item4 && + other.item5 == item5; @override int get hashCode => hashObjects([ @@ -309,47 +312,41 @@ /// Create a new tuple value with the specified list [items]. factory Tuple6.fromList(List items) { if (items.length != 6) { - throw new ArgumentError('items must have length 6'); + throw ArgumentError('items must have length 6'); } - return new Tuple6<T1, T2, T3, T4, T5, T6>(items[0] as T1, items[1] as T2, + return Tuple6<T1, T2, T3, T4, T5, T6>(items[0] as T1, items[1] as T2, items[2] as T3, items[3] as T4, items[4] as T5, items[5] as T6); } /// Returns a tuple with the first item set to the specified value. Tuple6<T1, T2, T3, T4, T5, T6> withItem1(T1 v) { - return new Tuple6<T1, T2, T3, T4, T5, T6>( - v, item2, item3, item4, item5, item6); + return Tuple6<T1, T2, T3, T4, T5, T6>(v, item2, item3, item4, item5, item6); } /// Returns a tuple with the second item set to the specified value. Tuple6<T1, T2, T3, T4, T5, T6> withItem2(T2 v) { - return new Tuple6<T1, T2, T3, T4, T5, T6>( - item1, v, item3, item4, item5, item6); + return Tuple6<T1, T2, T3, T4, T5, T6>(item1, v, item3, item4, item5, item6); } /// Returns a tuple with the third item set to the specified value. Tuple6<T1, T2, T3, T4, T5, T6> withItem3(T3 v) { - return new Tuple6<T1, T2, T3, T4, T5, T6>( - item1, item2, v, item4, item5, item6); + return Tuple6<T1, T2, T3, T4, T5, T6>(item1, item2, v, item4, item5, item6); } /// Returns a tuple with the fourth item set to the specified value. Tuple6<T1, T2, T3, T4, T5, T6> withItem4(T4 v) { - return new Tuple6<T1, T2, T3, T4, T5, T6>( - item1, item2, item3, v, item5, item6); + return Tuple6<T1, T2, T3, T4, T5, T6>(item1, item2, item3, v, item5, item6); } /// Returns a tuple with the fifth item set to the specified value. Tuple6<T1, T2, T3, T4, T5, T6> withItem5(T5 v) { - return new Tuple6<T1, T2, T3, T4, T5, T6>( - item1, item2, item3, item4, v, item6); + return Tuple6<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, v, item6); } /// Returns a tuple with the sixth item set to the specified value. Tuple6<T1, T2, T3, T4, T5, T6> withItem6(T6 v) { - return new Tuple6<T1, T2, T3, T4, T5, T6>( - item1, item2, item3, item4, item5, v); + return Tuple6<T1, T2, T3, T4, T5, T6>(item1, item2, item3, item4, item5, v); } /// Creates a [List] containing the items of this [Tuple5]. @@ -357,21 +354,20 @@ /// The elements are in item order. The list is variable-length /// if [growable] is true. List toList({bool growable = false}) => - new List.from([item1, item2, item3, item4, item5, item6], - growable: growable); + List.from([item1, item2, item3, item4, item5, item6], growable: growable); @override String toString() => '[$item1, $item2, $item3, $item4, $item5, $item6]'; @override - bool operator ==(o) => - o is Tuple6 && - o.item1 == item1 && - o.item2 == item2 && - o.item3 == item3 && - o.item4 == item4 && - o.item5 == item5 && - o.item6 == item6; + bool operator ==(other) => + other is Tuple6 && + other.item1 == item1 && + other.item2 == item2 && + other.item3 == item3 && + other.item4 == item4 && + other.item5 == item5 && + other.item6 == item6; @override int get hashCode => hashObjects([ @@ -414,10 +410,10 @@ /// Create a new tuple value with the specified list [items]. factory Tuple7.fromList(List items) { if (items.length != 7) { - throw new ArgumentError('items must have length 7'); + throw ArgumentError('items must have length 7'); } - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( items[0] as T1, items[1] as T2, items[2] as T3, @@ -429,43 +425,43 @@ /// Returns a tuple with the first item set to the specified value. Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem1(T1 v) { - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( v, item2, item3, item4, item5, item6, item7); } /// Returns a tuple with the second item set to the specified value. Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem2(T2 v) { - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( item1, v, item3, item4, item5, item6, item7); } /// Returns a tuple with the third item set to the specified value. Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem3(T3 v) { - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( item1, item2, v, item4, item5, item6, item7); } /// Returns a tuple with the fourth item set to the specified value. Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem4(T4 v) { - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( item1, item2, item3, v, item5, item6, item7); } /// Returns a tuple with the fifth item set to the specified value. Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem5(T5 v) { - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( item1, item2, item3, item4, v, item6, item7); } /// Returns a tuple with the sixth item set to the specified value. Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem6(T6 v) { - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( item1, item2, item3, item4, item5, v, item7); } /// Returns a tuple with the seventh item set to the specified value. Tuple7<T1, T2, T3, T4, T5, T6, T7> withItem7(T7 v) { - return new Tuple7<T1, T2, T3, T4, T5, T6, T7>( + return Tuple7<T1, T2, T3, T4, T5, T6, T7>( item1, item2, item3, item4, item5, item6, v); } @@ -473,8 +469,8 @@ /// /// The elements are in item order. The list is variable-length /// if [growable] is true. - List toList({bool growable: false}) => - new List.from([item1, item2, item3, item4, item5, item6, item7], + List toList({bool growable = false}) => + List.from([item1, item2, item3, item4, item5, item6, item7], growable: growable); @override @@ -482,15 +478,15 @@ '[$item1, $item2, $item3, $item4, $item5, $item6, $item7]'; @override - bool operator ==(o) => - o is Tuple7 && - o.item1 == item1 && - o.item2 == item2 && - o.item3 == item3 && - o.item4 == item4 && - o.item5 == item5 && - o.item5 == item6 && - o.item6 == item7; + bool operator ==(other) => + other is Tuple7 && + other.item1 == item1 && + other.item2 == item2 && + other.item3 == item3 && + other.item4 == item4 && + other.item5 == item5 && + other.item5 == item6 && + other.item6 == item7; @override int get hashCode => hashObjects([
diff --git a/pubspec.yaml b/pubspec.yaml index 5113a76..4a58383 100644 --- a/pubspec.yaml +++ b/pubspec.yaml
@@ -15,4 +15,5 @@ quiver: '>=0.22.0 <3.0.0' dev_dependencies: + pedantic: ^1.2.0 test: '>=1.0.0 <2.0.0'
diff --git a/test/all_tests.dart b/test/all_tests.dart deleted file mode 100644 index 6cf9e29..0000000 --- a/test/all_tests.dart +++ /dev/null
@@ -1,11 +0,0 @@ -// Copyright (c) 2015, the tuple project authors. Please see the AUTHORS -// file 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. - -library tuple.test; - -import 'tuple_test.dart' as tuple_test; - -main() { - tuple_test.main(); -}
diff --git a/test/tuple_test.dart b/test/tuple_test.dart index 6381e57..4f9a7ff 100644 --- a/test/tuple_test.dart +++ b/test/tuple_test.dart
@@ -2,67 +2,61 @@ // file 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. -library tuple.test; - import 'package:test/test.dart'; import 'package:tuple/tuple.dart'; -main() { - group("Tuple tests", () { - final t = new Tuple2<int, bool>(1, true); +void main() { + final t = Tuple2<int, bool>(1, true); - test('items', () { - expect(t.item1, equals(1)); - expect(t.item2, equals(true)); - }); + test('items', () { + expect(t.item1, equals(1)); + expect(t.item2, equals(true)); + }); - test('withItems', () { - expect(t.withItem1(2), equals(new Tuple2<int, bool>(2, true))); - expect(t.withItem2(false), equals(new Tuple2<int, bool>(1, false))); - }); + test('withItems', () { + expect(t.withItem1(2), equals(Tuple2<int, bool>(2, true))); + expect(t.withItem2(false), equals(Tuple2<int, bool>(1, false))); + }); - test('create a tuple from a list of items', () { - final t1 = new Tuple2.fromList([1, true]); - expect(t1.item1, equals(1)); - expect(t1.item2, equals(true)); + test('create a tuple from a list of items', () { + final t1 = Tuple2.fromList([1, true]); + expect(t1.item1, equals(1)); + expect(t1.item2, equals(true)); - expect(() => new Tuple2.fromList([1]), - throwsA(new TypeMatcher<ArgumentError>())); - expect(() => new Tuple2.fromList([1, true, 'a']), - throwsA(new TypeMatcher<ArgumentError>())); - }); + expect(() => Tuple2.fromList([1]), throwsA(TypeMatcher<ArgumentError>())); + expect(() => Tuple2.fromList([1, true, 'a']), + throwsA(TypeMatcher<ArgumentError>())); + }); - test('equality', () { - final otherT = new Tuple2<int, bool>(1, true); - expect(t, equals(otherT)); - }); + test('equality', () { + final otherT = Tuple2<int, bool>(1, true); + expect(t, equals(otherT)); + }); - test('nested equality', () { - final t1 = new Tuple2<Tuple2<int, String>, bool>( - new Tuple2<int, String>(3, 'a'), false); - final t2 = new Tuple2<Tuple2<int, String>, bool>( - new Tuple2<int, String>(3, 'a'), false); - expect(t1, equals(t2)); - }); + test('nested equality', () { + final t1 = + Tuple2<Tuple2<int, String>, bool>(Tuple2<int, String>(3, 'a'), false); + final t2 = + Tuple2<Tuple2<int, String>, bool>(Tuple2<int, String>(3, 'a'), false); + expect(t1, equals(t2)); + }); - test('can be used as keys in maps', () { - final map = {t: 'a'}; - final key = new Tuple2<int, bool>(1, true); - expect(map[key], equals('a')); - }); + test('can be used as keys in maps', () { + final map = {t: 'a'}; + final key = Tuple2<int, bool>(1, true); + expect(map[key], equals('a')); + }); - test('toList() should return a listing containing the items of the tuple', - () { - expect(t.toList(), orderedEquals([1, true])); - }); + test('toList() should return a listing containing the items of the tuple', + () { + expect(t.toList(), orderedEquals([1, true])); + }); - test('toList() should return a fixed list by default', () { - expect(() => t.toList().add(3), - throwsA(new TypeMatcher<UnsupportedError>())); - }); + test('toList() should return a fixed list by default', () { + expect(() => t.toList().add(3), throwsA(TypeMatcher<UnsupportedError>())); + }); - test('toList(growable: true) should return a growable list', () { - expect(t.toList(growable: true)..add('a'), orderedEquals([1, true, 'a'])); - }); + test('toList(growable: true) should return a growable list', () { + expect(t.toList(growable: true)..add('a'), orderedEquals([1, true, 'a'])); }); }