From 642f233580009a9288e90f5a9a1e75049a85b085 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:31:41 +0200 Subject: [PATCH] chore: configure ktlint/swiftformat and format code (#2592) --- .changeset/five-rivers-melt.md | 2 ++ .editorconfig | 2 ++ .swiftformat | 1 + .../reactnativesdk/auth/AuthErrorType.kt | 2 +- .../auth/ReactNativeAuthPackage.kt | 4 +++- packages/react-native-auth/package.json | 2 +- packages/react-native-host/package.json | 2 +- .../microsoft/reacttestapp/msal/AccountType.kt | 5 +++-- .../com/microsoft/reacttestapp/msal/Config.kt | 3 ++- .../msal/MicrosoftAccountsActivity.kt | 3 ++- .../microsoft/reacttestapp/msal/MsalPackage.kt | 18 ++++++++++-------- .../msal/ReactNativeAuthMSALModule.kt | 5 +++-- .../ios/AuthError.swift | 2 +- .../ios/SecretStore.swift | 2 +- .../ios/TokenBroker.swift | 8 ++++---- .../react-native-test-app-msal/package.json | 4 ++-- scripts/new-package.mjs | 2 +- 17 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 .changeset/five-rivers-melt.md create mode 100644 .editorconfig create mode 100644 .swiftformat diff --git a/.changeset/five-rivers-melt.md b/.changeset/five-rivers-melt.md new file mode 100644 index 000000000..a845151cc --- /dev/null +++ b/.changeset/five-rivers-melt.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..436d6f0ac --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.{kt,kts}] +ktlint_code_style = android_studio diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 000000000..ab3e86528 --- /dev/null +++ b/.swiftformat @@ -0,0 +1 @@ +--swiftversion 5.7 diff --git a/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/AuthErrorType.kt b/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/AuthErrorType.kt index aa0ba4a69..8f499f0f3 100644 --- a/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/AuthErrorType.kt +++ b/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/AuthErrorType.kt @@ -17,5 +17,5 @@ enum class AuthErrorType(val type: String) { SERVER_PROTECTION_POLICIES_REQUIRED("ServerProtectionPoliciesRequired"), TIMEOUT("Timeout"), USER_CANCELED("UserCanceled"), - WORKPLACE_JOIN_REQUIRED("WorkplaceJoinRequired"); + WORKPLACE_JOIN_REQUIRED("WorkplaceJoinRequired") } diff --git a/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/ReactNativeAuthPackage.kt b/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/ReactNativeAuthPackage.kt index e59ce877c..151a5c73f 100644 --- a/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/ReactNativeAuthPackage.kt +++ b/packages/react-native-auth/android/src/main/java/com/microsoft/reactnativesdk/auth/ReactNativeAuthPackage.kt @@ -13,7 +13,9 @@ class ReactNativeAuthPackage : ReactPackage { return emptyList() } - override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> { + override fun createViewManagers( + reactContext: ReactApplicationContext + ): List<ViewManager<*, *>> { return emptyList() } } diff --git a/packages/react-native-auth/package.json b/packages/react-native-auth/package.json index 74ee53e4a..893f2f2cc 100644 --- a/packages/react-native-auth/package.json +++ b/packages/react-native-auth/package.json @@ -26,7 +26,7 @@ "format": "rnx-kit-scripts format", "format:c": "clang-format -i $(git ls-files '*.c' '*.cpp' '*.h' '*.m' '*.mm')", "lint": "rnx-kit-scripts lint", - "lint:kt": "ktlint --relative --verbose 'android/src/**/*.kt'", + "lint:kt": "ktlint --relative 'android/src/**/*.kt'", "update-readme": "rnx-kit-scripts update-api-readme" }, "peerDependencies": { diff --git a/packages/react-native-host/package.json b/packages/react-native-host/package.json index 53e3bac66..5aa2d0523 100644 --- a/packages/react-native-host/package.json +++ b/packages/react-native-host/package.json @@ -21,7 +21,7 @@ "scripts": { "format": "rnx-kit-scripts format", "format:c": "clang-format -i $(git ls-files '*.c' '*.cpp' '*.h' '*.m' '*.mm')", - "lint:kt": "ktlint --relative --verbose 'android/src/**/*.kt'" + "lint:kt": "ktlint --relative 'android/src/**/*.kt'" }, "peerDependencies": { "react-native": ">=0.64" diff --git a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/AccountType.kt b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/AccountType.kt index 489910cf2..4c70442cf 100644 --- a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/AccountType.kt +++ b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/AccountType.kt @@ -12,10 +12,11 @@ enum class AccountType(val type: String) { private const val MSA_TENANT = "9188040d-6c67-4c5b-b112-36a304b66dad" fun fromIssuer(issuer: String): AccountType { - return if (issuer.contains(MSA_TENANT)) + return if (issuer.contains(MSA_TENANT)) { MICROSOFT_ACCOUNT - else + } else { ORGANIZATIONAL + } } } diff --git a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/Config.kt b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/Config.kt index 2a653970e..8e0c2c822 100644 --- a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/Config.kt +++ b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/Config.kt @@ -11,7 +11,8 @@ class Config { fun authorityFor(accountType: AccountType): String = when (accountType) { AccountType.INVALID -> throw InvalidParameterException() - AccountType.MICROSOFT_ACCOUNT -> "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize" + AccountType.MICROSOFT_ACCOUNT -> + "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize" AccountType.ORGANIZATIONAL -> "https://login.microsoftonline.com/common/" } diff --git a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MicrosoftAccountsActivity.kt b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MicrosoftAccountsActivity.kt index dca3108c9..2a6ee1c1b 100644 --- a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MicrosoftAccountsActivity.kt +++ b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MicrosoftAccountsActivity.kt @@ -122,7 +122,8 @@ class MicrosoftAccountsActivity : AppCompatActivity() { val userPrincipalName = sharedPreferences.getString(USERNAME_KEY, null) val accountType = sharedPreferences.getString(ACCOUNT_TYPE_KEY, null) val selectedAccount = allAccounts.find { - it.userPrincipalName == userPrincipalName && it.accountType.toString() == accountType + it.userPrincipalName == userPrincipalName && + it.accountType.toString() == accountType } tokenBroker.selectedAccount = selectedAccount viewModel.selectedAccount.postValue(selectedAccount) diff --git a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MsalPackage.kt b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MsalPackage.kt index e0b600f0a..958d364bd 100644 --- a/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MsalPackage.kt +++ b/packages/react-native-test-app-msal/android/src/main/java/com/microsoft/reacttestapp/msal/MsalPackage.kt @@ -12,17 +12,19 @@ class MsalPackage : TurboReactPackage() { return when (name) { info.name() -> ReactNativeAuthModuleProvider.create(reactContext) - ?: throw IllegalStateException("ReactNativeAuthModuleProvider.create() wasn't supposed to return null") + ?: throw IllegalStateException( + "ReactNativeAuthModuleProvider.create() wasn't supposed to return null" + ) else -> throw IllegalArgumentException("No module named '$name'") } } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = - ReactModuleInfoProvider { - val info = ReactNativeAuthModuleProvider.info() - if (info == null) - mapOf() - else - mapOf(info.name() to info).toMutableMap() + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { + val info = ReactNativeAuthModuleProvider.info() + if (info == null) { + mapOf() + } else { + mapOf(info.name() to info).toMutableMap() } + } } diff --git a/packages/react-native-test-app-msal/android/src/rnx/java/com/microsoft/reacttestapp/msal/ReactNativeAuthMSALModule.kt b/packages/react-native-test-app-msal/android/src/rnx/java/com/microsoft/reacttestapp/msal/ReactNativeAuthMSALModule.kt index fe9102e09..35c888ada 100644 --- a/packages/react-native-test-app-msal/android/src/rnx/java/com/microsoft/reacttestapp/msal/ReactNativeAuthMSALModule.kt +++ b/packages/react-native-test-app-msal/android/src/rnx/java/com/microsoft/reacttestapp/msal/ReactNativeAuthMSALModule.kt @@ -20,7 +20,7 @@ class ReactNativeAuthMSALModule(context: ReactApplicationContext?) : accountType: RnxAccountType, onTokenAcquired: OnTokenAcquired ) { - onTokenAcquired(null, RnxAuthError.notImplemented()) + onTokenAcquired(null, RnxAuthError.notImplemented()) } override fun acquireTokenWithScopes( @@ -64,7 +64,8 @@ fun AuthErrorType.toRnxAuthErrorType(): RnxAuthErrorType = when (this) { AuthErrorType.NO_RESPONSE -> RnxAuthErrorType.NO_RESPONSE AuthErrorType.PRECONDITION_VIOLATED -> RnxAuthErrorType.PRECONDITION_VIOLATED AuthErrorType.SERVER_DECLINED_SCOPES -> RnxAuthErrorType.SERVER_DECLINED_SCOPES - AuthErrorType.SERVER_PROTECTION_POLICIES_REQUIRED -> RnxAuthErrorType.SERVER_PROTECTION_POLICIES_REQUIRED + AuthErrorType.SERVER_PROTECTION_POLICIES_REQUIRED -> + RnxAuthErrorType.SERVER_PROTECTION_POLICIES_REQUIRED AuthErrorType.TIMEOUT -> RnxAuthErrorType.TIMEOUT AuthErrorType.USER_CANCELED -> RnxAuthErrorType.USER_CANCELED AuthErrorType.WORKPLACE_JOIN_REQUIRED -> RnxAuthErrorType.WORKPLACE_JOIN_REQUIRED diff --git a/packages/react-native-test-app-msal/ios/AuthError.swift b/packages/react-native-test-app-msal/ios/AuthError.swift index d123b7282..c71c9ce7e 100644 --- a/packages/react-native-test-app-msal/ios/AuthError.swift +++ b/packages/react-native-test-app-msal/ios/AuthError.swift @@ -16,7 +16,7 @@ public final class AuthError: NSObject { extension AuthError { convenience init(error: NSError?) { - if let error = error { + if let error { let correlationID = error.userInfo[MSALCorrelationIDKey] as? String let message = error.userInfo[MSALErrorDescriptionKey] as? String self.init( diff --git a/packages/react-native-test-app-msal/ios/SecretStore.swift b/packages/react-native-test-app-msal/ios/SecretStore.swift index 127e173a6..fea1104b9 100644 --- a/packages/react-native-test-app-msal/ios/SecretStore.swift +++ b/packages/react-native-test-app-msal/ios/SecretStore.swift @@ -39,7 +39,7 @@ extension CFDictionary { let service = "com.microsoft.ReactTestApp-MSAL" let account = "account" - guard let secret = secret else { + guard let secret else { return [ kSecAttrService: service, kSecAttrAccount: account, diff --git a/packages/react-native-test-app-msal/ios/TokenBroker.swift b/packages/react-native-test-app-msal/ios/TokenBroker.swift index 7e5d91421..98108e72b 100644 --- a/packages/react-native-test-app-msal/ios/TokenBroker.swift +++ b/packages/react-native-test-app-msal/ios/TokenBroker.swift @@ -47,7 +47,7 @@ public final class TokenBroker: NSObject { sender: RTAViewController, onTokenAcquired: @escaping TokenAcquiredHandler ) { - guard let selectedAccount = selectedAccount else { + guard let selectedAccount else { let error = AuthError( type: .preconditionViolated, correlationID: Constants.EmptyGUID, @@ -186,7 +186,7 @@ public final class TokenBroker: NSObject { application.acquireToken(with: parameters) { result, error in self.condition.signal() - guard let result = result else { + guard let result else { onTokenAcquired(nil, AuthError(error: error as NSError?)) return } @@ -207,7 +207,7 @@ public final class TokenBroker: NSObject { return } - guard let userPrincipalName = userPrincipalName, + guard let userPrincipalName, let cachedAccount = try? application.account(forUsername: userPrincipalName) else { acquireTokenInteractive( @@ -225,7 +225,7 @@ public final class TokenBroker: NSObject { DispatchQueue.main.async { application.acquireTokenSilent(with: parameters) { result, error in - guard let result = result else { + guard let result else { if let error = error as NSError? { if error.isInteractionRequiredError() { self.acquireTokenInteractive( diff --git a/packages/react-native-test-app-msal/package.json b/packages/react-native-test-app-msal/package.json index a58a00dc7..11b891bed 100644 --- a/packages/react-native-test-app-msal/package.json +++ b/packages/react-native-test-app-msal/package.json @@ -15,8 +15,8 @@ }, "scripts": { "format:c": "clang-format -i $(git ls-files '*.h' '*.m')", - "format:swift": "swiftformat --swiftversion 5.5 ios", - "lint:kt": "ktlint --relative --verbose 'android/src/**/*.kt'", + "format:swift": "swiftformat ios", + "lint:kt": "ktlint --relative 'android/src/**/*.kt'", "lint:swift": "swiftlint" }, "peerDependencies": { diff --git a/scripts/new-package.mjs b/scripts/new-package.mjs index 265c80a74..57ad1e9f4 100644 --- a/scripts/new-package.mjs +++ b/scripts/new-package.mjs @@ -7,7 +7,7 @@ import { fileURLToPath } from "node:url"; import yargs from "yargs"; const EXPERIMENTAL_BANNER = - "š§š§š§š§š§š§š§š§š§š§š§\n### THIS TOOL IS EXPERIMENTAL ā USE WITH CAUTION\nš§š§š§š§š§š§š§š§š§š§š§"; + "š§š§š§š§š§š§š§š§š§š§š§\n\n### THIS TOOL IS EXPERIMENTAL ā USE WITH CAUTION\n\nš§š§š§š§š§š§š§š§š§š§š§"; const USAGE_TOKEN_START = "<!-- usage start -->"; const USAGE_TOKEN_END = "<!-- usage end -->"; const WARNING_BANNER_TOKEN = "<!-- experimental-warning -->";