Skip to content

Commit

Permalink
feat: [FC-0072] setup linting on ci/cd (#549)
Browse files Browse the repository at this point in the history
* fix: resolve lint warnings

* fix: resolve warnings and update swiftlint.yml

* fix: update swiftlint

* fix: update swiftlint

* fix: test lint warning

* Revert "fix: test lint warning"

This reverts commit e3c1566.

* fix: update tests

* fix: update swiftlint

* fix: address feedback

* fix: address feedback
  • Loading branch information
IvanStepanok authored Dec 12, 2024
1 parent 17f9376 commit c104371
Show file tree
Hide file tree
Showing 87 changed files with 1,008 additions and 700 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: SwiftLint

on:
workflow_dispatch:

pull_request:

jobs:
Expand All @@ -11,8 +10,6 @@ jobs:
runs-on: macos-latest

concurrency:
# When running on develop, use the sha to allow all runs of this workflow to run concurrently.
# Otherwise only allow a single run of this workflow on each branch, automatically cancelling older runs.
group: ${{ github.ref == 'refs/heads/develop' && format('swiftlint-develop-{0}', github.sha) || format('swiftlint-{0}', github.ref) }}
cancel-in-progress: true

Expand All @@ -29,9 +26,22 @@ jobs:
${{ runner.os }}-gems-
- name: Setup environment
run:
run: |
source ci_scripts/ci_prepare_env.sh && setup_github_actions_environment
xcodes select 16.1
- name: SwiftLint
run:
bundle exec fastlane linting
run: |
export PODS_ROOT=$(pwd)/Pods
"${PODS_ROOT}/SwiftLint/swiftlint" --reporter sarif > swiftlint.report.sarif
- name: Prepare swiftlint.report.sarif
if: success() || failure()
run: |
swift PrepareSarifToUpload.swift
- name: Upload report
uses: github/codeql-action/upload-sarif@v3
if: success() || failure()
with:
sarif_file: swiftlint.report.sarif
16 changes: 6 additions & 10 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
warning_threshold: 1
disabled_rules: # rule identifiers to exclude from running
- identifier_name
- comment_spacing
Expand Down Expand Up @@ -31,6 +32,7 @@ excluded: # paths to ignore during linting. Takes precedence over `included`.
- Core/Core/SwiftGen
- Authorization/Authorization/SwiftGen
- Course/Course/SwiftGen
- Discussion/Discussion/SwiftGen
- Discovery/Discovery/SwiftGen
- Dashboard/Dashboard/SwiftGen
- Profile/Profile/SwiftGen
Expand All @@ -48,14 +50,15 @@ excluded: # paths to ignore during linting. Takes precedence over `included`.
force_try: error

line_length: 120
type_body_length: 300
type_body_length: 600
function_body_length: 100

trailing_whitespace:
ignores_empty_lines: true

file_length:
warning: 500
error: 1200
warning: 850
error: 1500

function_parameter_count:
warning: 10
Expand All @@ -70,11 +73,4 @@ type_name:
- iPhone
- API

identifier_name:
min_length: # only min_length
error: 1 # only error
# excluded: # excluded via string array
# - id
# - URL
# - GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
49 changes: 28 additions & 21 deletions Authorization/Authorization/Presentation/Login/SignInView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public struct SignInView: View {
HStack {
if !viewModel.config.features.startupScreenEnabled {
Button(CoreLocalization.SignIn.registerBtn) {
viewModel.router.showRegisterScreen(sourceScreen: viewModel.sourceScreen)
viewModel.router.showRegisterScreen(
sourceScreen: viewModel.sourceScreen
)
}
.foregroundColor(Theme.Colors.accentColor)
.accessibilityIdentifier("register_button")
Expand Down Expand Up @@ -159,7 +161,7 @@ public struct SignInView: View {
}
}
if viewModel.config.uiComponents.samlSSOLoginEnabled {
if !viewModel.config.uiComponents.loginRegistrationEnabled{
if !viewModel.config.uiComponents.loginRegistrationEnabled {
VStack(alignment: .center) {
Text(AuthLocalization.SignIn.ssoHeading)
.font(Theme.Fonts.headlineSmall)
Expand All @@ -169,7 +171,7 @@ public struct SignInView: View {
.padding(.horizontal, 20)
.accessibilityIdentifier("signin_sso_heading")
}

Divider()

VStack(alignment: .center) {
Expand All @@ -190,9 +192,8 @@ public struct SignInView: View {
.accessibilityIdentifier("signin_sso_login_subtitle")
}
}

VStack(alignment: .center) {

if viewModel.isShowProgress {
HStack(alignment: .center) {
ProgressBar(size: 40, lineWidth: 8)
Expand All @@ -202,24 +203,30 @@ public struct SignInView: View {
} else {
let languageCode = Locale.current.language.languageCode?.identifier ?? "en"
if viewModel.config.uiComponents.samlSSODefaultLoginButton {
StyledButton(viewModel.config.ssoButtonTitle[languageCode] as! String, action: {
viewModel.router.showSSOWebBrowser(title: CoreLocalization.SignIn.logInBtn)
})
StyledButton(
viewModel.config.ssoButtonTitle[languageCode] as! String,
action: {
viewModel.router
.showSSOWebBrowser(title: CoreLocalization.SignIn.logInBtn)
}
)
.frame(maxWidth: .infinity)
.padding(.top, 20)
.accessibilityIdentifier("signin_SSO_button")
} else {
StyledButton(viewModel.config.ssoButtonTitle[languageCode] as! String, action: {
viewModel.router.showSSOWebBrowser(title: CoreLocalization.SignIn.logInBtn)
},
color: .white,
textColor: Theme.Colors.accentColor,
borderColor: Theme.Colors.accentColor)
StyledButton(
viewModel.config.ssoButtonTitle[languageCode] as! String,
action: {
viewModel.router
.showSSOWebBrowser(title: CoreLocalization.SignIn.logInBtn)
},
color: .white,
textColor: Theme.Colors.accentColor,
borderColor: Theme.Colors.accentColor)
.frame(maxWidth: .infinity)
.padding(.top, 20)
.accessibilityIdentifier("signin_SSO_button")
}

}
}
}
Expand Down Expand Up @@ -258,7 +265,7 @@ public struct SignInView: View {
.transition(.move(edge: .top))
.onAppear {
doAfter(Theme.Timeout.snackbarMessageLongTimeout) {
viewModel.alertMessage = nil
viewModel.alertMessage = nil
}
}
}
Expand All @@ -271,7 +278,7 @@ public struct SignInView: View {
}.transition(.move(edge: .bottom))
.onAppear {
doAfter(Theme.Timeout.snackbarMessageLongTimeout) {
viewModel.errorMessage = nil
viewModel.errorMessage = nil
}
}
}
Expand All @@ -283,12 +290,12 @@ public struct SignInView: View {
viewModel.trackScreenEvent()
}
}

@ViewBuilder
private var agreements: some View {
if let eulaURL = viewModel.config.agreement.eulaURL,
let tosURL = viewModel.config.agreement.tosURL,
let policy = viewModel.config.agreement.privacyPolicyURL {
let tosURL = viewModel.config.agreement.tosURL,
let policy = viewModel.config.agreement.privacyPolicyURL {
let text = AuthLocalization.SignIn.agreement(
"\(viewModel.config.platformName)",
eulaURL,
Expand All @@ -306,7 +313,7 @@ public struct SignInView: View {
.environment(\.openURL, OpenURLAction(handler: handleURL))
}
}

private func handleURL(_ url: URL) -> OpenURLAction.Result {
viewModel.router.showWebBrowser(title: "", url: url)
return .handled
Expand Down
11 changes: 9 additions & 2 deletions Authorization/Authorization/Presentation/SSO/SSOWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public struct SSOWebView: UIViewRepresentable {
}

// WKScriptMessageHandler
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
public func userContentController(
_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage
) {
}

// WKNavigationDelegate
Expand All @@ -71,7 +74,11 @@ public struct SSOWebView: UIViewRepresentable {
}
}

public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
public func webView(
_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
) {
guard let url = webView.url?.absoluteString else {
decisionHandler(.allow)
return
Expand Down
Loading

0 comments on commit c104371

Please sign in to comment.