Enable and fix lint prefer_single_quotes (#304)
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 164ed9c..6d41948 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -3,5 +3,6 @@
rules:
- annotate_overrides
- prefer_generic_function_type_aliases
+ - prefer_single_quotes
- unnecessary_const
- unnecessary_new
diff --git a/example/main.dart b/example/main.dart
index 7b3eaa9..13f996f 100644
--- a/example/main.dart
+++ b/example/main.dart
@@ -4,15 +4,15 @@
main(List<String> arguments) async {
// This example uses the Google Books API to search for books about http.
// https://developers.google.com/books/docs/overview
- var url = "https://www.googleapis.com/books/v1/volumes?q={http}";
+ var url = 'https://www.googleapis.com/books/v1/volumes?q={http}';
// Await the http get response, then decode the json-formatted response.
var response = await http.get(url);
if (response.statusCode == 200) {
var jsonResponse = convert.jsonDecode(response.body);
var itemCount = jsonResponse['totalItems'];
- print("Number of books about http: $itemCount.");
+ print('Number of books about http: $itemCount.');
} else {
- print("Request failed with status: ${response.statusCode}.");
+ print('Request failed with status: ${response.statusCode}.');
}
}
diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart
index ab31376..3fc7da9 100644
--- a/lib/src/base_client.dart
+++ b/lib/src/base_client.dart
@@ -23,7 +23,7 @@
/// For more fine-grained control over the request, use [send] instead.
@override
Future<Response> head(url, {Map<String, String> headers}) =>
- _sendUnstreamed("HEAD", url, headers);
+ _sendUnstreamed('HEAD', url, headers);
/// Sends an HTTP GET request with the given headers to the given URL, which
/// can be a [Uri] or a [String].
@@ -31,7 +31,7 @@
/// For more fine-grained control over the request, use [send] instead.
@override
Future<Response> get(url, {Map<String, String> headers}) =>
- _sendUnstreamed("GET", url, headers);
+ _sendUnstreamed('GET', url, headers);
/// Sends an HTTP POST request with the given headers and body to the given
/// URL, which can be a [Uri] or a [String].
@@ -54,7 +54,7 @@
@override
Future<Response> post(url,
{Map<String, String> headers, body, Encoding encoding}) =>
- _sendUnstreamed("POST", url, headers, body, encoding);
+ _sendUnstreamed('POST', url, headers, body, encoding);
/// Sends an HTTP PUT request with the given headers and body to the given
/// URL, which can be a [Uri] or a [String].
@@ -77,7 +77,7 @@
@override
Future<Response> put(url,
{Map<String, String> headers, body, Encoding encoding}) =>
- _sendUnstreamed("PUT", url, headers, body, encoding);
+ _sendUnstreamed('PUT', url, headers, body, encoding);
/// Sends an HTTP PATCH request with the given headers and body to the given
/// URL, which can be a [Uri] or a [String].
@@ -100,7 +100,7 @@
@override
Future<Response> patch(url,
{Map<String, String> headers, body, Encoding encoding}) =>
- _sendUnstreamed("PATCH", url, headers, body, encoding);
+ _sendUnstreamed('PATCH', url, headers, body, encoding);
/// Sends an HTTP DELETE request with the given headers to the given URL,
/// which can be a [Uri] or a [String].
@@ -108,7 +108,7 @@
/// For more fine-grained control over the request, use [send] instead.
@override
Future<Response> delete(url, {Map<String, String> headers}) =>
- _sendUnstreamed("DELETE", url, headers);
+ _sendUnstreamed('DELETE', url, headers);
/// Sends an HTTP GET request with the given headers to the given URL, which
/// can be a [Uri] or a [String], and returns a Future that completes to the
@@ -181,12 +181,12 @@
/// Throws an error if [response] is not successful.
void _checkResponseSuccess(url, Response response) {
if (response.statusCode < 400) return;
- var message = "Request to $url failed with status ${response.statusCode}";
+ var message = 'Request to $url failed with status ${response.statusCode}';
if (response.reasonPhrase != null) {
- message = "$message: ${response.reasonPhrase}";
+ message = '$message: ${response.reasonPhrase}';
}
if (url is String) url = Uri.parse(url);
- throw ClientException("$message.", url);
+ throw ClientException('$message.', url);
}
/// Closes the client and cleans up any resources associated with it. It's
diff --git a/lib/src/base_request.dart b/lib/src/base_request.dart
index 71995aa..4c85588 100644
--- a/lib/src/base_request.dart
+++ b/lib/src/base_request.dart
@@ -34,7 +34,7 @@
set contentLength(int value) {
if (value != null && value < 0) {
- throw ArgumentError("Invalid content length $value.");
+ throw ArgumentError('Invalid content length $value.');
}
_checkFinalized();
_contentLength = value;
diff --git a/lib/src/base_response.dart b/lib/src/base_response.dart
index 7c44eea..68e1a73 100644
--- a/lib/src/base_response.dart
+++ b/lib/src/base_response.dart
@@ -44,9 +44,9 @@
this.persistentConnection = true,
this.reasonPhrase}) {
if (statusCode < 100) {
- throw ArgumentError("Invalid status code $statusCode.");
+ throw ArgumentError('Invalid status code $statusCode.');
} else if (contentLength != null && contentLength < 0) {
- throw ArgumentError("Invalid content length $contentLength.");
+ throw ArgumentError('Invalid content length $contentLength.');
}
}
}
diff --git a/lib/src/browser_client.dart b/lib/src/browser_client.dart
index 4891785..b19f13a 100644
--- a/lib/src/browser_client.dart
+++ b/lib/src/browser_client.dart
@@ -80,7 +80,7 @@
// Unfortunately, the underlying XMLHttpRequest API doesn't expose any
// specific information about the error itself.
completer.completeError(
- ClientException("XMLHttpRequest error.", request.url),
+ ClientException('XMLHttpRequest error.', request.url),
StackTrace.current);
}));
diff --git a/lib/src/multipart_file.dart b/lib/src/multipart_file.dart
index a3ca7fa..05db4cd 100644
--- a/lib/src/multipart_file.dart
+++ b/lib/src/multipart_file.dart
@@ -49,7 +49,7 @@
: this._stream = toByteStream(stream),
this.contentType = contentType != null
? contentType
- : MediaType("application", "octet-stream");
+ : MediaType('application', 'octet-stream');
/// Creates a new [MultipartFile] from a byte array.
///
@@ -71,7 +71,7 @@
factory MultipartFile.fromString(String field, String value,
{String filename, MediaType contentType}) {
contentType =
- contentType == null ? MediaType("text", "plain") : contentType;
+ contentType == null ? MediaType('text', 'plain') : contentType;
var encoding = encodingForCharset(contentType.parameters['charset'], utf8);
contentType = contentType.change(parameters: {'charset': encoding.name});
diff --git a/lib/src/multipart_request.dart b/lib/src/multipart_request.dart
index 773b9bb..0f15451 100644
--- a/lib/src/multipart_request.dart
+++ b/lib/src/multipart_request.dart
@@ -12,7 +12,7 @@
import 'multipart_file.dart';
import 'utils.dart';
-final _newlineRegExp = RegExp(r"\r\n|\r|\n");
+final _newlineRegExp = RegExp(r'\r\n|\r|\n');
/// A `multipart/form-data` request.
///
@@ -58,30 +58,30 @@
var length = 0;
fields.forEach((name, value) {
- length += "--".length +
+ length += '--'.length +
_boundaryLength +
- "\r\n".length +
+ '\r\n'.length +
utf8.encode(_headerForField(name, value)).length +
utf8.encode(value).length +
- "\r\n".length;
+ '\r\n'.length;
});
for (var file in _files) {
- length += "--".length +
+ length += '--'.length +
_boundaryLength +
- "\r\n".length +
+ '\r\n'.length +
utf8.encode(_headerForFile(file)).length +
file.length +
- "\r\n".length;
+ '\r\n'.length;
}
- return length + "--".length + _boundaryLength + "--\r\n".length;
+ return length + '--'.length + _boundaryLength + '--\r\n'.length;
}
@override
set contentLength(int value) {
- throw UnsupportedError("Cannot set the contentLength property of "
- "multipart requests.");
+ throw UnsupportedError('Cannot set the contentLength property of '
+ 'multipart requests.');
}
/// Freezes all mutable fields and returns a single-subscription [ByteStream]
@@ -158,17 +158,17 @@
// follow this at all. Instead, they URL-encode `\r`, `\n`, and `\r\n` as
// `\r\n`; URL-encode `"`; and do nothing else (even for `%` or non-ASCII
// characters). We follow their behavior.
- return value.replaceAll(_newlineRegExp, "%0D%0A").replaceAll('"', "%22");
+ return value.replaceAll(_newlineRegExp, '%0D%0A').replaceAll('"', '%22');
}
/// Returns a randomly-generated multipart boundary string
String _boundaryString() {
- var prefix = "dart-http-boundary-";
+ var prefix = 'dart-http-boundary-';
var list = List<int>.generate(
_boundaryLength - prefix.length,
(index) =>
BOUNDARY_CHARACTERS[_random.nextInt(BOUNDARY_CHARACTERS.length)],
growable: false);
- return "$prefix${String.fromCharCodes(list)}";
+ return '$prefix${String.fromCharCodes(list)}';
}
}
diff --git a/lib/src/request.dart b/lib/src/request.dart
index 61262e8..e3cff97 100644
--- a/lib/src/request.dart
+++ b/lib/src/request.dart
@@ -23,8 +23,8 @@
@override
set contentLength(int value) {
- throw UnsupportedError("Cannot set the contentLength property of "
- "non-streaming Request objects.");
+ throw UnsupportedError('Cannot set the contentLength property of '
+ 'non-streaming Request objects.');
}
/// The default encoding to use when converting between [bodyBytes] and
@@ -87,7 +87,7 @@
bodyBytes = encoding.encode(value);
var contentType = _contentType;
if (contentType == null) {
- _contentType = MediaType("text", "plain", {'charset': encoding.name});
+ _contentType = MediaType('text', 'plain', {'charset': encoding.name});
} else if (!contentType.parameters.containsKey('charset')) {
_contentType = contentType.change(parameters: {'charset': encoding.name});
}
@@ -110,7 +110,7 @@
Map<String, String> get bodyFields {
var contentType = _contentType;
if (contentType == null ||
- contentType.mimeType != "application/x-www-form-urlencoded") {
+ contentType.mimeType != 'application/x-www-form-urlencoded') {
throw StateError('Cannot access the body fields of a Request without '
'content-type "application/x-www-form-urlencoded".');
}
@@ -121,8 +121,8 @@
set bodyFields(Map<String, String> fields) {
var contentType = _contentType;
if (contentType == null) {
- _contentType = MediaType("application", "x-www-form-urlencoded");
- } else if (contentType.mimeType != "application/x-www-form-urlencoded") {
+ _contentType = MediaType('application', 'x-www-form-urlencoded');
+ } else if (contentType.mimeType != 'application/x-www-form-urlencoded') {
throw StateError('Cannot set the body fields of a Request with '
'content-type "${contentType.mimeType}".');
}
diff --git a/lib/src/response.dart b/lib/src/response.dart
index bdc39d1..6d49b8a 100644
--- a/lib/src/response.dart
+++ b/lib/src/response.dart
@@ -82,5 +82,5 @@
MediaType _contentTypeForHeaders(Map<String, String> headers) {
var contentType = headers['content-type'];
if (contentType != null) return MediaType.parse(contentType);
- return MediaType("application", "octet-stream");
+ return MediaType('application', 'octet-stream');
}
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 164c1e5..67aabe0 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -18,7 +18,7 @@
Uri.encodeQueryComponent(key, encoding: encoding),
Uri.encodeQueryComponent(value, encoding: encoding)
]));
- return pairs.map((pair) => "${pair[0]}=${pair[1]}").join("&");
+ return pairs.map((pair) => '${pair[0]}=${pair[1]}').join('&');
}
/// Like [String.split], but only splits on the first occurrence of the pattern.
@@ -58,7 +58,7 @@
/// A regular expression that matches strings that are composed entirely of
/// ASCII-compatible characters.
-final RegExp _ASCII_ONLY = RegExp(r"^[\x00-\x7F]+$");
+final RegExp _ASCII_ONLY = RegExp(r'^[\x00-\x7F]+$');
/// Returns whether [string] is composed entirely of ASCII-compatible
/// characters.
diff --git a/test/html/client_test.dart b/test/html/client_test.dart
index 8fe1c72..cd55d1d 100644
--- a/test/html/client_test.dart
+++ b/test/html/client_test.dart
@@ -13,7 +13,7 @@
void main() {
test('#send a StreamedRequest', () {
var client = BrowserClient();
- var request = http.StreamedRequest("POST", echoUrl);
+ var request = http.StreamedRequest('POST', echoUrl);
expect(
client.send(request).then((response) {
@@ -28,10 +28,10 @@
test('#send with an invalid URL', () {
var client = BrowserClient();
var url = Uri.parse('http://http.invalid');
- var request = http.StreamedRequest("POST", url);
+ var request = http.StreamedRequest('POST', url);
expect(
- client.send(request), throwsClientException("XMLHttpRequest error."));
+ client.send(request), throwsClientException('XMLHttpRequest error.'));
request.sink.add('{"hello": "world"}'.codeUnits);
request.sink.close();
diff --git a/test/io/client_test.dart b/test/io/client_test.dart
index 0301445..a77a026 100644
--- a/test/io/client_test.dart
+++ b/test/io/client_test.dart
@@ -19,7 +19,7 @@
expect(
startServer().then((_) {
var client = http.Client();
- var request = http.StreamedRequest("POST", serverUrl);
+ var request = http.StreamedRequest('POST', serverUrl);
request.headers[HttpHeaders.contentTypeHeader] =
'application/json; charset=utf-8';
request.headers[HttpHeaders.userAgentHeader] = 'Dart';
@@ -58,7 +58,7 @@
startServer().then((_) {
var ioClient = HttpClient();
var client = http_io.IOClient(ioClient);
- var request = http.StreamedRequest("POST", serverUrl);
+ var request = http.StreamedRequest('POST', serverUrl);
request.headers[HttpHeaders.contentTypeHeader] =
'application/json; charset=utf-8';
request.headers[HttpHeaders.userAgentHeader] = 'Dart';
@@ -97,7 +97,7 @@
startServer().then((_) {
var client = http.Client();
var url = Uri.parse('http://http.invalid');
- var request = http.StreamedRequest("POST", url);
+ var request = http.StreamedRequest('POST', url);
request.headers[HttpHeaders.contentTypeHeader] =
'application/json; charset=utf-8';
diff --git a/test/io/request_test.dart b/test/io/request_test.dart
index bdae677..bc980e3 100644
--- a/test/io/request_test.dart
+++ b/test/io/request_test.dart
@@ -14,7 +14,7 @@
expect(
startServer().then((_) {
var request = http.Request('POST', serverUrl);
- request.body = "hello";
+ request.body = 'hello';
request.headers['User-Agent'] = 'Dart';
expect(
diff --git a/test/io/utils.dart b/test/io/utils.dart
index 50e668b..f30ebf2 100644
--- a/test/io/utils.dart
+++ b/test/io/utils.dart
@@ -20,7 +20,7 @@
/// Starts a new HTTP server.
Future startServer() {
- return HttpServer.bind("localhost", 0).then((s) {
+ return HttpServer.bind('localhost', 0).then((s) {
_server = s;
s.listen((request) {
var path = request.uri.path;
@@ -69,7 +69,7 @@
}
response.headers.contentType =
- ContentType("application", "json", charset: outputEncoding.name);
+ ContentType('application', 'json', charset: outputEncoding.name);
response.headers.set('single', 'value');
var requestBody;
diff --git a/test/mock_client_test.dart b/test/mock_client_test.dart
index acd1007..3ec5ab0 100644
--- a/test/mock_client_test.dart
+++ b/test/mock_client_test.dart
@@ -19,7 +19,7 @@
});
expect(
- client.post("http://example.com/foo", body: {
+ client.post('http://example.com/foo', body: {
'field1': 'value1',
'field2': 'value2'
}).then((response) => response.body),
@@ -39,9 +39,9 @@
});
});
- var uri = Uri.parse("http://example.com/foo");
- var request = http.Request("POST", uri);
- request.body = "hello, world";
+ var uri = Uri.parse('http://example.com/foo');
+ var request = http.Request('POST', uri);
+ request.body = 'hello, world';
var future = client
.send(request)
.then(http.Response.fromStream)
@@ -54,7 +54,7 @@
return Future.value(http.Response('you did it', 200));
});
- expect(client.read("http://example.com/foo"),
+ expect(client.read('http://example.com/foo'),
completion(equals('you did it')));
});
}
diff --git a/test/multipart_test.dart b/test/multipart_test.dart
index 8b14197..e125932 100644
--- a/test/multipart_test.dart
+++ b/test/multipart_test.dart
@@ -30,9 +30,9 @@
var request = http.MultipartRequest('POST', dummyUrl);
request.fields['field1'] = 'value1';
request.fields['field2'] = 'value2';
- request.files.add(http.MultipartFile.fromString("file1", "contents1",
- filename: "filename1.txt"));
- request.files.add(http.MultipartFile.fromString("file2", "contents2"));
+ request.files.add(http.MultipartFile.fromString('file1', 'contents1',
+ filename: 'filename1.txt'));
+ request.files.add(http.MultipartFile.fromString('file2', 'contents2'));
expect(request, bodyMatches('''
--{{boundary}}
diff --git a/test/request_test.dart b/test/request_test.dart
index fecb983..8e19eb3 100644
--- a/test/request_test.dart
+++ b/test/request_test.dart
@@ -21,9 +21,9 @@
test('is computed from body', () {
var request = http.Request('POST', dummyUrl);
- request.body = "hello";
+ request.body = 'hello';
expect(request.contentLength, equals(5));
- request.body = "hello, world";
+ request.body = 'hello, world';
expect(request.contentLength, equals(12));
});
@@ -84,7 +84,7 @@
test('changes when body changes', () {
var request = http.Request('POST', dummyUrl);
- request.body = "hello";
+ request.body = 'hello';
expect(request.bodyBytes, equals([104, 101, 108, 108, 111]));
});
});
@@ -97,20 +97,20 @@
test('can be set', () {
var request = http.Request('POST', dummyUrl);
- request.body = "hello";
- expect(request.body, equals("hello"));
+ request.body = 'hello';
+ expect(request.body, equals('hello'));
});
test('changes when bodyBytes changes', () {
var request = http.Request('POST', dummyUrl);
request.bodyBytes = [104, 101, 108, 108, 111];
- expect(request.body, equals("hello"));
+ expect(request.body, equals('hello'));
});
test('is encoded according to the given encoding', () {
var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
- request.body = "föøbãr";
+ request.body = 'föøbãr';
expect(request.bodyBytes, equals([102, 246, 248, 98, 227, 114]));
});
@@ -118,7 +118,7 @@
var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
request.bodyBytes = [102, 246, 248, 98, 227, 114];
- expect(request.body, equals("föøbãr"));
+ expect(request.body, equals('föøbãr'));
});
});
@@ -164,7 +164,7 @@
var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
request.encoding = latin1;
- request.bodyFields = {"föø": "bãr"};
+ request.bodyFields = {'föø': 'bãr'};
expect(request.body, equals('f%F6%F8=b%E3r'));
});
@@ -173,7 +173,7 @@
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
request.encoding = latin1;
request.body = 'f%F6%F8=b%E3r';
- expect(request.bodyFields, equals({"föø": "bãr"}));
+ expect(request.bodyFields, equals({'föø': 'bãr'}));
});
});
@@ -269,9 +269,9 @@
group('#finalize', () {
test('returns a stream that emits the request body', () {
var request = http.Request('POST', dummyUrl);
- request.body = "Hello, world!";
+ request.body = 'Hello, world!';
expect(request.finalize().bytesToString(),
- completion(equals("Hello, world!")));
+ completion(equals('Hello, world!')));
});
test('freezes #persistentConnection', () {
@@ -317,19 +317,19 @@
test('freezes #body', () {
var request = http.Request('POST', dummyUrl);
- request.body = "hello";
+ request.body = 'hello';
request.finalize();
- expect(request.body, equals("hello"));
- expect(() => request.body = "goodbye", throwsStateError);
+ expect(request.body, equals('hello'));
+ expect(() => request.body = 'goodbye', throwsStateError);
});
test('freezes #bodyFields', () {
var request = http.Request('POST', dummyUrl);
- request.bodyFields = {"hello": "world"};
+ request.bodyFields = {'hello': 'world'};
request.finalize();
- expect(request.bodyFields, equals({"hello": "world"}));
+ expect(request.bodyFields, equals({'hello': 'world'}));
expect(() => request.bodyFields = {}, throwsStateError);
});
diff --git a/test/response_test.dart b/test/response_test.dart
index 110e5ec..69a8b95 100644
--- a/test/response_test.dart
+++ b/test/response_test.dart
@@ -10,12 +10,12 @@
void main() {
group('()', () {
test('sets body', () {
- var response = http.Response("Hello, world!", 200);
- expect(response.body, equals("Hello, world!"));
+ var response = http.Response('Hello, world!', 200);
+ expect(response.body, equals('Hello, world!'));
});
test('sets bodyBytes', () {
- var response = http.Response("Hello, world!", 200);
+ var response = http.Response('Hello, world!', 200);
expect(
response.bodyBytes,
equals(
@@ -23,7 +23,7 @@
});
test('respects the inferred encoding', () {
- var response = http.Response("föøbãr", 200,
+ var response = http.Response('föøbãr', 200,
headers: {'content-type': 'text/plain; charset=iso-8859-1'});
expect(response.bodyBytes, equals([102, 246, 248, 98, 227, 114]));
});
@@ -32,7 +32,7 @@
group('.bytes()', () {
test('sets body', () {
var response = http.Response.bytes([104, 101, 108, 108, 111], 200);
- expect(response.body, equals("hello"));
+ expect(response.body, equals('hello'));
});
test('sets bodyBytes', () {
@@ -43,7 +43,7 @@
test('respects the inferred encoding', () {
var response = http.Response.bytes([102, 246, 248, 98, 227, 114], 200,
headers: {'content-type': 'text/plain; charset=iso-8859-1'});
- expect(response.body, equals("föøbãr"));
+ expect(response.body, equals('föøbãr'));
});
});
@@ -54,7 +54,7 @@
http.StreamedResponse(controller.stream, 200, contentLength: 13);
var future = http.Response.fromStream(streamResponse)
.then((response) => response.body);
- expect(future, completion(equals("Hello, world!")));
+ expect(future, completion(equals('Hello, world!')));
controller.add([72, 101, 108, 108, 111, 44, 32]);
controller.add([119, 111, 114, 108, 100, 33]);
diff --git a/test/utils.dart b/test/utils.dart
index 995a1bb..97a66d8 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -89,8 +89,8 @@
var contentType = MediaType.parse(item.headers['content-type']);
var boundary = contentType.parameters['boundary'];
var expected = cleanUpLiteral(_pattern)
- .replaceAll("\n", "\r\n")
- .replaceAll("{{boundary}}", boundary);
+ .replaceAll('\n', '\r\n')
+ .replaceAll('{{boundary}}', boundary);
expect(body, equals(expected));
expect(item.contentLength, equals(bodyBytes.length));