chore: configure ktlint/swiftformat and format code (#2592)

This commit is contained in:
Tommy Nguyen 2023-08-09 14:31:41 +02:00 коммит произвёл GitHub
Родитель 513efaabcc
Коммит 642f233580
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
17 изменённых файлов: 40 добавлений и 27 удалений

Просмотреть файл

@ -0,0 +1,2 @@
---
---

2
.editorconfig Normal file
Просмотреть файл

@ -0,0 +1,2 @@
[*.{kt,kts}]
ktlint_code_style = android_studio

1
.swiftformat Normal file
Просмотреть файл

@ -0,0 +1 @@
--swiftversion 5.7

Просмотреть файл

@ -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")
}

Просмотреть файл

@ -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()
}
}

Просмотреть файл

@ -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": {

Просмотреть файл

@ -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"

Просмотреть файл

@ -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
}
}
}

Просмотреть файл

@ -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/"
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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()
}
}
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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(

Просмотреть файл

@ -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,

Просмотреть файл

@ -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(

Просмотреть файл

@ -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": {

Просмотреть файл

@ -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 -->";