Skip to content

Commit e1f4823

Browse files
authored
Enable and fix lint prefer_single_quotes (#304)
1 parent 92cf21c commit e1f4823

20 files changed

+84
-83
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ linter:
33
rules:
44
- annotate_overrides
55
- prefer_generic_function_type_aliases
6+
- prefer_single_quotes
67
- unnecessary_const
78
- unnecessary_new

example/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import 'package:http/http.dart' as http;
44
main(List<String> arguments) async {
55
// This example uses the Google Books API to search for books about http.
66
// https://developers.google.com/books/docs/overview
7-
var url = "https://www.googleapis.com/books/v1/volumes?q={http}";
7+
var url = 'https://www.googleapis.com/books/v1/volumes?q={http}';
88

99
// Await the http get response, then decode the json-formatted response.
1010
var response = await http.get(url);
1111
if (response.statusCode == 200) {
1212
var jsonResponse = convert.jsonDecode(response.body);
1313
var itemCount = jsonResponse['totalItems'];
14-
print("Number of books about http: $itemCount.");
14+
print('Number of books about http: $itemCount.');
1515
} else {
16-
print("Request failed with status: ${response.statusCode}.");
16+
print('Request failed with status: ${response.statusCode}.');
1717
}
1818
}

lib/src/base_client.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ abstract class BaseClient implements Client {
2323
/// For more fine-grained control over the request, use [send] instead.
2424
@override
2525
Future<Response> head(url, {Map<String, String> headers}) =>
26-
_sendUnstreamed("HEAD", url, headers);
26+
_sendUnstreamed('HEAD', url, headers);
2727

2828
/// Sends an HTTP GET request with the given headers to the given URL, which
2929
/// can be a [Uri] or a [String].
3030
///
3131
/// For more fine-grained control over the request, use [send] instead.
3232
@override
3333
Future<Response> get(url, {Map<String, String> headers}) =>
34-
_sendUnstreamed("GET", url, headers);
34+
_sendUnstreamed('GET', url, headers);
3535

3636
/// Sends an HTTP POST request with the given headers and body to the given
3737
/// URL, which can be a [Uri] or a [String].
@@ -54,7 +54,7 @@ abstract class BaseClient implements Client {
5454
@override
5555
Future<Response> post(url,
5656
{Map<String, String> headers, body, Encoding encoding}) =>
57-
_sendUnstreamed("POST", url, headers, body, encoding);
57+
_sendUnstreamed('POST', url, headers, body, encoding);
5858

5959
/// Sends an HTTP PUT request with the given headers and body to the given
6060
/// URL, which can be a [Uri] or a [String].
@@ -77,7 +77,7 @@ abstract class BaseClient implements Client {
7777
@override
7878
Future<Response> put(url,
7979
{Map<String, String> headers, body, Encoding encoding}) =>
80-
_sendUnstreamed("PUT", url, headers, body, encoding);
80+
_sendUnstreamed('PUT', url, headers, body, encoding);
8181

8282
/// Sends an HTTP PATCH request with the given headers and body to the given
8383
/// URL, which can be a [Uri] or a [String].
@@ -100,15 +100,15 @@ abstract class BaseClient implements Client {
100100
@override
101101
Future<Response> patch(url,
102102
{Map<String, String> headers, body, Encoding encoding}) =>
103-
_sendUnstreamed("PATCH", url, headers, body, encoding);
103+
_sendUnstreamed('PATCH', url, headers, body, encoding);
104104

105105
/// Sends an HTTP DELETE request with the given headers to the given URL,
106106
/// which can be a [Uri] or a [String].
107107
///
108108
/// For more fine-grained control over the request, use [send] instead.
109109
@override
110110
Future<Response> delete(url, {Map<String, String> headers}) =>
111-
_sendUnstreamed("DELETE", url, headers);
111+
_sendUnstreamed('DELETE', url, headers);
112112

113113
/// Sends an HTTP GET request with the given headers to the given URL, which
114114
/// can be a [Uri] or a [String], and returns a Future that completes to the
@@ -181,12 +181,12 @@ abstract class BaseClient implements Client {
181181
/// Throws an error if [response] is not successful.
182182
void _checkResponseSuccess(url, Response response) {
183183
if (response.statusCode < 400) return;
184-
var message = "Request to $url failed with status ${response.statusCode}";
184+
var message = 'Request to $url failed with status ${response.statusCode}';
185185
if (response.reasonPhrase != null) {
186-
message = "$message: ${response.reasonPhrase}";
186+
message = '$message: ${response.reasonPhrase}';
187187
}
188188
if (url is String) url = Uri.parse(url);
189-
throw ClientException("$message.", url);
189+
throw ClientException('$message.', url);
190190
}
191191

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

lib/src/base_request.dart

Lines changed: 1 addition & 1 deletion
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 ArgumentError("Invalid content length $value.");
37+
throw ArgumentError('Invalid content length $value.');
3838
}
3939
_checkFinalized();
4040
_contentLength = value;

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 ArgumentError("Invalid status code $statusCode.");
47+
throw ArgumentError('Invalid status code $statusCode.');
4848
} else if (contentLength != null && contentLength < 0) {
49-
throw ArgumentError("Invalid content length $contentLength.");
49+
throw ArgumentError('Invalid content length $contentLength.');
5050
}
5151
}
5252
}

lib/src/browser_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BrowserClient extends BaseClient {
8080
// Unfortunately, the underlying XMLHttpRequest API doesn't expose any
8181
// specific information about the error itself.
8282
completer.completeError(
83-
ClientException("XMLHttpRequest error.", request.url),
83+
ClientException('XMLHttpRequest error.', request.url),
8484
StackTrace.current);
8585
}));
8686

lib/src/multipart_file.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MultipartFile {
4949
: this._stream = toByteStream(stream),
5050
this.contentType = contentType != null
5151
? contentType
52-
: MediaType("application", "octet-stream");
52+
: MediaType('application', 'octet-stream');
5353

5454
/// Creates a new [MultipartFile] from a byte array.
5555
///
@@ -71,7 +71,7 @@ class MultipartFile {
7171
factory MultipartFile.fromString(String field, String value,
7272
{String filename, MediaType contentType}) {
7373
contentType =
74-
contentType == null ? MediaType("text", "plain") : contentType;
74+
contentType == null ? MediaType('text', 'plain') : contentType;
7575
var encoding = encodingForCharset(contentType.parameters['charset'], utf8);
7676
contentType = contentType.change(parameters: {'charset': encoding.name});
7777

lib/src/multipart_request.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'byte_stream.dart';
1212
import 'multipart_file.dart';
1313
import 'utils.dart';
1414

15-
final _newlineRegExp = RegExp(r"\r\n|\r|\n");
15+
final _newlineRegExp = RegExp(r'\r\n|\r|\n');
1616

1717
/// A `multipart/form-data` request.
1818
///
@@ -58,30 +58,30 @@ class MultipartRequest extends BaseRequest {
5858
var length = 0;
5959

6060
fields.forEach((name, value) {
61-
length += "--".length +
61+
length += '--'.length +
6262
_boundaryLength +
63-
"\r\n".length +
63+
'\r\n'.length +
6464
utf8.encode(_headerForField(name, value)).length +
6565
utf8.encode(value).length +
66-
"\r\n".length;
66+
'\r\n'.length;
6767
});
6868

6969
for (var file in _files) {
70-
length += "--".length +
70+
length += '--'.length +
7171
_boundaryLength +
72-
"\r\n".length +
72+
'\r\n'.length +
7373
utf8.encode(_headerForFile(file)).length +
7474
file.length +
75-
"\r\n".length;
75+
'\r\n'.length;
7676
}
7777

78-
return length + "--".length + _boundaryLength + "--\r\n".length;
78+
return length + '--'.length + _boundaryLength + '--\r\n'.length;
7979
}
8080

8181
@override
8282
set contentLength(int value) {
83-
throw UnsupportedError("Cannot set the contentLength property of "
84-
"multipart requests.");
83+
throw UnsupportedError('Cannot set the contentLength property of '
84+
'multipart requests.');
8585
}
8686

8787
/// Freezes all mutable fields and returns a single-subscription [ByteStream]
@@ -158,17 +158,17 @@ class MultipartRequest extends BaseRequest {
158158
// follow this at all. Instead, they URL-encode `\r`, `\n`, and `\r\n` as
159159
// `\r\n`; URL-encode `"`; and do nothing else (even for `%` or non-ASCII
160160
// characters). We follow their behavior.
161-
return value.replaceAll(_newlineRegExp, "%0D%0A").replaceAll('"', "%22");
161+
return value.replaceAll(_newlineRegExp, '%0D%0A').replaceAll('"', '%22');
162162
}
163163

164164
/// Returns a randomly-generated multipart boundary string
165165
String _boundaryString() {
166-
var prefix = "dart-http-boundary-";
166+
var prefix = 'dart-http-boundary-';
167167
var list = List<int>.generate(
168168
_boundaryLength - prefix.length,
169169
(index) =>
170170
BOUNDARY_CHARACTERS[_random.nextInt(BOUNDARY_CHARACTERS.length)],
171171
growable: false);
172-
return "$prefix${String.fromCharCodes(list)}";
172+
return '$prefix${String.fromCharCodes(list)}';
173173
}
174174
}

lib/src/request.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Request extends BaseRequest {
2323

2424
@override
2525
set contentLength(int value) {
26-
throw UnsupportedError("Cannot set the contentLength property of "
27-
"non-streaming Request objects.");
26+
throw UnsupportedError('Cannot set the contentLength property of '
27+
'non-streaming Request objects.');
2828
}
2929

3030
/// The default encoding to use when converting between [bodyBytes] and
@@ -87,7 +87,7 @@ class Request extends BaseRequest {
8787
bodyBytes = encoding.encode(value);
8888
var contentType = _contentType;
8989
if (contentType == null) {
90-
_contentType = MediaType("text", "plain", {'charset': encoding.name});
90+
_contentType = MediaType('text', 'plain', {'charset': encoding.name});
9191
} else if (!contentType.parameters.containsKey('charset')) {
9292
_contentType = contentType.change(parameters: {'charset': encoding.name});
9393
}
@@ -110,7 +110,7 @@ class Request extends BaseRequest {
110110
Map<String, String> get bodyFields {
111111
var contentType = _contentType;
112112
if (contentType == null ||
113-
contentType.mimeType != "application/x-www-form-urlencoded") {
113+
contentType.mimeType != 'application/x-www-form-urlencoded') {
114114
throw StateError('Cannot access the body fields of a Request without '
115115
'content-type "application/x-www-form-urlencoded".');
116116
}
@@ -121,8 +121,8 @@ class Request extends BaseRequest {
121121
set bodyFields(Map<String, String> fields) {
122122
var contentType = _contentType;
123123
if (contentType == null) {
124-
_contentType = MediaType("application", "x-www-form-urlencoded");
125-
} else if (contentType.mimeType != "application/x-www-form-urlencoded") {
124+
_contentType = MediaType('application', 'x-www-form-urlencoded');
125+
} else if (contentType.mimeType != 'application/x-www-form-urlencoded') {
126126
throw StateError('Cannot set the body fields of a Request with '
127127
'content-type "${contentType.mimeType}".');
128128
}

lib/src/response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ Encoding _encodingForHeaders(Map<String, String> headers) =>
8282
MediaType _contentTypeForHeaders(Map<String, String> headers) {
8383
var contentType = headers['content-type'];
8484
if (contentType != null) return MediaType.parse(contentType);
85-
return MediaType("application", "octet-stream");
85+
return MediaType('application', 'octet-stream');
8686
}

0 commit comments

Comments
 (0)