Skip to content

Commit

Permalink
🎨 Format all (cfug#2210)
Browse files Browse the repository at this point in the history
All works are done by `dart fix --apply` automatically.
  • Loading branch information
AlexV525 committed May 11, 2024
1 parent 87e6b1d commit 392d2d8
Show file tree
Hide file tree
Showing 59 changed files with 495 additions and 377 deletions.
27 changes: 26 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@ include: package:lints/recommended.yaml

analyzer:
errors:
always_declare_return_types: error
always_put_control_body_on_new_line: warning
avoid_renaming_method_parameters: error
avoid_void_async: error
camel_case_types: error
constant_identifier_names: error
deprecated_member_use_from_same_package: ignore
non_constant_identifier_names: error
prefer_single_quotes: warning
require_trailing_commas: warning
todo: ignore

linter:
rules:
always_declare_return_types: true
always_put_control_body_on_new_line: true
avoid_renaming_method_parameters: true
avoid_unnecessary_containers: true
avoid_void_async: true
prefer_final_locals: true
curly_braces_in_flow_control_structures: true
directives_ordering: true
library_annotations: false
prefer_const_constructors: true
prefer_const_constructors_in_immutables: false
prefer_final_fields: true
prefer_final_in_for_each: true
prefer_final_locals: true
prefer_single_quotes: true
require_trailing_commas: true
sort_constructors_first: true
sort_unnamed_constructors_first: true
unnecessary_await_in_return: true
unnecessary_breaks: true
unnecessary_late: true
unnecessary_parenthesis: true
5 changes: 2 additions & 3 deletions dio/lib/src/adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import 'dart:typed_data';

import 'package:meta/meta.dart';

import 'adapters/io_adapter.dart'
if (dart.library.html) 'adapters/browser_adapter.dart' as adapter;
import 'headers.dart';
import 'options.dart';
import 'redirect_record.dart';

import 'adapters/io_adapter.dart'
if (dart.library.html) 'adapters/browser_adapter.dart' as adapter;

/// {@template dio.HttpClientAdapter}
/// [HttpAdapter] is a bridge between [Dio] and [HttpClient].
///
Expand Down
14 changes: 8 additions & 6 deletions dio/lib/src/adapters/io_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ class IOHttpClientAdapter implements HttpClientAdapter {
"Can't establish connection after the adapter was closed.",
);
}
final operation = CancelableOperation.fromFuture(_fetch(
options,
requestStream,
cancelFuture,
));
final operation = CancelableOperation.fromFuture(
_fetch(
options,
requestStream,
cancelFuture,
),
);
cancelFuture?.whenComplete(() => operation.cancel());
return operation.value;
}
Expand Down Expand Up @@ -234,7 +236,7 @@ class IOHttpClientAdapter implements HttpClientAdapter {
if (createHttpClient != null) {
return createHttpClient!();
}
final client = HttpClient()..idleTimeout = Duration(seconds: 3);
final client = HttpClient()..idleTimeout = const Duration(seconds: 3);
// ignore: deprecated_member_use, deprecated_member_use_from_same_package
return onHttpClientCreate?.call(client) ?? client;
}
Expand Down
11 changes: 5 additions & 6 deletions dio/lib/src/dio.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'dart:async';

import 'adapter.dart';
import 'dio_mixin.dart';
import 'options.dart';
import 'headers.dart';
import 'cancel_token.dart';
import 'transformer.dart';
import 'response.dart';

import 'dio/dio_for_native.dart'
if (dart.library.html) 'dio/dio_for_browser.dart';
import 'dio_mixin.dart';
import 'headers.dart';
import 'options.dart';
import 'response.dart';
import 'transformer.dart';

/// Dio enables you to make HTTP requests easily.
///
Expand Down
6 changes: 3 additions & 3 deletions dio/lib/src/dio/dio_for_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 'dart:async';
import 'dart:io';

import '../adapter.dart';
import '../adapters/io_adapter.dart';
import '../cancel_token.dart';
import '../dio.dart';
import '../dio_exception.dart';
import '../dio_mixin.dart';
import '../response.dart';
import '../dio.dart';
import '../headers.dart';
import '../options.dart';
import '../adapters/io_adapter.dart';
import '../response.dart';

/// Create the [Dio] instance for native platforms.
Dio createDio([BaseOptions? baseOptions]) => DioForNative(baseOptions);
Expand Down
5 changes: 2 additions & 3 deletions dio/lib/src/dio_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import 'form_data.dart';
import 'headers.dart';
import 'interceptors/imply_content_type.dart';
import 'options.dart';
import 'progress_stream/io_progress_stream.dart'
if (dart.library.html) 'progress_stream/browser_progress_stream.dart';
import 'response.dart';
import 'response/response_stream_handler.dart';
import 'transformer.dart';
import 'transformers/background_transformer.dart';

import 'progress_stream/io_progress_stream.dart'
if (dart.library.html) 'progress_stream/browser_progress_stream.dart';

part 'interceptor.dart';

// TODO(EVERYONE): Use `mixin class` when the lower bound of SDK is raised to 3.0.0.
Expand Down
20 changes: 15 additions & 5 deletions dio/lib/src/headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ class Headers {
/// thrown.
String? value(String name) {
final arr = this[name];
if (arr == null) return null;
if (arr.length == 1) return arr.first;
if (arr == null) {
return null;
}
if (arr.length == 1) {
return arr.first;
}
throw Exception(
'"$name" header has more than one value, please use Headers[name]',
);
Expand All @@ -64,14 +68,18 @@ class Headers {
/// [value] added to its list of values.
void add(String name, String value) {
final arr = this[name];
if (arr == null) return set(name, value);
if (arr == null) {
return set(name, value);
}
arr.add(value);
}

/// Sets a header. The header named [name] will have all its values
/// cleared before the value [value] is added as its value.
void set(String name, dynamic value) {
if (value == null) return;
if (value == null) {
return;
}
name = name.trim();
if (value is List) {
_map[name] = value.map<String>((e) => '$e').toList();
Expand All @@ -83,7 +91,9 @@ class Headers {
/// Removes a specific value for a header name.
void remove(String name, String value) {
final arr = this[name];
if (arr == null) return;
if (arr == null) {
return;
}
arr.removeWhere((v) => v == value);
}

Expand Down
3 changes: 2 additions & 1 deletion dio/lib/src/multipart_file.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'dart:async';
import 'dart:convert';

import 'package:http_parser/http_parser.dart';
import 'utils.dart';

import 'multipart_file/io_multipart_file.dart'
if (dart.library.html) 'multipart_file/browser_multipart_file.dart';
import 'utils.dart';

/// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to
/// correspond to a physical file.
Expand Down
4 changes: 3 additions & 1 deletion dio/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ class Options {
}) {
final query = <String, dynamic>{};
query.addAll(baseOpt.queryParameters);
if (queryParameters != null) query.addAll(queryParameters);
if (queryParameters != null) {
query.addAll(queryParameters);
}
final headers = caseInsensitiveKeyMap(baseOpt.headers);
if (this.headers != null) {
Expand Down
12 changes: 9 additions & 3 deletions dio/lib/src/transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ abstract class Transformer {
return encodeMap(
map,
(key, value) {
if (value == null) return key;
if (value == null) {
return key;
}
return '$key=${Uri.encodeQueryComponent(value.toString())}';
},
listFormat: listFormat,
Expand All @@ -51,7 +53,9 @@ abstract class Transformer {
return encodeMap(
map,
(key, value) {
if (value == null) return key;
if (value == null) {
return key;
}
return '$key=$value';
},
listFormat: listFormat,
Expand All @@ -61,7 +65,9 @@ abstract class Transformer {

/// See https://mimesniff.spec.whatwg.org/#json-mime-type.
static bool isJsonMimeType(String? contentType) {
if (contentType == null) return false;
if (contentType == null) {
return false;
}
final mediaType = MediaType.parse(contentType);
return mediaType.mimeType == 'application/json' ||
mediaType.mimeType == 'text/json' ||
Expand Down
2 changes: 1 addition & 1 deletion dio/lib/src/transformers/sync_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SyncTransformer extends Transformer {
final decodeResponse = options.responseDecoder!(
responseBytes,
options,
responseBody..stream = Stream.empty(),
responseBody..stream = const Stream.empty(),
);

if (decodeResponse is Future) {
Expand Down
8 changes: 6 additions & 2 deletions dio/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Future writeStreamToSink(Stream stream, EventSink sink) {
/// [charset] is null or if no [Encoding] was found that corresponds to
/// [charset].
Encoding encodingForCharset(String? charset, [Encoding fallback = latin1]) {
if (charset == null) return fallback;
if (charset == null) {
return fallback;
}
final encoding = Encoding.getByName(charset);
return encoding ?? fallback;
}
Expand Down Expand Up @@ -145,7 +147,9 @@ Map<String, V> caseInsensitiveKeyMap<V>([Map<String, V>? value]) {
equals: (key1, key2) => key1.toLowerCase() == key2.toLowerCase(),
hashCode: (key) => key.toLowerCase().hashCode,
);
if (value != null && value.isNotEmpty) map.addAll(value);
if (value != null && value.isNotEmpty) {
map.addAll(value);
}
return map;
}

Expand Down
2 changes: 1 addition & 1 deletion dio/test/browser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
final browserAdapter = BrowserHttpClientAdapter(withCredentials: true);
final opts = RequestOptions();
final testStream = Stream<Uint8List>.periodic(
Duration(seconds: 1),
const Duration(seconds: 1),
(x) => Uint8List(x),
);
final cancelFuture = opts.cancelToken?.whenCancel;
Expand Down
2 changes: 1 addition & 1 deletion dio/test/dio_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
test('throws UnimplementedError when calling download', () {
expectLater(
() => _TestDioMixin().download('a', 'b'),
throwsA(TypeMatcher<UnimplementedError>()),
throwsA(const TypeMatcher<UnimplementedError>()),
);
});
}
Expand Down
32 changes: 16 additions & 16 deletions dio/test/encoding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void main() {
'd': 8,
'e': {
'a': 5,
'b': [66, 8]
}
}
'b': [66, 8],
},
},
};
test('default ', () {
// a=你好&b=5&b=6&c[d]=8&c[e][a]=5&c[e][b]=66&c[e][b]=8
Expand Down Expand Up @@ -76,18 +76,18 @@ void main() {
Transformer.urlEncodeMap(
{
'a': '你好',
'b': ListParam<int>([5, 6], ListFormat.pipes),
'b': const ListParam<int>([5, 6], ListFormat.pipes),
'c': {
'd': 8,
'e': {
'a': 5,
'b': ListParam<String>(['foo', 'bar'], ListFormat.csv),
'c': ListParam<String>(['foo', 'bar'], ListFormat.ssv),
'd': ListParam<String>(['foo', 'bar'], ListFormat.multi),
'e': ListParam<String>(['foo', 'bar'], ListFormat.tsv),
'b': const ListParam<String>(['foo', 'bar'], ListFormat.csv),
'c': const ListParam<String>(['foo', 'bar'], ListFormat.ssv),
'd': const ListParam<String>(['foo', 'bar'], ListFormat.multi),
'e': const ListParam<String>(['foo', 'bar'], ListFormat.tsv),
'f': [
'foo',
'bar'
'bar',
], // this uses ListFormat.multiCompatible set below
},
},
Expand All @@ -103,7 +103,7 @@ void main() {
test(ListFormat.csv, () {
expect(
Transformer.urlEncodeQueryMap({
'foo': ListParam(['1', '%', '\$'], ListFormat.csv)
'foo': const ListParam(['1', '%', '\$'], ListFormat.csv),
}),
'foo=1,%25,%24',
);
Expand All @@ -114,32 +114,32 @@ void main() {
Transformer.urlEncodeQueryMap(
{
'a': '你好',
'b': ListParam<int>([5, 6], ListFormat.pipes),
'b': const ListParam<int>([5, 6], ListFormat.pipes),
'c': {
'd': 8,
'e': {
'a': 5,
'b': ListParam<Object>(
'b': const ListParam<Object>(
['foo', 'bar', 1, 2.2],
ListFormat.csv,
),
'c': ListParam<Object>(
'c': const ListParam<Object>(
['foo', 'bar', 1, 2.2],
ListFormat.ssv,
),
'd': ListParam<Object>(
'd': const ListParam<Object>(
['foo', 'bar', 1, 2.2],
ListFormat.multi,
),
'e': ListParam<Object>(
'e': const ListParam<Object>(
['foo', 'bar', 1, 2.2],
ListFormat.tsv,
),
'f': [
'foo',
'bar',
1,
2.2
2.2,
], // this uses ListFormat.multiCompatible set below
},
},
Expand Down
Loading

0 comments on commit 392d2d8

Please sign in to comment.