Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: configure ktlint/swiftformat and format code #2592

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/five-rivers-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
ktlint_code_style = android_studio
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--swiftversion 5.7
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion packages/react-native-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ReactNativeAuthMSALModule(context: ReactApplicationContext?) :
accountType: RnxAccountType,
onTokenAcquired: OnTokenAcquired
) {
onTokenAcquired(null, RnxAuthError.notImplemented())
onTokenAcquired(null, RnxAuthError.notImplemented())
}

override fun acquireTokenWithScopes(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-test-app-msal/ios/AuthError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native-test-app-msal/ios/TokenBroker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-test-app-msal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/new-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->";
Expand Down