From 4f96a8f80ee0622e9052ad5d12de2324f52fbb67 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Tue, 19 Jul 2016 14:37:39 -0400 Subject: [PATCH] Fix Swift 3 guard warnings --- .swiftlint.yml | 1 + Sources/Game.swift | 21 ++++++++++++--------- Sources/Square.swift | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index cb5bf10..df0058c 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -12,6 +12,7 @@ disabled_rules: # rule identifiers to exclude from running - type_body_length - function_body_length - comma + - conditional_binding_cascade opt_in_rules: # some rules are only opt-in - empty_count diff --git a/Sources/Game.swift b/Sources/Game.swift index 8dfcfc4..64462e2 100644 --- a/Sources/Game.swift +++ b/Sources/Game.swift @@ -171,14 +171,17 @@ public final class Game { #else let parts = fen.characters.split(" ").map(String.init) #endif - guard parts.count == 6, - let board = Board(fen: parts[0]) - where parts[1].characters.count == 1, + guard + parts.count == 6, + let board = Board(fen: parts[0]), + parts[1].characters.count == 1, let playerTurn = parts[1].characters.first.flatMap(Color.init), - rights = CastlingRights(string: parts[2]), - halfmoves = UInt(parts[4]), - fullmoves = UInt(parts[5]) where fullmoves > 0 - else { return nil } + let rights = CastlingRights(string: parts[2]), + let halfmoves = UInt(parts[4]), + let fullmoves = UInt(parts[5]), + fullmoves > 0 else { + return nil + } var target: Square? = nil let targetStr = parts[3] let targetChars = targetStr.characters @@ -335,7 +338,7 @@ public final class Game { /// The target move location for an en passant. public var enPassantTarget: Square? { - guard let (move, piece, _, _, _, _) = _moveHistory.last where piece.kind.isPawn else { + guard let (move, piece, _, _, _, _) = _moveHistory.last, piece.kind.isPawn else { return nil } guard abs(move.rankChange) == 2 else { @@ -427,7 +430,7 @@ public final class Game { if considerHalfmoves && halfmoves >= 100 { return 0 } - guard let piece = board[square] where piece.color == playerTurn else { + guard let piece = board[square], piece.color == playerTurn else { return 0 } if kingIsDoubleChecked { diff --git a/Sources/Square.swift b/Sources/Square.swift index 2ff3d7d..d207ab9 100644 --- a/Sources/Square.swift +++ b/Sources/Square.swift @@ -474,7 +474,7 @@ extension Square { /// Create a square from `file` and `rank`. Returns `nil` if either is `nil`. public init?(file: File?, rank: Rank?) { - guard let file = file, rank = rank else { + guard let file = file, let rank = rank else { return nil } self.init(file: file, rank: rank)