Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up formatting via SwiftFormat and build phase #5

Draft
wants to merge 7 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Make indentation settings explicit, to override possible system-wide settings

[*.swift]
indent_style = space
indent_size = 4
9 changes: 9 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Formatting-only commits
#
# Make `git blame` ignore the commits in this list by feeding it this file via `--ignore-revs-file`
#
# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt
#
# GitHub supports this out of the box.
# See https://github.com/orgs/community/discussions/5033
7a7c96e1cd9889ff3221c09528a6e857feea4a61
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.0
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Use the default SwiftFormat ruleset so we don't have to think about it ;)
8 changes: 4 additions & 4 deletions 01-introduction/fizz_buzz.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ func fizzBuzz(_ number: Int) -> String {
let divisibleBy3 = number % 3 == 0
let divisibleBy5 = number % 5 == 0
switch (divisibleBy3, divisibleBy5) {
case (false, false): return "\(number)"
case (true, false): return "fizz"
case (false, true): return "buzz"
case (true, true): return "fizz buzz"
case (false, false): return "\(number)"
case (true, false): return "fizz"
case (false, true): return "buzz"
case (true, true): return "fizz buzz"
}
}

Expand Down
2 changes: 1 addition & 1 deletion 01-introduction/test_fizz_buzz.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func shell(_ command: String) -> String {

/// Call the fizz-buzz script with a given input and return the script's output.
func fizzBuzz(_ number: Int) -> String {
return shell("./fizz_buzz.swift \(number)")
shell("./fizz_buzz.swift \(number)")
}

/// Check if two input `String`s are equal, printing "PASSED" if true and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import XCTest
@testable import Albertos
import XCTest

class AlbertosTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
Expand All @@ -18,9 +17,8 @@ class AlbertosTests: XCTestCase {

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
measure {
// Put the code you want to measure the time of here.
}
}

}
1 change: 0 additions & 1 deletion 04-tdd-in-the-real-world/1-end/Albertos/AlbertosApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import SwiftUI

@main
struct AlbertosApp: App {

var body: some Scene {
WindowGroup {
NavigationView {
Expand Down
2 changes: 0 additions & 2 deletions 04-tdd-in-the-real-world/1-end/Albertos/MenuItem.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
struct MenuItem {

let category: String
let name: String
}

extension MenuItem: Identifiable {

var id: String { name }
}
2 changes: 0 additions & 2 deletions 04-tdd-in-the-real-world/1-end/Albertos/MenuSection.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
struct MenuSection {

let category: String
let items: [MenuItem]
}

extension MenuSection: Identifiable {

var id: String { category }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import XCTest

class MenuGroupingTests: XCTestCase {

func testMenuWithManyCategoriesReturnsAsManySectionsInReverseAlphabeticalOrder() {
let menu = [
MenuItem(category: "pastas", name: "a pasta"),
Expand All @@ -22,7 +21,7 @@ class MenuGroupingTests: XCTestCase {
func testMenuWithOneCategoryReturnsOneSection() throws {
let menu = [
MenuItem(category: "pastas", name: "name"),
MenuItem(category: "pastas", name: "other name")
MenuItem(category: "pastas", name: "other name"),
]

let sections = groupMenuByCategory(menu)
Expand Down
6 changes: 6 additions & 0 deletions 04-tdd-in-the-real-world/1-end/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ targets:
UIRequiredDeviceCapabilities: [armv7]
scheme:
testTargets: [AlbertosTests]
settings:
ENABLE_USER_SCRIPT_SANDBOXING: NO
preBuildScripts:
- name: Format
script: swift run -c release --package-path ../../BuildTools swiftformat "$SRCROOT"
basedOnDependencyAnalysis: false
AlbertosTests:
target: Albertos
type: bundle.unit-test
Expand Down
2 changes: 0 additions & 2 deletions 05-fixtures/1-end/Albertos/MenuItem.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
struct MenuItem {

let category: String
let name: String
let spicy: Bool
}

extension MenuItem: Identifiable {

var id: String { name }
}
3 changes: 1 addition & 2 deletions 05-fixtures/1-end/AlbertosTests/MenuGroupingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import XCTest

class MenuGroupingTests: XCTestCase {

func testMenuWithManyCategoriesReturnsAsManySectionsInReverseAlphabeticalOrder() {
let menu: [MenuItem] = [
.fixture(category: "pastas"),
Expand All @@ -22,7 +21,7 @@ class MenuGroupingTests: XCTestCase {
func testMenuWithOneCategoryReturnsOneSection() throws {
let menu: [MenuItem] = [
.fixture(category: "pastas", name: "name"),
.fixture(category: "pastas", name: "other name")
.fixture(category: "pastas", name: "other name"),
]

let sections = groupMenuByCategory(menu)
Expand Down
15 changes: 7 additions & 8 deletions 05-fixtures/1-end/AlbertosTests/MenuItem+Fixture.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@testable import Albertos

extension MenuItem {

static func fixture(
category: String = "category",
name: String = "name",
spicy: Bool = false
) -> MenuItem {
MenuItem(category: category, name: name, spicy: spicy)
}
static func fixture(
category: String = "category",
name: String = "name",
spicy: Bool = false
) -> MenuItem {
MenuItem(category: category, name: name, spicy: spicy)
}
}
3 changes: 1 addition & 2 deletions 05-fixtures/1-end/AlbertosTests/MenuSection+Fixture.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@testable import Albertos

extension MenuSection {

static func fixture(
category: String = "a category",
items: [MenuItem] = [.fixture()]
) -> MenuSection {
return MenuSection(category: category, items: items)
MenuSection(category: category, items: items)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
struct MenuItem {

let category: String
let name: String
let spicy: Bool
let price: Double
}

extension MenuItem: Identifiable {

var id: String { name }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
@testable import Albertos

extension MenuItem {

static func fixture(
category: String = "category",
name: String = "name",
spicy: Bool = false,
price: Double = 1.0
) -> MenuItem {
MenuItem(category: category, name: name, spicy: spicy, price: price)
}
static func fixture(
category: String = "category",
name: String = "name",
spicy: Bool = false,
price: Double = 1.0
) -> MenuItem {
MenuItem(category: category, name: name, spicy: spicy, price: price)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import SwiftUI

@main
struct AlbertosApp: App {

var body: some Scene {
WindowGroup {
NavigationView {
Expand Down
2 changes: 0 additions & 2 deletions 06-testing-static-swiftui-views/1-end/Albertos/MenuItem.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
struct MenuItem {

let category: String
let name: String
let spicy: Bool
let price: Double
}

extension MenuItem: Identifiable {

var id: String { name }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
extension MenuList {

struct ViewModel {

let sections: [MenuSection]

init(
menu: [MenuItem],
menuGrouping: @escaping ([MenuItem]) -> [MenuSection] = groupMenuByCategory
) {
self.sections = menuGrouping(menu)
sections = menuGrouping(menu)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SwiftUI

struct MenuList: View {

let viewModel: ViewModel

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
extension MenuRow {

struct ViewModel {

let text: String

init(item: MenuItem) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SwiftUI

struct MenuRow: View {

let viewModel: ViewModel

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
struct MenuSection {

let category: String
let items: [MenuItem]
}

extension MenuSection: Identifiable {

var id: String { category }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import XCTest

class MenuGroupingTests: XCTestCase {

func testMenuWithManyCategoriesReturnsAsManySectionsInReverseAlphabeticalOrder() {
let menu: [MenuItem] = [
.fixture(category: "pastas"),
Expand All @@ -22,7 +21,7 @@ class MenuGroupingTests: XCTestCase {
func testMenuWithOneCategoryReturnsOneSection() throws {
let menu: [MenuItem] = [
.fixture(category: "pastas", name: "name"),
.fixture(category: "pastas", name: "other name")
.fixture(category: "pastas", name: "other name"),
]

let sections = groupMenuByCategory(menu)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
@testable import Albertos

extension MenuItem {

static func fixture(
category: String = "category",
name: String = "name",
spicy: Bool = false,
price: Double = 1.0
) -> MenuItem {
MenuItem(category: category, name: name, spicy: spicy, price: price)
}
static func fixture(
category: String = "category",
name: String = "name",
spicy: Bool = false,
price: Double = 1.0
) -> MenuItem {
MenuItem(category: category, name: name, spicy: spicy, price: price)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import XCTest

class MenuListViewModelTests: XCTestCase {

func testCallsGivenGroupingFunction() {
var called = false
let inputSections = [MenuSection.fixture()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import XCTest

class MenuRowViewModelTests: XCTestCase {

func testWhenItemIsNotSpicyTextIsItemNameOnly() {
let item = MenuItem.fixture(name: "name", spicy: false)
let viewModel = MenuRow.ViewModel(item: item)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@testable import Albertos

extension MenuSection {

static func fixture(
category: String = "a category",
items: [MenuItem] = [.fixture()]
) -> MenuSection {
return MenuSection(category: category, items: items)
MenuSection(category: category, items: items)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import SwiftUI

@main
struct AlbertosApp: App {

var body: some Scene {
WindowGroup {
NavigationView {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Combine

protocol MenuFetching {

func fetchMenu() -> AnyPublisher<[MenuItem], Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation

class MenuFetchingPlaceholder: MenuFetching {
func fetchMenu() -> AnyPublisher<[MenuItem], Error> {
return Future { $0(.success(menu)) }
Future { $0(.success(menu)) }
// Use a delay to simulate async fetch
.delay(for: 0.5, scheduler: RunLoop.main)
.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Combine

extension MenuList {

class ViewModel: ObservableObject {

@Published private(set) var sections: [MenuSection] = []

private var cancellables = Set<AnyCancellable>()
Expand Down
Loading
Loading