Skip to content

Commit a6e4eea

Browse files
committed
Remove redundant return keywords
if and switch expressions are available since Swift 5.9
1 parent 250b173 commit a6e4eea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+386
-386
lines changed

Diff for: Sources/D2Commands/Coding/GermanCoder.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ fileprivate func germanDecodeByte(_ words: [String]) -> UInt8 {
1717
words
1818
.compactMap { (w: String) -> UInt8? in
1919
switch w {
20-
case encodedZero: return 0
21-
case encodedOne: return 1
22-
default: return nil
20+
case encodedZero: 0
21+
case encodedOne: 1
22+
default: nil
2323
}
2424
}
2525
.enumerated()

Diff for: Sources/D2Commands/CommandCategory.swift

+24-24
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ public enum CommandCategory: String, CaseIterable, CustomStringConvertible, Equa
3030

3131
public var description: String {
3232
switch self {
33-
case .administration: return "🖥️ Administration"
34-
case .cau: return "🏫 CAU-specific utilities"
35-
case .coding: return "💱 Encoders and decoders"
36-
case .d2script: return "📜 D2 scripting"
37-
case .dictionary: return "📚 Dictionaries, online search engines and more"
38-
case .emoji: return "😎 Emoji"
39-
case .feed: return "🗞️ Feeds"
40-
case .file: return "📁 File IO"
41-
case .finance: return "📈 Finance"
42-
case .food: return "🍹 Food and drinks"
43-
case .forum: return "📒 Forums"
44-
case .fun: return "🍬 Fun"
45-
case .game: return "🎲 Multiplayer games"
46-
case .imaging: return "🌄 Image and GIF generation/editing"
47-
case .math: return "📊 Mathematics"
48-
case .meta: return "✨ Meta, i.e. commands related to D2 itself"
49-
case .misc: return "🎨 Miscellaneous commands"
50-
case .moderation: return "📣 Moderation"
51-
case .music: return "🎸 Music, theory and chords"
52-
case .programming: return "🎩 Programming"
53-
case .quote: return "💬 Quotes"
54-
case .scripting: return "🛠️ Command scripting"
55-
case .videogame: return "🌲 Video games"
56-
case .web: return "🌐 Web browsing"
33+
case .administration: "🖥️ Administration"
34+
case .cau: "🏫 CAU-specific utilities"
35+
case .coding: "💱 Encoders and decoders"
36+
case .d2script: "📜 D2 scripting"
37+
case .dictionary: "📚 Dictionaries, online search engines and more"
38+
case .emoji: "😎 Emoji"
39+
case .feed: "🗞️ Feeds"
40+
case .file: "📁 File IO"
41+
case .finance: "📈 Finance"
42+
case .food: "🍹 Food and drinks"
43+
case .forum: "📒 Forums"
44+
case .fun: "🍬 Fun"
45+
case .game: "🎲 Multiplayer games"
46+
case .imaging: "🌄 Image and GIF generation/editing"
47+
case .math: "📊 Mathematics"
48+
case .meta: "✨ Meta, i.e. commands related to D2 itself"
49+
case .misc: "🎨 Miscellaneous commands"
50+
case .moderation: "📣 Moderation"
51+
case .music: "🎸 Music, theory and chords"
52+
case .programming: "🎩 Programming"
53+
case .quote: "💬 Quotes"
54+
case .scripting: "🛠️ Command scripting"
55+
case .videogame: "🌲 Video games"
56+
case .web: "🌐 Web browsing"
5757
}
5858
}
5959
public var plainDescription: String {

Diff for: Sources/D2Commands/CommandRegistry.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ public class CommandRegistry: Sequence {
1616

1717
var asCommand: (any Command)? {
1818
switch self {
19-
case .command(let cmd): return cmd
20-
default: return nil
19+
case .command(let cmd): cmd
20+
default: nil
2121
}
2222
}
2323
}
2424

2525
private func resolve(_ name: String) -> String {
2626
switch entries[name] {
27-
case .alias(let a)?: return resolve(a)
28-
default: return name
27+
case .alias(let a)?: resolve(a)
28+
default: name
2929
}
3030
}
3131

Diff for: Sources/D2Commands/Feed/FeedImagePresenter.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public struct FeedImagePresenter: FeedPresenter {
1313
public func present(feed: Feed) throws -> Embed? {
1414
// TODO: Atom, ...
1515
switch feed {
16-
case .rss(let rss): return try present(rss: rss)
17-
default: return nil
16+
case .rss(let rss): try present(rss: rss)
17+
default: nil
1818
}
1919
}
2020

Diff for: Sources/D2Commands/Feed/FeedListPresenter.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public struct FeedListPresenter: FeedPresenter {
1717
public func present(feed: Feed) throws -> Embed? {
1818
// TODO: Atom, ...
1919
switch feed {
20-
case .rss(let rss): return try present(rss: rss)
21-
default: return nil
20+
case .rss(let rss): try present(rss: rss)
21+
default: nil
2222
}
2323
}
2424

Diff for: Sources/D2Commands/Fun/DiscordinderCommand.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ public class DiscordinderCommand: StringCommand {
155155

156156
private func verbOf(activityType: Presence.Activity.ActivityType) -> String {
157157
switch activityType {
158-
case .game: return "play"
159-
case .stream: return "stream"
160-
case .listening: return "listen to"
161-
default: return "do"
158+
case .game: "play"
159+
case .stream: "stream"
160+
case .listening: "listen to"
161+
default: "do"
162162
}
163163
}
164164

Diff for: Sources/D2Commands/Fun/DiscordinderMatch.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ struct DiscordinderMatch {
3030

3131
var accepted: MatchState {
3232
switch self {
33-
case .waitingForCreation: return .waitingForInitiator
34-
case .waitingForInitiator: return .waitingForAcceptor
35-
default: return .accepted
33+
case .waitingForCreation: .waitingForInitiator
34+
case .waitingForInitiator: .waitingForAcceptor
35+
default: .accepted
3636
}
3737
}
3838
var rejected: MatchState { .rejected }

Diff for: Sources/D2Commands/Fun/LoveCommand.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public class LoveCommand: Command {
4646

4747
private func extractMentions(input: RichValue, context: CommandContext) -> (User, User)? {
4848
guard let mentions = input.asMentions else { return nil }
49-
switch mentions.count {
50-
case 1: return context.author.map { ($0, mentions[0]) }
51-
case 2: return (mentions[0], mentions[1])
52-
default: return nil
49+
return switch mentions.count {
50+
case 1: context.author.map { ($0, mentions[0]) }
51+
case 2: (mentions[0], mentions[1])
52+
default: nil
5353
}
5454
}
5555
}

Diff for: Sources/D2Commands/Fun/RockPaperScissorsCommand.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class RockPaperScissorsCommand: StringCommand {
3030

3131
func beats(_ other: RockPaperScissors) -> Bool? {
3232
guard self != other else { return nil }
33-
switch self {
34-
case .rock: return other == .scissors
35-
case .paper: return other == .rock
36-
case .scissors: return other == .paper
33+
return switch self {
34+
case .rock: other == .scissors
35+
case .paper: other == .rock
36+
case .scissors: other == .paper
3737
}
3838
}
3939
}

Diff for: Sources/D2Commands/Game/AlphaBetaSearch.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public struct AlphaBetaSearch<State>: GameIntelligence where State: GameState &
1616
// well for games where the entire game tree can feasibly
1717
// be explored (e.g. in tic-tac-toe).
1818
switch $0.winner {
19-
case $0.currentRole?: return 1
20-
case nil: return 0
21-
default: return -1
19+
case $0.currentRole?: 1
20+
case nil: 0
21+
default: -1
2222
}
2323
}
2424
) {

Diff for: Sources/D2Commands/Game/Chess/ChessMove.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public struct ChessMove: Hashable, CustomStringConvertible {
3838
}
3939
public var algebraicNotation: String {
4040
switch castlingType {
41-
case .short?: return "O-O"
42-
case .long?: return "O-O-O"
41+
case .short?: "O-O"
42+
case .long?: "O-O-O"
4343
default: break
4444
}
4545

@@ -53,8 +53,8 @@ public struct ChessMove: Hashable, CustomStringConvertible {
5353
promotionPieceType.flatMap(createPiece).flatMap(\.notationLetters.first).map { "=\($0)" },
5454
checkType.map {
5555
switch $0 {
56-
case .check: return "+"
57-
case .checkmate: return "#"
56+
case .check: "+"
57+
case .checkmate: "#"
5858
}
5959
},
6060
isEnPassant ? "e. p." : ""

Diff for: Sources/D2Commands/Game/Chess/ChessRole.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ public enum ChessRole: String, Hashable, CaseIterable, Codable, RichValueConvert
66

77
public var asRichValue: RichValue {
88
switch self {
9-
case .white: return .text(":white_circle:")
10-
case .black: return .text(":black_circle:")
9+
case .white: .text(":white_circle:")
10+
case .black: .text(":black_circle:")
1111
}
1212
}
1313

1414
var opponent: ChessRole {
1515
switch self {
16-
case .white: return .black
17-
case .black: return .white
16+
case .white: .black
17+
case .black: .white
1818
}
1919
}
2020
}

Diff for: Sources/D2Commands/Game/Chess/ChessState.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public struct ChessState: GameState, FinitePossibleMoves {
217217

218218
public func playersOf(role: Role) -> [GamePlayer] {
219219
switch role {
220-
case .white: return [whitePlayer]
221-
case .black: return [blackPlayer]
220+
case .white: [whitePlayer]
221+
case .black: [blackPlayer]
222222
}
223223
}
224224

Diff for: Sources/D2Commands/Game/Chess/Notation/ChessParseUtils.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ fileprivate let files: [Character] = ["a", "b", "c", "d", "e", "f", "g", "h"]
22

33
func parseRaw(checkType: String) -> CheckType? {
44
switch checkType {
5-
case "+": return .check
6-
case "#": return .checkmate
7-
default: return nil
5+
case "+": .check
6+
case "#": .checkmate
7+
default: nil
88
}
99
}
1010

Diff for: Sources/D2Commands/Game/Chess/Pieces/ChessPieceUtils.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import Utils
22

33
func createPiece(_ pieceType: ChessPieceType) -> ChessPiece {
44
switch pieceType {
5-
case .pawn: return Pawn()
6-
case .knight: return Knight()
7-
case .bishop: return Bishop()
8-
case .queen: return Queen()
9-
case .king: return King()
10-
case .rook: return Rook()
5+
case .pawn: Pawn()
6+
case .knight: Knight()
7+
case .bishop: Bishop()
8+
case .queen: Queen()
9+
case .king: King()
10+
case .rook: Rook()
1111
}
1212
}
1313

Diff for: Sources/D2Commands/Game/Chess/Pieces/RookSide.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ enum RookSide: CaseIterable {
44

55
var asCastlingType: CastlingType {
66
switch self {
7-
case .kingside: return .short
8-
case .queenside: return .long
7+
case .kingside: .short
8+
case .queenside: .long
99
}
1010
}
1111
}

Diff for: Sources/D2Commands/Game/Codenames/CodenamesBoardView.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ struct CodenamesBoardView {
3232

3333
private static func colorOf(card: CodenamesBoardModel.Card) -> Color {
3434
if card.hidden {
35-
return Color(rgb: 0xe0e0e0)
35+
Color(rgb: 0xe0e0e0)
3636
} else {
3737
switch card.agent {
38-
case .team(.red): return Color(rgb: 0xad2a10)
39-
case .team(.blue): return Color(rgb: 0x101dad)
40-
case .innocent: return Color(rgb: 0xf5efc6)
41-
case .assasin: return .black
38+
case .team(.red): Color(rgb: 0xad2a10)
39+
case .team(.blue): Color(rgb: 0x101dad)
40+
case .innocent: Color(rgb: 0xf5efc6)
41+
case .assasin: .black
4242
}
4343
}
4444
}

Diff for: Sources/D2Commands/Game/Codenames/CodenamesMove.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public enum CodenamesMove: Hashable, CustomStringConvertible {
66

77
public var description: String {
88
switch self {
9-
case .codeword(let count, let word): return "\(count) \("hint word".pluralized(with: count)) for codeword '\(word)'"
10-
case .guess(let words): return "Guess \(words.map { "'\($0)'" }.joined(separator: ", "))"
9+
case .codeword(let count, let word): "\(count) \("hint word".pluralized(with: count)) for codeword '\(word)'"
10+
case .guess(let words): "Guess \(words.map { "'\($0)'" }.joined(separator: ", "))"
1111
}
1212
}
1313
}

Diff for: Sources/D2Commands/Game/Codenames/CodenamesRole.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public enum CodenamesRole: Hashable, CaseIterable, RichValueConvertible {
99

1010
public var asRichValue: RichValue {
1111
switch self {
12-
case .team(let team): return team.asRichValue
13-
case .spymaster(let team): return .compound([.text(":detective:"), team.asRichValue])
12+
case .team(let team): team.asRichValue
13+
case .spymaster(let team): .compound([.text(":detective:"), team.asRichValue])
1414
}
1515
}
1616

@@ -20,15 +20,15 @@ public enum CodenamesRole: Hashable, CaseIterable, RichValueConvertible {
2020

2121
public var team: CodenamesTeam {
2222
switch self {
23-
case .team(let team): return team
24-
case .spymaster(let team): return team
23+
case .team(let team): team
24+
case .spymaster(let team): team
2525
}
2626
}
2727

2828
var opponent: CodenamesRole {
2929
switch self {
30-
case .team(let team): return .team(team.opponent)
31-
case .spymaster(let team): return .spymaster(team.opponent)
30+
case .team(let team): .team(team.opponent)
31+
case .spymaster(let team): .spymaster(team.opponent)
3232
}
3333
}
3434
}

Diff for: Sources/D2Commands/Game/Codenames/CodenamesTeam.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ public enum CodenamesTeam: Hashable, CaseIterable, RichValueConvertible {
44

55
public var asRichValue: RichValue {
66
switch self {
7-
case .red: return .text(":red_square:")
8-
case .blue: return .text(":blue_square:")
7+
case .red: .text(":red_square:")
8+
case .blue: .text(":blue_square:")
99
}
1010
}
1111

1212
public var opponent: CodenamesTeam {
1313
switch self {
14-
case .red: return .blue
15-
case .blue: return .red
14+
case .red: .blue
15+
case .blue: .red
1616
}
1717
}
1818
}

Diff for: Sources/D2Commands/Game/TicTacToe/TicTacToeMove.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public struct TicTacToeMove: Hashable {
3737

3838
var index: Int {
3939
switch self {
40-
case .top: return 0
41-
case .center: return 1
42-
case .bottom: return 2
40+
case .top: 0
41+
case .center: 1
42+
case .bottom: 2
4343
}
4444
}
4545
}
@@ -51,9 +51,9 @@ public struct TicTacToeMove: Hashable {
5151

5252
var index: Int {
5353
switch self {
54-
case .left: return 0
55-
case .center: return 1
56-
case .right: return 2
54+
case .left: 0
55+
case .center: 1
56+
case .right: 2
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)