Skip to content

Commit a5b0e9f

Browse files
authored
chore(all): Update KtLint to 1.5.0 (#3026)
1 parent 9dcbc9a commit a5b0e9f

File tree

301 files changed

+2749
-3410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

301 files changed

+2749
-3410
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@
22
#this is to match java checkstyle
33
max_line_length=120
44
ktlint_code_style=android_studio
5+
6+
# Disabled rules
7+
ktlint_standard_class-signature = disabled # don't force parameters onto one line in constructors
8+
ktlint_standard_value-parameter-comment = disabled # Allow same-line comments in parameters
9+
10+
# Disable ktlint on generated source code, see
11+
# https://github.com/JLLeitschuh/ktlint-gradle/issues/746
12+
[**/build/generated/**]
13+
ktlint = disabled

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

annotations/src/main/java/com/amplifyframework/annotations/InternalAmplifyApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ package com.amplifyframework.annotations
2424
@Suppress("DEPRECATION")
2525
@RequiresOptIn(
2626
level = RequiresOptIn.Level.ERROR,
27-
message = "This API is internal to Amplify and should not be used. It could be removed or changed without notice.",
27+
message = "This API is internal to Amplify and should not be used. It could be removed or changed without notice."
2828
)
2929
@Target(
3030
AnnotationTarget.CLASS,
3131
AnnotationTarget.TYPEALIAS,
3232
AnnotationTarget.FUNCTION,
3333
AnnotationTarget.PROPERTY,
3434
AnnotationTarget.FIELD,
35-
AnnotationTarget.CONSTRUCTOR,
35+
AnnotationTarget.CONSTRUCTOR
3636
)
3737
public annotation class InternalAmplifyApi

annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ package com.amplifyframework.annotations
2424
@Suppress("DEPRECATION")
2525
@RequiresOptIn(
2626
level = RequiresOptIn.Level.WARNING,
27-
message = "This API is internal to Amplify and should not be used. It could be removed or changed without notice.",
27+
message = "This API is internal to Amplify and should not be used. It could be removed or changed without notice."
2828
)
2929
@Target(
3030
AnnotationTarget.CLASS,
3131
AnnotationTarget.TYPEALIAS,
3232
AnnotationTarget.FUNCTION,
3333
AnnotationTarget.PROPERTY,
3434
AnnotationTarget.FIELD,
35-
AnnotationTarget.CONSTRUCTOR,
35+
AnnotationTarget.CONSTRUCTOR
3636
)
3737
public annotation class InternalApiWarning

aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsCanaryTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class PinpointAnalyticsCanaryTest {
6464
@JvmStatic
6565
fun setupBefore() {
6666
val context = ApplicationProvider.getApplicationContext<Context>()
67+
6768
@RawRes val resourceId = Resources.getRawResourceId(context, CONFIGURATION_NAME)
6869
appId = readAppIdFromResource(context, resourceId)
6970
preferences = context.getSharedPreferences(
@@ -117,6 +118,7 @@ class PinpointAnalyticsCanaryTest {
117118
@Before
118119
fun flushEvents() {
119120
val context = ApplicationProvider.getApplicationContext<Context>()
121+
120122
@RawRes val resourceId = Resources.getRawResourceId(context, CREDENTIALS_RESOURCE_NAME)
121123
val userAndPasswordPair = readCredentialsFromResource(context, resourceId)
122124
synchronousAuth.signOut()

aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PinpointAnalyticsInstrumentationTest {
5353
@Before
5454
fun flushEvents() {
5555
val context = ApplicationProvider.getApplicationContext<Context>()
56+
5657
@RawRes val resourceId = Resources.getRawResourceId(context, CREDENTIALS_RESOURCE_NAME)
5758
val userAndPasswordPair = readCredentialsFromResource(context, resourceId)
5859
synchronousAuth.signOut()
@@ -286,18 +287,18 @@ class PinpointAnalyticsInstrumentationTest {
286287
Amplify.Analytics.identifyUser(uuid, pinpointUserProfile)
287288
Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT)
288289
var endpointResponse = fetchEndpointResponse()
289-
var retry_count = 0
290-
while (retry_count < MAX_RETRIES && endpointResponse.attributes.isNullOrEmpty()) {
290+
var retryCount = 0
291+
while (retryCount < MAX_RETRIES && endpointResponse.attributes.isNullOrEmpty()) {
291292
Sleep.milliseconds(DEFAULT_TIMEOUT)
292293
endpointResponse = fetchEndpointResponse()
293-
retry_count++
294+
retryCount++
294295
}
295296
assertCommonEndpointResponseProperties(endpointResponse)
296297
Assert.assertEquals(
297298
"User attribute value",
298299
endpointResponse.user!!
299300
.userAttributes!!
300-
["SomeUserAttribute"]!!
301+
["SomeUserAttribute"]!!
301302
[0]
302303
)
303304
}
@@ -371,7 +372,7 @@ class PinpointAnalyticsInstrumentationTest {
371372
}
372373

373374
companion object {
374-
private const val EVENT_FLUSH_TIMEOUT_WAIT = 15 /* seconds */
375+
private const val EVENT_FLUSH_TIMEOUT_WAIT = 15 // seconds
375376
private const val CREDENTIALS_RESOURCE_NAME = "credentials"
376377
private const val CONFIGURATION_NAME = "amplifyconfiguration"
377378
private const val COGNITO_CONFIGURATION_TIMEOUT = 10 * 1000L
@@ -385,10 +386,12 @@ class PinpointAnalyticsInstrumentationTest {
385386
private lateinit var appId: String
386387
private lateinit var uniqueId: String
387388
private lateinit var pinpointClient: PinpointClient
389+
388390
@BeforeClass
389391
@JvmStatic
390392
fun setupBefore() {
391393
val context = ApplicationProvider.getApplicationContext<Context>()
394+
392395
@RawRes val resourceId = Resources.getRawResourceId(context, CONFIGURATION_NAME)
393396
appId = readAppIdFromResource(context, resourceId)
394397
preferences = context.getSharedPreferences(

aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsStressTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class PinpointAnalyticsStressTest {
6767
@JvmStatic
6868
fun setupBefore() {
6969
val context = ApplicationProvider.getApplicationContext<Context>()
70+
7071
@RawRes val resourceId = Resources.getRawResourceId(context, CONFIGURATION_NAME)
7172
appId = readAppIdFromResource(context, resourceId)
7273
preferences = context.getSharedPreferences(
@@ -120,6 +121,7 @@ class PinpointAnalyticsStressTest {
120121
@Before
121122
fun flushEvents() {
122123
val context = ApplicationProvider.getApplicationContext<Context>()
124+
123125
@RawRes val resourceId = Resources.getRawResourceId(context, CREDENTIALS_RESOURCE_NAME)
124126
val userAndPasswordPair = readCredentialsFromResource(context, resourceId)
125127
synchronousAuth.signOut()

aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/AWSPinpointAnalyticsPlugin.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ class AWSPinpointAnalyticsPlugin @JvmOverloads constructor(
6969
awsPinpointAnalyticsPluginBehavior.flushEvents()
7070
}
7171

72-
override fun getPluginKey(): String {
73-
return pluginKey
74-
}
72+
override fun getPluginKey(): String = pluginKey
7573

7674
override fun configure(pluginConfiguration: JSONObject?, context: Context) {
7775
requireNotNull(pluginConfiguration)
@@ -127,13 +125,9 @@ class AWSPinpointAnalyticsPlugin @JvmOverloads constructor(
127125
)
128126
}
129127

130-
override fun getEscapeHatch(): PinpointClient {
131-
return pinpointManager.pinpointClient
132-
}
128+
override fun getEscapeHatch(): PinpointClient = pinpointManager.pinpointClient
133129

134-
override fun getVersion(): String {
135-
return BuildConfig.VERSION_NAME
136-
}
130+
override fun getVersion(): String = BuildConfig.VERSION_NAME
137131

138132
/**
139133
* Options that can be specified to fine-tune the behavior of the Pinpoint Analytics Plugin.

aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/AWSPinpointAnalyticsPluginBehavior.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import com.amplifyframework.pinpoint.core.TargetingClient
2828

2929
internal class AWSPinpointAnalyticsPluginBehavior(
3030
private val analyticsClient: AnalyticsClient,
31-
private val targetingClient: TargetingClient,
31+
private val targetingClient: TargetingClient
3232
) : AnalyticsCategoryBehavior {
3333

3434
override fun identifyUser(userId: String, profile: UserProfile?) = targetingClient.identifyUser(userId, profile)

aws-analytics-pinpoint/src/main/java/com/amplifyframework/analytics/pinpoint/AnalyticsChannelEventName.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,5 @@ enum class AnalyticsChannelEventName(val eventName: String) {
2626
*/
2727
FLUSH_EVENTS("flushEvents");
2828

29-
override fun toString(): String {
30-
return eventName
31-
}
29+
override fun toString(): String = eventName
3230
}

aws-analytics-pinpoint/src/test/java/com/amplifyframework/analytics/pinpoint/AWSPinpointAnalyticsPluginBehaviorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AWSPinpointAnalyticsPluginBehaviorTest {
5757

5858
awsPinpointAnalyticsPluginBehavior = AWSPinpointAnalyticsPluginBehavior(
5959
analyticsClientMock,
60-
targetingClientMock,
60+
targetingClientMock
6161
)
6262
}
6363

aws-api-appsync/src/main/java/com/amplifyframework/api/aws/SelectionSetExtensions.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ private fun getSelectionSet(node: PropertyContainerPath): SelectionSet {
8585
return selectionSet
8686
}
8787

88-
private fun shouldProcessNode(node: PropertyContainerPath, includeRoot: Boolean): Boolean {
89-
return includeRoot || node.getMetadata().parent != null
90-
}
88+
private fun shouldProcessNode(node: PropertyContainerPath, includeRoot: Boolean): Boolean =
89+
includeRoot || node.getMetadata().parent != null
9190

9291
private fun nodesInPath(node: PropertyContainerPath, includeRoot: Boolean): List<PropertyContainerPath> {
9392
var currentNode: PropertyContainerPath? = node

aws-api/src/androidTest/java/com/amplifyframework/api/aws/GraphQLLazyQueryInstrumentationTest.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class GraphQLLazyQueryInstrumentationTest {
5757
const val PARENT2_ID = "GraphQLLazyQueryInstrumentationTest-Parent2"
5858
const val HAS_ONE_CHILD1_ID = "GraphQLLazyQueryInstrumentationTest-HasOneChild1"
5959
const val HAS_ONE_CHILD2_ID = "GraphQLLazyQueryInstrumentationTest-HasOneChild2"
60+
6061
@JvmStatic
6162
@BeforeClass
6263
fun setUp() {
@@ -177,7 +178,8 @@ class GraphQLLazyQueryInstrumentationTest {
177178
fun query_parent_with_includes() = runTest {
178179
// GIVEN
179180
val request = ModelQuery.get<Parent, ParentPath>(
180-
Parent::class.java, Parent.ParentIdentifier(PARENT1_ID)
181+
Parent::class.java,
182+
Parent.ParentIdentifier(PARENT1_ID)
181183
) {
182184
includes(it.child, it.children)
183185
}
@@ -199,7 +201,6 @@ class GraphQLLazyQueryInstrumentationTest {
199201

200202
@Test
201203
fun query_list_with_no_includes() = runTest(timeout = LONG_TIMEOUT) {
202-
203204
val request = ModelQuery.list(
204205
Parent::class.java,
205206
Parent.ID.beginsWith("GraphQLLazyQueryInstrumentationTest-Parent")
@@ -258,7 +259,6 @@ class GraphQLLazyQueryInstrumentationTest {
258259

259260
@Test
260261
fun query_list_with_includes() = runTest {
261-
262262
val request = ModelQuery.list<Parent, ParentPath>(
263263
Parent::class.java,
264264
Parent.ID.beginsWith("GraphQLLazyQueryInstrumentationTest-Parent")
@@ -302,7 +302,8 @@ class GraphQLLazyQueryInstrumentationTest {
302302
fun query_parent_with_no_child_with_includes() = runTest {
303303
// GIVEN
304304
val request = ModelQuery.get<Parent, ParentPath>(
305-
Parent::class.java, Parent.ParentIdentifier("GraphQLLazyQueryInstrumentationTest.ParentWithNoChildren")
305+
Parent::class.java,
306+
Parent.ParentIdentifier("GraphQLLazyQueryInstrumentationTest.ParentWithNoChildren")
306307
) {
307308
includes(it.child, it.children)
308309
}
@@ -362,7 +363,8 @@ class GraphQLLazyQueryInstrumentationTest {
362363
fun query_child_belongsTo_parent_with_includes() = runTest {
363364
// GIVEN
364365
val request = ModelQuery.get<HasManyChild, HasManyChildPath>(
365-
HasManyChild::class.java, HasManyChildIdentifier("GraphQLLazyQueryInstrumentationTest-HasManyChild1")
366+
HasManyChild::class.java,
367+
HasManyChildIdentifier("GraphQLLazyQueryInstrumentationTest-HasManyChild1")
366368
) {
367369
includes(it.parent)
368370
}

aws-api/src/main/java/com/amplifyframework/api/aws/AWSApiSchemaRegistry.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ internal class AWSApiSchemaRegistry {
2929
modelProvider.modelSchemas()
3030
}
3131

32-
fun getModelSchemaForModelClass(classSimpleName: String): ModelSchema {
33-
return modelSchemaMap[classSimpleName] ?: throw ApiException(
32+
fun getModelSchemaForModelClass(classSimpleName: String): ModelSchema =
33+
modelSchemaMap[classSimpleName] ?: throw ApiException(
3434
"Model type of `$classSimpleName` not found.",
3535
"Please regenerate codegen models and verify the class is found in AmplifyModelProvider."
3636
)
37-
}
3837

39-
fun <T : Model> getModelSchemaForModelClass(modelClass: Class<T>): ModelSchema {
40-
return getModelSchemaForModelClass(modelClass.simpleName)
41-
}
38+
fun <T : Model> getModelSchemaForModelClass(modelClass: Class<T>): ModelSchema =
39+
getModelSchemaForModelClass(modelClass.simpleName)
4240
}

aws-api/src/main/java/com/amplifyframework/api/aws/AWSGraphQLOperation.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,23 @@ abstract class AWSGraphQLOperation<R>(
3636
) : GraphQLOperation<R>(graphQLRequest, responseFactory) {
3737

3838
@Throws(ApiException::class)
39-
override fun wrapResponse(jsonResponse: String): GraphQLResponse<R> {
40-
return buildResponse(jsonResponse)
41-
}
39+
override fun wrapResponse(jsonResponse: String): GraphQLResponse<R> = buildResponse(jsonResponse)
4240

4341
// This method should be used in place of GraphQLOperation.wrapResponse. In order to pass
4442
// apiName, we had to stop using the default GraphQLResponse.Factory buildResponse method
4543
// as there was no place to inject api name for adding to LazyModel
4644
@Throws(ApiException::class)
47-
private fun buildResponse(jsonResponse: String): GraphQLResponse<R> {
48-
return try {
49-
(responseFactory as? GsonGraphQLResponseFactory)?.buildResponse(request, jsonResponse, apiName)
50-
?: throw ApiException(
51-
"Amplify encountered an error while deserializing an object. " +
52-
"GraphQLResponse.Factory was not of type GsonGraphQLResponseFactory",
53-
AmplifyException.REPORT_BUG_TO_AWS_SUGGESTION
54-
)
55-
} catch (cce: ClassCastException) {
56-
throw ApiException(
57-
"Amplify encountered an error while deserializing an object",
58-
AmplifyException.TODO_RECOVERY_SUGGESTION
45+
private fun buildResponse(jsonResponse: String): GraphQLResponse<R> = try {
46+
(responseFactory as? GsonGraphQLResponseFactory)?.buildResponse(request, jsonResponse, apiName)
47+
?: throw ApiException(
48+
"Amplify encountered an error while deserializing an object. " +
49+
"GraphQLResponse.Factory was not of type GsonGraphQLResponseFactory",
50+
AmplifyException.REPORT_BUG_TO_AWS_SUGGESTION
5951
)
60-
}
52+
} catch (cce: ClassCastException) {
53+
throw ApiException(
54+
"Amplify encountered an error while deserializing an object",
55+
AmplifyException.TODO_RECOVERY_SUGGESTION
56+
)
6157
}
6258
}

aws-api/src/main/java/com/amplifyframework/api/aws/ApiLazyModelReference.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ internal class ApiLazyModelReference<M : Model> internal constructor(
5151
}
5252
}
5353

54-
override fun getIdentifier(): Map<String, Any> {
55-
return keyMap
56-
}
54+
override fun getIdentifier(): Map<String, Any> = keyMap
5755

5856
override suspend fun fetchModel(): M? {
5957
val cached = cachedValue.get()
@@ -85,7 +83,6 @@ internal class ApiLazyModelReference<M : Model> internal constructor(
8583
private suspend fun fetchInternal(): M? {
8684
// Use mutex to only allow 1 execution at a time
8785
mutex.withLock {
88-
8986
// Quick return if value is already present
9087
val cached = cachedValue.get()
9188
if (cached != null) {

aws-api/src/main/java/com/amplifyframework/api/aws/ApiModelListTypes.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ import kotlinx.coroutines.CoroutineScope
3232
import kotlinx.coroutines.Dispatchers
3333
import kotlinx.coroutines.launch
3434

35-
internal class ApiLoadedModelList<out M : Model>(
36-
override val items: List<M>
37-
) : LoadedModelList<M>
35+
internal class ApiLoadedModelList<out M : Model>(override val items: List<M>) : LoadedModelList<M>
3836

39-
internal class ApiModelPage<out M : Model>(
40-
override val items: List<M>,
41-
override val nextToken: ApiPaginationToken?
42-
) : ModelPage<M>
37+
internal class ApiModelPage<out M : Model>(override val items: List<M>, override val nextToken: ApiPaginationToken?) :
38+
ModelPage<M>
4339

4440
internal class ApiPaginationToken(val nextToken: String) : PaginationToken
4541

@@ -90,13 +86,12 @@ internal class ApiLazyModelList<out M : Model> constructor(
9086
}
9187
}
9288

93-
private fun createRequest(paginationToken: PaginationToken? = null): GraphQLRequest<ModelPage<M>> {
94-
return AppSyncGraphQLRequestFactory.buildModelPageQuery(
89+
private fun createRequest(paginationToken: PaginationToken? = null): GraphQLRequest<ModelPage<M>> =
90+
AppSyncGraphQLRequestFactory.buildModelPageQuery(
9591
clazz,
9692
queryPredicate,
9793
(paginationToken as? ApiPaginationToken)?.nextToken
9894
)
99-
}
10095

10196
private fun createLazyException(exception: AmplifyException) =
10297
AmplifyException("Error lazy loading the model list.", exception, exception.message ?: "")

0 commit comments

Comments
 (0)