Skip to content

Commit

Permalink
Fix newly enforced package:pedantic lints (flutter#123)
Browse files Browse the repository at this point in the history
- prefer_single_quotes
- prefer_spread_collections
- unused_field
- use_function_type_syntax_for_parameters

Bump min sdk to 2.3.0 to allow for spreads in collection literals.

Drop unused author field from pubspec.
  • Loading branch information
natebosch authored Dec 6, 2019
1 parent 17a430f commit 533ec77
Show file tree
Hide file tree
Showing 21 changed files with 328 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: dart

dart:
- 2.2.0
- 2.3.0
- dev

dart_task:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/core_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class _ReturnsNormally extends FeatureMatcher<Function> {

@override
Description describe(Description description) =>
description.add("return normally");
description.add('return normally');

@override
Description describeTypedMismatch(Function item,
Expand Down Expand Up @@ -305,7 +305,7 @@ class _In<T> extends FeatureMatcher<T> {
/// For example:
///
/// expect(v, predicate((x) => ((x % 2) == 0), "is even"))
Matcher predicate<T>(bool f(T value),
Matcher predicate<T>(bool Function(T) f,
[String description = 'satisfies function']) =>
_Predicate(f, description);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/equals_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class _DeepMatcher extends Matcher {
}

// We're not adding any value to the actual value.
return ["", location];
return ['', location];
}

String _match(expected, actual, Map matchState) {
Expand All @@ -237,7 +237,7 @@ class _DeepMatcher extends Matcher {
String reason;
if (rp[0].isNotEmpty) {
if (rp[1].isNotEmpty) {
reason = "${rp[0]} at location ${rp[1]}";
reason = '${rp[0]} at location ${rp[1]}';
} else {
reason = rp[0];
}
Expand Down
11 changes: 6 additions & 5 deletions lib/src/having_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ class HavingMatcher<T> implements TypeMatcher<T> {
final List<_FunctionMatcher> _functionMatchers;

HavingMatcher(TypeMatcher<T> parent, String description,
Object feature(T source), Object matcher,
Object Function(T) feature, Object matcher,
[Iterable<_FunctionMatcher> existing])
: _parent = parent,
_functionMatchers = <_FunctionMatcher>[]
..addAll(existing ?? [])
..add(_FunctionMatcher<T>(description, feature, matcher));
_functionMatchers = <_FunctionMatcher>[
...?existing,
_FunctionMatcher<T>(description, feature, matcher)
];

@override
TypeMatcher<T> having(
Object feature(T source), String description, Object matcher) =>
Object Function(T) feature, String description, Object matcher) =>
HavingMatcher(_parent, description, feature, matcher, _functionMatchers);

@override
Expand Down
8 changes: 4 additions & 4 deletions lib/src/iterable_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ class _UnorderedMatches extends _IterableMatcher {
/// The [comparator] function, taking an expected and an actual argument, and
/// returning whether they match, will be applied to each pair in order.
/// [description] should be a meaningful name for the comparator.
Matcher pairwiseCompare<S, T>(
Iterable<S> expected, bool comparator(S a, T b), String description) =>
Matcher pairwiseCompare<S, T>(Iterable<S> expected,
bool Function(S, T) comparator, String description) =>
_PairwiseCompare(expected, comparator, description);

typedef _Comparator<S, T> = bool Function(S a, T b);
Expand Down Expand Up @@ -280,9 +280,9 @@ class _PairwiseCompare<S, T> extends _IterableMatcher {
} else {
return mismatchDescription
.add('has ')
.addDescriptionOf(matchState["actual"])
.addDescriptionOf(matchState['actual'])
.add(' which is not $_description ')
.addDescriptionOf(matchState["expected"])
.addDescriptionOf(matchState['expected'])
.add(' at index ${matchState["index"]}');
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/numeric_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class _InRange extends FeatureMatcher<num> {

@override
Description describe(Description description) =>
description.add("be in range from "
description.add('be in range from '
"$_low (${_lowMatchValue ? 'inclusive' : 'exclusive'}) to "
"$_high (${_highMatchValue ? 'inclusive' : 'exclusive'})");
}
46 changes: 23 additions & 23 deletions lib/src/pretty_print.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ String prettyPrint(object, {int maxLineLength, int maxItems}) {
if (object is Matcher) {
var description = StringDescription();
object.describe(description);
return "<$description>";
return '<$description>';
}

// Avoid looping infinitely on recursively-nested data structures.
if (seen.contains(object)) return "(recursive)";
if (seen.contains(object)) return '(recursive)';
seen = seen.union({object});
String pp(child) => _prettyPrint(child, indent + 2, seen, false);

if (object is Iterable) {
// Print the type name for non-List iterables.
var type = object is List ? "" : _typeName(object) + ":";
var type = object is List ? '' : _typeName(object) + ':';

// Truncate the list of strings if it's longer than [maxItems].
var strings = object.map(pp).toList();
Expand All @@ -44,18 +44,18 @@ String prettyPrint(object, {int maxLineLength, int maxItems}) {
var singleLine = "$type[${strings.join(', ')}]";
if ((maxLineLength == null ||
singleLine.length + indent <= maxLineLength) &&
!singleLine.contains("\n")) {
!singleLine.contains('\n')) {
return singleLine;
}

// Otherwise, print each member on its own line.
return "$type[\n" +
return '$type[\n' +
strings.map((string) {
return _indent(indent + 2) + string;
}).join(",\n") +
"\n" +
}).join(',\n') +
'\n' +
_indent(indent) +
"]";
']';
} else if (object is Map) {
// Convert the contents of the map to string representations.
var strings = object.keys.map((key) {
Expand All @@ -69,34 +69,34 @@ String prettyPrint(object, {int maxLineLength, int maxItems}) {

// If the printed string is short and doesn't contain a newline, print it
// as a single line.
var singleLine = "{${strings.join(", ")}}";
var singleLine = '{${strings.join(", ")}}';
if ((maxLineLength == null ||
singleLine.length + indent <= maxLineLength) &&
!singleLine.contains("\n")) {
!singleLine.contains('\n')) {
return singleLine;
}

// Otherwise, print each key/value pair on its own line.
return "{\n" +
return '{\n' +
strings.map((string) {
return _indent(indent + 2) + string;
}).join(",\n") +
"\n" +
}).join(',\n') +
'\n' +
_indent(indent) +
"}";
'}';
} else if (object is String) {
// Escape strings and print each line on its own line.
var lines = object.split("\n");
var lines = object.split('\n');
return "'" +
lines.map(_escapeString).join("\\n'\n${_indent(indent + 2)}'") +
"'";
} else {
var value = object.toString().replaceAll("\n", _indent(indent) + "\n");
var defaultToString = value.startsWith("Instance of ");
var value = object.toString().replaceAll('\n', _indent(indent) + '\n');
var defaultToString = value.startsWith('Instance of ');

// If this is the top-level call to [prettyPrint], wrap the value on angle
// brackets to set it apart visually.
if (top) value = "<$value>";
if (top) value = '<$value>';

// Print the type of objects with custom [toString] methods. Primitive
// objects and objects that don't implement a custom [toString] don't need
Expand All @@ -111,7 +111,7 @@ String prettyPrint(object, {int maxLineLength, int maxItems}) {
defaultToString) {
return value;
} else {
return "${_typeName(object)}:$value";
return '${_typeName(object)}:$value';
}
}
}
Expand All @@ -124,10 +124,10 @@ String _indent(int length) => List.filled(length, ' ').join('');
/// Returns the name of the type of [x] with fallbacks for core types with
/// private implementations.
String _typeName(x) {
if (x is Type) return "Type";
if (x is Uri) return "Uri";
if (x is Set) return "Set";
if (x is BigInt) return "BigInt";
if (x is Type) return 'Type';
if (x is Uri) return 'Uri';
if (x is Set) return 'Set';
if (x is BigInt) return 'BigInt';
return '${x.runtimeType}';
}

Expand Down
4 changes: 1 addition & 3 deletions lib/src/string_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ Matcher equalsIgnoringWhitespace(String value) =>
_IsEqualIgnoringWhitespace(value);

class _IsEqualIgnoringWhitespace extends FeatureMatcher<String> {
final String _value;
final String _matchValue;

_IsEqualIgnoringWhitespace(String value)
: _value = value,
_matchValue = collapseWhitespace(value);
: _matchValue = collapseWhitespace(value);

@override
bool typedMatches(String item, Map matchState) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/type_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class TypeMatcher<T> extends Matcher {
/// .having((e) => e.end, 'end', isNull);
/// ```
TypeMatcher<T> having(
Object feature(T source), String description, Object matcher) =>
Object Function(T) feature, String description, Object matcher) =>
HavingMatcher(this, description, feature, matcher);

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const _escapeMap = {

/// A [RegExp] that matches whitespace characters that should be escaped.
final _escapeRegExp = RegExp(
"[\\x00-\\x07\\x0E-\\x1F${_escapeMap.keys.map(_getHexLiteral).join()}]");
'[\\x00-\\x07\\x0E-\\x1F${_escapeMap.keys.map(_getHexLiteral).join()}]');

/// Useful utility for nesting match states.
void addStateInfo(Map matchState, Map values) {
Expand Down
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: matcher
version: 0.12.6
version: 0.12.7-dev

description: >-
Support for specifying test expectations via an extensible Matcher class.
Also includes a number of built-in Matcher implementations for common cases.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/matcher

environment:
sdk: '>=2.2.0 <3.0.0'
sdk: '>=2.3.0 <3.0.0'

dependencies:
stack_trace: ^1.2.0
Expand Down
Loading

0 comments on commit 533ec77

Please sign in to comment.