Skip to content

Commit 6592a70

Browse files
authored
Merge pull request #37 from yml-org/style/add-swift-lint
[CM-1193] Add swift lint support
2 parents 9dd37ed + 50d88be commit 6592a70

File tree

23 files changed

+210
-207
lines changed

23 files changed

+210
-207
lines changed

ios-sample/.swiftlint.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# By default, SwiftLint uses a set of sensible default rules you can adjust:
2+
disabled_rules: # rule identifiers turned on by default to exclude from running
3+
4+
- multiple_closures_with_trailing_closure
5+
6+
opt_in_rules: # some rules are turned off by default, so you need to opt-in
7+
- contains_over_first_not_nil
8+
- empty_count
9+
- first_where
10+
- force_unwrapping
11+
- implicit_return
12+
- missing_docs
13+
- multiline_arguments
14+
- multiline_arguments_brackets
15+
- multiline_function_chains
16+
- multiline_literal_brackets
17+
- multiline_parameters
18+
- multiline_parameters_brackets
19+
- operator_whitespace
20+
- prohibited_interface_builder
21+
- unneeded_parentheses_in_closure_argument
22+
- vertical_whitespace_closing_braces
23+
- vertical_whitespace_opening_braces
24+
25+
excluded: # paths to ignore during linting. Takes precedence over `included`.
26+
- Pods
27+
- docs
28+
- .build
29+
30+
# configurable rules can be customized from this configuration file
31+
# binary rules can set their severity level
32+
33+
cyclomatic_complexity:
34+
ignores_case_statements: true
35+
36+
identifier_name:
37+
min_length: 1
38+
39+
trailing_whitespace:
40+
ignores_empty_lines: true
41+
42+
function_parameter_count:
43+
warning: 6

ios-sample/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# YChat GPT iOS Sample
1+
# YChat iOS Sample
22

33
## Setup
44

ios-sample/ios-sample.xcodeproj/project.pbxproj

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
1010
058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
1111
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
12-
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
12+
2152FB042600AC8F00CF470E /* SampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* SampleApp.swift */; };
1313
488448D9297B8419005B8A24 /* CompletionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 488448D8297B8419005B8A24 /* CompletionViewModel.swift */; };
1414
488448DD297B8DD2005B8A24 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 488448DC297B8DD2005B8A24 /* Color.swift */; };
1515
488448DF297B8DF6005B8A24 /* Typography.swift in Sources */ = {isa = PBXBuildFile; fileRef = 488448DE297B8DF6005B8A24 /* Typography.swift */; };
@@ -47,7 +47,7 @@
4747
/* Begin PBXFileReference section */
4848
058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4949
058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
50-
2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
50+
2152FB032600AC8F00CF470E /* SampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleApp.swift; sourceTree = "<group>"; };
5151
488448D8297B8419005B8A24 /* CompletionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompletionViewModel.swift; sourceTree = "<group>"; };
5252
488448DC297B8DD2005B8A24 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
5353
488448DE297B8DF6005B8A24 /* Typography.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Typography.swift; sourceTree = "<group>"; };
@@ -68,6 +68,7 @@
6868
489A546A297F916C00A6532C /* EnvConfig.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = EnvConfig.xcconfig; sourceTree = "<group>"; };
6969
489A546C297F93F700A6532C /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
7070
489A5471297F99FC00A6532C /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
71+
48D4A78629ACF39F00968B0B /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
7172
7555FF7B242A565900829871 /* ios-sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ios-sample.app"; sourceTree = BUILT_PRODUCTS_DIR; };
7273
7555FF82242A565900829871 /* CompletionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompletionView.swift; sourceTree = "<group>"; };
7374
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -97,7 +98,7 @@
9798
children = (
9899
488448FA297CDFF2005B8A24 /* Presenter */,
99100
488448FD297CE019005B8A24 /* Router */,
100-
2152FB032600AC8F00CF470E /* iOSApp.swift */,
101+
2152FB032600AC8F00CF470E /* SampleApp.swift */,
101102
);
102103
path = App;
103104
sourceTree = "<group>";
@@ -268,6 +269,7 @@
268269
7555FFB0242A642200829871 /* Frameworks */,
269270
489A546A297F916C00A6532C /* EnvConfig.xcconfig */,
270271
489A5471297F99FC00A6532C /* README.md */,
272+
48D4A78629ACF39F00968B0B /* .swiftlint.yml */,
271273
);
272274
sourceTree = "<group>";
273275
};
@@ -312,6 +314,7 @@
312314
7555FF78242A565900829871 /* Frameworks */,
313315
7555FF79242A565900829871 /* Resources */,
314316
7555FFB4242A642300829871 /* Embed Frameworks */,
317+
48D4A78029A9835700968B0B /* SwiftLint */,
315318
);
316319
buildRules = (
317320
);
@@ -368,6 +371,25 @@
368371
/* End PBXResourcesBuildPhase section */
369372

370373
/* Begin PBXShellScriptBuildPhase section */
374+
48D4A78029A9835700968B0B /* SwiftLint */ = {
375+
isa = PBXShellScriptBuildPhase;
376+
alwaysOutOfDate = 1;
377+
buildActionMask = 2147483647;
378+
files = (
379+
);
380+
inputFileListPaths = (
381+
);
382+
inputPaths = (
383+
);
384+
name = SwiftLint;
385+
outputFileListPaths = (
386+
);
387+
outputPaths = (
388+
);
389+
runOnlyForDeploymentPostprocessing = 0;
390+
shellPath = /bin/sh;
391+
shellScript = "# Adds support for Apple Silicon brew directory\nexport PATH=\"$PATH:/opt/homebrew/bin\"\n\nif which swiftlint >/dev/null; then\n swiftlint lint --strict\nelse\n echo \"warning: SwiftLint not installed run `brew install swiftlint`\"\nfi\n";
392+
};
371393
7555FFB5242A651A00829871 /* ShellScript */ = {
372394
isa = PBXShellScriptBuildPhase;
373395
buildActionMask = 2147483647;
@@ -405,7 +427,7 @@
405427
488448F1297CD209005B8A24 /* ImageButton.swift in Sources */,
406428
488448FF297CE035005B8A24 /* AppRouter.swift in Sources */,
407429
488448F6297CDF67005B8A24 /* SideMenu.swift in Sources */,
408-
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
430+
2152FB042600AC8F00CF470E /* SampleApp.swift in Sources */,
409431
488448E8297B9198005B8A24 /* ViewModifer.swift in Sources */,
410432
7555FF83242A565900829871 /* CompletionView.swift in Sources */,
411433
488448E6297B9116005B8A24 /* RoundedCorner.swift in Sources */,

ios-sample/ios-sample/App/Presenter/Main/MainView.swift

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@
99
import SwiftUI
1010

1111
internal struct MainView: View {
12-
1312
@ObservedObject
1413
private var mainRouter: MainRouter = MainRouter.shared
15-
14+
1615
@State private var showSidebar: Bool = false
17-
16+
1817
private var topBarTitle: String {
1918
switch mainRouter.navGraph.destination {
2019
case .completion: return "Completion"
2120
}
2221
}
23-
22+
2423
var body: some View {
2524
NavigationStack {
26-
ZStack() {
25+
ZStack {
2726
VStack(alignment: .leading) {
28-
TopBar()
27+
topBar()
2928
Group {
3029
switch mainRouter.navGraph.destination {
3130
case .completion: CompletionView()
@@ -36,17 +35,17 @@ internal struct MainView: View {
3635
}
3736
.fullScreen()
3837
SideMenu(isVisible: $showSidebar) {
39-
SideMenuContent()
38+
sideMenuContent()
4039
}
4140
}
4241
}
4342
}
44-
43+
4544
@ViewBuilder
46-
private func TopBar() -> some View {
45+
private func topBar() -> some View {
4746
HStack(spacing: 0) {
4847
ImageButton(
49-
.menu,
48+
Icon.menu.uiImage,
5049
color: .accentColor,
5150
action: { showSidebar.toggle() }
5251
)
@@ -59,21 +58,21 @@ internal struct MainView: View {
5958
.frame(maxWidth: .infinity)
6059
.compositingGroup()
6160
}
62-
61+
6362
@ViewBuilder
64-
private func SideMenuContent() -> some View {
63+
private func sideMenuContent() -> some View {
6564
VStack(alignment: .leading, spacing: 0) {
6665
HStack(spacing: 8) {
67-
Image(uiImage: .logo)
66+
Image(uiImage: Icon.logo.uiImage)
6867
Text("YChat GPT")
6968
.style(.bodyBold)
7069
}
7170
.padding(.horizontal, 16)
7271
.padding(.vertical, 16)
7372
Divider()
7473
.padding(.bottom, 16)
75-
MenuItem(
76-
icon: .chat,
74+
menuItem(
75+
icon: Icon.chat.uiImage,
7776
text: "Completion",
7877
destination: .completion
7978
)
@@ -84,22 +83,20 @@ internal struct MainView: View {
8483
alignment: .topLeading
8584
)
8685
}
87-
86+
8887
@ViewBuilder
89-
private func MenuItem(
88+
private func menuItem(
9089
icon: UIImage,
9190
text: String,
9291
destination: MainRouter.Destination
9392
) -> some View {
9493
let isSelected: Bool = mainRouter.navGraph.destination == destination
9594
let bgColor = isSelected ? Color.primaryExtraLight : .background
9695
let foregroundColor = isSelected ? Color.accentColor : .grayDark
97-
Button(
98-
action: {
99-
mainRouter.replace(destination)
100-
showSidebar.toggle()
101-
}
102-
) {
96+
Button {
97+
mainRouter.replace(destination)
98+
showSidebar.toggle()
99+
} label: {
103100
HStack(spacing: 8) {
104101
Image(uiImage: icon)
105102
.renderingMode(.template)

ios-sample/ios-sample/App/Presenter/Splash/SplashView.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
import SwiftUI
1010

1111
internal struct SplashView: View {
12-
1312
private let appRouter: AppRouter
14-
13+
1514
init(appRouter: AppRouter = AppRouter.shared) {
1615
self.appRouter = appRouter
1716
}
18-
17+
1918
var body: some View {
2019
VStack {
2120
HStack(spacing: 8) {
22-
Image(uiImage: .logoBig)
21+
Image(uiImage: Icon.logoBig.uiImage)
2322
Text("YChat GPT")
2423
.font(.system(size: 24))
2524
.foregroundColor(.grayDark)
@@ -40,4 +39,3 @@ internal struct SplashView_Previews: PreviewProvider {
4039
SplashView()
4140
}
4241
}
43-

ios-sample/ios-sample/App/Router/AppRouter.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
import Foundation
1010

1111
internal final class AppRouter: ObservableObject {
12-
1312
static var shared = AppRouter()
14-
13+
1514
private init() {}
16-
15+
1716
enum Destination: Equatable {
1817
case splash
1918
case main
2019
}
21-
20+
2221
@Published var navGraph: NavGraph<Destination> = .init(destination: .splash)
23-
22+
2423
func push(_ destination: Destination) {
2524
navGraph.push(destination: destination)
2625
}

ios-sample/ios-sample/App/Router/MainRouter.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
import Foundation
1010

1111
internal final class MainRouter: ObservableObject {
12-
1312
static var shared = MainRouter()
14-
13+
1514
private init() {}
16-
15+
1716
enum Destination: Equatable {
1817
case completion
1918
}
20-
19+
2120
@Published var navGraph: NavGraph<Destination> = .init(destination: .completion)
22-
21+
2322
func replace(_ destination: Destination) {
2423
navGraph.replace(destination, animation: .opacity)
2524
}

ios-sample/ios-sample/App/iOSApp.swift renamed to ios-sample/ios-sample/App/SampleApp.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import SwiftUI
22

33
@main
4-
struct iOSApp: App {
5-
4+
struct SampleApp: App {
65
@ObservedObject
76
private var appRouter: AppRouter = AppRouter.shared
8-
7+
98
var body: some Scene {
109
WindowGroup {
1110
Group {

ios-sample/ios-sample/Core/Env/Config.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import Foundation
1010

1111
enum Config {
12-
1312
static var apiKey: String {
1413
string(for: "API_KEY")
1514
}
16-
15+
1716
private static func string(for key: String) -> String {
18-
Bundle.main.infoDictionary?[key] as! String
17+
guard let value = ((Bundle.main.infoDictionary?[key] as? String)) else {
18+
fatalError("Value not found for the given key: " + key)
19+
}
20+
return value
1921
}
2022
}

ios-sample/ios-sample/Core/Navigation/NavGraph.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ struct NavGraph<T> {
1212
var navStack: [T] = []
1313
var destination: T
1414
var animation: AnyTransition
15-
15+
1616
init(destination: T) {
1717
self.animation = .nextSlide
1818
self.navStack.append(destination)
1919
self.destination = destination
2020
}
21-
21+
2222
mutating func replace(_ destination: T, animation: AnyTransition = .nextSlide) {
2323
self.animation = animation
24-
let _ = navStack.popLast()
24+
_ = navStack.popLast()
2525
self.navStack.append(destination)
2626
self.destination = destination
2727
}
28-
28+
2929
mutating func push(destination: T) {
3030
self.animation = .nextSlide
3131
self.navStack.append(destination)
3232
self.destination = destination
3333
}
34-
34+
3535
mutating func pop() {
3636
self.animation = .backSlide
37-
let _ = navStack.popLast()
37+
_ = navStack.popLast()
3838
guard let lastDestination = navStack.last else { return }
3939
self.destination = lastDestination
4040
}

0 commit comments

Comments
 (0)