diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2542c27..59f8a19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,7 +78,7 @@ jobs: run: dart pub get - name: Format - run: dart format --set-exit-if-changed -l120 ./lib + run: dart format --set-exit-if-changed -l 160 ./lib unit-tests: needs: [ format, analyze, fix ] diff --git a/Makefile b/Makefile index b1652dd..1aa3fdc 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ help: @fgrep -h "##" $(MAKEFILE_LIST) | sed -e 's/\(\:.*\#\#\)/\:\ /' | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' format: ## Run dart format - dart format -l120 . + dart format -l 160 . fix: ## Run dart fix dart fix --apply diff --git a/lib/src/extensions/channel.dart b/lib/src/extensions/channel.dart index babad9d..246228d 100644 --- a/lib/src/extensions/channel.dart +++ b/lib/src/extensions/channel.dart @@ -13,8 +13,7 @@ extension PartialChannelExtensions on PartialChannel { /// Extensions on [Channel]s. extension ChannelExtensions on Channel { /// A URL clients can visit to navigate to this channel. - Uri get url => Uri.https(manager.client.apiOptions.host, - '/channels/${this is GuildChannel ? '${(this as GuildChannel).guildId}' : '@me'}/$id'); + Uri get url => Uri.https(manager.client.apiOptions.host, '/channels/${this is GuildChannel ? '${(this as GuildChannel).guildId}' : '@me'}/$id'); } /// Extensions on [GuildChannel]s. @@ -22,8 +21,7 @@ extension GuildChannelExtensions on GuildChannel { /// Compute [member]'s permissions in this channel. /// /// {@macro compute_permissions_detail} - Future computePermissionsFor(PartialMember member) async => - await computePermissions(this, await member.get()); + Future computePermissionsFor(PartialMember member) async => await computePermissions(this, await member.get()); } /// Extensions on all [GuildChannel] types @@ -49,9 +47,8 @@ extension GuildChannelsExtension on T { ) as GuildChannelBuilder, GuildVoiceChannel channel => GuildVoiceChannelBuilder( name: channel.name, - permissionOverwrites: channel.permissionOverwrites - .map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)) - .toList(), + permissionOverwrites: + channel.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(), position: channel.position, isNsfw: channel.isNsfw, parentId: channel.parentId, @@ -65,9 +62,8 @@ extension GuildChannelsExtension on T { bitRate: channel.bitrate, isNsfw: channel.isNsfw, parentId: channel.parentId, - permissionOverwrites: channel.permissionOverwrites - .map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)) - .toList(), + permissionOverwrites: + channel.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(), position: channel.position, rtcRegion: channel.rtcRegion, userLimit: channel.userLimit, @@ -86,9 +82,8 @@ extension GuildChannelsExtension on T { ) as GuildChannelBuilder, GuildCategory category => GuildCategoryBuilder( name: category.name, - permissionOverwrites: category.permissionOverwrites - .map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)) - .toList(), + permissionOverwrites: + category.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(), position: category.position, ) as GuildChannelBuilder, GuildAnnouncementChannel channel => GuildAnnouncementChannelBuilder( @@ -96,9 +91,8 @@ extension GuildChannelsExtension on T { defaultAutoArchiveDuration: channel.defaultAutoArchiveDuration, isNsfw: channel.isNsfw, parentId: channel.parentId, - permissionOverwrites: channel.permissionOverwrites - .map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)) - .toList(), + permissionOverwrites: + channel.permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(), position: channel.position, topic: channel.topic, ) as GuildChannelBuilder, @@ -106,9 +100,7 @@ extension GuildChannelsExtension on T { name: name, type: type, position: position, - permissionOverwrites: permissionOverwrites - .map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)) - .toList(), + permissionOverwrites: permissionOverwrites.map((e) => PermissionOverwriteBuilder(id: e.id, type: e.type, allow: e.allow, deny: e.deny)).toList(), ), }; } diff --git a/lib/src/extensions/client.dart b/lib/src/extensions/client.dart index b102b9d..b390e7d 100644 --- a/lib/src/extensions/client.dart +++ b/lib/src/extensions/client.dart @@ -5,11 +5,9 @@ import 'package:nyxx_extensions/src/utils/emoji.dart'; extension NyxxRestExtensions on NyxxRest { /// List all the text emoji available to this client. Future> getTextEmojis() async => (await getEmojiDefinitions()) - .map((definition) => - TextEmoji(id: Snowflake.zero, manager: guilds[Snowflake.zero].emojis, name: definition.surrogates)) + .map((definition) => TextEmoji(id: Snowflake.zero, manager: guilds[Snowflake.zero].emojis, name: definition.surrogates)) .toList(); /// Get a text emoji by name. - TextEmoji getTextEmoji(String name) => - TextEmoji(id: Snowflake.zero, manager: guilds[Snowflake.zero].emojis, name: name); + TextEmoji getTextEmoji(String name) => TextEmoji(id: Snowflake.zero, manager: guilds[Snowflake.zero].emojis, name: name); } diff --git a/lib/src/extensions/emoji.dart b/lib/src/extensions/emoji.dart index 4c5df88..8ff7fa7 100644 --- a/lib/src/extensions/emoji.dart +++ b/lib/src/extensions/emoji.dart @@ -4,6 +4,6 @@ import 'package:nyxx_extensions/src/utils/emoji.dart'; /// Extensions on [TextEmoji]. extension TextEmojiExtensions on TextEmoji { /// Get the definition of this emoji. - Future getDefinition() async => (await getEmojiDefinitions()) - .singleWhere((definition) => definition.surrogates == name || definition.alternateSurrogates == name); + Future getDefinition() async => + (await getEmojiDefinitions()).singleWhere((definition) => definition.surrogates == name || definition.alternateSurrogates == name); } diff --git a/lib/src/extensions/guild.dart b/lib/src/extensions/guild.dart index f3e1308..8dd668a 100644 --- a/lib/src/extensions/guild.dart +++ b/lib/src/extensions/guild.dart @@ -9,21 +9,16 @@ extension PartialGuildExtensions on PartialGuild { /// Same as [listBans], but has no limit on the number of bans returned. /// /// {@macro paginated_endpoint_streaming_parameters} - Stream streamBans({Snowflake? after, Snowflake? before, int? pageSize}) => - manager.streamBans(id, after: after, before: before, pageSize: pageSize); + Stream streamBans({Snowflake? after, Snowflake? before, int? pageSize}) => manager.streamBans(id, after: after, before: before, pageSize: pageSize); /// Return a list of channels in the client's cache that are in this guild. - List get cachedChannels => - manager.client.channels.cache.values.whereType().where((element) => element.guildId == id).toList(); + List get cachedChannels => manager.client.channels.cache.values.whereType().where((element) => element.guildId == id).toList(); } /// Extensions on [Guild]s. extension GuildExtensions on Guild { /// The acronym of the guild if no icon is chosen. String get acronym { - return name - .replaceAll(r"'s ", ' ') - .replaceAllMapped(RegExp(r'\w+'), (match) => match[0]![0]) - .replaceAll(RegExp(r'\s'), ''); + return name.replaceAll(r"'s ", ' ').replaceAllMapped(RegExp(r'\w+'), (match) => match[0]![0]).replaceAll(RegExp(r'\s'), ''); } } diff --git a/lib/src/extensions/managers/scheduled_event_manager.dart b/lib/src/extensions/managers/scheduled_event_manager.dart index da7988d..645ba35 100644 --- a/lib/src/extensions/managers/scheduled_event_manager.dart +++ b/lib/src/extensions/managers/scheduled_event_manager.dart @@ -17,8 +17,7 @@ extension ScheduledEventManagerExtensions on ScheduledEventManager { StreamOrder? order, }) => streamPaginatedEndpoint( - ({after, before, limit}) => - listEventUsers(id, after: after, before: before, limit: limit, withMembers: withMembers), + ({after, before, limit}) => listEventUsers(id, after: after, before: before, limit: limit, withMembers: withMembers), extractId: (user) => user.user.id, before: before, after: after, diff --git a/lib/src/extensions/managers/user_manager.dart b/lib/src/extensions/managers/user_manager.dart index 5f843ad..e4102eb 100644 --- a/lib/src/extensions/managers/user_manager.dart +++ b/lib/src/extensions/managers/user_manager.dart @@ -16,8 +16,7 @@ extension UserManagerExtensions on UserManager { StreamOrder? order, }) => streamPaginatedEndpoint( - ({after, before, limit}) => - listCurrentUserGuilds(after: after, before: before, limit: limit, withCounts: withCounts), + ({after, before, limit}) => listCurrentUserGuilds(after: after, before: before, limit: limit, withCounts: withCounts), extractId: (guild) => guild.id, before: before, after: after, diff --git a/lib/src/extensions/member.dart b/lib/src/extensions/member.dart index a859cd4..8c08dd0 100644 --- a/lib/src/extensions/member.dart +++ b/lib/src/extensions/member.dart @@ -6,6 +6,5 @@ extension PartialMemberExtensions on PartialMember { /// Compute this member's permissions in [channel]. /// /// {@macro compute_permissions_detail} - Future computePermissionsIn(GuildChannel channel) async => - await computePermissions(channel, await get()); + Future computePermissionsIn(GuildChannel channel) async => await computePermissions(channel, await get()); } diff --git a/lib/src/utils/formatters.dart b/lib/src/utils/formatters.dart index ec33b39..eb23179 100644 --- a/lib/src/utils/formatters.dart +++ b/lib/src/utils/formatters.dart @@ -28,8 +28,7 @@ String quoteBlock(String content) => '>>> $content'; String hideEmbed(String url) => '<$url>'; /// Format the [content] and the URL into a hyperlink (aka [Markdown link](https://www.markdownguide.org/basic-syntax/#links)), and optionally, add a [title] that will be displayed on hover. -String hyperlink(String content, String url, [String? title]) => - '[$content](<$url>${title != null ? ' "$title"' : ''})'; +String hyperlink(String content, String url, [String? title]) => '[$content](<$url>${title != null ? ' "$title"' : ''})'; /// Wraps the [content] inside `||`. String spoiler(String content) => '||$content||'; diff --git a/lib/src/utils/pagination.dart b/lib/src/utils/pagination.dart index 9dc0c84..6896f4c 100644 --- a/lib/src/utils/pagination.dart +++ b/lib/src/utils/pagination.dart @@ -122,15 +122,12 @@ class Pagination extends NyxxPlugin { /// A stream of interactions that were recognized as being created by a [Pagination] plugin different to this one. /// /// This is often a sign of leftover menus from a previous client session. - Stream> get onUnhandledInteraction => - _unhandledInteractionsController.stream; - final StreamController> _unhandledInteractionsController = - StreamController.broadcast(); + Stream> get onUnhandledInteraction => _unhandledInteractionsController.stream; + final StreamController> _unhandledInteractionsController = StreamController.broadcast(); /// A stream of interactions that were recognized by this plugin but were not handled because the wrong user triggered the interaction. Stream> get onDisallowedUse => _disallowedUseController.stream; - final StreamController> _disallowedUseController = - StreamController.broadcast(); + final StreamController> _disallowedUseController = StreamController.broadcast(); /// Create a new [Pagination] instance. Pagination(this.options); @@ -436,9 +433,7 @@ class _PaginationState { } final knownIds = {jumpToStartId, jumpToEndId, previousId, nextId}; - if (builder.components?.any((row) => - row.components.any((element) => element is ButtonBuilder && knownIds.contains(element.customId))) == - true) { + if (builder.components?.any((row) => row.components.any((element) => element is ButtonBuilder && knownIds.contains(element.customId))) == true) { // We've already added controls to this builder, likely when the user navigated to this page previously. return; } diff --git a/lib/src/utils/sanitizer.dart b/lib/src/utils/sanitizer.dart index 15f832c..ab7bb07 100644 --- a/lib/src/utils/sanitizer.dart +++ b/lib/src/utils/sanitizer.dart @@ -137,8 +137,7 @@ Future sanitizeContent( SanitizerTarget.roles => '<@&$_whitespaceCharacter${match.group(1)!}>', SanitizerTarget.everyone => '@$_whitespaceCharacter${match.group(1)!}', SanitizerTarget.channels => '<#$_whitespaceCharacter${match.group(1)!}>', - SanitizerTarget.emojis => - '<$_whitespaceCharacter${match.group(1) ?? ''}\\:${match.group(2)}\\:${match.group(3)}>', + SanitizerTarget.emojis => '<$_whitespaceCharacter${match.group(1) ?? ''}\\:${match.group(2)}\\:${match.group(3)}>', SanitizerTarget.commands => '', }, }; diff --git a/test/integration/endpoint_streaming_test.dart b/test/integration/endpoint_streaming_test.dart index e89864c..8b92456 100644 --- a/test/integration/endpoint_streaming_test.dart +++ b/test/integration/endpoint_streaming_test.dart @@ -52,8 +52,7 @@ void main() { expect(oldestFirstMessages[i].id.isBefore(oldestFirstMessages[i + 1].id), isTrue); } - final mostRecentFirstMessages = - await channel.messages.stream(order: StreamOrder.mostRecentFirst).take(50).toList(); + final mostRecentFirstMessages = await channel.messages.stream(order: StreamOrder.mostRecentFirst).take(50).toList(); for (int i = 0; i < mostRecentFirstMessages.length - 1; i++) { expect(mostRecentFirstMessages[i].id.isAfter(mostRecentFirstMessages[i + 1].id), isTrue); } diff --git a/test/integration/member_test.dart b/test/integration/member_test.dart index 518da0c..14942f7 100644 --- a/test/integration/member_test.dart +++ b/test/integration/member_test.dart @@ -35,8 +35,7 @@ void main() { expect( self.avatar.get(size: 3072, format: CdnFormat.jpeg), - Uri.https( - 'cdn.discordapp.com', 'avatars/${self.id}/${self.avatarHash}.${CdnFormat.jpeg.extension}', {'size': '3072'}), + Uri.https('cdn.discordapp.com', 'avatars/${self.id}/${self.avatarHash}.${CdnFormat.jpeg.extension}', {'size': '3072'}), ); }); } diff --git a/test/unit/sanitizer_test.dart b/test/unit/sanitizer_test.dart index dafe1af..101f897 100644 --- a/test/unit/sanitizer_test.dart +++ b/test/unit/sanitizer_test.dart @@ -32,20 +32,17 @@ void main() { test( 'ignore', - () async => expect(await sanitizeContent(sampleContent, channel: channel, action: SanitizerAction.ignore), - equals(sampleContent)), + () async => expect(await sanitizeContent(sampleContent, channel: channel, action: SanitizerAction.ignore), equals(sampleContent)), ); test( 'remove', - () async => expect( - await sanitizeContent(sampleContent, channel: channel, action: SanitizerAction.remove), equals(removed)), + () async => expect(await sanitizeContent(sampleContent, channel: channel, action: SanitizerAction.remove), equals(removed)), ); test( 'sanitize', - () async => expect( - await sanitizeContent(sampleContent, channel: channel, action: SanitizerAction.sanitize), equals(sanitized)), + () async => expect(await sanitizeContent(sampleContent, channel: channel, action: SanitizerAction.sanitize), equals(sanitized)), ); }); } diff --git a/test/unit/timestamp_style_test.dart b/test/unit/timestamp_style_test.dart index 8ae0cd2..989634f 100644 --- a/test/unit/timestamp_style_test.dart +++ b/test/unit/timestamp_style_test.dart @@ -7,33 +7,12 @@ final baseDate = Snowflake(846136758470443069).timestamp; void main() { group('Timestamp Test', () { test('None', () => expect(baseDate.format(), equals(''))); - test( - 'Short Time', - () => expect( - baseDate.format(TimestampStyle.shortTime), equals(''))); - test( - 'Long Time', - () => expect( - baseDate.format(TimestampStyle.longTime), equals(''))); - test( - 'Short Date', - () => expect( - baseDate.format(TimestampStyle.shortDate), equals(''))); - test( - 'Long Date', - () => expect( - baseDate.format(TimestampStyle.longDate), equals(''))); - test( - 'Short Date Time', - () => expect( - baseDate.format(TimestampStyle.shortDateTime), equals(''))); - test( - 'Long Date Time', - () => expect( - baseDate.format(TimestampStyle.longDateTime), equals(''))); - test( - 'Relative Time', - () => expect( - baseDate.format(TimestampStyle.relativeTime), equals(''))); + test('Short Time', () => expect(baseDate.format(TimestampStyle.shortTime), equals(''))); + test('Long Time', () => expect(baseDate.format(TimestampStyle.longTime), equals(''))); + test('Short Date', () => expect(baseDate.format(TimestampStyle.shortDate), equals(''))); + test('Long Date', () => expect(baseDate.format(TimestampStyle.longDate), equals(''))); + test('Short Date Time', () => expect(baseDate.format(TimestampStyle.shortDateTime), equals(''))); + test('Long Date Time', () => expect(baseDate.format(TimestampStyle.longDateTime), equals(''))); + test('Relative Time', () => expect(baseDate.format(TimestampStyle.relativeTime), equals(''))); }); }