From 5beeed23875761dd939b07a652b2a58756969612 Mon Sep 17 00:00:00 2001 From: Hexah Date: Wed, 10 Jun 2020 00:08:16 +0200 Subject: [PATCH] Code style --- analysis_options.yaml | 67 +++++++++++++++---- lib/src/channels/channel_client.dart | 2 +- lib/src/channels/channel_id.dart | 4 +- lib/src/playlists/playlist_client.dart | 1 + lib/src/playlists/playlist_id.dart | 2 +- lib/src/retry.dart | 1 + .../responses/video_info_response.dart | 21 +----- lib/src/videos/streams/streams_client.dart | 6 +- test/video_test.dart | 4 +- 9 files changed, 67 insertions(+), 41 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index fd82153..3464177 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -6,17 +6,60 @@ include: package:effective_dart/analysis_options.yaml # For lint rules and documentation, see http://dart-lang.github.io/linter/lints. # Uncomment to specify additional rules. linter: - rules: - - valid_regexps - - prefer_const_constructors - - prefer_const_declarations - - prefer_const_literals_to_create_immutables - - prefer_constructors_over_static_methods - - prefer_contains - - annotate_overrides - - await_only_futures - - unawaited_futures + rules: + - valid_regexps + - prefer_const_constructors + - prefer_const_declarations + - prefer_const_literals_to_create_immutables + - prefer_constructors_over_static_methods + - prefer_contains + - annotate_overrides + - await_only_futures + - unawaited_futures + - avoid_empty_else + - avoid_returning_null_for_future + - avoid_types_as_parameter_names + - control_flow_in_finally + - empty_statements + - invariant_booleans + - iterable_contains_unrelated_type + - list_remove_unrelated_type + - literal_only_boolean_expressions + - no_adjacent_strings_in_list + - no_duplicate_case_values + - prefer_void_to_null + - test_types_in_equals + - throw_in_finally + - unnecessary_statements + - unrelated_type_equality_checks + - always_declare_return_types + - always_put_control_body_on_new_line + - avoid_returning_null_for_void + - avoid_setters_without_getters + - avoid_shadowing_type_parameters + - avoid_unnecessary_containers + - avoid_void_async + - empty_catches + - null_closures + - prefer_conditional_assignment + - prefer_if_null_operators + - prefer_is_empty + - prefer_is_not_empty + - prefer_is_not_operator + - prefer_null_aware_operators + - recursive_getters + - unnecessary_await_in_return + - unnecessary_null_aware_assignments + - unnecessary_null_in_if_null_operators + - unnecessary_overrides + - unnecessary_parenthesis + - unnecessary_raw_strings + - unnecessary_string_escapes + - unnecessary_string_interpolations + - use_string_buffers + - void_checks + - package_names analyzer: - exclude: - - example\** + exclude: + - example\** diff --git a/lib/src/channels/channel_client.dart b/lib/src/channels/channel_client.dart index 743187e..f0f4b50 100644 --- a/lib/src/channels/channel_client.dart +++ b/lib/src/channels/channel_client.dart @@ -45,7 +45,7 @@ class ChannelClient { var playerResponse = videoInfoResponse.playerResponse; var channelId = playerResponse.videoChannelId; - return await get(ChannelId(channelId)); + return get(ChannelId(channelId)); } /// Enumerates videos uploaded by the specified channel. diff --git a/lib/src/channels/channel_id.dart b/lib/src/channels/channel_id.dart index bf1f902..ff3888a 100644 --- a/lib/src/channels/channel_id.dart +++ b/lib/src/channels/channel_id.dart @@ -28,7 +28,7 @@ class ChannelId extends Equatable { return false; } - return !RegExp('[^0-9a-zA-Z_\-]').hasMatch(id); + return !RegExp(r'[^0-9a-zA-Z_\-]').hasMatch(id); } /// Parses a channel id from an url. @@ -61,7 +61,7 @@ class ChannelId extends Equatable { } @override - String toString() => '$value'; + String toString() => value; @override List get props => [value]; diff --git a/lib/src/playlists/playlist_client.dart b/lib/src/playlists/playlist_client.dart index 247c60b..2af3b6e 100644 --- a/lib/src/playlists/playlist_client.dart +++ b/lib/src/playlists/playlist_client.dart @@ -32,6 +32,7 @@ class PlaylistClient { id = PlaylistId.fromString(id); var encounteredVideoIds = {}; var index = 0; + // ignore: literal_only_boolean_expressions while (true) { var response = await PlaylistResponse.get(_httpClient, id.value, index: index); diff --git a/lib/src/playlists/playlist_id.dart b/lib/src/playlists/playlist_id.dart index c318539..f199add 100644 --- a/lib/src/playlists/playlist_id.dart +++ b/lib/src/playlists/playlist_id.dart @@ -5,7 +5,7 @@ class PlaylistId { static final _regMatchExp = RegExp(r'youtube\..+?/playlist.*?list=(.*?)(?:&|/|$)'); static final _compositeMatchExp = RegExp( - r'https://www.youtube.com/watch?v=b8m9zhNAgKs&list=PL9tY0BWXOZFuFEG_GtOBZ8-8wbkH-NVAr'); + 'https://www.youtube.com/watch?v=b8m9zhNAgKs&list=PL9tY0BWXOZFuFEG_GtOBZ8-8wbkH-NVAr'); static final _shortCompositeMatchExp = RegExp(r'youtu\.be/.*?/.*?list=(.*?)(?:&|/|$)'); static final _embedCompositeMatchExp = diff --git a/lib/src/retry.dart b/lib/src/retry.dart index 85bbae5..54f1ebc 100644 --- a/lib/src/retry.dart +++ b/lib/src/retry.dart @@ -9,6 +9,7 @@ import 'exceptions/exceptions.dart'; Future retry(FutureOr function()) async { var retryCount = 5; + // ignore: literal_only_boolean_expressions while (true) { try { return await function(); diff --git a/lib/src/reverse_engineering/responses/video_info_response.dart b/lib/src/reverse_engineering/responses/video_info_response.dart index 8d0948a..589dbc5 100644 --- a/lib/src/reverse_engineering/responses/video_info_response.dart +++ b/lib/src/reverse_engineering/responses/video_info_response.dart @@ -108,23 +108,4 @@ class _StreamInfo extends StreamInfoProvider { @override int get framerate => int.tryParse(_root['fps'] ?? ''); -} - -extension on String { - String get nullIfWhitespace => trim().isEmpty ? null : this; - - bool get isNullOrWhiteSpace { - if (this == null) { - return true; - } - if (trim().isEmpty) { - return true; - } - return false; - } - - String substringUntil(String separator) => substring(0, indexOf(separator)); - - String substringAfter(String separator) => - substring(indexOf(separator) + length); -} +} \ No newline at end of file diff --git a/lib/src/videos/streams/streams_client.dart b/lib/src/videos/streams/streams_client.dart index a311ad6..5d4a632 100644 --- a/lib/src/videos/streams/streams_client.dart +++ b/lib/src/videos/streams/streams_client.dart @@ -43,9 +43,9 @@ class StreamsClient { await PlayerSource.get(_httpClient, playerConfig.sourceUrl); var cipherOperations = playerSource.getCiperOperations(); - var videoInfoReponse = await VideoInfoResponse.get( + var videoInfoResponse = await VideoInfoResponse.get( _httpClient, videoId.toString(), playerSource.sts); - var playerResponse = videoInfoReponse.playerResponse; + var playerResponse = videoInfoResponse.playerResponse; var previewVideoId = playerResponse.previewVideoId; if (!previewVideoId.isNullOrWhiteSpace) { @@ -63,7 +63,7 @@ class StreamsClient { } var streamInfoProviders = [ - ...videoInfoReponse.streams, + ...videoInfoResponse.streams, ...playerResponse.streams ]; diff --git a/test/video_test.dart b/test/video_test.dart index 93e6ba8..3157ff1 100644 --- a/test/video_test.dart +++ b/test/video_test.dart @@ -48,9 +48,9 @@ void main() { }); test('GetMetadataOfInvalidVideo', () async { - expect(() async => await yt.videos.get(VideoId('qld9w0b-1ao')), + expect(() async => yt.videos.get(VideoId('qld9w0b-1ao')), throwsA(const TypeMatcher())); - expect(() async => await yt.videos.get(VideoId('pb_hHv3fByo')), + expect(() async => yt.videos.get(VideoId('pb_hHv3fByo')), throwsA(const TypeMatcher())); }); });