Skip to content

Commit

Permalink
Add Swiftlint step to CI (#14)
Browse files Browse the repository at this point in the history
* Update swift.yml

* Update tests.yml

* removed odd github actions config

* swiftlint autocorrect
  • Loading branch information
KazaiMazai authored Jun 16, 2024
1 parent 0da5835 commit 23bcb2d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ on:
branches: [ "main" ]

jobs:
lint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: cirruslabs/swiftlint-action@v1
with:
version: latest

build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- name: Build for iOS
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ let package = Package(
products: [
.library(
name: "SegmentedPicker",
targets: ["SegmentedPicker"]),
targets: ["SegmentedPicker"])
],
dependencies: [
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
from: "1.12.0"
)

],
targets: [
.target(
Expand All @@ -30,6 +30,6 @@ let package = Package(
dependencies: [
"SegmentedPicker",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
]),
])
]
)
2 changes: 1 addition & 1 deletion Sources/SegmentedPicker/HorizontalAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension HorizontalAlignment {
return dimension[HorizontalAlignment.center]
}
}

static var horizontalCenterAlignment: HorizontalAlignment {
HorizontalAlignment(CenterAlignmentID.self)
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/SegmentedPicker/SegmentedPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public struct SegmentedPicker<Element, Content, Selection>: View
where
Content: View,
Selection: View {

public typealias Data = [Element]

@State private var segmentSizes: [Data.Index: CGSize] = [:]
@Binding private var selectedIndex: Data.Index?

Expand All @@ -34,7 +34,7 @@ public struct SegmentedPicker<Element, Content, Selection>: View
self._selectedIndex = selectedIndex
self.selectionAlignment = selectionAlignment
}

public var body: some View {
ZStack(alignment: Alignment(horizontal: .horizontalCenterAlignment,
vertical: selectionAlignment)) {
Expand Down Expand Up @@ -74,7 +74,7 @@ public struct SegmentedPicker<Element, Content, Selection>: View
}

private extension SegmentedPicker {

func selectionSize(at index: Data.Index) -> CGSize {
segmentSizes[index] ?? .zero
}
Expand All @@ -85,13 +85,13 @@ private extension SegmentedPicker {
let index: Int
let size: CGSize
}

struct SegmentSizePreferenceKey: PreferenceKey {
static var defaultValue: SegmentSize { SegmentSize(index: .zero, size: .zero) }
static func reduce(value: inout SegmentSize,

static func reduce(value: inout SegmentSize,
nextValue: () -> SegmentSize) {

value = nextValue()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/SegmentedPickerTests/CapsuleSelectionViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import UIKit
import XCTest
import SnapshotTesting
@testable import SegmentedPicker

final class CapsuleSelectionViewTests: XCTestCase {
func test_WhenSelectionIsNotProvided_SelectionIsNotVisible_Snapshot() {
let view = CapsuleSelectionView(titles: ["One", "Two", "Three"])
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
}

func test_WhenSelectionIsProvided_SelectionIsVisible_Snapshot() {
let view = CapsuleSelectionView(titles: ["One", "Two", "Three"], selectedIndex: 1)
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct CapsuleSelectionView: View {
.fill(Color.gray)
})
}

Spacer()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct UnderlineSelectionView: View {
let titles: [String]
@State var selectedIndex: Int?

var body: some View {
VStack {
SegmentedPicker(
Expand All @@ -22,7 +22,7 @@ struct UnderlineSelectionView: View {
selectionAlignment: .bottom,
content: { item, isSelected in
Text(item)

.foregroundColor(isSelected ? Color.black : Color.gray )
.padding(.horizontal, 16)
.padding(.vertical, 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class UnderlineSelectionViewTest: XCTestCase {
let view = UnderlineSelectionView(titles: ["One", "Two", "Three"])
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
}

func test_WhenSelectionIsProvided_SelectionIsVisible_Snapshot() {
let view = UnderlineSelectionView(titles: ["One", "Two", "Three"], selectedIndex: 1)
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
Expand Down

0 comments on commit 23bcb2d

Please sign in to comment.