Enable and fix lint type_annotate_public_apis (#171)
Add explicit dynamic to parameters.
Add some field types in a test file.
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 2e8ef68..4e9babb 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -34,6 +34,7 @@
- prefer_typing_uninitialized_variables
- test_types_in_equals
- throw_in_finally
+ - type_annotate_public_apis
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
diff --git a/lib/src/feature_matcher.dart b/lib/src/feature_matcher.dart
index 7a42d87..1dbe56c 100644
--- a/lib/src/feature_matcher.dart
+++ b/lib/src/feature_matcher.dart
@@ -12,7 +12,7 @@
const FeatureMatcher();
@override
- bool matches(item, Map matchState) =>
+ bool matches(dynamic item, Map matchState) =>
super.matches(item, matchState) && typedMatches(item as T, matchState);
bool typedMatches(T item, Map matchState);
diff --git a/lib/src/having_matcher.dart b/lib/src/having_matcher.dart
index 4c19019..8536cfe 100644
--- a/lib/src/having_matcher.dart
+++ b/lib/src/having_matcher.dart
@@ -28,7 +28,7 @@
HavingMatcher(_parent, description, feature, matcher, _functionMatchers);
@override
- bool matches(item, Map matchState) {
+ bool matches(dynamic item, Map matchState) {
for (var matcher in <Matcher>[_parent].followedBy(_functionMatchers)) {
if (!matcher.matches(item, matchState)) {
addStateInfo(matchState, {'matcher': matcher});
diff --git a/lib/src/iterable_matchers.dart b/lib/src/iterable_matchers.dart
index 1ae9f17..0345661 100644
--- a/lib/src/iterable_matchers.dart
+++ b/lib/src/iterable_matchers.dart
@@ -36,8 +36,8 @@
description.add('every element(').addDescriptionOf(_matcher).add(')');
@override
- Description describeTypedMismatch(
- item, Description mismatchDescription, Map matchState, bool verbose) {
+ Description describeTypedMismatch(dynamic item,
+ Description mismatchDescription, Map matchState, bool verbose) {
if (matchState['index'] != null) {
var index = matchState['index'];
var element = matchState['element'];
@@ -204,8 +204,8 @@
.add(' unordered');
@override
- Description describeTypedMismatch(item, Description mismatchDescription,
- Map matchState, bool verbose) =>
+ Description describeTypedMismatch(dynamic item,
+ Description mismatchDescription, Map matchState, bool verbose) =>
mismatchDescription.add(_test(item.toList())!);
/// Returns `true` if the value at [valueIndex] can be paired with some
diff --git a/lib/src/numeric_matchers.dart b/lib/src/numeric_matchers.dart
index cee90ca..5193d30 100644
--- a/lib/src/numeric_matchers.dart
+++ b/lib/src/numeric_matchers.dart
@@ -18,7 +18,7 @@
const _IsCloseTo(this._value, this._delta);
@override
- bool typedMatches(item, Map matchState) {
+ bool typedMatches(dynamic item, Map matchState) {
var diff = item - _value;
if (diff < 0) diff = -diff;
return diff <= _delta;
@@ -32,8 +32,8 @@
.addDescriptionOf(_value);
@override
- Description describeTypedMismatch(
- item, Description mismatchDescription, Map matchState, bool verbose) {
+ Description describeTypedMismatch(dynamic item,
+ Description mismatchDescription, Map matchState, bool verbose) {
var diff = item - _value;
if (diff < 0) diff = -diff;
return mismatchDescription.add(' differs by ').addDescriptionOf(diff);
@@ -67,7 +67,7 @@
this._low, this._high, this._lowMatchValue, this._highMatchValue);
@override
- bool typedMatches(value, Map matchState) {
+ bool typedMatches(dynamic value, Map matchState) {
if (value < _low || value > _high) {
return false;
}
diff --git a/lib/src/operator_matchers.dart b/lib/src/operator_matchers.dart
index e532fd3..ced25fc 100644
--- a/lib/src/operator_matchers.dart
+++ b/lib/src/operator_matchers.dart
@@ -14,7 +14,8 @@
const _IsNot(this._matcher);
@override
- bool matches(item, Map matchState) => !_matcher.matches(item, matchState);
+ bool matches(dynamic item, Map matchState) =>
+ !_matcher.matches(item, matchState);
@override
Description describe(Description description) =>
@@ -43,7 +44,7 @@
const _AllOf(this._matchers);
@override
- bool matches(item, Map matchState) {
+ bool matches(dynamic item, Map matchState) {
for (var matcher in _matchers) {
if (!matcher.matches(item, matchState)) {
addStateInfo(matchState, {'matcher': matcher});
@@ -54,8 +55,8 @@
}
@override
- Description describeMismatch(
- item, Description mismatchDescription, Map matchState, bool verbose) {
+ Description describeMismatch(dynamic item, Description mismatchDescription,
+ Map matchState, bool verbose) {
var matcher = matchState['matcher'];
matcher.describeMismatch(
item, mismatchDescription, matchState['state'], verbose);
@@ -93,7 +94,7 @@
const _AnyOf(this._matchers);
@override
- bool matches(item, Map matchState) {
+ bool matches(dynamic item, Map matchState) {
for (var matcher in _matchers) {
if (matcher.matches(item, matchState)) {
return true;
diff --git a/lib/src/order_matchers.dart b/lib/src/order_matchers.dart
index 8741b93..1146f6a 100644
--- a/lib/src/order_matchers.dart
+++ b/lib/src/order_matchers.dart
@@ -100,8 +100,8 @@
}
@override
- Description describeMismatch(
- item, Description mismatchDescription, Map matchState, bool verbose) {
+ Description describeMismatch(dynamic item, Description mismatchDescription,
+ Map matchState, bool verbose) {
mismatchDescription.add('is not ');
return describe(mismatchDescription);
}
diff --git a/lib/src/string_matchers.dart b/lib/src/string_matchers.dart
index 9484a9c..a0371c7 100644
--- a/lib/src/string_matchers.dart
+++ b/lib/src/string_matchers.dart
@@ -61,8 +61,8 @@
description.addDescriptionOf(_matchValue).add(' ignoring whitespace');
@override
- Description describeTypedMismatch(
- item, Description mismatchDescription, Map matchState, bool verbose) {
+ Description describeTypedMismatch(dynamic item,
+ Description mismatchDescription, Map matchState, bool verbose) {
return mismatchDescription
.add('is ')
.addDescriptionOf(collapseWhitespace(item))
@@ -80,7 +80,7 @@
const _StringStartsWith(this._prefix);
@override
- bool typedMatches(item, Map matchState) => item.startsWith(_prefix);
+ bool typedMatches(dynamic item, Map matchState) => item.startsWith(_prefix);
@override
Description describe(Description description) =>
@@ -97,7 +97,7 @@
const _StringEndsWith(this._suffix);
@override
- bool typedMatches(item, Map matchState) => item.endsWith(_suffix);
+ bool typedMatches(dynamic item, Map matchState) => item.endsWith(_suffix);
@override
Description describe(Description description) =>
@@ -119,7 +119,7 @@
const _StringContainsInOrder(this._substrings);
@override
- bool typedMatches(item, Map matchState) {
+ bool typedMatches(dynamic item, Map matchState) {
var fromIndex = 0;
for (var s in _substrings) {
fromIndex = item.indexOf(s, fromIndex);
@@ -151,7 +151,7 @@
: throw ArgumentError('matches requires a regexp or string');
@override
- bool typedMatches(item, Map matchState) => _regexp.hasMatch(item);
+ bool typedMatches(dynamic item, Map matchState) => _regexp.hasMatch(item);
@override
Description describe(Description description) =>
diff --git a/lib/src/type_matcher.dart b/lib/src/type_matcher.dart
index 07a7d3c..388adb5 100644
--- a/lib/src/type_matcher.dart
+++ b/lib/src/type_matcher.dart
@@ -93,8 +93,8 @@
bool matches(Object? item, Map matchState) => item is T;
@override
- Description describeMismatch(
- item, Description mismatchDescription, Map matchState, bool verbose) {
+ Description describeMismatch(dynamic item, Description mismatchDescription,
+ Map matchState, bool verbose) {
var name = _name ?? _stripDynamic(T);
return mismatchDescription.add("is not an instance of '$name'");
}
diff --git a/test/custom_matcher_test.dart b/test/custom_matcher_test.dart
index d310d22..d0a17c9 100644
--- a/test/custom_matcher_test.dart
+++ b/test/custom_matcher_test.dart
@@ -10,7 +10,7 @@
class _BadCustomMatcher extends CustomMatcher {
_BadCustomMatcher() : super('feature', 'description', {1: 'a'});
@override
- Object? featureValueOf(actual) => throw Exception('bang');
+ Object? featureValueOf(dynamic actual) => throw Exception('bang');
}
class _HasPrice extends CustomMatcher {
diff --git a/test/mirror_matchers_test.dart b/test/mirror_matchers_test.dart
index beff992..b19fe3e 100644
--- a/test/mirror_matchers_test.dart
+++ b/test/mirror_matchers_test.dart
@@ -12,9 +12,9 @@
import 'test_utils.dart';
class C {
- var instanceField = 1;
+ int instanceField = 1;
int get instanceGetter => 2;
- static var staticField = 3;
+ static int staticField = 3;
static int get staticGetter => 4;
}
diff --git a/test/type_matcher_test.dart b/test/type_matcher_test.dart
index 057ebe7..c23d34f 100644
--- a/test/type_matcher_test.dart
+++ b/test/type_matcher_test.dart
@@ -61,7 +61,7 @@
'String');
@override
- bool matches(item, Map matchState) => item is String;
+ bool matches(dynamic item, Map matchState) => item is String;
}
class _TestType {