Enable and fix a number of additional lints
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 246b080..124a642 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -14,15 +14,17 @@
- 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_shadowing_type_parameters
- 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
@@ -41,10 +43,11 @@
- 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_api_docs
- package_names
- package_prefixed_library_names
- prefer_adjacent_string_concatenation
@@ -67,10 +70,14 @@
- 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
diff --git a/lib/mirror_matchers.dart b/lib/mirror_matchers.dart
index eb2225a..24a2201 100644
--- a/lib/mirror_matchers.dart
+++ b/lib/mirror_matchers.dart
@@ -12,7 +12,7 @@
/// with name [name], and optionally, if that property in turn satisfies
/// a [matcher].
Matcher hasProperty(String name, [matcher]) =>
- new _HasProperty(name, matcher == null ? null : wrapMatcher(matcher));
+ _HasProperty(name, matcher == null ? null : wrapMatcher(matcher));
class _HasProperty extends Matcher {
final String _name;
@@ -23,7 +23,7 @@
bool matches(item, Map matchState) {
var mirror = reflect(item);
var classMirror = mirror.type;
- var symbol = new Symbol(_name);
+ var symbol = Symbol(_name);
var candidate = classMirror.declarations[symbol];
if (candidate == null) {
addStateInfo(matchState, {'reason': 'has no property named "$_name"'});
@@ -65,7 +65,7 @@
mismatchDescription
.add('has property "$_name" with value ')
.addDescriptionOf(matchState['value']);
- var innerDescription = new StringDescription();
+ var innerDescription = StringDescription();
_matcher.describeMismatch(matchState['value'], innerDescription,
matchState['state'] as Map, verbose);
if (innerDescription.length > 0) {
diff --git a/lib/src/core_matchers.dart b/lib/src/core_matchers.dart
index 86bb1db..7d9da1c 100644
--- a/lib/src/core_matchers.dart
+++ b/lib/src/core_matchers.dart
@@ -8,7 +8,7 @@
import 'util.dart';
/// Returns a matcher that matches the isEmpty property.
-const Matcher isEmpty = const _Empty();
+const Matcher isEmpty = _Empty();
class _Empty extends Matcher {
const _Empty();
@@ -19,7 +19,7 @@
}
/// Returns a matcher that matches the isNotEmpty property.
-const Matcher isNotEmpty = const _NotEmpty();
+const Matcher isNotEmpty = _NotEmpty();
class _NotEmpty extends Matcher {
const _NotEmpty();
@@ -30,10 +30,10 @@
}
/// A matcher that matches any null value.
-const Matcher isNull = const _IsNull();
+const Matcher isNull = _IsNull();
/// A matcher that matches any non-null value.
-const Matcher isNotNull = const _IsNotNull();
+const Matcher isNotNull = _IsNotNull();
class _IsNull extends Matcher {
const _IsNull();
@@ -48,10 +48,10 @@
}
/// A matcher that matches the Boolean value true.
-const Matcher isTrue = const _IsTrue();
+const Matcher isTrue = _IsTrue();
/// A matcher that matches anything except the Boolean value true.
-const Matcher isFalse = const _IsFalse();
+const Matcher isFalse = _IsFalse();
class _IsTrue extends Matcher {
const _IsTrue();
@@ -66,10 +66,10 @@
}
/// A matcher that matches the numeric value NaN.
-const Matcher isNaN = const _IsNaN();
+const Matcher isNaN = _IsNaN();
/// A matcher that matches any non-NaN value.
-const Matcher isNotNaN = const _IsNotNaN();
+const Matcher isNotNaN = _IsNotNaN();
class _IsNaN extends FeatureMatcher<num> {
const _IsNaN();
@@ -87,7 +87,7 @@
/// Returns a matches that matches if the value is the same instance
/// as [expected], using [identical].
-Matcher same(expected) => new _IsSameAs(expected);
+Matcher same(expected) => _IsSameAs(expected);
class _IsSameAs extends Matcher {
final Object _expected;
@@ -99,7 +99,7 @@
}
/// A matcher that matches any value.
-const Matcher anything = const _IsAnything();
+const Matcher anything = _IsAnything();
class _IsAnything extends Matcher {
const _IsAnything();
@@ -123,7 +123,7 @@
/// The value passed to expect() should be a reference to the function.
/// Note that the function cannot take arguments; to handle this
/// a wrapper will have to be created.
-const Matcher returnsNormally = const _ReturnsNormally();
+const Matcher returnsNormally = _ReturnsNormally();
class _ReturnsNormally extends FeatureMatcher<Function> {
const _ReturnsNormally();
@@ -152,14 +152,14 @@
}
/// A matcher for [Map].
-const isMap = const TypeMatcher<Map>();
+const isMap = TypeMatcher<Map>();
/// A matcher for [List].
-const isList = const TypeMatcher<List>();
+const isList = TypeMatcher<List>();
/// Returns a matcher that matches if an object has a length property
/// that matches [matcher].
-Matcher hasLength(matcher) => new _HasLength(wrapMatcher(matcher));
+Matcher hasLength(matcher) => _HasLength(wrapMatcher(matcher));
class _HasLength extends Matcher {
final Matcher _matcher;
@@ -175,7 +175,7 @@
} catch (e) {
return false;
}
- throw new UnsupportedError('Should never get here');
+ throw UnsupportedError('Should never get here');
}
Description describe(Description description) =>
@@ -194,7 +194,7 @@
} catch (e) {
return mismatchDescription.add('has no length property');
}
- throw new UnsupportedError('Should never get here');
+ throw UnsupportedError('Should never get here');
}
}
@@ -205,7 +205,7 @@
/// for [Map]s it means the map has the key, and for [Iterable]s
/// it means the iterable has a matching element. In the case of iterables,
/// [expected] can itself be a matcher.
-Matcher contains(expected) => new _Contains(expected);
+Matcher contains(expected) => _Contains(expected);
class _Contains extends Matcher {
final Object _expected;
@@ -246,14 +246,14 @@
/// the expected value. This is the converse of [contains].
Matcher isIn(expected) {
if (expected is Iterable) {
- return new _In(expected, expected.contains);
+ return _In(expected, expected.contains);
} else if (expected is String) {
- return new _In<Pattern>(expected, expected.contains);
+ return _In<Pattern>(expected, expected.contains);
} else if (expected is Map) {
- return new _In(expected, expected.containsKey);
+ return _In(expected, expected.containsKey);
}
- throw new ArgumentError.value(
+ throw ArgumentError.value(
expected, 'expected', 'Only Iterable, Map, and String are supported.');
}
@@ -277,9 +277,9 @@
/// expect(v, predicate((x) => ((x % 2) == 0), "is even"))
Matcher predicate<T>(bool f(T value),
[String description = 'satisfies function']) =>
- new _Predicate(f, description);
+ _Predicate(f, description);
-typedef bool _PredicateFunction<T>(T value);
+typedef _PredicateFunction<T> = bool Function(T value);
class _Predicate<T> extends FeatureMatcher<T> {
final _PredicateFunction<T> _matcher;
diff --git a/lib/src/custom_matcher.dart b/lib/src/custom_matcher.dart
index c3c7270..35c4d7e 100644
--- a/lib/src/custom_matcher.dart
+++ b/lib/src/custom_matcher.dart
@@ -49,7 +49,7 @@
} catch (exception, stack) {
addStateInfo(matchState, {
'custom.exception': exception.toString(),
- 'custom.stack': new Chain.forTrace(stack)
+ 'custom.stack': Chain.forTrace(stack)
.foldFrames(
(frame) =>
frame.package == 'test' ||
@@ -81,7 +81,7 @@
.add(_featureName)
.add(' with value ')
.addDescriptionOf(matchState['custom.feature']);
- var innerDescription = new StringDescription();
+ var innerDescription = StringDescription();
_matcher.describeMismatch(matchState['custom.feature'], innerDescription,
matchState['state'] as Map, verbose);
diff --git a/lib/src/description.dart b/lib/src/description.dart
index 17c5ad4..300798b 100644
--- a/lib/src/description.dart
+++ b/lib/src/description.dart
@@ -9,7 +9,7 @@
/// substitution, although conceivably it is a place where other languages
/// could be supported.
class StringDescription implements Description {
- final StringBuffer _out = new StringBuffer();
+ final StringBuffer _out = StringBuffer();
/// Initialize the description with initial contents [init].
StringDescription([String init = '']) {
diff --git a/lib/src/equals_matcher.dart b/lib/src/equals_matcher.dart
index 52f6688..9798d96 100644
--- a/lib/src/equals_matcher.dart
+++ b/lib/src/equals_matcher.dart
@@ -17,8 +17,8 @@
/// handle cyclic structures a recursion depth [limit] can be provided. The
/// default limit is 100. [Set]s will be compared order-independently.
Matcher equals(expected, [int limit = 100]) => expected is String
- ? new _StringEqualsMatcher(expected)
- : new _DeepMatcher(expected, limit);
+ ? _StringEqualsMatcher(expected)
+ : _DeepMatcher(expected, limit);
typedef _RecursiveMatcher = List<String> Function(
dynamic, dynamic, String, int);
@@ -36,7 +36,7 @@
Description describeTypedMismatch(String item,
Description mismatchDescription, Map matchState, bool verbose) {
- var buff = new StringBuffer();
+ var buff = StringBuffer();
buff.write('is different.');
var escapedItem = escape(item);
var escapedValue = escape(_value);
@@ -67,7 +67,7 @@
_writeLeading(buff, escapedItem, start);
_writeTrailing(buff, escapedItem, start);
buff.write('\n ');
- for (var i = (start > 10 ? 14 : start); i > 0; i--) buff.write(' ');
+ for (var i = start > 10 ? 14 : start; i > 0; i--) buff.write(' ');
buff.write('^\n Differ at offset $start');
}
@@ -159,7 +159,7 @@
var matchState = {};
if (expected.matches(actual, matchState)) return null;
- var description = new StringDescription();
+ var description = StringDescription();
expected.describe(description);
return ['does not match $description', location];
} else {
@@ -184,7 +184,7 @@
expected, actual, _recursiveMatch, depth + 1, location);
} else if (expected is Map) {
if (actual is! Map) return ['expected a map', location];
- var map = (actual as Map);
+ var map = actual as Map;
var err =
(expected.length == map.length) ? '' : 'has different length and ';
for (var key in expected.keys) {
@@ -209,7 +209,7 @@
}
}
- var description = new StringDescription();
+ var description = StringDescription();
// If we have recursed, show the expected value too; if not, expect() will
// show it for us.
diff --git a/lib/src/error_matchers.dart b/lib/src/error_matchers.dart
index eaa8182..5116975 100644
--- a/lib/src/error_matchers.dart
+++ b/lib/src/error_matchers.dart
@@ -5,39 +5,38 @@
import 'type_matcher.dart';
/// A matcher for [ArgumentError].
-const isArgumentError = const TypeMatcher<ArgumentError>();
+const isArgumentError = TypeMatcher<ArgumentError>();
/// A matcher for [CastError].
-const isCastError = const TypeMatcher<CastError>();
+const isCastError = TypeMatcher<CastError>();
/// A matcher for [ConcurrentModificationError].
const isConcurrentModificationError =
- const TypeMatcher<ConcurrentModificationError>();
+ TypeMatcher<ConcurrentModificationError>();
/// A matcher for [CyclicInitializationError].
-const isCyclicInitializationError =
- const TypeMatcher<CyclicInitializationError>();
+const isCyclicInitializationError = TypeMatcher<CyclicInitializationError>();
/// A matcher for [Exception].
-const isException = const TypeMatcher<Exception>();
+const isException = TypeMatcher<Exception>();
/// A matcher for [FormatException].
-const isFormatException = const TypeMatcher<FormatException>();
+const isFormatException = TypeMatcher<FormatException>();
/// A matcher for [NoSuchMethodError].
-const isNoSuchMethodError = const TypeMatcher<NoSuchMethodError>();
+const isNoSuchMethodError = TypeMatcher<NoSuchMethodError>();
/// A matcher for [NullThrownError].
-const isNullThrownError = const TypeMatcher<NullThrownError>();
+const isNullThrownError = TypeMatcher<NullThrownError>();
/// A matcher for [RangeError].
-const isRangeError = const TypeMatcher<RangeError>();
+const isRangeError = TypeMatcher<RangeError>();
/// A matcher for [StateError].
-const isStateError = const TypeMatcher<StateError>();
+const isStateError = TypeMatcher<StateError>();
/// A matcher for [UnimplementedError].
-const isUnimplementedError = const TypeMatcher<UnimplementedError>();
+const isUnimplementedError = TypeMatcher<UnimplementedError>();
/// A matcher for [UnsupportedError].
-const isUnsupportedError = const TypeMatcher<UnsupportedError>();
+const isUnsupportedError = TypeMatcher<UnsupportedError>();
diff --git a/lib/src/having_matcher.dart b/lib/src/having_matcher.dart
index 8ca98c6..259ffa7 100644
--- a/lib/src/having_matcher.dart
+++ b/lib/src/having_matcher.dart
@@ -19,12 +19,11 @@
: _parent = parent,
_functionMatchers = <_FunctionMatcher>[]
..addAll(existing ?? [])
- ..add(new _FunctionMatcher<T>(description, feature, matcher));
+ ..add(_FunctionMatcher<T>(description, feature, matcher));
TypeMatcher<T> having(
Object feature(T source), String description, Object matcher) =>
- new HavingMatcher(
- _parent, description, feature, matcher, _functionMatchers);
+ HavingMatcher(_parent, description, feature, matcher, _functionMatchers);
bool matches(item, Map matchState) {
for (var matcher in <Matcher>[_parent].followedBy(_functionMatchers)) {
diff --git a/lib/src/iterable_matchers.dart b/lib/src/iterable_matchers.dart
index 02c41aa..4884b4e 100644
--- a/lib/src/iterable_matchers.dart
+++ b/lib/src/iterable_matchers.dart
@@ -10,7 +10,7 @@
/// Returns a matcher which matches [Iterable]s in which all elements
/// match the given [matcher].
-Matcher everyElement(matcher) => new _EveryElement(wrapMatcher(matcher));
+Matcher everyElement(matcher) => _EveryElement(wrapMatcher(matcher));
class _EveryElement extends _IterableMatcher {
final Matcher _matcher;
@@ -41,7 +41,7 @@
.add('has value ')
.addDescriptionOf(element)
.add(' which ');
- var subDescription = new StringDescription();
+ var subDescription = StringDescription();
_matcher.describeMismatch(
element, subDescription, matchState['state'] as Map, verbose);
if (subDescription.length > 0) {
@@ -60,7 +60,7 @@
/// Returns a matcher which matches [Iterable]s in which at least one
/// element matches the given [matcher].
-Matcher anyElement(matcher) => new _AnyElement(wrapMatcher(matcher));
+Matcher anyElement(matcher) => _AnyElement(wrapMatcher(matcher));
class _AnyElement extends _IterableMatcher {
final Matcher _matcher;
@@ -78,7 +78,7 @@
/// length and the same elements as [expected], in the same order.
///
/// This is equivalent to [equals] but does not recurse.
-Matcher orderedEquals(Iterable expected) => new _OrderedEquals(expected);
+Matcher orderedEquals(Iterable expected) => _OrderedEquals(expected);
class _OrderedEquals extends _IterableMatcher {
final Iterable _expected;
@@ -104,7 +104,7 @@
///
/// Note that this is worst case O(n^2) runtime and memory usage so it should
/// only be used on small iterables.
-Matcher unorderedEquals(Iterable expected) => new _UnorderedEquals(expected);
+Matcher unorderedEquals(Iterable expected) => _UnorderedEquals(expected);
class _UnorderedEquals extends _UnorderedMatches {
final List _expectedValues;
@@ -130,7 +130,7 @@
///
/// Note that this is worst case O(n^2) runtime and memory usage so it should
/// only be used on small iterables.
-Matcher unorderedMatches(Iterable expected) => new _UnorderedMatches(expected);
+Matcher unorderedMatches(Iterable expected) => _UnorderedMatches(expected);
class _UnorderedMatches extends _IterableMatcher {
final List<Matcher> _expected;
@@ -148,8 +148,7 @@
return 'has too many elements (${values.length} > ${_expected.length})';
}
- var edges =
- new List.generate(values.length, (_) => <int>[], growable: false);
+ var edges = List.generate(values.length, (_) => <int>[], growable: false);
for (var v = 0; v < values.length; v++) {
for (var m = 0; m < _expected.length; m++) {
if (_expected[m].matches(values[v], {})) {
@@ -159,7 +158,7 @@
}
// The index into `values` matched with each matcher or `null` if no value
// has been matched yet.
- var matched = new List<int>(_expected.length);
+ var matched = List<int>(_expected.length);
for (var valueIndex = 0; valueIndex < values.length; valueIndex++) {
_findPairing(edges, valueIndex, matched);
}
@@ -167,7 +166,7 @@
matcherIndex < _expected.length;
matcherIndex++) {
if (matched[matcherIndex] == null) {
- final description = new StringDescription()
+ final description = StringDescription()
.add('has no match for ')
.addDescriptionOf(_expected[matcherIndex])
.add(' at index $matcherIndex');
@@ -203,7 +202,7 @@
/// tracks the matchers that have been used _during_ this search.
bool _findPairing(List<List<int>> edges, int valueIndex, List<int> matched,
[Set<int> reserved]) {
- reserved ??= new Set<int>();
+ reserved ??= Set<int>();
final possiblePairings =
edges[valueIndex].where((m) => !reserved.contains(m));
for (final matcherIndex in possiblePairings) {
@@ -228,9 +227,9 @@
/// [description] should be a meaningful name for the comparator.
Matcher pairwiseCompare<S, T>(
Iterable<S> expected, bool comparator(S a, T b), String description) =>
- new _PairwiseCompare(expected, comparator, description);
+ _PairwiseCompare(expected, comparator, description);
-typedef bool _Comparator<S, T>(S a, T b);
+typedef _Comparator<S, T> = bool Function(S a, T b);
class _PairwiseCompare<S, T> extends _IterableMatcher {
final Iterable<S> _expected;
@@ -291,7 +290,7 @@
///
/// Note that this is worst case O(n^2) runtime and memory usage so it should
/// only be used on small iterables.
-Matcher containsAll(Iterable expected) => new _ContainsAll(expected);
+Matcher containsAll(Iterable expected) => _ContainsAll(expected);
class _ContainsAll extends _UnorderedMatches {
final Iterable _unwrappedExpected;
@@ -312,8 +311,7 @@
/// `containsAllInOrder([2, 1])` or `containsAllInOrder([1, 2, 3])`.
///
/// Will only match values which implement [Iterable].
-Matcher containsAllInOrder(Iterable expected) =>
- new _ContainsAllInOrder(expected);
+Matcher containsAllInOrder(Iterable expected) => _ContainsAllInOrder(expected);
class _ContainsAllInOrder extends _IterableMatcher {
final Iterable _expected;
@@ -327,7 +325,7 @@
if (matchers[matcherIndex].matches(value, matchState)) matcherIndex++;
if (matcherIndex == matchers.length) return null;
}
- return new StringDescription()
+ return StringDescription()
.add('did not find a value matching ')
.addDescriptionOf(matchers[matcherIndex])
.add(' following expected prior values')
diff --git a/lib/src/map_matchers.dart b/lib/src/map_matchers.dart
index 9825c9b..8671323 100644
--- a/lib/src/map_matchers.dart
+++ b/lib/src/map_matchers.dart
@@ -6,7 +6,7 @@
import 'util.dart';
/// Returns a matcher which matches maps containing the given [value].
-Matcher containsValue(value) => new _ContainsValue(value);
+Matcher containsValue(value) => _ContainsValue(value);
class _ContainsValue extends Matcher {
final Object _value;
@@ -20,8 +20,7 @@
/// Returns a matcher which matches maps containing the key-value pair
/// with [key] => [value].
-Matcher containsPair(key, value) =>
- new _ContainsMapping(key, wrapMatcher(value));
+Matcher containsPair(key, value) => _ContainsMapping(key, wrapMatcher(value));
class _ContainsMapping extends Matcher {
final Object _key;
diff --git a/lib/src/numeric_matchers.dart b/lib/src/numeric_matchers.dart
index 4187078..0497849 100644
--- a/lib/src/numeric_matchers.dart
+++ b/lib/src/numeric_matchers.dart
@@ -10,7 +10,7 @@
///
/// In other words, this matches if the match argument is greater than
/// than or equal [value]-[delta] and less than or equal to [value]+[delta].
-Matcher closeTo(num value, num delta) => new _IsCloseTo(value, delta);
+Matcher closeTo(num value, num delta) => _IsCloseTo(value, delta);
class _IsCloseTo extends FeatureMatcher<num> {
final num _value, _delta;
@@ -20,7 +20,7 @@
bool typedMatches(item, Map matchState) {
var diff = item - _value;
if (diff < 0) diff = -diff;
- return (diff <= _delta);
+ return diff <= _delta;
}
Description describe(Description description) => description
@@ -39,23 +39,22 @@
/// Returns a matcher which matches if the match argument is greater
/// than or equal to [low] and less than or equal to [high].
-Matcher inInclusiveRange(num low, num high) =>
- new _InRange(low, high, true, true);
+Matcher inInclusiveRange(num low, num high) => _InRange(low, high, true, true);
/// Returns a matcher which matches if the match argument is greater
/// than [low] and less than [high].
Matcher inExclusiveRange(num low, num high) =>
- new _InRange(low, high, false, false);
+ _InRange(low, high, false, false);
/// Returns a matcher which matches if the match argument is greater
/// than [low] and less than or equal to [high].
Matcher inOpenClosedRange(num low, num high) =>
- new _InRange(low, high, false, true);
+ _InRange(low, high, false, true);
/// Returns a matcher which matches if the match argument is greater
/// than or equal to a [low] and less than [high].
Matcher inClosedOpenRange(num low, num high) =>
- new _InRange(low, high, true, false);
+ _InRange(low, high, true, false);
class _InRange extends FeatureMatcher<num> {
final num _low, _high;
diff --git a/lib/src/operator_matchers.dart b/lib/src/operator_matchers.dart
index 827fbf1..77ed0c6 100644
--- a/lib/src/operator_matchers.dart
+++ b/lib/src/operator_matchers.dart
@@ -6,7 +6,7 @@
import 'util.dart';
/// This returns a matcher that inverts [matcher] to its logical negation.
-Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher));
+Matcher isNot(matcher) => _IsNot(wrapMatcher(matcher));
class _IsNot extends Matcher {
final Matcher _matcher;
@@ -26,7 +26,7 @@
/// List argument. Any argument that is not a matcher is implicitly wrapped in a
/// Matcher to check for equality.
Matcher allOf(arg0, [arg1, arg2, arg3, arg4, arg5, arg6]) {
- return new _AllOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6));
+ return _AllOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6));
}
class _AllOf extends Matcher {
@@ -67,7 +67,7 @@
/// Any argument that is not a matcher is implicitly wrapped in a
/// Matcher to check for equality.
Matcher anyOf(arg0, [arg1, arg2, arg3, arg4, arg5, arg6]) {
- return new _AnyOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6));
+ return _AnyOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6));
}
class _AnyOf extends Matcher {
@@ -97,7 +97,7 @@
arg4 != null ||
arg5 != null ||
arg6 != null) {
- throw new ArgumentError('If arg0 is a List, all other arguments must be'
+ throw ArgumentError('If arg0 is a List, all other arguments must be'
' null.');
}
diff --git a/lib/src/order_matchers.dart b/lib/src/order_matchers.dart
index a62ffb9..80bc2d5 100644
--- a/lib/src/order_matchers.dart
+++ b/lib/src/order_matchers.dart
@@ -7,46 +7,46 @@
/// Returns a matcher which matches if the match argument is greater
/// than the given [value].
Matcher greaterThan(value) =>
- new _OrderingMatcher(value, false, false, true, 'a value greater than');
+ _OrderingMatcher(value, false, false, true, 'a value greater than');
/// Returns a matcher which matches if the match argument is greater
/// than or equal to the given [value].
-Matcher greaterThanOrEqualTo(value) => new _OrderingMatcher(
+Matcher greaterThanOrEqualTo(value) => _OrderingMatcher(
value, true, false, true, 'a value greater than or equal to');
/// Returns a matcher which matches if the match argument is less
/// than the given [value].
Matcher lessThan(value) =>
- new _OrderingMatcher(value, false, true, false, 'a value less than');
+ _OrderingMatcher(value, false, true, false, 'a value less than');
/// Returns a matcher which matches if the match argument is less
/// than or equal to the given [value].
-Matcher lessThanOrEqualTo(value) => new _OrderingMatcher(
- value, true, true, false, 'a value less than or equal to');
+Matcher lessThanOrEqualTo(value) =>
+ _OrderingMatcher(value, true, true, false, 'a value less than or equal to');
/// A matcher which matches if the match argument is zero.
const Matcher isZero =
- const _OrderingMatcher(0, true, false, false, 'a value equal to');
+ _OrderingMatcher(0, true, false, false, 'a value equal to');
/// A matcher which matches if the match argument is non-zero.
const Matcher isNonZero =
- const _OrderingMatcher(0, false, true, true, 'a value not equal to');
+ _OrderingMatcher(0, false, true, true, 'a value not equal to');
/// A matcher which matches if the match argument is positive.
const Matcher isPositive =
- const _OrderingMatcher(0, false, false, true, 'a positive value', false);
+ _OrderingMatcher(0, false, false, true, 'a positive value', false);
/// A matcher which matches if the match argument is zero or negative.
const Matcher isNonPositive =
- const _OrderingMatcher(0, true, true, false, 'a non-positive value', false);
+ _OrderingMatcher(0, true, true, false, 'a non-positive value', false);
/// A matcher which matches if the match argument is negative.
const Matcher isNegative =
- const _OrderingMatcher(0, false, true, false, 'a negative value', false);
+ _OrderingMatcher(0, false, true, false, 'a negative value', false);
/// A matcher which matches if the match argument is zero or positive.
const Matcher isNonNegative =
- const _OrderingMatcher(0, true, false, true, 'a non-negative value', false);
+ _OrderingMatcher(0, true, false, true, 'a non-negative value', false);
// TODO(kevmoo) Note that matchers that use _OrderingComparison only use
// `==` and `<` operators to evaluate the match. Or change the matcher.
diff --git a/lib/src/pretty_print.dart b/lib/src/pretty_print.dart
index 1cbe139..71941b8 100644
--- a/lib/src/pretty_print.dart
+++ b/lib/src/pretty_print.dart
@@ -19,14 +19,14 @@
String _prettyPrint(object, int indent, Set seen, bool top) {
// If the object is a matcher, use its description.
if (object is Matcher) {
- var description = new StringDescription();
+ var description = StringDescription();
object.describe(description);
return "<$description>";
}
// Avoid looping infinitely on recursively-nested data structures.
if (seen.contains(object)) return "(recursive)";
- seen = seen.union(new Set.from([object]));
+ seen = seen.union(Set.from([object]));
String pp(child) => _prettyPrint(child, indent + 2, seen, false);
if (object is Iterable) {
@@ -113,10 +113,10 @@
}
}
- return _prettyPrint(object, 0, new Set(), true);
+ return _prettyPrint(object, 0, Set(), true);
}
-String _indent(int length) => new List.filled(length, ' ').join('');
+String _indent(int length) => List.filled(length, ' ').join('');
/// Returns the name of the type of [x], or "Unknown" if the type name can't be
/// determined.
diff --git a/lib/src/string_matchers.dart b/lib/src/string_matchers.dart
index 47703c3..1d9f1f8 100644
--- a/lib/src/string_matchers.dart
+++ b/lib/src/string_matchers.dart
@@ -7,7 +7,7 @@
/// Returns a matcher which matches if the match argument is a string and
/// is equal to [value] when compared case-insensitively.
-Matcher equalsIgnoringCase(String value) => new _IsEqualIgnoringCase(value);
+Matcher equalsIgnoringCase(String value) => _IsEqualIgnoringCase(value);
class _IsEqualIgnoringCase extends FeatureMatcher<String> {
final String _value;
@@ -42,7 +42,7 @@
/// expect("helloworld", equalsIgnoringWhitespace("hello world"));
/// expect("he llo world", equalsIgnoringWhitespace("hello world"));
Matcher equalsIgnoringWhitespace(String value) =>
- new _IsEqualIgnoringWhitespace(value);
+ _IsEqualIgnoringWhitespace(value);
class _IsEqualIgnoringWhitespace extends FeatureMatcher<String> {
final String _value;
@@ -69,7 +69,7 @@
/// Returns a matcher that matches if the match argument is a string and
/// starts with [prefixString].
-Matcher startsWith(String prefixString) => new _StringStartsWith(prefixString);
+Matcher startsWith(String prefixString) => _StringStartsWith(prefixString);
class _StringStartsWith extends FeatureMatcher<String> {
final String _prefix;
@@ -84,7 +84,7 @@
/// Returns a matcher that matches if the match argument is a string and
/// ends with [suffixString].
-Matcher endsWith(String suffixString) => new _StringEndsWith(suffixString);
+Matcher endsWith(String suffixString) => _StringEndsWith(suffixString);
class _StringEndsWith extends FeatureMatcher<String> {
final String _suffix;
@@ -104,7 +104,7 @@
/// "abcdefghijklmnopqrstuvwxyz".
Matcher stringContainsInOrder(List<String> substrings) =>
- new _StringContainsInOrder(substrings);
+ _StringContainsInOrder(substrings);
class _StringContainsInOrder extends FeatureMatcher<String> {
final List<String> _substrings;
@@ -129,18 +129,18 @@
///
/// [re] can be a [RegExp] instance or a [String]; in the latter case it will be
/// used to create a RegExp instance.
-Matcher matches(re) => new _MatchesRegExp(re);
+Matcher matches(re) => _MatchesRegExp(re);
class _MatchesRegExp extends FeatureMatcher<String> {
RegExp _regexp;
_MatchesRegExp(re) {
if (re is String) {
- _regexp = new RegExp(re);
+ _regexp = RegExp(re);
} else if (re is RegExp) {
_regexp = re;
} else {
- throw new ArgumentError('matches requires a regexp or string');
+ throw ArgumentError('matches requires a regexp or string');
}
}
@@ -153,7 +153,7 @@
/// Utility function to collapse whitespace runs to single spaces
/// and strip leading/trailing whitespace.
String collapseWhitespace(String string) {
- var result = new StringBuffer();
+ var result = StringBuffer();
var skipSpace = true;
for (var i = 0; i < string.length; i++) {
var character = string[i];
diff --git a/lib/src/type_matcher.dart b/lib/src/type_matcher.dart
index 1f2db26..885b3ae 100644
--- a/lib/src/type_matcher.dart
+++ b/lib/src/type_matcher.dart
@@ -67,7 +67,7 @@
/// ```
TypeMatcher<T> having(
Object feature(T source), String description, Object matcher) =>
- new HavingMatcher(this, description, feature, matcher);
+ HavingMatcher(this, description, feature, matcher);
Description describe(Description description) {
var name = _name ?? _stripDynamic(T);
@@ -77,7 +77,7 @@
bool matches(Object item, Map matchState) => item is T;
}
-final _dart2DynamicArgs = new RegExp('<dynamic(, dynamic)*>');
+final _dart2DynamicArgs = RegExp('<dynamic(, dynamic)*>');
/// With this expression `{}.runtimeType.toString`,
/// Dart 1: "<Instance of Map>
diff --git a/lib/src/util.dart b/lib/src/util.dart
index 1df39ef..6c52b42 100644
--- a/lib/src/util.dart
+++ b/lib/src/util.dart
@@ -6,10 +6,10 @@
import 'equals_matcher.dart';
import 'interfaces.dart';
-typedef bool _Predicate<T>(T value);
+typedef _Predicate<T> = bool Function(T value);
/// A [Map] between whitespace characters and their escape sequences.
-const _escapeMap = const {
+const _escapeMap = {
'\n': r'\n',
'\r': r'\r',
'\f': r'\f',
@@ -20,12 +20,12 @@
};
/// A [RegExp] that matches whitespace characters that should be escaped.
-final _escapeRegExp = new RegExp(
+final _escapeRegExp = RegExp(
"[\\x00-\\x07\\x0E-\\x1F${_escapeMap.keys.map(_getHexLiteral).join()}]");
/// Useful utility for nesting match states.
void addStateInfo(Map matchState, Map values) {
- var innerState = new Map.from(matchState);
+ var innerState = Map.from(matchState);
matchState.clear();
matchState['state'] = innerState;
matchState.addAll(values);
diff --git a/pubspec.yaml b/pubspec.yaml
index 7c598b9..227d852 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,12 +1,12 @@
name: matcher
-version: 0.12.4
+version: 0.12.5-dev
description: Support for specifying test expectations
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/matcher
environment:
- sdk: '>=2.0.0-dev.17.0 <3.0.0'
+ sdk: '>=2.0.0 <3.0.0'
dependencies:
stack_trace: ^1.2.0
diff --git a/test/custom_matcher_test.dart b/test/custom_matcher_test.dart
index 537679c..e8cd22c 100644
--- a/test/custom_matcher_test.dart
+++ b/test/custom_matcher_test.dart
@@ -9,7 +9,7 @@
class _BadCustomMatcher extends CustomMatcher {
_BadCustomMatcher() : super("feature", "description", {1: "a"});
- Object featureValueOf(actual) => throw new Exception("bang");
+ Object featureValueOf(actual) => throw Exception("bang");
}
class _HasPrice extends CustomMatcher {
@@ -19,13 +19,13 @@
void main() {
test("Feature Matcher", () {
- var w = new Widget();
+ var w = Widget();
w.price = 10;
- shouldPass(w, new _HasPrice(10));
- shouldPass(w, new _HasPrice(greaterThan(0)));
+ shouldPass(w, _HasPrice(10));
+ shouldPass(w, _HasPrice(greaterThan(0)));
shouldFail(
w,
- new _HasPrice(greaterThan(10)),
+ _HasPrice(greaterThan(10)),
"Expected: Widget with a price that is a value greater than <10> "
"Actual: <Instance of 'Widget'> "
"Which: has price with value <10> which is not "
@@ -35,7 +35,7 @@
test("Custom Matcher Exception", () {
shouldFail(
"a",
- new _BadCustomMatcher(),
+ _BadCustomMatcher(),
allOf([
contains("Expected: feature {1: 'a'} "),
contains("Actual: 'a' "),
diff --git a/test/having_test.dart b/test/having_test.dart
index 31cf7ac..cc0f20a 100644
--- a/test/having_test.dart
+++ b/test/having_test.dart
@@ -9,12 +9,12 @@
void main() {
test('success', () {
- shouldPass(new RangeError('details'), _rangeMatcher);
+ shouldPass(RangeError('details'), _rangeMatcher);
});
test('failure', () {
shouldFail(
- new RangeError.range(-1, 1, 10),
+ RangeError.range(-1, 1, 10),
_rangeMatcher,
"Expected: <Instance of 'RangeError'> with "
"`message`: contains 'details' and `start`: null and `end`: null "
@@ -26,7 +26,7 @@
// This code is used in the [TypeMatcher] doc comments.
test('integaration and example', () {
void shouldThrowRangeError(int value) {
- throw new RangeError.range(value, 10, 20);
+ throw RangeError.range(value, 10, 20);
}
expect(
@@ -44,7 +44,7 @@
group('CustomMater copy', () {
test("Feature Matcher", () {
- var w = new Widget();
+ var w = Widget();
w.price = 10;
shouldPass(w, _hasPrice(10));
shouldPass(w, _hasPrice(greaterThan(0)));
@@ -67,7 +67,7 @@
contains("Actual: 'a'"),
]));
shouldFail(
- new Widget(),
+ Widget(),
_badCustomMatcher(),
allOf([
contains(
@@ -88,4 +88,4 @@
const TypeMatcher<Widget>().having((e) => e.price, 'price', matcher);
Matcher _badCustomMatcher() => const TypeMatcher<Widget>()
- .having((e) => throw new Exception("bang"), 'feature', {1: "a"});
+ .having((e) => throw Exception("bang"), 'feature', {1: "a"});
diff --git a/test/iterable_matchers_test.dart b/test/iterable_matchers_test.dart
index 7c28338..583e17d 100644
--- a/test/iterable_matchers_test.dart
+++ b/test/iterable_matchers_test.dart
@@ -326,8 +326,8 @@
});
test('isEmpty', () {
- var d = new SimpleIterable(0);
- var e = new SimpleIterable(1);
+ var d = SimpleIterable(0);
+ var e = SimpleIterable(1);
shouldPass(d, isEmpty);
shouldFail(
e,
@@ -337,8 +337,8 @@
});
test('isNotEmpty', () {
- var d = new SimpleIterable(0);
- var e = new SimpleIterable(1);
+ var d = SimpleIterable(0);
+ var e = SimpleIterable(1);
shouldPass(e, isNotEmpty);
shouldFail(
d,
@@ -348,7 +348,7 @@
});
test('contains', () {
- var d = new SimpleIterable(3);
+ var d = SimpleIterable(3);
shouldPass(d, contains(2));
shouldFail(
d,
diff --git a/test/mirror_matchers_test.dart b/test/mirror_matchers_test.dart
index e9f88b4..c88e168 100644
--- a/test/mirror_matchers_test.dart
+++ b/test/mirror_matchers_test.dart
@@ -32,7 +32,7 @@
'Expected: has property "length" which matches <2> '
'Actual: [3] '
'Which: has property "length" with value <1>');
- var c = new C();
+ var c = C();
shouldPass(c, hasProperty('instanceField', 1));
shouldPass(c, hasProperty('instanceGetter', 2));
shouldFail(
diff --git a/test/pretty_print_test.dart b/test/pretty_print_test.dart
index 59a5950..106deae 100644
--- a/test/pretty_print_test.dart
+++ b/test/pretty_print_test.dart
@@ -229,18 +229,17 @@
});
group('with an object', () {
test('with a default [toString]', () {
- expect(prettyPrint(new DefaultToString()),
+ expect(prettyPrint(DefaultToString()),
equals("<Instance of 'DefaultToString'>"));
});
test('with a custom [toString]', () {
- expect(prettyPrint(new CustomToString()),
+ expect(prettyPrint(CustomToString()),
equals('CustomToString:<string representation>'));
});
test('with a custom [toString] and a private name', () {
- expect(
- prettyPrint(new _PrivateName()), equals('?:<string representation>'));
+ expect(prettyPrint(_PrivateName()), equals('?:<string representation>'));
});
});
@@ -254,7 +253,7 @@
});
test("that's not a list and has a private name", () {
- expect(prettyPrint(new _PrivateNameIterable()), equals("?:[1, 2, 3]"));
+ expect(prettyPrint(_PrivateNameIterable()), equals("?:[1, 2, 3]"));
});
});
diff --git a/test/string_matchers_test.dart b/test/string_matchers_test.dart
index 834df8c..d08d6c3 100644
--- a/test/string_matchers_test.dart
+++ b/test/string_matchers_test.dart
@@ -129,7 +129,7 @@
test('matches', () {
shouldPass('c0d', matches('[a-z][0-9][a-z]'));
- shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]')));
+ shouldPass('c0d', matches(RegExp('[a-z][0-9][a-z]')));
shouldFail('cOd', matches('[a-z][0-9][a-z]'),
"Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'");
shouldFail(42, matches('[a-z][0-9][a-z]'),
diff --git a/test/test_utils.dart b/test/test_utils.dart
index 22ad681..c0dfcff 100644
--- a/test/test_utils.dart
+++ b/test/test_utils.dart
@@ -34,7 +34,7 @@
void doesNotThrow() {}
void doesThrow() {
- throw new StateError('X');
+ throw StateError('X');
}
class Widget {
@@ -46,7 +46,7 @@
SimpleIterable(this.count);
- Iterator<int> get iterator => new _SimpleIterator(count);
+ Iterator<int> get iterator => _SimpleIterator(count);
}
class _SimpleIterator implements Iterator<int> {
diff --git a/test/type_matcher_test.dart b/test/type_matcher_test.dart
index 94cbd17..d6f3474 100644
--- a/test/type_matcher_test.dart
+++ b/test/type_matcher_test.dart
@@ -10,21 +10,20 @@
void main() {
_test('Map', isMap, {});
_test('List', isList, []);
- _test('ArgumentError', isArgumentError, new ArgumentError());
- _test('CastError', isCastError, new CastError());
+ _test('ArgumentError', isArgumentError, ArgumentError());
+ _test('CastError', isCastError, CastError());
_test('Exception', isException, const FormatException());
_test('FormatException', isFormatException, const FormatException());
- _test('StateError', isStateError, new StateError('oops'));
- _test('RangeError', isRangeError, new RangeError('oops'));
- _test('UnimplementedError', isUnimplementedError,
- new UnimplementedError('oops'));
- _test('UnsupportedError', isUnsupportedError, new UnsupportedError('oops'));
+ _test('StateError', isStateError, StateError('oops'));
+ _test('RangeError', isRangeError, RangeError('oops'));
+ _test('UnimplementedError', isUnimplementedError, UnimplementedError('oops'));
+ _test('UnsupportedError', isUnsupportedError, UnsupportedError('oops'));
_test('ConcurrentModificationError', isConcurrentModificationError,
- new ConcurrentModificationError());
+ ConcurrentModificationError());
_test('CyclicInitializationError', isCyclicInitializationError,
- new CyclicInitializationError());
+ CyclicInitializationError());
_test('NoSuchMethodError', isNoSuchMethodError, null);
- _test('NullThrownError', isNullThrownError, new NullThrownError());
+ _test('NullThrownError', isNullThrownError, NullThrownError());
group('custom `TypeMatcher`', () {
// ignore: deprecated_member_use