Skip to content

Commit 89e7b66

Browse files
authored
Enable and fix lints, tweak SDK range and description (#272)
1 parent 45f4082 commit 89e7b66

33 files changed

+220
-216
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ dart_task:
99
# No parallelism on Firefox (-j 1)
1010
# Causes flakiness – need to investigate
1111
- test: --platform firefox -j 1
12-
- dartanalyzer
12+
- dartanalyzer: --fatal-infos --fatal-warnings .
13+
14+
matrix:
15+
include:
16+
# Only validate formatting using the dev release
17+
- dart: dev
18+
dart_task: dartfmt
1319

1420
# Only building master means that we don't run two builds for each pull request.
1521
branches:

analysis_options.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
include: package:pedantic/analysis_options.yaml
2+
linter:
3+
rules:
4+
- prefer_generic_function_type_aliases
5+
- unnecessary_const
6+
- unnecessary_new

lib/http.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Future<Uint8List> readBytes(url, {Map<String, String> headers}) =>
161161
_withClient((client) => client.readBytes(url, headers: headers));
162162

163163
Future<T> _withClient<T>(Future<T> fn(Client client)) async {
164-
var client = new Client();
164+
var client = Client();
165165
try {
166166
return await fn(client);
167167
} finally {

lib/src/base_client.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ abstract class BaseClient implements Client {
150150
String method, url, Map<String, String> headers,
151151
[body, Encoding encoding]) async {
152152
if (url is String) url = Uri.parse(url);
153-
var request = new Request(method, url);
153+
var request = Request(method, url);
154154

155155
if (headers != null) request.headers.addAll(headers);
156156
if (encoding != null) request.encoding = encoding;
@@ -162,7 +162,7 @@ abstract class BaseClient implements Client {
162162
} else if (body is Map) {
163163
request.bodyFields = body.cast<String, String>();
164164
} else {
165-
throw new ArgumentError('Invalid request body "$body".');
165+
throw ArgumentError('Invalid request body "$body".');
166166
}
167167
}
168168

@@ -177,7 +177,7 @@ abstract class BaseClient implements Client {
177177
message = "$message: ${response.reasonPhrase}";
178178
}
179179
if (url is String) url = Uri.parse(url);
180-
throw new ClientException("$message.", url);
180+
throw ClientException("$message.", url);
181181
}
182182

183183
/// Closes the client and cleans up any resources associated with it. It's

lib/src/base_request.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class BaseRequest {
3434

3535
set contentLength(int value) {
3636
if (value != null && value < 0) {
37-
throw new ArgumentError("Invalid content length $value.");
37+
throw ArgumentError("Invalid content length $value.");
3838
}
3939
_checkFinalized();
4040
_contentLength = value;
@@ -83,7 +83,7 @@ abstract class BaseRequest {
8383

8484
/// Creates a new HTTP request.
8585
BaseRequest(this.method, this.url)
86-
: headers = new LinkedHashMap(
86+
: headers = LinkedHashMap(
8787
equals: (key1, key2) => key1.toLowerCase() == key2.toLowerCase(),
8888
hashCode: (key) => key.toLowerCase().hashCode);
8989

@@ -98,7 +98,7 @@ abstract class BaseRequest {
9898
/// change after the request headers are sent.
9999
ByteStream finalize() {
100100
// TODO(nweiz): freeze headers
101-
if (finalized) throw new StateError("Can't finalize a finalized Request.");
101+
if (finalized) throw StateError("Can't finalize a finalized Request.");
102102
_finalized = true;
103103
return null;
104104
}
@@ -110,12 +110,12 @@ abstract class BaseRequest {
110110
/// the same server, you should use a single [Client] for all of those
111111
/// requests.
112112
Future<StreamedResponse> send() async {
113-
var client = new Client();
113+
var client = Client();
114114

115115
try {
116116
var response = await client.send(this);
117117
var stream = onDone(response.stream, client.close);
118-
return new StreamedResponse(new ByteStream(stream), response.statusCode,
118+
return StreamedResponse(ByteStream(stream), response.statusCode,
119119
contentLength: response.contentLength,
120120
request: response.request,
121121
headers: response.headers,
@@ -131,7 +131,7 @@ abstract class BaseRequest {
131131
// Throws an error if this request has been finalized.
132132
void _checkFinalized() {
133133
if (!finalized) return;
134-
throw new StateError("Can't modify a finalized Request.");
134+
throw StateError("Can't modify a finalized Request.");
135135
}
136136

137137
String toString() => "$method $url";

lib/src/base_response.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ abstract class BaseResponse {
4444
this.persistentConnection = true,
4545
this.reasonPhrase}) {
4646
if (statusCode < 100) {
47-
throw new ArgumentError("Invalid status code $statusCode.");
47+
throw ArgumentError("Invalid status code $statusCode.");
4848
} else if (contentLength != null && contentLength < 0) {
49-
throw new ArgumentError("Invalid content length $contentLength.");
49+
throw ArgumentError("Invalid content length $contentLength.");
5050
}
5151
}
5252
}

lib/src/boundary_characters.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
///
1010
/// [RFC 2046]: http://tools.ietf.org/html/rfc2046#section-5.1.1.
1111
/// [RFC 1521]: https://tools.ietf.org/html/rfc1521#section-4
12-
const List<int> BOUNDARY_CHARACTERS = const <int>[
12+
const List<int> BOUNDARY_CHARACTERS = <int>[
1313
43,
1414
95,
1515
45,

lib/src/browser_client.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BrowserClient extends BaseClient {
2929
/// The currently active XHRs.
3030
///
3131
/// These are aborted if the client is closed.
32-
final _xhrs = new Set<HttpRequest>();
32+
final _xhrs = Set<HttpRequest>();
3333

3434
/// Creates a new HTTP client.
3535
BrowserClient();
@@ -43,24 +43,24 @@ class BrowserClient extends BaseClient {
4343
/// Sends an HTTP request and asynchronously returns the response.
4444
Future<StreamedResponse> send(BaseRequest request) async {
4545
var bytes = await request.finalize().toBytes();
46-
var xhr = new HttpRequest();
46+
var xhr = HttpRequest();
4747
_xhrs.add(xhr);
4848
_openHttpRequest(xhr, request.method, request.url.toString(), asynch: true);
4949
xhr.responseType = 'blob';
5050
xhr.withCredentials = withCredentials;
5151
request.headers.forEach(xhr.setRequestHeader);
5252

53-
var completer = new Completer<StreamedResponse>();
53+
var completer = Completer<StreamedResponse>();
5454
unawaited(xhr.onLoad.first.then((_) {
5555
// TODO(nweiz): Set the response type to "arraybuffer" when issue 18542
5656
// is fixed.
57-
var blob = xhr.response == null ? new Blob([]) : xhr.response;
58-
var reader = new FileReader();
57+
var blob = xhr.response == null ? Blob([]) : xhr.response;
58+
var reader = FileReader();
5959

6060
reader.onLoad.first.then((_) {
6161
var body = reader.result as Uint8List;
62-
completer.complete(new StreamedResponse(
63-
new ByteStream.fromBytes(body), xhr.status,
62+
completer.complete(StreamedResponse(
63+
ByteStream.fromBytes(body), xhr.status,
6464
contentLength: body.length,
6565
request: request,
6666
headers: xhr.responseHeaders,
@@ -69,8 +69,7 @@ class BrowserClient extends BaseClient {
6969

7070
reader.onError.first.then((error) {
7171
completer.completeError(
72-
new ClientException(error.toString(), request.url),
73-
StackTrace.current);
72+
ClientException(error.toString(), request.url), StackTrace.current);
7473
});
7574

7675
reader.readAsArrayBuffer(blob);
@@ -80,7 +79,7 @@ class BrowserClient extends BaseClient {
8079
// Unfortunately, the underlying XMLHttpRequest API doesn't expose any
8180
// specific information about the error itself.
8281
completer.completeError(
83-
new ClientException("XMLHttpRequest error.", request.url),
82+
ClientException("XMLHttpRequest error.", request.url),
8483
StackTrace.current);
8584
}));
8685

lib/src/byte_stream.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class ByteStream extends StreamView<List<int>> {
1313
/// Returns a single-subscription byte stream that will emit the given bytes
1414
/// in a single chunk.
1515
factory ByteStream.fromBytes(List<int> bytes) =>
16-
new ByteStream(new Stream.fromIterable([bytes]));
16+
ByteStream(Stream.fromIterable([bytes]));
1717

1818
/// Collects the data of this stream in a [Uint8List].
1919
Future<Uint8List> toBytes() {
20-
var completer = new Completer<Uint8List>();
21-
var sink = new ByteConversionSink.withCallback(
22-
(bytes) => completer.complete(new Uint8List.fromList(bytes)));
20+
var completer = Completer<Uint8List>();
21+
var sink = ByteConversionSink.withCallback(
22+
(bytes) => completer.complete(Uint8List.fromList(bytes)));
2323
listen(sink.add,
2424
onError: completer.completeError,
2525
onDone: sink.close,

lib/src/io_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class IOClient extends BaseClient {
2323
HttpClient _inner;
2424

2525
/// Creates a new HTTP client.
26-
IOClient([HttpClient inner]) : _inner = inner ?? new HttpClient();
26+
IOClient([HttpClient inner]) : _inner = inner ?? HttpClient();
2727

2828
/// Sends an HTTP request and asynchronously returns the response.
2929
Future<StreamedResponse> send(BaseRequest request) async {
@@ -49,9 +49,9 @@ class IOClient extends BaseClient {
4949
headers[key] = values.join(',');
5050
});
5151

52-
return new StreamedResponse(
52+
return StreamedResponse(
5353
DelegatingStream.typed<List<int>>(response).handleError(
54-
(error) => throw new ClientException(error.message, error.uri),
54+
(error) => throw ClientException(error.message, error.uri),
5555
test: (error) => error is HttpException),
5656
response.statusCode,
5757
contentLength:
@@ -62,7 +62,7 @@ class IOClient extends BaseClient {
6262
persistentConnection: response.persistentConnection,
6363
reasonPhrase: response.reasonPhrase);
6464
} on HttpException catch (error) {
65-
throw new ClientException(error.message, error.uri);
65+
throw ClientException(error.message, error.uri);
6666
}
6767
}
6868

0 commit comments

Comments
 (0)